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