Commit b305d27b by Francois Gygi

Redesign of constraints.


git-svn-id: http://qboxcode.org/svn/qb/trunk@422 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 3dcc6e96
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// AngleConstraint.C // AngleConstraint.C
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: AngleConstraint.C,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: AngleConstraint.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#include "AngleConstraint.h" #include "AngleConstraint.h"
#include "AtomSet.h" #include "AtomSet.h"
...@@ -249,15 +249,15 @@ vector<vector<double> > &v0) const ...@@ -249,15 +249,15 @@ vector<vector<double> > &v0) const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
double AngleConstraint::projection(const vector<vector<double> > &r0, void AngleConstraint::compute_force(const vector<vector<double> > &r0,
const vector<vector<double> > &x) const const vector<vector<double> > &f)
{ {
const double* pr1 = &r0[is1_][3*ia1_]; const double* pr1 = &r0[is1_][3*ia1_];
const double* pr2 = &r0[is2_][3*ia2_]; const double* pr2 = &r0[is2_][3*ia2_];
const double* pr3 = &r0[is3_][3*ia3_]; const double* pr3 = &r0[is3_][3*ia3_];
const double* px1 = &x[is1_][3*ia1_]; const double* pf1 = &f[is1_][3*ia1_];
const double* px2 = &x[is2_][3*ia2_]; const double* pf2 = &f[is2_][3*ia2_];
const double* px3 = &x[is3_][3*ia3_]; const double* pf3 = &f[is3_][3*ia3_];
D3vector r1(pr1); D3vector r1(pr1);
D3vector r2(pr2); D3vector r2(pr2);
...@@ -266,16 +266,40 @@ double AngleConstraint::projection(const vector<vector<double> > &r0, ...@@ -266,16 +266,40 @@ double AngleConstraint::projection(const vector<vector<double> > &r0,
grad_sigma(r1,r2,r3,g1,g2,g3); grad_sigma(r1,r2,r3,g1,g2,g3);
D3vector x1(px1); D3vector f1(pf1);
D3vector x2(px2); D3vector f2(pf2);
D3vector x3(px3); D3vector f3(pf3);
const double norm2 = g1*g1 + g2*g2 + g3*g3; const double norm2 = g1*g1 + g2*g2 + g3*g3;
if ( norm2 == 0.0 ) if ( norm2 == 0.0 )
return 0.0; {
force_ = 0.0;
return;
}
const double proj = x1*g1 + x2*g2 + x3*g3; const double proj = f1*g1 + f2*g2 + f3*g3;
return proj/sqrt(norm2); force_ = -proj/norm2;
// compute weight
const double z = m1_inv_ * g1 * g1 +
m2_inv_ * g2 * g2 +
m3_inv_ * g3 * g3;
assert(z > 0.0);
weight_ = 1.0 / sqrt(z);
#if DEBUG_CONSTRAINTS
// check value of z
const double r12s = norm(r1-r2);
const double r32s = norm(r3-r2);
const double fac = 180.0/M_PI;
const double cos_theta = normalized(r1-r2)*normalized(r3-r2);
const double zcheck = fac*fac *
( m1_inv_ / r12s +
m2_inv_ * ( (r12s+r32s-2*sqrt(r12s*r32s)*cos_theta) /(r12s*r32s) ) +
m3_inv_ / r32s
);
cout << " <!-- AngleConstraint: z=" << z << " zcheck=" << zcheck << " -->"
<< endl;
#endif
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -371,14 +395,15 @@ double AngleConstraint::bond_angle(D3vector a, D3vector b, D3vector c) const ...@@ -371,14 +395,15 @@ double AngleConstraint::bond_angle(D3vector a, D3vector b, D3vector c) const
ostream& AngleConstraint::print( ostream &os ) ostream& AngleConstraint::print( ostream &os )
{ {
os.setf(ios::left,ios::adjustfield); os.setf(ios::left,ios::adjustfield);
os << " <!-- constraint "; os << " <constraint name=\"" << name();
os << type() << " "; os << "\" type=\"" << type();
os << setw(4) << name1_ << " "; os << "\" atoms=\"" << name1_ << " ";
os << setw(4) << name2_ << " "; os << name2_ << " " << name3_ << "\"\n";
os << setw(4) << name3_ << " ";
os.setf(ios::fixed,ios::floatfield); os.setf(ios::fixed,ios::floatfield);
os.setf(ios::right,ios::adjustfield); os.setf(ios::right,ios::adjustfield);
os << setw(10) << setprecision(6) << angle_ << " " os << " value=\"" << setprecision(6) << angle_;
<< setw(10) << setprecision(6) << velocity_ << " -->"; os << "\" velocity=\"" << setprecision(6) << velocity_ << "\"\n";
os << " force=\"" << setprecision(6) << force_;
os << "\" weight=\"" << setprecision(6) << weight_ << "\"/>";
return os; return os;
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// AngleConstraint.h // AngleConstraint.h
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: AngleConstraint.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: AngleConstraint.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef ANGLECONSTRAINT_H #ifndef ANGLECONSTRAINT_H
#define ANGLECONSTRAINT_H #define ANGLECONSTRAINT_H
...@@ -18,7 +18,7 @@ class AngleConstraint : public Constraint ...@@ -18,7 +18,7 @@ class AngleConstraint : public Constraint
string name1_, name2_, name3_; string name1_, name2_, name3_;
int ia1_, ia2_, ia3_, is1_, is2_, is3_; int ia1_, ia2_, ia3_, is1_, is2_, is3_;
double m1_, m2_, m3_, m1_inv_, m2_inv_, m3_inv_; double m1_, m2_, m3_, m1_inv_, m2_inv_, m3_inv_;
double angle_, velocity_, tol_; double angle_, velocity_, force_, weight_, tol_;
double sigma(D3vector a, D3vector b, D3vector c) const; double sigma(D3vector a, D3vector b, D3vector c) const;
void grad_sigma(const D3vector &r1, const D3vector &r2, const D3vector &r3, void grad_sigma(const D3vector &r1, const D3vector &r2, const D3vector &r3,
D3vector &g1, D3vector &g2,D3vector &g3) const; D3vector &g1, D3vector &g2,D3vector &g3) const;
...@@ -26,22 +26,27 @@ class AngleConstraint : public Constraint ...@@ -26,22 +26,27 @@ class AngleConstraint : public Constraint
public: public:
AngleConstraint(string name1, string name2, string name3, AngleConstraint(string name, string name1, string name2, string name3,
double angle, double velocity, double tolerance): double angle, double velocity, double tolerance):
name1_(name1), name2_(name2), name3_(name3), name1_(name1), name2_(name2), name3_(name3),
velocity_(velocity), velocity_(velocity),
tol_(tolerance), m1_(0.0), m2_(0.0), m3_(0.0) tol_(tolerance), m1_(0.0), m2_(0.0), m3_(0.0)
{ {
set_value(angle); set_value(angle);
name_ = name;
names_.resize(3); names_.resize(3);
names_[0] = name1_; names_[0] = name1_;
names_[1] = name2_; names_[1] = name2_;
names_[2] = name3_; names_[2] = name3_;
force_ = 0.0;
weight_ = 1.0;
} }
string type(void) const { return "angle"; } string type(void) const { return "angle"; }
double value(void) const { return angle_; } double value(void) const { return angle_; }
double velocity(void) const { return velocity_; } double velocity(void) const { return velocity_; }
double force(void) const { return force_; }
double weight(void) const { return weight_; }
double tolerance(void) const { return tol_; } double tolerance(void) const { return tol_; }
void set_value(double value) void set_value(double value)
{ {
...@@ -60,8 +65,8 @@ class AngleConstraint : public Constraint ...@@ -60,8 +65,8 @@ class AngleConstraint : public Constraint
vector<vector<double> > &rp) const; vector<vector<double> > &rp) const;
bool enforce_v(const vector<vector<double> > &r0, bool enforce_v(const vector<vector<double> > &r0,
vector<vector<double> > &v0) const; vector<vector<double> > &v0) const;
double projection(const vector<vector<double> > &r0, void compute_force(const vector<vector<double> > &r0,
const vector<vector<double> > &x) const; const vector<vector<double> > &f);
ostream& print( ostream& os ); ostream& print( ostream& os );
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// BOSampleStepper.C // BOSampleStepper.C
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: BOSampleStepper.C,v 1.24 2005-06-27 22:31:39 fgygi Exp $ // $Id: BOSampleStepper.C,v 1.25 2005-09-16 23:08:11 fgygi Exp $
#include "BOSampleStepper.h" #include "BOSampleStepper.h"
#include "EnergyFunctional.h" #include "EnergyFunctional.h"
...@@ -255,20 +255,14 @@ void BOSampleStepper::step(int niter) ...@@ -255,20 +255,14 @@ void BOSampleStepper::step(int niter)
if ( compute_forces ) if ( compute_forces )
{ {
#if 0
if ( s_.constraints.size() > 0 ) if ( s_.constraints.size() > 0 )
{ {
const double projected_force = s_.constraints.compute_forces(ionic_stepper->r0(), fion);
s_.constraints.projection(ionic_stepper->r0(), fion);
if ( onpe0 ) if ( onpe0 )
{ {
cout << " <constraint_projected_force> " s_.constraints.list_constraints(cout);
<< projected_force
<< " </constraint_projected_force>"
<< endl;
} }
} }
#endif
// move atoms to new position: r0 <- r0 + v0*dt + dt2/m * fion // move atoms to new position: r0 <- r0 + v0*dt + dt2/m * fion
ionic_stepper->compute_r(energy,fion); ionic_stepper->compute_r(energy,fion);
ef_.atoms_moved(); ef_.atoms_moved();
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// CPSampleStepper.C // CPSampleStepper.C
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: CPSampleStepper.C,v 1.10 2005-06-27 22:30:28 fgygi Exp $ // $Id: CPSampleStepper.C,v 1.11 2005-09-16 23:08:11 fgygi Exp $
#include "CPSampleStepper.h" #include "CPSampleStepper.h"
#include "SlaterDet.h" #include "SlaterDet.h"
...@@ -190,17 +190,13 @@ void CPSampleStepper::step(int niter) ...@@ -190,17 +190,13 @@ void CPSampleStepper::step(int niter)
} }
} }
} }
#if 0 #if 1
if ( s_.constraints.size() > 0 ) if ( s_.constraints.size() > 0 )
{ {
const double projected_force = s_.constraints.compute_forces(mdionic_stepper->r0(), fion);
s_.constraints.projection(mdionic_stepper->r0(), fion);
if ( onpe0 ) if ( onpe0 )
{ {
cout << " <constraint_projected_force> " s_.constraints.list_constraints(cout);
<< projected_force
<< " </constraint_projected_force>"
<< endl;
} }
} }
#endif #endif
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// Constraint.h // Constraint.h
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: Constraint.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: Constraint.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef CONSTRAINT_H #ifndef CONSTRAINT_H
#define CONSTRAINT_H #define CONSTRAINT_H
...@@ -19,6 +19,7 @@ class Constraint ...@@ -19,6 +19,7 @@ class Constraint
{ {
protected: protected:
string name_; // constraint name
vector<string> names_; // names of atoms involved in the constraint vector<string> names_; // names of atoms involved in the constraint
public: public:
...@@ -26,6 +27,8 @@ class Constraint ...@@ -26,6 +27,8 @@ class Constraint
virtual string type(void) const = 0; virtual string type(void) const = 0;
virtual double value(void) const = 0; virtual double value(void) const = 0;
virtual double velocity(void) const = 0; virtual double velocity(void) const = 0;
virtual double force(void) const = 0;
virtual double weight(void) const = 0;
virtual double tolerance(void) const = 0; virtual double tolerance(void) const = 0;
virtual void set_value(double value) = 0; virtual void set_value(double value) = 0;
virtual void set_velocity(double velocity) = 0; virtual void set_velocity(double velocity) = 0;
...@@ -33,12 +36,13 @@ class Constraint ...@@ -33,12 +36,13 @@ class Constraint
vector<vector<double> > &rp) const = 0; vector<vector<double> > &rp) const = 0;
virtual bool enforce_v(const vector<vector<double> > &r0, virtual bool enforce_v(const vector<vector<double> > &r0,
vector<vector<double> > &v0) const = 0; vector<vector<double> > &v0) const = 0;
virtual double projection(const vector<vector<double> > &r0, virtual void compute_force(const vector<vector<double> > &r0,
const vector<vector<double> > &x) const = 0; const vector<vector<double> > &f) = 0;
virtual void update(double dt) = 0; virtual void update(double dt) = 0;
virtual void setup(const AtomSet& atoms) = 0; virtual void setup(const AtomSet& atoms) = 0;
virtual ostream& print(ostream &os) = 0; virtual ostream& print(ostream &os) = 0;
string names(int i) string name(void) const { return name_; }
string names(int i) const
{ {
assert( i >= 0 && i < names_.size() ); assert( i >= 0 && i < names_.size() );
return names_[i]; return names_[i];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// ConstraintCmd.h: // ConstraintCmd.h:
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: ConstraintCmd.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: ConstraintCmd.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef CONSTRAINTCMD_H #ifndef CONSTRAINTCMD_H
#define CONSTRAINTCMD_H #define CONSTRAINTCMD_H
...@@ -25,25 +25,57 @@ class ConstraintCmd : public Cmd ...@@ -25,25 +25,57 @@ class ConstraintCmd : public Cmd
return return
"\n constraint\n\n" "\n constraint\n\n"
" syntax:\n\n" " syntax:\n\n"
" constraint distance name1 name2 distance [velocity]\n" " constraint define distance name atom1 atom2 distance [velocity]\n"
" The constraint command defines a new constraint and adds it to\n" " constraint define angle name atom1 atom2 atom3 angle [velocity]\n"
" the constraint list. Constraints are enforced at each MD step\n" " constraint define torsion name atom1 atom2 atom3 atom4 angle [velocity]\n"
" if ions are allowed to move. The optional velocity parameter\n" " constraint set name value [velocity]\n"
" must be given in atomic units.\n\n"; " constraint delete name\n"
" constraint list\n"
" constraint enforce\n\n"
" Constraints are enforced at each MD step if ions are allowed to move.\n"
" Velocity parameters are optional.\n\n";
//" constraint multidistance weight name1 name2 \n" //" constraint multidistance weight name1 name2 \n"
//" [weight name1 name2] distance [velocity]\n" //" [weight name1 name2] distance [velocity]\n"
} }
int action(int argc, char **argv) int action(int argc, char **argv)
{ {
const bool onpe0 = s->ctxt_.onpe0();
if ( argc < 2 )
{
if ( onpe0 )
cout << help_msg();
return 1;
}
string subcmd(argv[1]); string subcmd(argv[1]);
if ( subcmd == "distance" || subcmd == "angle" || subcmd == "torsion" ) if ( subcmd == "define" )
return s->constraints.set_constraint(s->atoms,argc,argv); {
return s->constraints.define_constraint(s->atoms,argc,argv);
}
else if ( subcmd == "set" )
{
return s->constraints.set_constraint(argc,argv);
}
else if ( subcmd == "delete" )
{
return s->constraints.delete_constraint(argc,argv);
}
else if ( subcmd == "enforce" ) else if ( subcmd == "enforce" )
{ {
s->constraints.enforce(s->atoms); s->constraints.enforce(s->atoms);
// Note: should catch exception here if constraints could not be enforced // Note: should catch exception here if constraints could not be enforced
} }
else if ( subcmd == "list" )
{
if ( onpe0 )
s->constraints.list_constraints(cout);
}
else
{
if ( onpe0 )
cout << help_msg();
}
return 0; return 0;
} }
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// ConstraintSet.h // ConstraintSet.h
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: ConstraintSet.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: ConstraintSet.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef CONSTRAINTSET_H #ifndef CONSTRAINTSET_H
#define CONSTRAINTSET_H #define CONSTRAINTSET_H
...@@ -27,8 +27,9 @@ class ConstraintSet ...@@ -27,8 +27,9 @@ class ConstraintSet
public: public:
ConstraintSet(const Context& ctxt) : ctxt_(ctxt) {} ConstraintSet(const Context& ctxt) : ctxt_(ctxt) {}
bool set_constraint(AtomSet &atoms, int argc, char **argv); bool define_constraint(AtomSet &atoms, int argc, char **argv);
bool del_constraint(int argc, char **argv); bool set_constraint(int argc, char **argv);
bool delete_constraint(int argc, char **argv);
void list_constraints(ostream &os); void list_constraints(ostream &os);
int size(void) const { return constraint_list.size(); } int size(void) const { return constraint_list.size(); }
void enforce(AtomSet& atoms); void enforce(AtomSet& atoms);
...@@ -36,8 +37,8 @@ class ConstraintSet ...@@ -36,8 +37,8 @@ class ConstraintSet
vector<vector<double> > &rp); vector<vector<double> > &rp);
void enforce_v(const vector<vector<double> > &r0, void enforce_v(const vector<vector<double> > &r0,
vector<vector<double> > &v0); vector<vector<double> > &v0);
double projection(const vector<vector<double> > &r0, void compute_forces(const vector<vector<double> > &r0,
const vector<vector<double> > &x); const vector<vector<double> > &f);
void update_constraints(double dt); void update_constraints(double dt);
void setup(AtomSet& atoms); void setup(AtomSet& atoms);
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// DistanceCmd.h: // DistanceCmd.h:
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: DistanceCmd.h,v 1.1 2005-06-27 22:35:26 fgygi Exp $ // $Id: DistanceCmd.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef DISTANCECMD_H #ifndef DISTANCECMD_H
#define DISTANCECMD_H #define DISTANCECMD_H
...@@ -66,7 +66,7 @@ class DistanceCmd : public Cmd ...@@ -66,7 +66,7 @@ class DistanceCmd : public Cmd
cout.setf(ios::fixed,ios::floatfield); cout.setf(ios::fixed,ios::floatfield);
cout << " <!-- distance " << name1 << "-" << name2 << ": " cout << " <!-- distance " << name1 << "-" << name2 << ": "
<< setprecision(3) << setprecision(3)
<< d << " (a.u.) / " << 0.529177*d << " (Ang)" << endl; << d << " (a.u.) / " << 0.529177*d << " (Ang) -->" << endl;
} }
return 0; return 0;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// DistanceConstraint.C // DistanceConstraint.C
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: DistanceConstraint.C,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: DistanceConstraint.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#include "DistanceConstraint.h" #include "DistanceConstraint.h"
#include "AtomSet.h" #include "AtomSet.h"
...@@ -177,17 +177,17 @@ vector<vector<double> > &v0) const ...@@ -177,17 +177,17 @@ vector<vector<double> > &v0) const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
double DistanceConstraint::projection(const vector<vector<double> > &r0, void DistanceConstraint::compute_force(const vector<vector<double> > &r0,
const vector<vector<double> > &x) const const vector<vector<double> > &f)
{ {
const double* pr1 = &r0[is1_][3*ia1_]; const double* pr1 = &r0[is1_][3*ia1_];
const double* pr2 = &r0[is2_][3*ia2_]; const double* pr2 = &r0[is2_][3*ia2_];
D3vector r1(pr1); D3vector r1(pr1);
D3vector r2(pr2); D3vector r2(pr2);
const double* px1 = &x[is1_][3*ia1_]; const double* pf1 = &f[is1_][3*ia1_];
const double* px2 = &x[is2_][3*ia2_]; const double* pf2 = &f[is2_][3*ia2_];
D3vector x1(px1); D3vector f1(pf1);
D3vector x2(px2); D3vector f2(pf2);
// compute gradient at r // compute gradient at r
D3vector r12(r1-r2); D3vector r12(r1-r2);
...@@ -197,30 +197,34 @@ double DistanceConstraint::projection(const vector<vector<double> > &r0, ...@@ -197,30 +197,34 @@ double DistanceConstraint::projection(const vector<vector<double> > &r0,
const double norm2 = g1*g1; const double norm2 = g1*g1;
assert(norm2>=0.0); assert(norm2>=0.0);
if ( norm2 == 0.0 ) if ( norm2 == 0.0 )
return 0.0; {
force_ = 0.0;
return;
}
const double norm = sqrt(norm2); const double norm = sqrt(norm2);
D3vector e1(g1/norm); D3vector e1(g1/norm);
D3vector e2(-e1); D3vector e2(-e1);
const double proj1 = x1*e1; const double proj1 = f1*e1;
const double proj2 = x2*e2; const double proj2 = f2*e2;
return 0.5*(proj1+proj2); force_ = -0.5*(proj1+proj2);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ostream& DistanceConstraint::print( ostream &os ) ostream& DistanceConstraint::print( ostream &os )
{ {
os.setf(ios::left,ios::adjustfield); os.setf(ios::left,ios::adjustfield);
os << " <!-- constraint "; os << " <constraint name=\"" << name();
os << type() << " "; os << "\" type=\"" << type();
os << setw(4) << name1_ << " "; os << "\" atoms=\"" << name1_ << " " << name2_ << "\"\n";
os << setw(4) << name2_ << " ";
os.setf(ios::fixed,ios::floatfield); os.setf(ios::fixed,ios::floatfield);
os.setf(ios::right,ios::adjustfield); os.setf(ios::right,ios::adjustfield);
os << setw(10) << setprecision(6) << distance_ << " " os << " value=\"" << setprecision(6) << distance_;
<< setw(10) << setprecision(6) << velocity_ << " -->"; os << "\" velocity=\"" << setprecision(6) << velocity_ << "\"\n";
os << " force=\"" << setprecision(6) << force_;
os << "\" weight=\"" << setprecision(6) << weight_ << "\"/>";
return os; return os;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// DistanceConstraint.h // DistanceConstraint.h
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// $Id: DistanceConstraint.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ // $Id: DistanceConstraint.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $
#ifndef DISTANCECONSTRAINT_H #ifndef DISTANCECONSTRAINT_H
#define DISTANCECONSTRAINT_H #define DISTANCECONSTRAINT_H
...@@ -18,23 +18,28 @@ class DistanceConstraint : public Constraint ...@@ -18,23 +18,28 @@ class DistanceConstraint : public Constraint
string name1_, name2_; string name1_, name2_;
int ia1_, ia2_, is1_, is2_; int ia1_, ia2_, is1_, is2_;
double m1_, m2_, m1_inv_, m2_inv_; double m1_, m2_, m1_inv_, m2_inv_;
double distance_, velocity_, tol_; double distance_, velocity_, force_, weight_, tol_;
public: public:
DistanceConstraint(string name1, string name2, DistanceConstraint(string name, string name1, string name2,
double distance, double velocity, double tolerance): double distance, double velocity, double tolerance):
name1_(name1), name2_(name2), distance_(distance), velocity_(velocity), name1_(name1), name2_(name2), distance_(distance),
tol_(tolerance), m1_(0.0), m2_(0.0) velocity_(velocity), tol_(tolerance), m1_(0.0), m2_(0.0)
{ {
name_ = name;
names_.resize(2); names_.resize(2);
names_[0] = name1_; names_[0] = name1_;
names_[1] = name2_; names_[1] = name2_;
force_ = 0.0;
weight_ = 1.0;
} }
string type(void) const { return "distance"; } string type(void) const { return "distance"; }
double value(void) const { return distance_; } double value(void) const { return distance_; }
double velocity(void) const { return velocity_; } double velocity(void) const { return velocity_; }
double force(void) const { return force_; }
double weight(void) const { return weight_; }
double tolerance(void) const { return tol_; } double tolerance(void) const { return tol_; }
void set_value(double value) void set_value(double value)
{ {
...@@ -51,8 +56,8 @@ class DistanceConstraint : public Constraint ...@@ -51,8 +56,8 @@ class DistanceConstraint : public Constraint
vector<vector<double> > &rp) const; vector<vector<double> > &rp) const;
bool enforce_v(const vector<vector<double> > &r0, bool enforce_v(const vector<vector<double> > &r0,
vector<vector<double> > &v0) const; vector<vector<double> > &v0) const;
double projection(const vector<vector<double> > &r0, void compute_force(const vector<vector<double> > &r0,
const vector<vector<double> > &x) const; const vector<vector<double> > &f);
ostream& print( ostream& os ); ostream& print( ostream& os );
}; };
......
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# $Id: Makefile,v 1.35 2005-06-27 22:37:32 fgygi Exp $ # $Id: Makefile,v 1.36 2005-09-16 23:08:11 fgygi Exp $
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# #
include $(TARGET).mk include $(TARGET).mk
...@@ -258,9 +258,6 @@ LDAFunctional.o: XCFunctional.h ...@@ -258,9 +258,6 @@ LDAFunctional.o: XCFunctional.h
ListAtomsCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h ListAtomsCmd.o: UserInterface.h Sample.h AtomSet.h Context.h Atom.h