ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 1161
Committed: Tue May 11 21:44:05 2004 UTC (20 years, 4 months ago) by tim
File size: 14356 byte(s)
Log Message:
adding instantiation of Integrator<BaseIntegrator> in order to make OOPSE compiled by icc8

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 1097 #include "StuntDouble.hpp"
8 gezelter 604 #include "Molecule.hpp"
9 mmeineke 377 #include "SRI.hpp"
10     #include "AbstractClasses.hpp"
11     #include "SimInfo.hpp"
12     #include "ForceFields.hpp"
13 mmeineke 540 #include "Thermo.hpp"
14     #include "ReadWrite.hpp"
15 tim 658 #include "ZConsWriter.hpp"
16 mmeineke 377
17 tim 658 using namespace std;
18 mmeineke 561 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 mmeineke 586 const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm
21 mmeineke 561 const int maxIteration = 300;
22     const double tol = 1.0e-6;
23    
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 tim 837 virtual string getAdditionalParameters(void);
32 mmeineke 377
33 mmeineke 540 protected:
34 mmeineke 778
35 mmeineke 540 virtual void integrateStep( int calcPot, int calcStress );
36 mmeineke 548 virtual void preMove( void );
37 mmeineke 540 virtual void moveA( void );
38     virtual void moveB( void );
39     virtual void constrainA( void );
40     virtual void constrainB( void );
41 mmeineke 559 virtual int readyCheck( void ) { return 1; }
42 tim 677
43 mmeineke 746 virtual void resetIntegrator( void ) { }
44 tim 837
45     virtual void calcForce( int calcPot, int calcStress );
46 tim 677 virtual void thermalize();
47 tim 837
48 tim 1108 virtual bool stopIntegrator() {return false;}
49    
50 gezelter 1097 virtual void rotationPropagation( StuntDouble* sd, double ji[3] );
51 mmeineke 778
52 mmeineke 540 void checkConstraints( void );
53 tim 837 void rotate( int axes1, int axes2, double angle, double j[3],
54 tim 701 double A[3][3] );
55 tim 837
56 mmeineke 377 ForceFields* myFF;
57    
58 mmeineke 540 SimInfo *info; // all the info we'll ever need
59 gezelter 1097 vector<StuntDouble*> integrableObjects;
60 mmeineke 540 int nAtoms; /* the number of atoms */
61 mmeineke 548 int oldAtoms;
62 mmeineke 540 Atom **atoms; /* array of atom pointers */
63 mmeineke 423 Molecule* molecules;
64     int nMols;
65    
66 mmeineke 548 int isConstrained; // boolean to know whether the systems contains
67 tim 701 // constraints.
68 tim 837 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 mmeineke 548 int* moving; // tells whether we are moving atom i
74     int* moved; // tells whether we have moved atom i
75 tim 837 double* oldPos; // pre constrained positions
76 mmeineke 548
77 mmeineke 540 short isFirst; /*boolean for the first time integrate is called */
78 tim 837
79 mmeineke 540 double dt;
80 mmeineke 541 double dt2;
81 gezelter 560
82 mmeineke 540 Thermo *tStats;
83     StatWriter* statOut;
84     DumpWriter* dumpOut;
85 tim 837
86 mmeineke 377 };
87    
88 tim 645 typedef Integrator<BaseIntegrator> RealIntegrator;
89 mmeineke 540
90 tim 1161 // ansi instantiation
91     template class Integrator<BaseIntegrator>;
92    
93 tim 645 template<typename T> class NVE : public T {
94    
95 mmeineke 561 public:
96     NVE ( SimInfo *theInfo, ForceFields* the_ff ):
97 tim 645 T( theInfo, the_ff ){}
98 tim 837 virtual ~NVE(){}
99 tim 645 };
100 mmeineke 555
101    
102 tim 645 template<typename T> class NVT : public T {
103 mmeineke 555
104 gezelter 560 public:
105    
106 mmeineke 561 NVT ( SimInfo *theInfo, ForceFields* the_ff);
107 tim 763 virtual ~NVT();
108 mmeineke 540
109 gezelter 560 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
110     void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
111 tim 763 void setChiTolerance(double tol) {chiTolerance = tol;}
112     virtual double getConservedQuantity(void);
113 tim 837 virtual string getAdditionalParameters(void);
114 gezelter 560
115 mmeineke 540 protected:
116 gezelter 560
117 mmeineke 561 virtual void moveA( void );
118     virtual void moveB( void );
119 mmeineke 540
120 mmeineke 561 virtual int readyCheck();
121 gezelter 560
122 mmeineke 746 virtual void resetIntegrator( void );
123    
124 gezelter 565 // chi is a propagated degree of freedom.
125 gezelter 560
126 gezelter 565 double chi;
127 gezelter 560
128 tim 763 //integral of chi(t)dt
129     double integralOfChidt;
130    
131 gezelter 565 // targetTemp must be set. tauThermostat must also be set;
132 gezelter 560
133     double targetTemp;
134     double tauThermostat;
135 tim 837
136 gezelter 565 short int have_tau_thermostat, have_target_temp;
137 gezelter 560
138 tim 763 double *oldVel;
139     double *oldJi;
140    
141     double chiTolerance;
142     short int have_chi_tolerance;
143    
144 mmeineke 540 };
145    
146    
147    
148 mmeineke 778 template<typename T> class NPT : public T{
149 tim 645
150 gezelter 560 public:
151    
152 mmeineke 778 NPT ( SimInfo *theInfo, ForceFields* the_ff);
153     virtual ~NPT();
154 tim 837
155 mmeineke 594 virtual void integrateStep( int calcPot, int calcStress ){
156     calcStress = 1;
157 tim 645 T::integrateStep( calcPot, calcStress );
158 mmeineke 594 }
159    
160 mmeineke 778 virtual double getConservedQuantity(void) = 0;
161 tim 837 virtual string getAdditionalParameters(void) = 0;
162 mmeineke 843
163     double myTauThermo( void ) { return tauThermostat; }
164     double myTauBaro( void ) { return tauBarostat; }
165    
166 gezelter 560 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 tim 763 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 gezelter 560
174     protected:
175    
176 mmeineke 561 virtual void moveA( void );
177     virtual void moveB( void );
178 gezelter 560
179 mmeineke 561 virtual int readyCheck();
180 gezelter 560
181 mmeineke 746 virtual void resetIntegrator( void );
182    
183 mmeineke 778 virtual void getVelScaleA( double sc[3], double vel[3] ) = 0;
184     virtual void getVelScaleB( double sc[3], int index ) = 0;
185 tim 837 virtual void getPosScale(double pos[3], double COM[3],
186 mmeineke 778 int index, double sc[3]) = 0;
187    
188 mmeineke 857 virtual void calcVelScale( void ) = 0;
189    
190 mmeineke 778 virtual bool chiConverged( void );
191     virtual bool etaConverged( void ) = 0;
192 tim 837
193 mmeineke 778 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 tim 763 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
201    
202 gezelter 565 // chi and eta are the propagated degrees of freedom
203 gezelter 560
204 mmeineke 778 double oldChi;
205     double prevChi;
206 gezelter 565 double chi;
207 gezelter 574 double NkBT;
208 tim 763 double fkBT;
209 gezelter 560
210 mmeineke 778 double tt2, tb2;
211     double instaTemp, instaPress, instaVol;
212 mmeineke 780 double press[3][3];
213 mmeineke 778
214 tim 763 int Nparticles;
215    
216     double integralOfChidt;
217    
218 tim 837 // targetTemp, targetPressure, and tauBarostat must be set.
219 gezelter 560 // 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 gezelter 565 short int have_target_pressure;
228 gezelter 560
229 tim 763 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 gezelter 560 };
241    
242 mmeineke 778 template<typename T> class NPTi : public T{
243 tim 837
244 mmeineke 778 public:
245     NPTi( SimInfo *theInfo, ForceFields* the_ff);
246     ~NPTi();
247    
248     virtual double getConservedQuantity(void);
249     virtual void resetIntegrator(void);
250 tim 837 virtual string getAdditionalParameters(void);
251 mmeineke 778 protected:
252    
253    
254 tim 837
255 mmeineke 778 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 tim 837 virtual void getPosScale(double pos[3], double COM[3],
265 mmeineke 778 int index, double sc[3]);
266    
267 mmeineke 857 virtual void calcVelScale( void );
268    
269 mmeineke 778 double eta, oldEta, prevEta;
270 mmeineke 857 double vScale;
271 mmeineke 778 };
272    
273 tim 645 template<typename T> class NPTf : public T{
274 gezelter 576
275     public:
276    
277     NPTf ( SimInfo *theInfo, ForceFields* the_ff);
278 tim 767 virtual ~NPTf();
279 gezelter 576
280 tim 763 virtual double getConservedQuantity(void);
281 tim 837 virtual string getAdditionalParameters(void);
282 mmeineke 780 virtual void resetIntegrator(void);
283 mmeineke 594
284 gezelter 576 protected:
285    
286 mmeineke 780 virtual void evolveEtaA(void);
287     virtual void evolveEtaB(void);
288 gezelter 576
289 mmeineke 780 virtual bool etaConverged( void );
290 mmeineke 746
291 mmeineke 780 virtual void scaleSimBox( void );
292 gezelter 576
293 mmeineke 780 virtual void getVelScaleA( double sc[3], double vel[3] );
294     virtual void getVelScaleB( double sc[3], int index );
295 tim 837 virtual void getPosScale(double pos[3], double COM[3],
296 mmeineke 780 int index, double sc[3]);
297 tim 763
298 mmeineke 857 virtual void calcVelScale( void );
299    
300 gezelter 588 double eta[3][3];
301 mmeineke 780 double oldEta[3][3];
302     double prevEta[3][3];
303 mmeineke 857 double vScale[3][3];
304 gezelter 576 };
305    
306 mmeineke 812 template<typename T> class NPTxyz : public T{
307 mmeineke 755
308     public:
309    
310 mmeineke 812 NPTxyz ( SimInfo *theInfo, ForceFields* the_ff);
311     virtual ~NPTxyz();
312 mmeineke 755
313 mmeineke 812 virtual double getConservedQuantity(void);
314 tim 837 virtual string getAdditionalParameters(void);
315 mmeineke 812 virtual void resetIntegrator(void);
316 mmeineke 755
317     protected:
318    
319 mmeineke 812 virtual void evolveEtaA(void);
320     virtual void evolveEtaB(void);
321 mmeineke 755
322 mmeineke 812 virtual bool etaConverged( void );
323 mmeineke 755
324 mmeineke 812 virtual void scaleSimBox( void );
325 mmeineke 755
326 mmeineke 812 virtual void getVelScaleA( double sc[3], double vel[3] );
327     virtual void getVelScaleB( double sc[3], int index );
328 tim 837 virtual void getPosScale(double pos[3], double COM[3],
329 mmeineke 812 int index, double sc[3]);
330 mmeineke 755
331 mmeineke 857 virtual void calcVelScale( void );
332    
333 mmeineke 812 double eta[3][3];
334     double oldEta[3][3];
335     double prevEta[3][3];
336 mmeineke 857 double vScale[3][3];
337 mmeineke 812 };
338 mmeineke 755
339    
340 tim 658 template<typename T> class ZConstraint : public T {
341 tim 837
342     public:
343 tim 738 class ForceSubtractionPolicy{
344 tim 699 public:
345 tim 738 ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
346 tim 658
347 tim 837 virtual void update() = 0;
348 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
349     virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
350 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
351     virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
352 tim 837
353 tim 701 protected:
354 mmeineke 788 ZConstraint<T>* zconsIntegrator;
355 tim 699 };
356    
357 tim 738 class PolicyByNumber : public ForceSubtractionPolicy{
358 gezelter 747
359 tim 699 public:
360 tim 837 PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
361     virtual void update();
362 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
363     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
364 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
365     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
366 tim 837
367 tim 699 private:
368 tim 763 int totNumOfMovingAtoms;
369 tim 699 };
370    
371 tim 738 class PolicyByMass : public ForceSubtractionPolicy{
372 gezelter 747
373 tim 699 public:
374 tim 837 PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
375    
376     virtual void update();
377 tim 699 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
378     virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
379 tim 701 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
380     virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
381 tim 699
382 tim 701 private:
383     double totMassOfMovingAtoms;
384 tim 699 };
385    
386 tim 658 public:
387    
388     ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
389     ~ZConstraint();
390 tim 837
391 tim 658 void setZConsTime(double time) {this->zconsTime = time;}
392     void getZConsTime() {return zconsTime;}
393 tim 837
394 tim 701 void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
395     void getIndexOfAllZConsMols() {return indexOfAllZConsMols;}
396 tim 837
397 tim 701 void setZConsOutput(const char * fileName) {zconsOutput = fileName;}
398 tim 658 string getZConsOutput() {return zconsOutput;}
399 tim 837
400 tim 677 virtual void integrate();
401 tim 658
402 tim 837
403 tim 658 #ifdef IS_MPI
404 tim 701 virtual void update(); //which is called to indicate the molecules' migration
405 mmeineke 377 #endif
406 tim 658
407 tim 837 enum ZConsState {zcsMoving, zcsFixed};
408 mmeineke 790
409     vector<Molecule*> zconsMols; //z-constraint molecules array
410     vector<ZConsState> states; //state of z-constraint molecules
411    
412    
413 tim 837
414 mmeineke 790 int totNumOfUnconsAtoms; //total number of uncontraint atoms
415     double totalMassOfUncons; //total mas of unconstraint molecules
416    
417    
418 tim 658 protected:
419    
420 mmeineke 790
421 tim 837
422     virtual void calcForce( int calcPot, int calcStress );
423 tim 677 virtual void thermalize(void);
424 tim 837
425 tim 677 void zeroOutVel();
426     void doZconstraintForce();
427 tim 1093 void doHarmonic(vector<double>& resPos);
428 tim 677 bool checkZConsState();
429    
430     bool haveFixedZMols();
431     bool haveMovingZMols();
432    
433     double calcZSys();
434    
435     int isZConstraintMol(Molecule* mol);
436    
437    
438 tim 701 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 mmeineke 790
443 tim 837
444     vector<double> massOfZConsMols; //mass of z-constraint molecule
445 tim 701 vector<double> kz; //force constant array
446 mmeineke 790
447 tim 701 vector<double> zPos; //
448 tim 837
449    
450 tim 701 vector<Molecule*> unconsMols; //unconstraint molecules array
451     vector<double> massOfUnconsMols; //mass array of unconstraint molecules
452 tim 682
453 mmeineke 790
454 tim 701 vector<ZConsParaItem>* parameters; //
455 tim 837
456 tim 658 vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels
457 tim 677
458 tim 1093 vector<int> indexOfZConsMols; //index of local Z-Constraint Molecules
459     vector<double> fz;
460     vector<double> curZPos;
461 tim 677
462 tim 1093 bool usingSMD;
463 tim 1141 vector<double> prevCantPos;
464 tim 1093 vector<double> cantPos;
465     vector<double> cantVel;
466    
467 tim 1091 double zconsFixTime;
468     double zconsGap;
469     bool hasZConsGap;
470     vector<double> endFixTime;
471    
472 tim 837 int whichDirection; //constraint direction
473    
474 tim 658 private:
475 tim 837
476 tim 701 string zconsOutput; //filename of zconstraint output
477     ZConsWriter* fzOut; //z-constraint writer
478 tim 677
479 tim 837 double curZconsTime;
480 tim 699
481 tim 696 double calcMovingMolsCOMVel();
482     double calcSysCOMVel();
483     double calcTotalForce();
484 tim 1091 void updateZPos();
485 tim 1093 void updateCantPos();
486    
487 gezelter 747 ForceSubtractionPolicy* forcePolicy; //force subtraction policy
488 tim 738 friend class ForceSubtractionPolicy;
489 tim 677
490 tim 658 };
491    
492 tim 1064 /*
493 tim 1108 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 tim 1091 template<typename T> class SMD : public T{
521 tim 969 public:
522 tim 1091 SMD( SimInfo *theInfo, ForceFields* the_ff);
523     ~SMD();
524    
525 tim 1108 virtual void integrate();
526     virtual void calcForce( int calcPot, int calcStress );
527     bool stopIntegrator();
528     private:
529    
530 tim 969 };
531 tim 1108
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 tim 658 #endif