ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 780
Committed: Mon Sep 22 21:23:25 2003 UTC (20 years, 9 months ago) by mmeineke
File size: 16946 byte(s)
Log Message:
Converted NPTf to work with the NPT base class.

Removed NPTfm and NPTim from cvs

File Contents

# User Rev Content
1 mmeineke 377 #ifndef _INTEGRATOR_H_
2     #define _INTEGRATOR_H_
3    
4 tim 658 #include <string>
5     #include <vector>
6 mmeineke 377 #include "Atom.hpp"
7 gezelter 604 #include "Molecule.hpp"
8 mmeineke 377 #include "SRI.hpp"
9     #include "AbstractClasses.hpp"
10     #include "SimInfo.hpp"
11     #include "ForceFields.hpp"
12 mmeineke 540 #include "Thermo.hpp"
13     #include "ReadWrite.hpp"
14 tim 658 #include "ZConsWriter.hpp"
15 mmeineke 377
16 tim 658 using namespace std;
17 mmeineke 561 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 mmeineke 586 const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm
20 mmeineke 561 const int maxIteration = 300;
21     const double tol = 1.0e-6;
22    
23 mmeineke 377
24 tim 645 template<typename T = BaseIntegrator> class Integrator : public T {
25    
26 mmeineke 377 public:
27 mmeineke 561 Integrator( SimInfo *theInfo, ForceFields* the_ff );
28 mmeineke 548 virtual ~Integrator();
29 mmeineke 377 void integrate( void );
30 tim 763 virtual double getConservedQuantity(void);
31 mmeineke 377
32 mmeineke 540 protected:
33 mmeineke 778
34 mmeineke 540 virtual void integrateStep( int calcPot, int calcStress );
35 mmeineke 548 virtual void preMove( void );
36 mmeineke 540 virtual void moveA( void );
37     virtual void moveB( void );
38     virtual void constrainA( void );
39     virtual void constrainB( void );
40 mmeineke 559 virtual int readyCheck( void ) { return 1; }
41 tim 677
42 mmeineke 746 virtual void resetIntegrator( void ) { }
43 tim 763
44 tim 677 virtual void calcForce( int calcPot, int calcStress );
45     virtual void thermalize();
46 mmeineke 377
47 mmeineke 778 virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] );
48    
49 mmeineke 540 void checkConstraints( void );
50 mmeineke 377 void rotate( int axes1, int axes2, double angle, double j[3],
51 tim 701 double A[3][3] );
52    
53 mmeineke 377 ForceFields* myFF;
54    
55 mmeineke 540 SimInfo *info; // all the info we'll ever need
56     int nAtoms; /* the number of atoms */
57 mmeineke 548 int oldAtoms;
58 mmeineke 540 Atom **atoms; /* array of atom pointers */
59 mmeineke 423 Molecule* molecules;
60     int nMols;
61    
62 mmeineke 548 int isConstrained; // boolean to know whether the systems contains
63 tim 701 // constraints.
64 mmeineke 548 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 mmeineke 561 double* oldPos; // pre constrained positions
72 mmeineke 548
73 mmeineke 540 short isFirst; /*boolean for the first time integrate is called */
74    
75     double dt;
76 mmeineke 541 double dt2;
77 gezelter 560
78 mmeineke 540 Thermo *tStats;
79     StatWriter* statOut;
80     DumpWriter* dumpOut;
81 mmeineke 377
82     };
83    
84 tim 645 typedef Integrator<BaseIntegrator> RealIntegrator;
85 mmeineke 540
86 tim 645 template<typename T> class NVE : public T {
87    
88 mmeineke 561 public:
89     NVE ( SimInfo *theInfo, ForceFields* the_ff ):
90 tim 645 T( theInfo, the_ff ){}
91     virtual ~NVE(){}
92     };
93 mmeineke 555
94    
95 tim 645 template<typename T> class NVT : public T {
96 mmeineke 555
97 gezelter 560 public:
98    
99 mmeineke 561 NVT ( SimInfo *theInfo, ForceFields* the_ff);
100 tim 763 virtual ~NVT();
101 mmeineke 540
102 gezelter 560 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
103     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
104 tim 763 void setChiTolerance(double tol) {chiTolerance = tol;}
105     virtual double getConservedQuantity(void);
106 gezelter 560
107 mmeineke 540 protected:
108 gezelter 560
109 mmeineke 561 virtual void moveA( void );
110     virtual void moveB( void );
111 mmeineke 540
112 mmeineke 561 virtual int readyCheck();
113 gezelter 560
114 mmeineke 746 virtual void resetIntegrator( void );
115    
116 gezelter 565 // chi is a propagated degree of freedom.
117 gezelter 560
118 gezelter 565 double chi;
119 gezelter 560
120 tim 763 //integral of chi(t)dt
121     double integralOfChidt;
122    
123 gezelter 565 // targetTemp must be set. tauThermostat must also be set;
124 gezelter 560
125     double targetTemp;
126     double tauThermostat;
127 mmeineke 561
128 gezelter 565 short int have_tau_thermostat, have_target_temp;
129 gezelter 560
130 tim 763 double *oldVel;
131     double *oldJi;
132    
133     double chiTolerance;
134     short int have_chi_tolerance;
135    
136 mmeineke 540 };
137    
138    
139    
140 mmeineke 778 template<typename T> class NPT : public T{
141 tim 645
142 gezelter 560 public:
143    
144 mmeineke 778 NPT ( SimInfo *theInfo, ForceFields* the_ff);
145     virtual ~NPT();
146 tim 763
147 mmeineke 594 virtual void integrateStep( int calcPot, int calcStress ){
148     calcStress = 1;
149 tim 645 T::integrateStep( calcPot, calcStress );
150 mmeineke 594 }
151    
152 mmeineke 778 virtual double getConservedQuantity(void) = 0;
153 tim 763
154 gezelter 560 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 tim 763 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 gezelter 560
162     protected:
163    
164 mmeineke 561 virtual void moveA( void );
165     virtual void moveB( void );
166 gezelter 560
167 mmeineke 561 virtual int readyCheck();
168 gezelter 560
169 mmeineke 746 virtual void resetIntegrator( void );
170    
171 mmeineke 778 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 tim 763 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
187    
188 gezelter 565 // chi and eta are the propagated degrees of freedom
189 gezelter 560
190 mmeineke 778 double oldChi;
191     double prevChi;
192 gezelter 565 double chi;
193 gezelter 574 double NkBT;
194 tim 763 double fkBT;
195 gezelter 560
196 mmeineke 778 double tt2, tb2;
197     double instaTemp, instaPress, instaVol;
198 mmeineke 780 double press[3][3];
199 mmeineke 778
200 tim 763 int Nparticles;
201    
202     double integralOfChidt;
203    
204 gezelter 560 // 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 gezelter 565 short int have_target_pressure;
214 gezelter 560
215 tim 763 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 gezelter 560 };
227    
228 mmeineke 778 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 mmeineke 755 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 tim 645 template<typename T> class NPTf : public T{
306 gezelter 576
307     public:
308    
309     NPTf ( SimInfo *theInfo, ForceFields* the_ff);
310 tim 767 virtual ~NPTf();
311 gezelter 576
312 tim 763 virtual double getConservedQuantity(void);
313 mmeineke 780 virtual void resetIntegrator(void);
314 mmeineke 594
315 gezelter 576 protected:
316    
317 mmeineke 780 virtual void evolveEtaA(void);
318     virtual void evolveEtaB(void);
319 gezelter 576
320 mmeineke 780 virtual bool etaConverged( void );
321 mmeineke 746
322 mmeineke 780 virtual void scaleSimBox( void );
323 gezelter 576
324 mmeineke 780 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 tim 763
329 gezelter 588 double eta[3][3];
330 mmeineke 780 double oldEta[3][3];
331     double prevEta[3][3];
332 gezelter 576 };
333    
334 mmeineke 755 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    
385 tim 645 template<typename T> class NPTfm : public T{
386 gezelter 596
387     public:
388    
389     NPTfm ( SimInfo *theInfo, ForceFields* the_ff);
390     virtual ~NPTfm() {};
391    
392     virtual void integrateStep( int calcPot, int calcStress ){
393     calcStress = 1;
394 tim 645 T::integrateStep( calcPot, calcStress );
395 tim 763 accIntegralOfChidt();
396 gezelter 596 }
397    
398 tim 763 virtual double getConservedQuantity(void);
399    
400 gezelter 596 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
401     void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
402     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
403     void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
404 tim 763 void setChiTolerance(double tol) {chiTolerance = tol;}
405     void setPosIterTolerance(double tol) {posIterTolerance = tol;}
406 gezelter 596
407     protected:
408    
409     virtual void moveA( void );
410     virtual void moveB( void );
411    
412 mmeineke 746 virtual void resetIntegrator( void );
413    
414 gezelter 596 virtual int readyCheck();
415    
416 tim 763 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
417    
418 gezelter 605 Molecule* myMolecules;
419     Atom** myAtoms;
420    
421 gezelter 596 // chi and eta are the propagated degrees of freedom
422    
423     double chi;
424     double eta[3][3];
425     double NkBT;
426 tim 763 double integralOfChidt;
427 gezelter 596
428     // targetTemp, targetPressure, and tauBarostat must be set.
429     // One of qmass or tauThermostat must be set;
430    
431     double targetTemp;
432     double targetPressure;
433     double tauThermostat;
434     double tauBarostat;
435    
436     short int have_tau_thermostat, have_tau_barostat, have_target_temp;
437     short int have_target_pressure;
438 tim 763 double chiTolerance;
439     short int have_chi_tolerance;
440     double posIterTolerance;
441     short int have_pos_iter_tolerance;
442 gezelter 596
443     };
444    
445 gezelter 718
446     template<typename T> class NPTpr : public T{
447    
448     public:
449    
450     NPTpr ( SimInfo *theInfo, ForceFields* the_ff);
451     virtual ~NPTpr() {};
452    
453     virtual void integrateStep( int calcPot, int calcStress ){
454     calcStress = 1;
455     T::integrateStep( calcPot, calcStress );
456     }
457    
458     void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
459     void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
460     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
461     void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
462 tim 763 void setChiTolerance(double tol) {chiTolerance = tol;}
463     void setPosIterTolerance(double tol) {posIterTolerance = tol;}
464 gezelter 718
465     protected:
466    
467     virtual void moveA( void );
468     virtual void moveB( void );
469    
470     virtual int readyCheck();
471    
472 mmeineke 746 virtual void resetIntegrator( void );
473    
474 gezelter 718 // chi and eta are the propagated degrees of freedom
475    
476     double chi;
477     double eta[3][3];
478     double NkBT;
479    
480     // targetTemp, targetPressure, and tauBarostat must be set.
481     // One of qmass or tauThermostat must be set;
482    
483     double targetTemp;
484     double targetPressure;
485     double tauThermostat;
486     double tauBarostat;
487    
488     short int have_tau_thermostat, have_tau_barostat, have_target_temp;
489     short int have_target_pressure;
490 tim 763 double chiTolerance;
491     short int have_chi_tolerance;
492     double posIterTolerance;
493     short int have_pos_iter_tolerance;
494 gezelter 718
495     };
496    
497    
498 tim 658 template<typename T> class ZConstraint : public T {
499 tim 701
500     public:
501 tim 738 class ForceSubtractionPolicy{
502 tim 699 public:
503 tim 738 ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
504 tim 658
505 tim 701 virtual void update() = 0;
506 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
507     virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
508 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
509     virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
510    
511     protected:
512     ZConstraint<T>* zconsIntegrator;;
513 tim 699 };
514    
515 tim 738 class PolicyByNumber : public ForceSubtractionPolicy{
516 gezelter 747
517 tim 699 public:
518 tim 738 PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
519 tim 701 virtual void update();
520 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
521     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
522 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
523     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
524    
525 tim 699 private:
526 tim 763 int totNumOfMovingAtoms;
527 tim 699 };
528    
529 tim 738 class PolicyByMass : public ForceSubtractionPolicy{
530 gezelter 747
531 tim 699 public:
532 tim 738 PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
533 tim 701
534     virtual void update();
535 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
536     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
537 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
538     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
539 tim 699
540 tim 701 private:
541     double totMassOfMovingAtoms;
542 tim 699 };
543    
544 tim 658 public:
545    
546     ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
547     ~ZConstraint();
548 tim 677
549 tim 658 void setZConsTime(double time) {this->zconsTime = time;}
550     void getZConsTime() {return zconsTime;}
551    
552 tim 701 void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
553     void getIndexOfAllZConsMols() {return indexOfAllZConsMols;}
554 tim 658
555 tim 701 void setZConsOutput(const char * fileName) {zconsOutput = fileName;}
556 tim 658 string getZConsOutput() {return zconsOutput;}
557 tim 677
558     virtual void integrate();
559    
560 tim 658
561     #ifdef IS_MPI
562 tim 701 virtual void update(); //which is called to indicate the molecules' migration
563 mmeineke 377 #endif
564 tim 658
565     protected:
566    
567 tim 701 enum ZConsState {zcsMoving, zcsFixed};
568 tim 677
569     virtual void calcForce( int calcPot, int calcStress );
570     virtual void thermalize(void);
571    
572     void zeroOutVel();
573     void doZconstraintForce();
574 tim 682 void doHarmonic();
575 tim 677 bool checkZConsState();
576    
577     bool haveFixedZMols();
578     bool haveMovingZMols();
579    
580     double calcZSys();
581    
582     int isZConstraintMol(Molecule* mol);
583    
584    
585 tim 701 double zconsTime; //sample time
586     double zconsTol; //tolerance of z-contratint
587     double zForceConst; //base force constant term
588     //which is estimate by OOPSE
589 tim 658
590 tim 701 vector<Molecule*> zconsMols; //z-constraint molecules array
591     vector<double> massOfZConsMols; //mass of z-constraint molecule
592     vector<double> kz; //force constant array
593     vector<ZConsState> states; //state of z-constraint molecules
594     vector<double> zPos; //
595 tim 658
596 tim 677
597 tim 701 vector<Molecule*> unconsMols; //unconstraint molecules array
598     vector<double> massOfUnconsMols; //mass array of unconstraint molecules
599     double totalMassOfUncons; //total mas of unconstraint molecules
600 tim 682
601 tim 701 vector<ZConsParaItem>* parameters; //
602 tim 658
603     vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels
604 tim 677
605     int* indexOfZConsMols; //index of local Z-Constraint Molecules
606 tim 658 double* fz;
607 tim 699 double* curZPos;
608 tim 658
609 tim 701 int totNumOfUnconsAtoms; //total number of uncontraint atoms
610 tim 677
611     int whichDirection; //constraint direction
612    
613 tim 658 private:
614 tim 677
615 tim 701 string zconsOutput; //filename of zconstraint output
616     ZConsWriter* fzOut; //z-constraint writer
617 tim 677
618 tim 701 double curZconsTime;
619 tim 699
620 tim 696 double calcMovingMolsCOMVel();
621     double calcSysCOMVel();
622     double calcTotalForce();
623 tim 701
624 gezelter 747 ForceSubtractionPolicy* forcePolicy; //force subtraction policy
625 tim 738 friend class ForceSubtractionPolicy;
626 tim 677
627 tim 658 };
628    
629     #endif