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 |
tim |
658 |
#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 |
tim |
645 |
template<typename T = BaseIntegrator> class Integrator : public T { |
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 |
|
|
|
31 |
|
|
|
32 |
mmeineke |
540 |
protected: |
33 |
mmeineke |
377 |
|
34 |
mmeineke |
540 |
virtual void integrateStep( int calcPot, int calcStress ); |
35 |
mmeineke |
548 |
virtual void preMove( void ); |
36 |
mmeineke |
540 |
virtual void moveA( void ); |
37 |
|
|
virtual void moveB( void ); |
38 |
|
|
virtual void constrainA( void ); |
39 |
|
|
virtual void constrainB( void ); |
40 |
mmeineke |
559 |
virtual int readyCheck( void ) { return 1; } |
41 |
tim |
677 |
|
42 |
|
|
virtual void calcForce( int calcPot, int calcStress ); |
43 |
|
|
virtual void thermalize(); |
44 |
mmeineke |
377 |
|
45 |
mmeineke |
540 |
void checkConstraints( void ); |
46 |
mmeineke |
377 |
void rotate( int axes1, int axes2, double angle, double j[3], |
47 |
gezelter |
600 |
double A[3][3] ); |
48 |
tim |
677 |
|
49 |
mmeineke |
377 |
ForceFields* myFF; |
50 |
|
|
|
51 |
mmeineke |
540 |
SimInfo *info; // all the info we'll ever need |
52 |
|
|
int nAtoms; /* the number of atoms */ |
53 |
mmeineke |
548 |
int oldAtoms; |
54 |
mmeineke |
540 |
Atom **atoms; /* array of atom pointers */ |
55 |
mmeineke |
423 |
Molecule* molecules; |
56 |
|
|
int nMols; |
57 |
|
|
|
58 |
mmeineke |
548 |
int isConstrained; // boolean to know whether the systems contains |
59 |
|
|
// constraints. |
60 |
|
|
int nConstrained; // counter for number of constraints |
61 |
|
|
int *constrainedA; // the i of a constraint pair |
62 |
|
|
int *constrainedB; // the j of a constraint pair |
63 |
|
|
double *constrainedDsqr; // the square of the constraint distance |
64 |
|
|
|
65 |
|
|
int* moving; // tells whether we are moving atom i |
66 |
|
|
int* moved; // tells whether we have moved atom i |
67 |
mmeineke |
561 |
double* oldPos; // pre constrained positions |
68 |
mmeineke |
548 |
|
69 |
mmeineke |
540 |
short isFirst; /*boolean for the first time integrate is called */ |
70 |
|
|
|
71 |
|
|
double dt; |
72 |
mmeineke |
541 |
double dt2; |
73 |
gezelter |
560 |
|
74 |
mmeineke |
540 |
Thermo *tStats; |
75 |
|
|
StatWriter* statOut; |
76 |
|
|
DumpWriter* dumpOut; |
77 |
mmeineke |
377 |
|
78 |
|
|
}; |
79 |
|
|
|
80 |
tim |
645 |
typedef Integrator<BaseIntegrator> RealIntegrator; |
81 |
mmeineke |
540 |
|
82 |
tim |
645 |
template<typename T> class NVE : public T { |
83 |
|
|
|
84 |
mmeineke |
561 |
public: |
85 |
|
|
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
86 |
tim |
645 |
T( theInfo, the_ff ){} |
87 |
|
|
virtual ~NVE(){} |
88 |
|
|
}; |
89 |
mmeineke |
555 |
|
90 |
|
|
|
91 |
tim |
645 |
template<typename T> class NVT : public T { |
92 |
mmeineke |
555 |
|
93 |
gezelter |
560 |
public: |
94 |
|
|
|
95 |
mmeineke |
561 |
NVT ( SimInfo *theInfo, ForceFields* the_ff); |
96 |
|
|
virtual ~NVT() {} |
97 |
mmeineke |
540 |
|
98 |
gezelter |
560 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
99 |
|
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
100 |
|
|
|
101 |
mmeineke |
540 |
protected: |
102 |
gezelter |
560 |
|
103 |
mmeineke |
561 |
virtual void moveA( void ); |
104 |
|
|
virtual void moveB( void ); |
105 |
mmeineke |
540 |
|
106 |
mmeineke |
561 |
virtual int readyCheck(); |
107 |
gezelter |
560 |
|
108 |
gezelter |
565 |
// chi is a propagated degree of freedom. |
109 |
gezelter |
560 |
|
110 |
gezelter |
565 |
double chi; |
111 |
gezelter |
560 |
|
112 |
gezelter |
565 |
// targetTemp must be set. tauThermostat must also be set; |
113 |
gezelter |
560 |
|
114 |
|
|
double targetTemp; |
115 |
|
|
double tauThermostat; |
116 |
mmeineke |
561 |
|
117 |
gezelter |
565 |
short int have_tau_thermostat, have_target_temp; |
118 |
gezelter |
560 |
|
119 |
mmeineke |
540 |
}; |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
tim |
645 |
template<typename T> class NPTi : public T{ |
124 |
|
|
|
125 |
gezelter |
560 |
public: |
126 |
|
|
|
127 |
gezelter |
574 |
NPTi ( SimInfo *theInfo, ForceFields* the_ff); |
128 |
|
|
virtual ~NPTi() {}; |
129 |
gezelter |
560 |
|
130 |
mmeineke |
594 |
virtual void integrateStep( int calcPot, int calcStress ){ |
131 |
|
|
calcStress = 1; |
132 |
tim |
645 |
T::integrateStep( calcPot, calcStress ); |
133 |
mmeineke |
594 |
} |
134 |
|
|
|
135 |
gezelter |
560 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
136 |
|
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
137 |
|
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
138 |
|
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
139 |
|
|
|
140 |
|
|
protected: |
141 |
|
|
|
142 |
mmeineke |
561 |
virtual void moveA( void ); |
143 |
|
|
virtual void moveB( void ); |
144 |
gezelter |
560 |
|
145 |
mmeineke |
561 |
virtual int readyCheck(); |
146 |
gezelter |
560 |
|
147 |
gezelter |
565 |
// chi and eta are the propagated degrees of freedom |
148 |
gezelter |
560 |
|
149 |
gezelter |
565 |
double chi; |
150 |
|
|
double eta; |
151 |
gezelter |
574 |
double NkBT; |
152 |
gezelter |
560 |
|
153 |
|
|
// targetTemp, targetPressure, and tauBarostat must be set. |
154 |
|
|
// One of qmass or tauThermostat must be set; |
155 |
|
|
|
156 |
|
|
double targetTemp; |
157 |
|
|
double targetPressure; |
158 |
|
|
double tauThermostat; |
159 |
|
|
double tauBarostat; |
160 |
|
|
|
161 |
|
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
162 |
gezelter |
565 |
short int have_target_pressure; |
163 |
gezelter |
560 |
|
164 |
|
|
}; |
165 |
|
|
|
166 |
tim |
645 |
template<typename T> class NPTim : public T{ |
167 |
gezelter |
596 |
|
168 |
|
|
public: |
169 |
|
|
|
170 |
|
|
NPTim ( SimInfo *theInfo, ForceFields* the_ff); |
171 |
|
|
virtual ~NPTim() {}; |
172 |
|
|
|
173 |
|
|
virtual void integrateStep( int calcPot, int calcStress ){ |
174 |
|
|
calcStress = 1; |
175 |
tim |
645 |
T::integrateStep( calcPot, calcStress ); |
176 |
gezelter |
596 |
} |
177 |
|
|
|
178 |
|
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
179 |
|
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
180 |
|
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
181 |
|
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
182 |
|
|
|
183 |
|
|
protected: |
184 |
|
|
|
185 |
gezelter |
604 |
virtual void moveA( void ); |
186 |
gezelter |
596 |
virtual void moveB( void ); |
187 |
|
|
|
188 |
|
|
virtual int readyCheck(); |
189 |
|
|
|
190 |
gezelter |
604 |
Molecule* myMolecules; |
191 |
|
|
Atom** myAtoms; |
192 |
|
|
|
193 |
gezelter |
596 |
// chi and eta are the propagated degrees of freedom |
194 |
|
|
|
195 |
|
|
double chi; |
196 |
|
|
double eta; |
197 |
|
|
double NkBT; |
198 |
|
|
|
199 |
|
|
// targetTemp, targetPressure, and tauBarostat must be set. |
200 |
|
|
// One of qmass or tauThermostat must be set; |
201 |
|
|
|
202 |
|
|
double targetTemp; |
203 |
|
|
double targetPressure; |
204 |
|
|
double tauThermostat; |
205 |
|
|
double tauBarostat; |
206 |
|
|
|
207 |
|
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
208 |
|
|
short int have_target_pressure; |
209 |
|
|
|
210 |
|
|
}; |
211 |
|
|
|
212 |
tim |
645 |
template<typename T> class NPTf : public T{ |
213 |
gezelter |
576 |
|
214 |
|
|
public: |
215 |
|
|
|
216 |
|
|
NPTf ( SimInfo *theInfo, ForceFields* the_ff); |
217 |
|
|
virtual ~NPTf() {}; |
218 |
|
|
|
219 |
mmeineke |
594 |
virtual void integrateStep( int calcPot, int calcStress ){ |
220 |
|
|
calcStress = 1; |
221 |
tim |
645 |
T::integrateStep( calcPot, calcStress ); |
222 |
mmeineke |
594 |
} |
223 |
|
|
|
224 |
gezelter |
576 |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
225 |
|
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
226 |
|
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
227 |
|
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
228 |
|
|
|
229 |
|
|
protected: |
230 |
|
|
|
231 |
|
|
virtual void moveA( void ); |
232 |
|
|
virtual void moveB( void ); |
233 |
|
|
|
234 |
|
|
virtual int readyCheck(); |
235 |
|
|
|
236 |
|
|
// chi and eta are the propagated degrees of freedom |
237 |
|
|
|
238 |
|
|
double chi; |
239 |
gezelter |
588 |
double eta[3][3]; |
240 |
gezelter |
576 |
double NkBT; |
241 |
|
|
|
242 |
|
|
// targetTemp, targetPressure, and tauBarostat must be set. |
243 |
|
|
// One of qmass or tauThermostat must be set; |
244 |
|
|
|
245 |
|
|
double targetTemp; |
246 |
|
|
double targetPressure; |
247 |
|
|
double tauThermostat; |
248 |
|
|
double tauBarostat; |
249 |
|
|
|
250 |
|
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
251 |
|
|
short int have_target_pressure; |
252 |
|
|
|
253 |
|
|
}; |
254 |
|
|
|
255 |
tim |
645 |
template<typename T> class NPTfm : public T{ |
256 |
gezelter |
596 |
|
257 |
|
|
public: |
258 |
|
|
|
259 |
|
|
NPTfm ( SimInfo *theInfo, ForceFields* the_ff); |
260 |
|
|
virtual ~NPTfm() {}; |
261 |
|
|
|
262 |
|
|
virtual void integrateStep( int calcPot, int calcStress ){ |
263 |
|
|
calcStress = 1; |
264 |
tim |
645 |
T::integrateStep( calcPot, calcStress ); |
265 |
gezelter |
596 |
} |
266 |
|
|
|
267 |
|
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
268 |
|
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
269 |
|
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
270 |
|
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
271 |
|
|
|
272 |
|
|
protected: |
273 |
|
|
|
274 |
|
|
virtual void moveA( void ); |
275 |
|
|
virtual void moveB( void ); |
276 |
|
|
|
277 |
|
|
virtual int readyCheck(); |
278 |
|
|
|
279 |
gezelter |
605 |
Molecule* myMolecules; |
280 |
|
|
Atom** myAtoms; |
281 |
|
|
|
282 |
gezelter |
596 |
// chi and eta are the propagated degrees of freedom |
283 |
|
|
|
284 |
|
|
double chi; |
285 |
|
|
double eta[3][3]; |
286 |
|
|
double NkBT; |
287 |
|
|
|
288 |
|
|
// targetTemp, targetPressure, and tauBarostat must be set. |
289 |
|
|
// One of qmass or tauThermostat must be set; |
290 |
|
|
|
291 |
|
|
double targetTemp; |
292 |
|
|
double targetPressure; |
293 |
|
|
double tauThermostat; |
294 |
|
|
double tauBarostat; |
295 |
|
|
|
296 |
|
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
297 |
|
|
short int have_target_pressure; |
298 |
|
|
|
299 |
|
|
}; |
300 |
|
|
|
301 |
tim |
658 |
template<typename T> class ZConstraint : public T { |
302 |
|
|
|
303 |
|
|
public: |
304 |
|
|
|
305 |
|
|
ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
306 |
|
|
~ZConstraint(); |
307 |
tim |
677 |
|
308 |
tim |
658 |
void setZConsTime(double time) {this->zconsTime = time;} |
309 |
|
|
void getZConsTime() {return zconsTime;} |
310 |
|
|
|
311 |
|
|
void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
312 |
|
|
void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
313 |
|
|
|
314 |
|
|
void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
315 |
|
|
string getZConsOutput() {return zconsOutput;} |
316 |
tim |
677 |
|
317 |
|
|
virtual void integrate(); |
318 |
|
|
|
319 |
tim |
658 |
|
320 |
|
|
#ifdef IS_MPI |
321 |
|
|
virtual void update(); //which is called to indicate the molecules' migration |
322 |
mmeineke |
377 |
#endif |
323 |
tim |
658 |
|
324 |
|
|
protected: |
325 |
|
|
|
326 |
tim |
677 |
enum ZConsState {zcsMoving, zcsFixed}; |
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
virtual void calcForce( int calcPot, int calcStress ); |
331 |
|
|
virtual void thermalize(void); |
332 |
|
|
|
333 |
|
|
void zeroOutVel(); |
334 |
|
|
void doZconstraintForce(); |
335 |
|
|
bool checkZConsState(); |
336 |
|
|
|
337 |
|
|
bool haveFixedZMols(); |
338 |
|
|
bool haveMovingZMols(); |
339 |
|
|
|
340 |
|
|
double calcZSys(); |
341 |
|
|
|
342 |
|
|
int isZConstraintMol(Molecule* mol); |
343 |
|
|
|
344 |
|
|
|
345 |
tim |
658 |
double zconsTime; |
346 |
tim |
677 |
double ztol; |
347 |
tim |
658 |
|
348 |
|
|
vector<Molecule*> zconsMols; |
349 |
|
|
vector<double> massOfZConsMols; |
350 |
tim |
677 |
vector<double> zconsPos; |
351 |
|
|
vector<double> kz; |
352 |
|
|
vector<ZConsState> states; |
353 |
|
|
vector<double> ZPos; |
354 |
tim |
658 |
|
355 |
tim |
677 |
|
356 |
tim |
658 |
vector<Molecule*> unconsMols; |
357 |
|
|
vector<double> massOfUnconsMols; |
358 |
|
|
double totalMassOfUncons; |
359 |
|
|
|
360 |
|
|
vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
361 |
tim |
677 |
|
362 |
|
|
int* indexOfZConsMols; //index of local Z-Constraint Molecules |
363 |
tim |
658 |
double* fz; |
364 |
|
|
|
365 |
tim |
677 |
int totNumOfUnconsAtoms; |
366 |
|
|
|
367 |
|
|
int whichDirection; //constraint direction |
368 |
|
|
|
369 |
tim |
658 |
private: |
370 |
tim |
677 |
|
371 |
tim |
658 |
string zconsOutput; |
372 |
|
|
ZConsWriter* fzOut; |
373 |
tim |
677 |
|
374 |
|
|
|
375 |
tim |
658 |
}; |
376 |
|
|
|
377 |
|
|
#endif |