ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 1097
Committed: Mon Apr 12 20:32:20 2004 UTC (20 years, 2 months ago) by gezelter
File size: 13275 byte(s)
Log Message:
Changes for RigidBody dynamics (Somewhat extensive)

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