ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 1198
Committed: Thu May 27 00:48:12 2004 UTC (20 years, 1 month ago) by tim
File size: 13201 byte(s)
Log Message:
in the progress of fixing MPI version of cutoff group

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