1 |
#ifndef _INTEGRATOR_H_ |
2 |
#define _INTEGRATOR_H_ |
3 |
|
4 |
#include <string> |
5 |
#include <vector> |
6 |
#include "Atom.hpp" |
7 |
#include "Molecule.hpp" |
8 |
#include "SRI.hpp" |
9 |
#include "AbstractClasses.hpp" |
10 |
#include "SimInfo.hpp" |
11 |
#include "ForceFields.hpp" |
12 |
#include "Thermo.hpp" |
13 |
#include "ReadWrite.hpp" |
14 |
// #include "ZConsWriter.hpp" |
15 |
|
16 |
using namespace std; |
17 |
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 |
const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm |
20 |
const int maxIteration = 300; |
21 |
const double tol = 1.0e-6; |
22 |
|
23 |
|
24 |
class Integrator : public BaseIntegrator{ |
25 |
|
26 |
public: |
27 |
Integrator( SimInfo *theInfo, ForceFields* the_ff ); |
28 |
virtual ~Integrator(); |
29 |
void integrate( void ); |
30 |
virtual double getConservedQuantity(void); |
31 |
virtual string getAdditionalParameters(void); |
32 |
|
33 |
protected: |
34 |
|
35 |
virtual void integrateStep( int calcPot, int calcStress ); |
36 |
virtual void preMove( void ); |
37 |
virtual void moveA( void ); |
38 |
virtual void moveB( void ); |
39 |
virtual void constrainA( void ); |
40 |
virtual void constrainB( void ); |
41 |
virtual int readyCheck( void ) { return 1; } |
42 |
|
43 |
virtual void resetIntegrator( void ) { } |
44 |
|
45 |
virtual void calcForce( int calcPot, int calcStress ); |
46 |
virtual void thermalize(); |
47 |
|
48 |
virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] ); |
49 |
|
50 |
void checkConstraints( void ); |
51 |
void rotate( int axes1, int axes2, double angle, double j[3], |
52 |
double A[3][3] ); |
53 |
|
54 |
ForceFields* myFF; |
55 |
|
56 |
SimInfo *info; // all the info we'll ever need |
57 |
int nAtoms; /* the number of atoms */ |
58 |
int oldAtoms; |
59 |
Atom **atoms; /* array of atom pointers */ |
60 |
Molecule* molecules; |
61 |
int nMols; |
62 |
|
63 |
int isConstrained; // boolean to know whether the systems contains |
64 |
// constraints. |
65 |
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 |
int* moving; // tells whether we are moving atom i |
71 |
int* moved; // tells whether we have moved atom i |
72 |
double* oldPos; // pre constrained positions |
73 |
|
74 |
short isFirst; /*boolean for the first time integrate is called */ |
75 |
|
76 |
double dt; |
77 |
double dt2; |
78 |
|
79 |
Thermo *tStats; |
80 |
StatWriter* statOut; |
81 |
DumpWriter* dumpOut; |
82 |
|
83 |
}; |
84 |
|
85 |
class NVE : public Integrator { |
86 |
|
87 |
public: |
88 |
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
89 |
Integrator( theInfo, the_ff ){} |
90 |
virtual ~NVE(){} |
91 |
}; |
92 |
|
93 |
|
94 |
class NVT : public Integrator { |
95 |
|
96 |
public: |
97 |
|
98 |
NVT ( SimInfo *theInfo, ForceFields* the_ff); |
99 |
virtual ~NVT(); |
100 |
|
101 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
102 |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
103 |
void setChiTolerance(double tol) {chiTolerance = tol;} |
104 |
virtual double getConservedQuantity(void); |
105 |
virtual string getAdditionalParameters(void); |
106 |
|
107 |
protected: |
108 |
|
109 |
virtual void moveA( void ); |
110 |
virtual void moveB( void ); |
111 |
|
112 |
virtual int readyCheck(); |
113 |
|
114 |
virtual void resetIntegrator( void ); |
115 |
|
116 |
// chi is a propagated degree of freedom. |
117 |
|
118 |
double chi; |
119 |
|
120 |
//integral of chi(t)dt |
121 |
double integralOfChidt; |
122 |
|
123 |
// targetTemp must be set. tauThermostat must also be set; |
124 |
|
125 |
double targetTemp; |
126 |
double tauThermostat; |
127 |
|
128 |
short int have_tau_thermostat, have_target_temp; |
129 |
|
130 |
double *oldVel; |
131 |
double *oldJi; |
132 |
|
133 |
double chiTolerance; |
134 |
short int have_chi_tolerance; |
135 |
|
136 |
}; |
137 |
|
138 |
|
139 |
|
140 |
class NPT : public Integrator{ |
141 |
|
142 |
public: |
143 |
|
144 |
NPT ( SimInfo *theInfo, ForceFields* the_ff); |
145 |
virtual ~NPT(); |
146 |
|
147 |
virtual void integrateStep( int calcPot, int calcStress ){ |
148 |
calcStress = 1; |
149 |
T::integrateStep( calcPot, calcStress ); |
150 |
} |
151 |
|
152 |
virtual double getConservedQuantity(void) = 0; |
153 |
virtual string getAdditionalParameters(void) = 0; |
154 |
|
155 |
double myTauThermo( void ) { return tauThermostat; } |
156 |
double myTauBaro( void ) { return tauBarostat; } |
157 |
|
158 |
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 |
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 |
|
166 |
protected: |
167 |
|
168 |
virtual void moveA( void ); |
169 |
virtual void moveB( void ); |
170 |
|
171 |
virtual int readyCheck(); |
172 |
|
173 |
virtual void resetIntegrator( void ); |
174 |
|
175 |
virtual void getVelScaleA( double sc[3], double vel[3] ) = 0; |
176 |
virtual void getVelScaleB( double sc[3], int index ) = 0; |
177 |
virtual void getPosScale(double pos[3], double COM[3], |
178 |
int index, double sc[3]) = 0; |
179 |
|
180 |
virtual bool chiConverged( void ); |
181 |
virtual bool etaConverged( void ) = 0; |
182 |
|
183 |
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 |
void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} |
191 |
|
192 |
// chi and eta are the propagated degrees of freedom |
193 |
|
194 |
double oldChi; |
195 |
double prevChi; |
196 |
double chi; |
197 |
double NkBT; |
198 |
double fkBT; |
199 |
|
200 |
double tt2, tb2; |
201 |
double instaTemp, instaPress, instaVol; |
202 |
double press[3][3]; |
203 |
|
204 |
int Nparticles; |
205 |
|
206 |
double integralOfChidt; |
207 |
|
208 |
// targetTemp, targetPressure, and tauBarostat must be set. |
209 |
// 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 |
short int have_target_pressure; |
218 |
|
219 |
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 |
}; |
231 |
|
232 |
class NPTi : public NPT{ |
233 |
|
234 |
public: |
235 |
NPTi( SimInfo *theInfo, ForceFields* the_ff); |
236 |
~NPTi(); |
237 |
|
238 |
virtual double getConservedQuantity(void); |
239 |
virtual void resetIntegrator(void); |
240 |
virtual string getAdditionalParameters(void); |
241 |
protected: |
242 |
|
243 |
|
244 |
|
245 |
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 |
virtual void getPosScale(double pos[3], double COM[3], |
255 |
int index, double sc[3]); |
256 |
|
257 |
double eta, oldEta, prevEta; |
258 |
}; |
259 |
|
260 |
class NPTf : public NPT{ |
261 |
|
262 |
public: |
263 |
|
264 |
NPTf ( SimInfo *theInfo, ForceFields* the_ff); |
265 |
virtual ~NPTf(); |
266 |
|
267 |
virtual double getConservedQuantity(void); |
268 |
virtual string getAdditionalParameters(void); |
269 |
virtual void resetIntegrator(void); |
270 |
|
271 |
protected: |
272 |
|
273 |
virtual void evolveEtaA(void); |
274 |
virtual void evolveEtaB(void); |
275 |
|
276 |
virtual bool etaConverged( void ); |
277 |
|
278 |
virtual void scaleSimBox( void ); |
279 |
|
280 |
virtual void getVelScaleA( double sc[3], double vel[3] ); |
281 |
virtual void getVelScaleB( double sc[3], int index ); |
282 |
virtual void getPosScale(double pos[3], double COM[3], |
283 |
int index, double sc[3]); |
284 |
|
285 |
double eta[3][3]; |
286 |
double oldEta[3][3]; |
287 |
double prevEta[3][3]; |
288 |
}; |
289 |
|
290 |
class NPTxyz : public NPT{ |
291 |
|
292 |
public: |
293 |
|
294 |
NPTxyz ( SimInfo *theInfo, ForceFields* the_ff); |
295 |
virtual ~NPTxyz(); |
296 |
|
297 |
virtual double getConservedQuantity(void); |
298 |
virtual string getAdditionalParameters(void); |
299 |
virtual void resetIntegrator(void); |
300 |
|
301 |
protected: |
302 |
|
303 |
virtual void evolveEtaA(void); |
304 |
virtual void evolveEtaB(void); |
305 |
|
306 |
virtual bool etaConverged( void ); |
307 |
|
308 |
virtual void scaleSimBox( void ); |
309 |
|
310 |
virtual void getVelScaleA( double sc[3], double vel[3] ); |
311 |
virtual void getVelScaleB( double sc[3], int index ); |
312 |
virtual void getPosScale(double pos[3], double COM[3], |
313 |
int index, double sc[3]); |
314 |
|
315 |
double eta[3][3]; |
316 |
double oldEta[3][3]; |
317 |
double prevEta[3][3]; |
318 |
}; |
319 |
|
320 |
|
321 |
// template<typename T> class ZConstraint : public T { |
322 |
|
323 |
// public: |
324 |
// class ForceSubtractionPolicy{ |
325 |
// public: |
326 |
// ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;} |
327 |
|
328 |
// 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 |
|
334 |
// protected: |
335 |
// ZConstraint<T>* zconsIntegrator; |
336 |
// }; |
337 |
|
338 |
// class PolicyByNumber : public ForceSubtractionPolicy{ |
339 |
|
340 |
// 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 |
|
348 |
// private: |
349 |
// int totNumOfMovingAtoms; |
350 |
// }; |
351 |
|
352 |
// class PolicyByMass : public ForceSubtractionPolicy{ |
353 |
|
354 |
// public: |
355 |
// PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
356 |
|
357 |
// 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 |
|
363 |
// private: |
364 |
// double totMassOfMovingAtoms; |
365 |
// }; |
366 |
|
367 |
// public: |
368 |
|
369 |
// ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
370 |
// ~ZConstraint(); |
371 |
|
372 |
// void setZConsTime(double time) {this->zconsTime = time;} |
373 |
// void getZConsTime() {return zconsTime;} |
374 |
|
375 |
// void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
376 |
// void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
377 |
|
378 |
// void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
379 |
// string getZConsOutput() {return zconsOutput;} |
380 |
|
381 |
// virtual void integrate(); |
382 |
|
383 |
|
384 |
// #ifdef IS_MPI |
385 |
// virtual void update(); //which is called to indicate the molecules' migration |
386 |
// #endif |
387 |
|
388 |
// enum ZConsState {zcsMoving, zcsFixed}; |
389 |
|
390 |
// vector<Molecule*> zconsMols; //z-constraint molecules array |
391 |
// vector<ZConsState> states; //state of z-constraint molecules |
392 |
|
393 |
|
394 |
|
395 |
// int totNumOfUnconsAtoms; //total number of uncontraint atoms |
396 |
// double totalMassOfUncons; //total mas of unconstraint molecules |
397 |
|
398 |
|
399 |
// protected: |
400 |
|
401 |
|
402 |
|
403 |
// virtual void calcForce( int calcPot, int calcStress ); |
404 |
// virtual void thermalize(void); |
405 |
|
406 |
// void zeroOutVel(); |
407 |
// void doZconstraintForce(); |
408 |
// void doHarmonic(); |
409 |
// bool checkZConsState(); |
410 |
|
411 |
// bool haveFixedZMols(); |
412 |
// bool haveMovingZMols(); |
413 |
|
414 |
// double calcZSys(); |
415 |
|
416 |
// int isZConstraintMol(Molecule* mol); |
417 |
|
418 |
|
419 |
// 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 |
|
424 |
|
425 |
// vector<double> massOfZConsMols; //mass of z-constraint molecule |
426 |
// vector<double> kz; //force constant array |
427 |
|
428 |
// vector<double> zPos; // |
429 |
|
430 |
|
431 |
// vector<Molecule*> unconsMols; //unconstraint molecules array |
432 |
// vector<double> massOfUnconsMols; //mass array of unconstraint molecules |
433 |
|
434 |
|
435 |
// vector<ZConsParaItem>* parameters; // |
436 |
|
437 |
// vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
438 |
|
439 |
// int* indexOfZConsMols; //index of local Z-Constraint Molecules |
440 |
// double* fz; |
441 |
// double* curZPos; |
442 |
|
443 |
|
444 |
|
445 |
// int whichDirection; //constraint direction |
446 |
|
447 |
// private: |
448 |
|
449 |
// string zconsOutput; //filename of zconstraint output |
450 |
// ZConsWriter* fzOut; //z-constraint writer |
451 |
|
452 |
// double curZconsTime; |
453 |
|
454 |
// double calcMovingMolsCOMVel(); |
455 |
// double calcSysCOMVel(); |
456 |
// double calcTotalForce(); |
457 |
|
458 |
// ForceSubtractionPolicy* forcePolicy; //force subtraction policy |
459 |
// friend class ForceSubtractionPolicy; |
460 |
|
461 |
// }; |
462 |
|
463 |
#endif |