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 559 by mmeineke, Thu Jun 19 22:02:44 2003 UTC vs.
Revision 1161 by tim, Tue May 11 21:44:05 2004 UTC

# Line 1 | Line 1
1   #ifndef _INTEGRATOR_H_
2   #define _INTEGRATOR_H_
3  
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"
11   #include "SimInfo.hpp"
12   #include "ForceFields.hpp"
13   #include "Thermo.hpp"
14   #include "ReadWrite.hpp"
15 + #include "ZConsWriter.hpp"
16  
17 < class Integrator : public BaseIntegrator {
17 > using namespace std;
18 > const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K
19 > const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2
20 > const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm
21 > const int maxIteration = 300;
22 > const double tol = 1.0e-6;
23  
24 + template<typename T = BaseIntegrator> class Integrator : public T {
25 +
26   public:
27 <  Integrator( SimInfo &theInfo, ForceFields* the_ff );
27 >  Integrator( SimInfo *theInfo, ForceFields* the_ff );
28    virtual ~Integrator();
29    void integrate( void );
30 +  virtual double  getConservedQuantity(void);
31 +  virtual string getAdditionalParameters(void);
32  
19
33   protected:
34  
22  
35    virtual void integrateStep( int calcPot, int calcStress );
36    virtual void preMove( void );
37    virtual void moveA( void );
# Line 27 | Line 39 | class Integrator : public BaseIntegrator { (protected)
39    virtual void constrainA( void );
40    virtual void constrainB( void );
41    virtual int  readyCheck( void ) { return 1; }
30  
31  void checkConstraints( void );
32  void rotate( int axes1, int axes2, double angle, double j[3],
33               double A[3][3] );
42  
43 +  virtual void resetIntegrator( void ) { }
44  
45 +  virtual void calcForce( int calcPot, int calcStress );
46 +  virtual void thermalize();
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],
54 +         double A[3][3] );
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 43 | Line 64 | class Integrator : public BaseIntegrator { (protected)
64    int nMols;
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 <  
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 >
73    int* moving; // tells whether we are moving atom i
74    int* moved;  // tells whether we have moved atom i
75 <  double* prePos; // 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;
60  const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2
81  
62  const int maxIteration = 300;
63  const double tol = 1.0e-6;
64
65  
66  double* pos;
67  double* vel;
68  double* frc;
69  double* trq;
70  double* Amat;
71  
72
73
82    Thermo *tStats;
83    StatWriter*  statOut;
84    DumpWriter*  dumpOut;
85 <  
85 >
86   };
87  
88 < class NVE : public Integrator{
88 > typedef Integrator<BaseIntegrator> RealIntegrator;
89  
90 <  NVE ( void ):
91 <    Integrator( theInfo, the_ff ){}
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(){}
99 + };
100  
101 +
102 + template<typename T> class NVT : public T {
103 +
104 + public:
105 +
106 +  NVT ( SimInfo *theInfo, ForceFields* the_ff);
107 +  virtual ~NVT();
108 +
109 +  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
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 +
117 +  virtual void moveA( void );
118 +  virtual void moveB( void );
119 +
120 +  virtual int readyCheck();
121 +
122 +  virtual void resetIntegrator( void );
123 +
124 +  // chi is a propagated degree of freedom.
125 +
126 +  double chi;
127 +
128 +  //integral of chi(t)dt
129 +  double integralOfChidt;
130 +
131 +  // targetTemp must be set.  tauThermostat must also be set;
132 +
133 +  double targetTemp;
134 +  double tauThermostat;
135 +
136 +  short int have_tau_thermostat, have_target_temp;
137 +
138 +  double *oldVel;
139 +  double *oldJi;
140 +
141 +  double chiTolerance;
142 +  short int have_chi_tolerance;
143 +
144 + };
145 +
146 +
147 +
148 + template<typename T> class NPT : public T{
149 +
150 + public:
151 +
152 +  NPT ( SimInfo *theInfo, ForceFields* the_ff);
153 +  virtual ~NPT();
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;}
168 +  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
169 +  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
170 +  void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;}
171 +  void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;}
172 +  void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;}
173 +
174 + protected:
175 +
176 +  virtual void  moveA( void );
177 +  virtual void moveB( void );
178 +
179 +  virtual int readyCheck();
180 +
181 +  virtual void resetIntegrator( void );
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],
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 +
193 +  virtual void evolveChiA( void );
194 +  virtual void evolveEtaA( void ) = 0;
195 +  virtual void evolveChiB( void );
196 +  virtual void evolveEtaB( void ) = 0;
197 +
198 +  virtual void scaleSimBox( void ) = 0;
199 +
200 +  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
201 +
202 +  // chi and eta are the propagated degrees of freedom
203 +
204 +  double oldChi;
205 +  double prevChi;
206 +  double chi;
207 +  double NkBT;
208 +  double fkBT;
209 +
210 +  double tt2, tb2;
211 +  double instaTemp, instaPress, instaVol;
212 +  double press[3][3];
213 +
214 +  int Nparticles;
215 +
216 +  double integralOfChidt;
217 +
218 +  // targetTemp, targetPressure, and tauBarostat must be set.
219 +  // One of qmass or tauThermostat must be set;
220 +
221 +  double targetTemp;
222 +  double targetPressure;
223 +  double tauThermostat;
224 +  double tauBarostat;
225 +
226 +  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
227 +  short int have_target_pressure;
228 +
229 +  double *oldPos;
230 +  double *oldVel;
231 +  double *oldJi;
232 +
233 +  double chiTolerance;
234 +  short int have_chi_tolerance;
235 +  double posIterTolerance;
236 +  short int have_pos_iter_tolerance;
237 +  double etaTolerance;
238 +  short int have_eta_tolerance;
239 +
240   };
241  
242 < class NVT : public Integrator{
242 > template<typename T> class NPTi : public T{
243  
244 <  NVT ( SimInfo &theInfo, ForceFields* the_ff ) :
245 <    Integrator( theInfo, the_ff );
246 <  virtual ~NVT();
244 > public:
245 >  NPTi( SimInfo *theInfo, ForceFields* the_ff);
246 >  ~NPTi();
247  
248 +  virtual double getConservedQuantity(void);
249 +  virtual void resetIntegrator(void);
250 +  virtual string getAdditionalParameters(void);
251   protected:
252 <  virtual moveA( void );
253 <  virtual moveB( void );
252 >
253 >
254 >
255 >  virtual void evolveEtaA(void);
256 >  virtual void evolveEtaB(void);
257 >
258 >  virtual bool etaConverged( void );
259 >
260 >  virtual void scaleSimBox( void );
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],
265 >                           int index, double sc[3]);
266 >
267 >  virtual void calcVelScale( void );
268 >
269 >  double eta, oldEta, prevEta;
270 >  double vScale;
271 > };
272 >
273 > template<typename T> class NPTf : public T{
274 >
275 > public:
276 >
277 >  NPTf ( SimInfo *theInfo, ForceFields* the_ff);
278 >  virtual ~NPTf();
279 >
280 >  virtual double getConservedQuantity(void);
281 >  virtual string getAdditionalParameters(void);
282 >  virtual void resetIntegrator(void);
283  
284 + protected:
285 +
286 +  virtual void evolveEtaA(void);
287 +  virtual void evolveEtaB(void);
288 +
289 +  virtual bool etaConverged( void );
290 +
291 +  virtual void scaleSimBox( void );
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],
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 NPTxyz : public T{
307 +
308 + public:
309 +
310 +  NPTxyz ( SimInfo *theInfo, ForceFields* the_ff);
311 +  virtual ~NPTxyz();
312 +
313 +  virtual double getConservedQuantity(void);
314 +  virtual string getAdditionalParameters(void);
315 +  virtual void resetIntegrator(void);
316 +
317 + protected:
318 +
319 +  virtual void evolveEtaA(void);
320 +  virtual void evolveEtaB(void);
321 +
322 +  virtual bool etaConverged( void );
323 +
324 +  virtual void scaleSimBox( void );
325 +
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 +  virtual void calcVelScale( void );
332 +
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:
343 +  class ForceSubtractionPolicy{
344 +    public:
345 +      ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
346 +
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 +
353 +   protected:
354 +     ZConstraint<T>* zconsIntegrator;
355 +  };
356 +
357 +  class PolicyByNumber : public ForceSubtractionPolicy{
358 +
359 +    public:
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 +
367 +    private:
368 +      int totNumOfMovingAtoms;
369 +  };
370 +
371 +  class PolicyByMass : public ForceSubtractionPolicy{
372 +
373 +    public:
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);
380 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
381 +
382 +   private:
383 +     double totMassOfMovingAtoms;
384 +  };
385 +
386 + public:
387 +
388 +  ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
389 +  ~ZConstraint();
390 +
391 +  void setZConsTime(double time)                  {this->zconsTime = time;}
392 +  void getZConsTime()                             {return zconsTime;}
393 +
394 +  void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
395 +  void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
396 +
397 +  void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
398 +  string getZConsOutput()                         {return zconsOutput;}
399 +
400 +  virtual void integrate();
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};
408 +
409 +  vector<Molecule*> zconsMols;              //z-constraint molecules array
410 +  vector<ZConsState> states;                 //state of z-constraint molecules
411 +
412 +
413 +
414 +  int totNumOfUnconsAtoms;              //total number of uncontraint atoms
415 +  double totalMassOfUncons;                //total mas of unconstraint molecules
416 +
417 +
418 + protected:
419 +
420 +
421 +
422 +  virtual void calcForce( int calcPot, int calcStress );
423 +  virtual void thermalize(void);
424 +
425 +  void zeroOutVel();
426 +  void doZconstraintForce();
427 +  void doHarmonic(vector<double>& resPos);
428 +  bool checkZConsState();
429 +
430 +  bool haveFixedZMols();
431 +  bool haveMovingZMols();
432 +
433 +  double calcZSys();
434 +
435 +  int isZConstraintMol(Molecule* mol);
436 +
437 +
438 +  double zconsTime;                              //sample time
439 +  double zconsTol;                                 //tolerance of z-contratint
440 +  double zForceConst;                           //base force constant term
441 +                                                          //which is estimate by OOPSE
442 +
443 +
444 +  vector<double> massOfZConsMols;       //mass of z-constraint molecule
445 +  vector<double> kz;                              //force constant array
446 +
447 +  vector<double> zPos;                          //
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 +
456 +  vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
457 +
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 +  double zconsFixTime;  
468 +  double zconsGap;
469 +  bool hasZConsGap;
470 +  vector<double> endFixTime;
471    
472 +  int whichDirection;                           //constraint direction
473  
474 + private:
475  
476 +  string zconsOutput;                         //filename of zconstraint output
477 +  ZConsWriter* fzOut;                         //z-constraint writer
478 +
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