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