ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new-templateless/OOPSE/libmdtools/Integrator.hpp
Revision: 849
Committed: Fri Oct 31 21:06:47 2003 UTC (21 years, 9 months ago) by mmeineke
File size: 12607 byte(s)
Log Message:
started work on template removal.

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