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" |
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 |
|
|
19 |
– |
class Integrator : public BaseIntegrator { |
23 |
|
|
24 |
+ |
template<typename T = BaseIntegrator> class Integrator : public T { |
25 |
+ |
|
26 |
|
public: |
27 |
|
Integrator( SimInfo *theInfo, ForceFields* the_ff ); |
28 |
|
virtual ~Integrator(); |
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 |
|
void checkConstraints( void ); |
48 |
|
void rotate( int axes1, int axes2, double angle, double j[3], |
49 |
< |
double A[3][3] ); |
50 |
< |
|
41 |
< |
|
49 |
> |
double A[3][3] ); |
50 |
> |
|
51 |
|
ForceFields* myFF; |
52 |
|
|
53 |
|
SimInfo *info; // all the info we'll ever need |
58 |
|
int nMols; |
59 |
|
|
60 |
|
int isConstrained; // boolean to know whether the systems contains |
61 |
< |
// constraints. |
61 |
> |
// constraints. |
62 |
|
int nConstrained; // counter for number of constraints |
63 |
|
int *constrainedA; // the i of a constraint pair |
64 |
|
int *constrainedB; // the j of a constraint pair |
79 |
|
|
80 |
|
}; |
81 |
|
|
82 |
< |
class NVE : public Integrator{ |
82 |
> |
typedef Integrator<BaseIntegrator> RealIntegrator; |
83 |
|
|
84 |
+ |
template<typename T> class NVE : public T { |
85 |
+ |
|
86 |
|
public: |
87 |
|
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
88 |
< |
Integrator( theInfo, the_ff ){} |
89 |
< |
virtual ~NVE(){} |
79 |
< |
|
80 |
< |
|
81 |
< |
|
88 |
> |
T( theInfo, the_ff ){} |
89 |
> |
virtual ~NVE(){} |
90 |
|
}; |
91 |
|
|
84 |
– |
class NVT : public Integrator{ |
92 |
|
|
93 |
+ |
template<typename T> class NVT : public T { |
94 |
+ |
|
95 |
|
public: |
96 |
|
|
97 |
|
NVT ( SimInfo *theInfo, ForceFields* the_ff); |
107 |
|
|
108 |
|
virtual int readyCheck(); |
109 |
|
|
110 |
+ |
virtual void resetIntegrator( void ); |
111 |
+ |
|
112 |
|
// chi is a propagated degree of freedom. |
113 |
|
|
114 |
|
double chi; |
123 |
|
}; |
124 |
|
|
125 |
|
|
115 |
– |
class NPTi : public Integrator{ |
126 |
|
|
127 |
+ |
template<typename T> class NPTi : public T{ |
128 |
+ |
|
129 |
|
public: |
130 |
|
|
131 |
|
NPTi ( SimInfo *theInfo, ForceFields* the_ff); |
133 |
|
|
134 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
135 |
|
calcStress = 1; |
136 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
136 |
> |
T::integrateStep( calcPot, calcStress ); |
137 |
|
} |
138 |
|
|
139 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
148 |
|
|
149 |
|
virtual int readyCheck(); |
150 |
|
|
151 |
+ |
virtual void resetIntegrator( void ); |
152 |
+ |
|
153 |
|
// chi and eta are the propagated degrees of freedom |
154 |
|
|
155 |
|
double chi; |
169 |
|
|
170 |
|
}; |
171 |
|
|
172 |
< |
class NPTim : public Integrator{ |
172 |
> |
template<typename T> class NPTim : public T{ |
173 |
|
|
174 |
|
public: |
175 |
|
|
178 |
|
|
179 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
180 |
|
calcStress = 1; |
181 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
181 |
> |
T::integrateStep( calcPot, calcStress ); |
182 |
|
} |
183 |
|
|
184 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
193 |
|
|
194 |
|
virtual int readyCheck(); |
195 |
|
|
196 |
+ |
virtual void resetIntegrator( void ); |
197 |
+ |
|
198 |
|
Molecule* myMolecules; |
199 |
|
Atom** myAtoms; |
200 |
|
|
217 |
|
|
218 |
|
}; |
219 |
|
|
220 |
< |
class NPTf : public Integrator{ |
220 |
> |
template<typename T> class NPTf : public T{ |
221 |
|
|
222 |
|
public: |
223 |
|
|
226 |
|
|
227 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
228 |
|
calcStress = 1; |
229 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
229 |
> |
T::integrateStep( calcPot, calcStress ); |
230 |
|
} |
231 |
|
|
232 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
239 |
|
virtual void moveA( void ); |
240 |
|
virtual void moveB( void ); |
241 |
|
|
242 |
+ |
virtual void resetIntegrator( void ); |
243 |
+ |
|
244 |
|
virtual int readyCheck(); |
245 |
|
|
246 |
|
// chi and eta are the propagated degrees of freedom |
262 |
|
|
263 |
|
}; |
264 |
|
|
265 |
< |
class NPTfm : public Integrator{ |
265 |
> |
template<typename T> class NPTfm : public T{ |
266 |
|
|
267 |
|
public: |
268 |
|
|
271 |
|
|
272 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
273 |
|
calcStress = 1; |
274 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
274 |
> |
T::integrateStep( calcPot, calcStress ); |
275 |
|
} |
276 |
|
|
277 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
283 |
|
|
284 |
|
virtual void moveA( void ); |
285 |
|
virtual void moveB( void ); |
286 |
+ |
|
287 |
+ |
virtual void resetIntegrator( void ); |
288 |
|
|
289 |
|
virtual int readyCheck(); |
290 |
|
|
307 |
|
|
308 |
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
309 |
|
short int have_target_pressure; |
310 |
+ |
|
311 |
+ |
}; |
312 |
+ |
|
313 |
+ |
|
314 |
+ |
template<typename T> class NPTpr : public T{ |
315 |
+ |
|
316 |
+ |
public: |
317 |
+ |
|
318 |
+ |
NPTpr ( SimInfo *theInfo, ForceFields* the_ff); |
319 |
+ |
virtual ~NPTpr() {}; |
320 |
+ |
|
321 |
+ |
virtual void integrateStep( int calcPot, int calcStress ){ |
322 |
+ |
calcStress = 1; |
323 |
+ |
T::integrateStep( calcPot, calcStress ); |
324 |
+ |
} |
325 |
+ |
|
326 |
+ |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
327 |
+ |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
328 |
+ |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
329 |
+ |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
330 |
+ |
|
331 |
+ |
protected: |
332 |
+ |
|
333 |
+ |
virtual void moveA( void ); |
334 |
+ |
virtual void moveB( void ); |
335 |
+ |
|
336 |
+ |
virtual int readyCheck(); |
337 |
+ |
|
338 |
+ |
virtual void resetIntegrator( void ); |
339 |
+ |
|
340 |
+ |
// chi and eta are the propagated degrees of freedom |
341 |
+ |
|
342 |
+ |
double chi; |
343 |
+ |
double eta[3][3]; |
344 |
+ |
double NkBT; |
345 |
+ |
|
346 |
+ |
// targetTemp, targetPressure, and tauBarostat must be set. |
347 |
+ |
// One of qmass or tauThermostat must be set; |
348 |
+ |
|
349 |
+ |
double targetTemp; |
350 |
+ |
double targetPressure; |
351 |
+ |
double tauThermostat; |
352 |
+ |
double tauBarostat; |
353 |
+ |
|
354 |
+ |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
355 |
+ |
short int have_target_pressure; |
356 |
+ |
|
357 |
+ |
}; |
358 |
+ |
|
359 |
+ |
|
360 |
+ |
template<typename T> class ZConstraint : public T { |
361 |
+ |
|
362 |
+ |
public: |
363 |
+ |
class ForceSubtractionPolicy{ |
364 |
+ |
public: |
365 |
+ |
ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;} |
366 |
+ |
|
367 |
+ |
virtual void update() = 0; |
368 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
369 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0; |
370 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
371 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0; |
372 |
+ |
|
373 |
+ |
protected: |
374 |
+ |
ZConstraint<T>* zconsIntegrator;; |
375 |
+ |
}; |
376 |
|
|
377 |
+ |
class PolicyByNumber : public ForceSubtractionPolicy{ |
378 |
+ |
public: |
379 |
+ |
PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
380 |
+ |
virtual void update(); |
381 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
382 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
383 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
384 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce); |
385 |
+ |
|
386 |
+ |
private: |
387 |
+ |
int totNumOfMovingAtoms; |
388 |
+ |
}; |
389 |
+ |
|
390 |
+ |
class PolicyByMass : public ForceSubtractionPolicy{ |
391 |
+ |
public: |
392 |
+ |
PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
393 |
+ |
|
394 |
+ |
virtual void update(); |
395 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
396 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
397 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
398 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce); |
399 |
+ |
|
400 |
+ |
private: |
401 |
+ |
double totMassOfMovingAtoms; |
402 |
+ |
}; |
403 |
+ |
|
404 |
+ |
public: |
405 |
+ |
|
406 |
+ |
ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
407 |
+ |
~ZConstraint(); |
408 |
+ |
|
409 |
+ |
void setZConsTime(double time) {this->zconsTime = time;} |
410 |
+ |
void getZConsTime() {return zconsTime;} |
411 |
+ |
|
412 |
+ |
void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
413 |
+ |
void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
414 |
+ |
|
415 |
+ |
void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
416 |
+ |
string getZConsOutput() {return zconsOutput;} |
417 |
+ |
|
418 |
+ |
virtual void integrate(); |
419 |
+ |
|
420 |
+ |
|
421 |
+ |
#ifdef IS_MPI |
422 |
+ |
virtual void update(); //which is called to indicate the molecules' migration |
423 |
+ |
#endif |
424 |
+ |
|
425 |
+ |
protected: |
426 |
+ |
|
427 |
+ |
enum ZConsState {zcsMoving, zcsFixed}; |
428 |
+ |
|
429 |
+ |
virtual void calcForce( int calcPot, int calcStress ); |
430 |
+ |
virtual void thermalize(void); |
431 |
+ |
|
432 |
+ |
void zeroOutVel(); |
433 |
+ |
void doZconstraintForce(); |
434 |
+ |
void doHarmonic(); |
435 |
+ |
bool checkZConsState(); |
436 |
+ |
|
437 |
+ |
bool haveFixedZMols(); |
438 |
+ |
bool haveMovingZMols(); |
439 |
+ |
|
440 |
+ |
double calcZSys(); |
441 |
+ |
|
442 |
+ |
int isZConstraintMol(Molecule* mol); |
443 |
+ |
|
444 |
+ |
|
445 |
+ |
double zconsTime; //sample time |
446 |
+ |
double zconsTol; //tolerance of z-contratint |
447 |
+ |
double zForceConst; //base force constant term |
448 |
+ |
//which is estimate by OOPSE |
449 |
+ |
|
450 |
+ |
vector<Molecule*> zconsMols; //z-constraint molecules array |
451 |
+ |
vector<double> massOfZConsMols; //mass of z-constraint molecule |
452 |
+ |
vector<double> kz; //force constant array |
453 |
+ |
vector<ZConsState> states; //state of z-constraint molecules |
454 |
+ |
vector<double> zPos; // |
455 |
+ |
|
456 |
+ |
|
457 |
+ |
vector<Molecule*> unconsMols; //unconstraint molecules array |
458 |
+ |
vector<double> massOfUnconsMols; //mass array of unconstraint molecules |
459 |
+ |
double totalMassOfUncons; //total mas of unconstraint molecules |
460 |
+ |
|
461 |
+ |
vector<ZConsParaItem>* parameters; // |
462 |
+ |
|
463 |
+ |
vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
464 |
+ |
|
465 |
+ |
int* indexOfZConsMols; //index of local Z-Constraint Molecules |
466 |
+ |
double* fz; |
467 |
+ |
double* curZPos; |
468 |
+ |
|
469 |
+ |
int totNumOfUnconsAtoms; //total number of uncontraint atoms |
470 |
+ |
|
471 |
+ |
int whichDirection; //constraint direction |
472 |
+ |
|
473 |
+ |
private: |
474 |
+ |
|
475 |
+ |
string zconsOutput; //filename of zconstraint output |
476 |
+ |
ZConsWriter* fzOut; //z-constraint writer |
477 |
+ |
|
478 |
+ |
double curZconsTime; |
479 |
+ |
|
480 |
+ |
double calcMovingMolsCOMVel(); |
481 |
+ |
double calcSysCOMVel(); |
482 |
+ |
double calcTotalForce(); |
483 |
+ |
|
484 |
+ |
ForceSubtractionPolicy* forcePolicy; //force substration policy |
485 |
+ |
friend class ForceSubtractionPolicy; |
486 |
+ |
|
487 |
|
}; |
488 |
|
|
489 |
|
#endif |