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 466 by gezelter, Mon Apr 7 14:30:36 2003 UTC vs.
Revision 782 by mmeineke, Tue Sep 23 20:34:31 2003 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 "Molecule.hpp"
8   #include "SRI.hpp"
9   #include "AbstractClasses.hpp"
10   #include "SimInfo.hpp"
11   #include "ForceFields.hpp"
12 < #include "ExtendedSystem.hpp"
12 > #include "Thermo.hpp"
13 > #include "ReadWrite.hpp"
14 > #include "ZConsWriter.hpp"
15  
16 < class Verlet : public Integrator {
16 > using namespace std;
17 > const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K
18 > const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2
19 > const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm
20 > const int maxIteration = 300;
21 > const double tol = 1.0e-6;
22  
23 +
24 + template<typename T = BaseIntegrator> class Integrator : public T {
25 +
26   public:
27 <  Verlet( SimInfo &info, ForceFields* the_ff, ExtendedSystem* the_es );
28 <  ~Verlet();
27 >  Integrator( SimInfo *theInfo, ForceFields* the_ff );
28 >  virtual ~Integrator();
29    void integrate( void );
30 +  virtual double  getConservedQuantity(void);
31  
32 < private:
32 > protected:
33 >
34 >  virtual void integrateStep( int calcPot, int calcStress );
35 >  virtual void preMove( void );
36 >  virtual void moveA( void );
37 >  virtual void moveB( void );
38 >  virtual void constrainA( void );
39 >  virtual void constrainB( void );
40 >  virtual int  readyCheck( void ) { return 1; }
41 >
42 >  virtual void resetIntegrator( void ) { }
43 >
44 >  virtual void calcForce( int calcPot, int calcStress );  
45 >  virtual void thermalize();
46    
47 <  void move_a( double dt );
21 <  void move_b( double dt );
47 >  virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] );
48  
49 +  void checkConstraints( void );
50 +  void rotate( int axes1, int axes2, double angle, double j[3],
51 +         double A[3][3] );
52 +        
53    ForceFields* myFF;
24  ExtendedSystem* myES;
54  
55 <  SimInfo *entry_plug; // all the info we'll ever need
56 <  int c_natoms;  /* the number of atoms */
57 <  Atom **c_atoms; /* array of atom pointers */
55 >  SimInfo *info; // all the info we'll ever need
56 >  int nAtoms;  /* the number of atoms */
57 >  int oldAtoms;
58 >  Atom **atoms; /* array of atom pointers */
59    Molecule* molecules;
60    int nMols;
61  
62 <  int c_is_constrained; /*boolean to know whether the systems contains
63 <                          constraints. */
64 <  int c_n_constrained; /*counter for number of constraints */
65 <  int *c_constrained_i; /* the i of a constraint pair */
66 <  int *c_constrained_j; /* the j of a constraint pair */
67 <  double *c_constrained_dsqr; /* the square of the constraint distance */
68 <  double *c_mass; /* the array of masses */
69 <  short is_first; /*boolean for the first time integrate is called */
70 <  double c_box_x;
71 <  double c_box_y;
72 <  double c_box_z;
62 >  int isConstrained; // boolean to know whether the systems contains
63 >         // constraints.
64 >  int nConstrained;  // counter for number of constraints
65 >  int *constrainedA; // the i of a constraint pair
66 >  int *constrainedB; // the j of a constraint pair
67 >  double *constrainedDsqr; // the square of the constraint distance
68 >  
69 >  int* moving; // tells whether we are moving atom i
70 >  int* moved;  // tells whether we have moved atom i
71 >  double* oldPos; // pre constrained positions
72 >
73 >  short isFirst; /*boolean for the first time integrate is called */
74 >  
75 >  double dt;
76 >  double dt2;
77 >
78 >  Thermo *tStats;
79 >  StatWriter*  statOut;
80 >  DumpWriter*  dumpOut;
81 >  
82   };
83  
84 < class Symplectic : public Integrator {
84 > typedef Integrator<BaseIntegrator> RealIntegrator;
85 >
86 > template<typename T> class NVE : public T {
87 >
88 > public:
89 >  NVE ( SimInfo *theInfo, ForceFields* the_ff ):
90 >    T( theInfo, the_ff ){}
91 >  virtual ~NVE(){}  
92 > };
93 >
94 >
95 > template<typename T> class NVT : public T {
96 >
97 > public:
98 >
99 >  NVT ( SimInfo *theInfo, ForceFields* the_ff);
100 >  virtual ~NVT();
101 >
102 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
103 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
104 >  void setChiTolerance(double tol) {chiTolerance = tol;}
105 >  virtual double  getConservedQuantity(void);
106 >
107 > protected:
108 >
109 >  virtual void moveA( void );
110 >  virtual void moveB( void );
111 >
112 >  virtual int readyCheck();
113 >
114 >  virtual void resetIntegrator( void );
115 >
116 >  // chi is a propagated degree of freedom.
117 >
118 >  double chi;
119 >
120 >  //integral of chi(t)dt
121 >  double integralOfChidt;
122 >
123 >  // targetTemp must be set.  tauThermostat must also be set;
124 >
125 >  double targetTemp;
126 >  double tauThermostat;
127    
128 +  short int have_tau_thermostat, have_target_temp;
129 +
130 +  double *oldVel;
131 +  double *oldJi;
132 +
133 +  double chiTolerance;
134 +  short int have_chi_tolerance;
135 +
136 + };
137 +
138 +
139 +
140 + template<typename T> class NPT : public T{
141 +
142   public:
143 <  Symplectic( SimInfo* the_entry_plug,  
144 <              ForceFields* the_ff,
145 <              ExtendedSystem* the_es);
51 <  ~Symplectic();
143 >
144 >  NPT ( SimInfo *theInfo, ForceFields* the_ff);
145 >  virtual ~NPT();
146    
147 <  void integrate( void );
147 >  virtual void integrateStep( int calcPot, int calcStress ){
148 >    calcStress = 1;
149 >    T::integrateStep( calcPot, calcStress );
150 >  }
151  
152 < private:
152 >  virtual double getConservedQuantity(void) = 0;
153  
154 <  void rotate( int axes1, int axes2, double angle, double j[3],
155 <               double A[3][3] );
154 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
155 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
156 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
157 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
158 >  void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;}
159 >  void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;}
160 >  void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;}
161  
162 <  SimInfo* entry_plug;
61 <  ForceFields* myFF;
62 <  ExtendedSystem* myES;
162 > protected:
163  
164 <  Molecule* molecules;
165 <  int nMols;
164 >  virtual void  moveA( void );
165 >  virtual void moveB( void );
166  
167 <  int is_constrained; /*boolean to know whether the systems contains
68 <                          constraints. */
69 <  int n_constrained; /*counter for number of constraints */
70 <  int *constrained_i; /* the i of a constraint pair */
71 <  int *constrained_j; /* the j of a constraint pair */
72 <  double *constrained_dsqr; /* the square of the constraint distance */
73 <  double *mass; /* the array of masses */
167 >  virtual int readyCheck();
168  
169 <  short int isFirst;
169 >  virtual void resetIntegrator( void );
170  
171 <  SRI **srInteractions; /* array of SRI pointers */
172 <  int nSRI; /* the number of short range interactions */
171 >  virtual void getVelScaleA( double sc[3], double vel[3] ) = 0;
172 >  virtual void getVelScaleB( double sc[3], int index ) = 0;
173 >  virtual void getPosScale(double pos[3], double COM[3],
174 >                           int index, double sc[3]) = 0;
175 >
176 >  virtual bool chiConverged( void );
177 >  virtual bool etaConverged( void ) = 0;
178    
179 +  virtual void evolveChiA( void );
180 +  virtual void evolveEtaA( void ) = 0;
181 +  virtual void evolveChiB( void );
182 +  virtual void evolveEtaB( void ) = 0;
183 +
184 +  virtual void scaleSimBox( void ) = 0;
185 +
186 +  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
187 +
188 +  // chi and eta are the propagated degrees of freedom
189 +
190 +  double oldChi;
191 +  double prevChi;
192 +  double chi;
193 +  double NkBT;
194 +  double fkBT;
195 +
196 +  double tt2, tb2;
197 +  double instaTemp, instaPress, instaVol;
198 +  double press[3][3];
199 +
200 +  int Nparticles;
201 +
202 +  double integralOfChidt;
203 +
204 +  // targetTemp, targetPressure, and tauBarostat must be set.  
205 +  // One of qmass or tauThermostat must be set;
206 +
207 +  double targetTemp;
208 +  double targetPressure;
209 +  double tauThermostat;
210 +  double tauBarostat;
211 +
212 +  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
213 +  short int have_target_pressure;
214 +
215 +  double *oldPos;
216 +  double *oldVel;
217 +  double *oldJi;
218 +
219 +  double chiTolerance;
220 +  short int have_chi_tolerance;
221 +  double posIterTolerance;
222 +  short int have_pos_iter_tolerance;
223 +  double etaTolerance;
224 +  short int have_eta_tolerance;
225 +
226   };
227  
228 + template<typename T> class NPTi : public T{
229 +  
230 + public:
231 +  NPTi( SimInfo *theInfo, ForceFields* the_ff);
232 +  ~NPTi();
233 +
234 +  virtual double getConservedQuantity(void);
235 +  virtual void resetIntegrator(void);
236 +
237 + protected:
238 +
239 +
240 +
241 +  virtual void evolveEtaA(void);
242 +  virtual void evolveEtaB(void);
243 +
244 +  virtual bool etaConverged( void );
245 +
246 +  virtual void scaleSimBox( void );
247 +
248 +  virtual void getVelScaleA( double sc[3], double vel[3] );
249 +  virtual void getVelScaleB( double sc[3], int index );
250 +  virtual void getPosScale(double pos[3], double COM[3],
251 +                           int index, double sc[3]);
252 +
253 +  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:
274 +
275 +  virtual void moveA( void );
276 +  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 +
303 + };
304 +
305 + template<typename T> class NPTf : public T{
306 +
307 + public:
308 +
309 +  NPTf ( SimInfo *theInfo, ForceFields* the_ff);
310 +  virtual ~NPTf();
311 +
312 +  virtual double getConservedQuantity(void);
313 +  virtual void resetIntegrator(void);
314 +
315 + protected:
316 +
317 +  virtual void evolveEtaA(void);
318 +  virtual void evolveEtaB(void);
319 +
320 +  virtual bool etaConverged( void );
321 +
322 +  virtual void scaleSimBox( void );
323 +
324 +  virtual void getVelScaleA( double sc[3], double vel[3] );
325 +  virtual void getVelScaleB( double sc[3], int index );
326 +  virtual void getPosScale(double pos[3], double COM[3],
327 +                           int index, double sc[3]);
328 +
329 +  double eta[3][3];
330 +  double oldEta[3][3];
331 +  double prevEta[3][3];
332 + };
333 +
334 + template<typename T> class NPTxym : public T{
335 +
336 + public:
337 +
338 +  NPTxym ( SimInfo *theInfo, ForceFields* the_ff);
339 +  virtual ~NPTxym() {};
340 +
341 +  virtual void integrateStep( int calcPot, int calcStress ){
342 +    calcStress = 1;
343 +    T::integrateStep( calcPot, calcStress );
344 +  }
345 +
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 +
351 + protected:
352 +
353 +  virtual void moveA( void );
354 +  virtual void moveB( void );
355 +
356 +  virtual int readyCheck();
357 +
358 +  virtual void resetIntegrator( void );
359 +
360 +  Molecule* myMolecules;
361 +  Atom** myAtoms;
362 +
363 +  // 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;
370 +
371 +  // targetTemp, targetPressure, and tauBarostat must be set.  
372 +  // One of qmass or tauThermostat must be set;
373 +
374 +  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 +
382 + };
383 +
384 + template<typename T> class ZConstraint : public T {
385 +  
386 +  public:
387 +  class ForceSubtractionPolicy{
388 +    public:
389 +      ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
390 +
391 +      virtual void update() = 0;    
392 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
393 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
394 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
395 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
396 +    
397 +   protected:
398 +     ZConstraint<T>* zconsIntegrator;;
399 +  };
400 +
401 +  class PolicyByNumber : public ForceSubtractionPolicy{
402 +
403 +    public:
404 +      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}    
405 +      virtual void update();    
406 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
407 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
408 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
409 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
410 +    
411 +    private:
412 +      int totNumOfMovingAtoms;
413 +  };
414 +
415 +  class PolicyByMass : public ForceSubtractionPolicy{
416 +
417 +    public:
418 +      PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}  
419 +      
420 +      virtual void update();    
421 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
422 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
423 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
424 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
425 +
426 +   private:
427 +     double totMassOfMovingAtoms;
428 +  };
429 +
430 + public:
431 +
432 +  ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
433 +  ~ZConstraint();
434 +    
435 +  void setZConsTime(double time)                  {this->zconsTime = time;}
436 +  void getZConsTime()                             {return zconsTime;}
437 +  
438 +  void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
439 +  void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
440 +  
441 +  void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
442 +  string getZConsOutput()                         {return zconsOutput;}
443 +  
444 +  virtual void integrate();
445 +  
446 +
447 + #ifdef IS_MPI
448 +  virtual void update();                      //which is called to indicate the molecules' migration
449   #endif
450 +
451 + protected:
452 +
453 +  enum ZConsState {zcsMoving, zcsFixed};  
454 +
455 +  virtual void calcForce( int calcPot, int calcStress );
456 +  virtual void thermalize(void);
457 +  
458 +  void zeroOutVel();
459 +  void doZconstraintForce();
460 +  void doHarmonic();
461 +  bool checkZConsState();
462 +
463 +  bool haveFixedZMols();
464 +  bool haveMovingZMols();
465 +
466 +  double calcZSys();
467 +
468 +  int isZConstraintMol(Molecule* mol);
469 +
470 +
471 +  double zconsTime;                              //sample time
472 +  double zconsTol;                                 //tolerance of z-contratint
473 +  double zForceConst;                           //base force constant term
474 +                                                          //which is estimate by OOPSE
475 +  
476 +  vector<Molecule*> zconsMols;              //z-constraint molecules array
477 +  vector<double> massOfZConsMols;       //mass of z-constraint molecule
478 +  vector<double> kz;                              //force constant array
479 +  vector<ZConsState> states;                 //state of z-constraint molecules
480 +  vector<double> zPos;                          //
481 +  
482 +  
483 +  vector<Molecule*> unconsMols;           //unconstraint molecules array
484 +  vector<double> massOfUnconsMols;    //mass array of unconstraint molecules
485 +  double totalMassOfUncons;                //total mas of unconstraint molecules
486 +
487 +  vector<ZConsParaItem>* parameters; //
488 +  
489 +  vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
490 +
491 +  int* indexOfZConsMols;                   //index of local Z-Constraint Molecules  
492 +  double* fz;
493 +  double* curZPos;
494 +  
495 +  int totNumOfUnconsAtoms;              //total number of uncontraint atoms
496 +
497 +  int whichDirection;                           //constraint direction
498 +  
499 + private:
500 +  
501 +  string zconsOutput;                         //filename of zconstraint output
502 +  ZConsWriter* fzOut;                         //z-constraint writer
503 +
504 +  double curZconsTime;                      
505 +
506 +  double calcMovingMolsCOMVel();
507 +  double calcSysCOMVel();
508 +  double calcTotalForce();
509 +  
510 +  ForceSubtractionPolicy* forcePolicy; //force subtraction policy
511 +  friend class ForceSubtractionPolicy;
512 +
513 + };
514 +
515 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines