ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Integrator.hpp (file contents):
Revision 790 by mmeineke, Mon Sep 29 21:16:11 2003 UTC vs.
Revision 1161 by tim, Tue May 11 21:44:05 2004 UTC

# Line 4 | Line 4
4   #include <string>
5   #include <vector>
6   #include "Atom.hpp"
7 + #include "StuntDouble.hpp"
8   #include "Molecule.hpp"
9   #include "SRI.hpp"
10   #include "AbstractClasses.hpp"
# Line 20 | Line 21 | const double tol = 1.0e-6;
21   const int maxIteration = 300;
22   const double tol = 1.0e-6;
23  
23
24   template<typename T = BaseIntegrator> class Integrator : public T {
25  
26   public:
# Line 28 | Line 28 | template<typename T = BaseIntegrator> class Integrator
28    virtual ~Integrator();
29    void integrate( void );
30    virtual double  getConservedQuantity(void);
31 +  virtual string getAdditionalParameters(void);
32  
33   protected:
34  
# Line 40 | Line 41 | template<typename T = BaseIntegrator> class Integrator
41    virtual int  readyCheck( void ) { return 1; }
42  
43    virtual void resetIntegrator( void ) { }
44 <
45 <  virtual void calcForce( int calcPot, int calcStress );  
44 >
45 >  virtual void calcForce( int calcPot, int calcStress );
46    virtual void thermalize();
46  
47  virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] );
47  
48 +  virtual bool stopIntegrator() {return false;}
49 +
50 +  virtual void rotationPropagation( StuntDouble* sd, double ji[3] );
51 +
52    void checkConstraints( void );
53 <  void rotate( int axes1, int axes2, double angle, double j[3],
53 >  void rotate( int axes1, int axes2, double angle, double j[3],
54           double A[3][3] );
55 <        
55 >
56    ForceFields* myFF;
57  
58    SimInfo *info; // all the info we'll ever need
59 +  vector<StuntDouble*> integrableObjects;
60    int nAtoms;  /* the number of atoms */
61    int oldAtoms;
62    Atom **atoms; /* array of atom pointers */
# Line 61 | Line 65 | template<typename T = BaseIntegrator> class Integrator
65  
66    int isConstrained; // boolean to know whether the systems contains
67           // constraints.
68 <  int nConstrained;  // counter for number of constraints
69 <  int *constrainedA; // the i of a constraint pair
70 <  int *constrainedB; // the j of a constraint pair
71 <  double *constrainedDsqr; // the square of the constraint distance
72 <  
68 >  int nConstrained;  // counter for number of constraints
69 >  int *constrainedA; // the i of a constraint pair
70 >  int *constrainedB; // the j of a constraint pair
71 >  double *constrainedDsqr; // the square of the constraint distance
72 >
73    int* moving; // tells whether we are moving atom i
74    int* moved;  // tells whether we have moved atom i
75 <  double* oldPos; // pre constrained positions
75 >  double* oldPos; // pre constrained positions
76  
77    short isFirst; /*boolean for the first time integrate is called */
78 <  
78 >
79    double dt;
80    double dt2;
81  
82    Thermo *tStats;
83    StatWriter*  statOut;
84    DumpWriter*  dumpOut;
85 <  
85 >
86   };
87  
88   typedef Integrator<BaseIntegrator> RealIntegrator;
89  
90 + // ansi instantiation
91 + template class Integrator<BaseIntegrator>;
92 +
93   template<typename T> class NVE : public T {
94  
95   public:
96    NVE ( SimInfo *theInfo, ForceFields* the_ff ):
97      T( theInfo, the_ff ){}
98 <  virtual ~NVE(){}  
98 >  virtual ~NVE(){}
99   };
100  
101  
# Line 103 | Line 110 | template<typename T> class NVT : public T { (public)
110    void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
111    void setChiTolerance(double tol) {chiTolerance = tol;}
112    virtual double  getConservedQuantity(void);
113 +  virtual string getAdditionalParameters(void);
114  
115   protected:
116  
# Line 124 | Line 132 | template<typename T> class NVT : public T { (public)
132  
133    double targetTemp;
134    double tauThermostat;
135 <  
135 >
136    short int have_tau_thermostat, have_target_temp;
137  
138    double *oldVel;
# Line 143 | Line 151 | template<typename T> class NPT : public T{ (public)
151  
152    NPT ( SimInfo *theInfo, ForceFields* the_ff);
153    virtual ~NPT();
154 <  
154 >
155    virtual void integrateStep( int calcPot, int calcStress ){
156      calcStress = 1;
157      T::integrateStep( calcPot, calcStress );
158    }
159  
160    virtual double getConservedQuantity(void) = 0;
161 +  virtual string getAdditionalParameters(void) = 0;
162 +  
163 +  double myTauThermo( void ) { return tauThermostat; }
164 +  double myTauBaro( void ) { return tauBarostat; }
165  
166    void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
167    void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
# Line 170 | Line 182 | template<typename T> class NPT : public T{ (public)
182  
183    virtual void getVelScaleA( double sc[3], double vel[3] ) = 0;
184    virtual void getVelScaleB( double sc[3], int index ) = 0;
185 <  virtual void getPosScale(double pos[3], double COM[3],
185 >  virtual void getPosScale(double pos[3], double COM[3],
186                             int index, double sc[3]) = 0;
187  
188 +  virtual void calcVelScale( void ) = 0;
189 +
190    virtual bool chiConverged( void );
191    virtual bool etaConverged( void ) = 0;
192 <  
192 >
193    virtual void evolveChiA( void );
194    virtual void evolveEtaA( void ) = 0;
195    virtual void evolveChiB( void );
# Line 201 | Line 215 | template<typename T> class NPT : public T{ (public)
215  
216    double integralOfChidt;
217  
218 <  // targetTemp, targetPressure, and tauBarostat must be set.  
218 >  // targetTemp, targetPressure, and tauBarostat must be set.
219    // One of qmass or tauThermostat must be set;
220  
221    double targetTemp;
# Line 226 | Line 240 | template<typename T> class NPTi : public T{
240   };
241  
242   template<typename T> class NPTi : public T{
243 <  
243 >
244   public:
245    NPTi( SimInfo *theInfo, ForceFields* the_ff);
246    ~NPTi();
247  
248    virtual double getConservedQuantity(void);
249    virtual void resetIntegrator(void);
250 <
250 >  virtual string getAdditionalParameters(void);
251   protected:
252  
239
253  
254 +
255    virtual void evolveEtaA(void);
256    virtual void evolveEtaB(void);
257  
# Line 247 | Line 261 | template<typename T> class NPTi : public T{
261  
262    virtual void getVelScaleA( double sc[3], double vel[3] );
263    virtual void getVelScaleB( double sc[3], int index );
264 <  virtual void getPosScale(double pos[3], double COM[3],
264 >  virtual void getPosScale(double pos[3], double COM[3],
265                             int index, double sc[3]);
266  
267 <  double eta, oldEta, prevEta;
254 < };
255 <
256 < template<typename T> class NPTzm : public T{
257 <
258 < public:
259 <
260 <  NPTzm ( SimInfo *theInfo, ForceFields* the_ff);
261 <  virtual ~NPTzm() {};
262 <
263 <  virtual void integrateStep( int calcPot, int calcStress ){
264 <    calcStress = 1;
265 <    T::integrateStep( calcPot, calcStress );
266 <  }
267 <
268 <  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
269 <  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
270 <  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
271 <  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
272 <
273 < protected:
267 >  virtual void calcVelScale( void );
268  
269 <  virtual void moveA( void );
270 <  virtual void moveB( void );
277 <
278 <  virtual int readyCheck();
279 <
280 <  virtual void resetIntegrator( void );
281 <
282 <  Molecule* myMolecules;
283 <  Atom** myAtoms;
284 <
285 <  // chi and eta are the propagated degrees of freedom
286 <
287 <  double chi;
288 <  double eta;
289 <  double etaZ;
290 <  double NkBT;
291 <
292 <  // targetTemp, targetPressure, and tauBarostat must be set.  
293 <  // One of qmass or tauThermostat must be set;
294 <
295 <  double targetTemp;
296 <  double targetPressure;
297 <  double tauThermostat;
298 <  double tauBarostat;
299 <
300 <  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
301 <  short int have_target_pressure;
302 <
269 >  double eta, oldEta, prevEta;
270 >  double vScale;
271   };
272  
273   template<typename T> class NPTf : public T{
# Line 310 | Line 278 | template<typename T> class NPTf : public T{ (public)
278    virtual ~NPTf();
279  
280    virtual double getConservedQuantity(void);
281 +  virtual string getAdditionalParameters(void);
282    virtual void resetIntegrator(void);
283  
284   protected:
# Line 323 | Line 292 | template<typename T> class NPTf : public T{ (public)
292  
293    virtual void getVelScaleA( double sc[3], double vel[3] );
294    virtual void getVelScaleB( double sc[3], int index );
295 <  virtual void getPosScale(double pos[3], double COM[3],
295 >  virtual void getPosScale(double pos[3], double COM[3],
296                             int index, double sc[3]);
297  
298 +  virtual void calcVelScale( void );
299 +
300    double eta[3][3];
301    double oldEta[3][3];
302    double prevEta[3][3];
303 +  double vScale[3][3];
304   };
305  
306 < template<typename T> class NPTxym : public T{
306 > template<typename T> class NPTxyz : public T{
307  
308   public:
309  
310 <  NPTxym ( SimInfo *theInfo, ForceFields* the_ff);
311 <  virtual ~NPTxym() {};
310 >  NPTxyz ( SimInfo *theInfo, ForceFields* the_ff);
311 >  virtual ~NPTxyz();
312  
313 <  virtual void integrateStep( int calcPot, int calcStress ){
314 <    calcStress = 1;
315 <    T::integrateStep( calcPot, calcStress );
344 <  }
313 >  virtual double getConservedQuantity(void);
314 >  virtual string getAdditionalParameters(void);
315 >  virtual void resetIntegrator(void);
316  
346  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
347  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
348  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
349  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
350
317   protected:
318  
319 <  virtual void moveA( void );
320 <  virtual void moveB( void );
319 >  virtual void evolveEtaA(void);
320 >  virtual void evolveEtaB(void);
321  
322 <  virtual int readyCheck();
322 >  virtual bool etaConverged( void );
323  
324 <  virtual void resetIntegrator( void );
324 >  virtual void scaleSimBox( void );
325  
326 <  Molecule* myMolecules;
327 <  Atom** myAtoms;
326 >  virtual void getVelScaleA( double sc[3], double vel[3] );
327 >  virtual void getVelScaleB( double sc[3], int index );
328 >  virtual void getPosScale(double pos[3], double COM[3],
329 >                           int index, double sc[3]);
330  
331 <  // chi and eta are the propagated degrees of freedom
364 <
365 <  double chi;
366 <  double eta;
367 <  double etaX;
368 <  double etaY;
369 <  double NkBT;
331 >  virtual void calcVelScale( void );
332  
333 <  // targetTemp, targetPressure, and tauBarostat must be set.  
334 <  // One of qmass or tauThermostat must be set;
335 <
336 <  double targetTemp;
375 <  double targetPressure;
376 <  double tauThermostat;
377 <  double tauBarostat;
378 <
379 <  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
380 <  short int have_target_pressure;
381 <
333 >  double eta[3][3];
334 >  double oldEta[3][3];
335 >  double prevEta[3][3];
336 >  double vScale[3][3];
337   };
338  
339 +
340   template<typename T> class ZConstraint : public T {
341 <  
342 <  public:
341 >
342 >  public:
343    class ForceSubtractionPolicy{
344      public:
345        ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
346  
347 <      virtual void update() = 0;    
347 >      virtual void update() = 0;
348        virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
349        virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
350        virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
351        virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
352 <    
352 >
353     protected:
354       ZConstraint<T>* zconsIntegrator;
355    };
# Line 401 | Line 357 | template<typename T> class ZConstraint : public T {
357    class PolicyByNumber : public ForceSubtractionPolicy{
358  
359      public:
360 <      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}    
361 <      virtual void update();    
360 >      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
361 >      virtual void update();
362        virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
363        virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
364        virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
365        virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
366 <    
366 >
367      private:
368        int totNumOfMovingAtoms;
369    };
# Line 415 | Line 371 | template<typename T> class ZConstraint : public T {
371    class PolicyByMass : public ForceSubtractionPolicy{
372  
373      public:
374 <      PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}  
375 <      
376 <      virtual void update();    
374 >      PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
375 >
376 >      virtual void update();
377        virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
378        virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
379        virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
# Line 431 | Line 387 | template<typename T> class ZConstraint : public T {
387  
388    ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
389    ~ZConstraint();
390 <    
390 >
391    void setZConsTime(double time)                  {this->zconsTime = time;}
392    void getZConsTime()                             {return zconsTime;}
393 <  
393 >
394    void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
395    void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
396 <  
396 >
397    void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
398    string getZConsOutput()                         {return zconsOutput;}
399 <  
399 >
400    virtual void integrate();
445  
401  
402 +
403   #ifdef IS_MPI
404    virtual void update();                      //which is called to indicate the molecules' migration
405   #endif
406  
407 <  enum ZConsState {zcsMoving, zcsFixed};  
407 >  enum ZConsState {zcsMoving, zcsFixed};
408  
409    vector<Molecule*> zconsMols;              //z-constraint molecules array
410    vector<ZConsState> states;                 //state of z-constraint molecules
411  
456
412  
413 +
414    int totNumOfUnconsAtoms;              //total number of uncontraint atoms
415    double totalMassOfUncons;                //total mas of unconstraint molecules
416  
# Line 462 | Line 418 | template<typename T> class ZConstraint : public T {
418   protected:
419  
420  
421 <
422 <  virtual void calcForce( int calcPot, int calcStress );
421 >
422 >  virtual void calcForce( int calcPot, int calcStress );
423    virtual void thermalize(void);
424 <  
424 >
425    void zeroOutVel();
426    void doZconstraintForce();
427 <  void doHarmonic();
427 >  void doHarmonic(vector<double>& resPos);
428    bool checkZConsState();
429  
430    bool haveFixedZMols();
# Line 483 | Line 439 | template<typename T> class ZConstraint : public T {
439    double zconsTol;                                 //tolerance of z-contratint
440    double zForceConst;                           //base force constant term
441                                                            //which is estimate by OOPSE
486  
442  
443 <  vector<double> massOfZConsMols;       //mass of z-constraint molecule
443 >
444 >  vector<double> massOfZConsMols;       //mass of z-constraint molecule
445    vector<double> kz;                              //force constant array
446  
447    vector<double> zPos;                          //
448 <  
449 <  
448 >
449 >
450    vector<Molecule*> unconsMols;           //unconstraint molecules array
451    vector<double> massOfUnconsMols;    //mass array of unconstraint molecules
452  
453  
454    vector<ZConsParaItem>* parameters; //
455 <  
455 >
456    vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
457  
458 <  int* indexOfZConsMols;                   //index of local Z-Constraint Molecules  
459 <  double* fz;
460 <  double* curZPos;
505 <  
458 >  vector<int> indexOfZConsMols;                   //index of local Z-Constraint Molecules
459 >  vector<double> fz;
460 >  vector<double> curZPos;
461  
462 +  bool usingSMD;
463 +  vector<double> prevCantPos;
464 +  vector<double> cantPos;
465 +  vector<double> cantVel;
466  
467 <  int whichDirection;                           //constraint direction
467 >  double zconsFixTime;  
468 >  double zconsGap;
469 >  bool hasZConsGap;
470 >  vector<double> endFixTime;
471    
472 +  int whichDirection;                           //constraint direction
473 +
474   private:
475 <  
475 >
476    string zconsOutput;                         //filename of zconstraint output
477    ZConsWriter* fzOut;                         //z-constraint writer
478  
479 <  double curZconsTime;                      
479 >  double curZconsTime;
480  
481    double calcMovingMolsCOMVel();
482    double calcSysCOMVel();
483    double calcTotalForce();
484 +  void updateZPos();
485 +  void updateCantPos();
486    
487    ForceSubtractionPolicy* forcePolicy; //force subtraction policy
488    friend class ForceSubtractionPolicy;
489  
490   };
491  
492 + /*
493 + template<typename T> class SingleZConstrain : public T{
494 +
495 +
496 + };
497 + */
498 +
499 + template<typename T> class NonEquMD : public T {
500 +  public:
501 +    
502 +
503 +
504 + };
505 +
506 +
507 + //
508 + template<typename T> class SingleZConstraint : public T{
509 +  public:
510 +    SingleZConstraint(SimInfo *theInfo, ForceFields* the_ff);
511 +    ~SingleZConstraint();
512 +    
513 +    bool stopIntegrator();
514 +    
515 +  protected:
516 +    
517 + };
518 +
519 + //Steered Molecular Dynamics, curret implement only support one steered molecule
520 + template<typename T> class SMD : public T{
521 +  public:
522 +    SMD( SimInfo *theInfo, ForceFields* the_ff);
523 +    ~SMD();
524 +  
525 +    virtual void integrate();
526 +    virtual void calcForce( int calcPot, int calcStress );  
527 +    bool stopIntegrator();
528 +  private:
529 +    
530 + };
531 +
532 + //By using state pattern, Coordinate Drive is responsible for switching back and forth between
533 + //Driven Molecular Dynamics and ZConstraint Method.
534 + template<typename T> class CoordinateDriver : public T {
535 +  public:
536 +    typedef T ParentIntegrator;
537 +
538 +    CoordinateDriver(SimInfo*, ForceFields*, BaseIntegrator*, BaseIntegrator*);
539 +    ~CoordinateDriver();
540 +    
541 +    virtual void integrate();
542 +
543 +  private:    
544 +    BaseIntegrator* zconsIntegrator;
545 +    BaseIntegrator* drivenIntegrator;
546 +    
547 + };
548 +
549   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines