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(); |
29 |
|
void integrate( void ); |
30 |
+ |
virtual double getConservedQuantity(void); |
31 |
|
|
26 |
– |
|
32 |
|
protected: |
33 |
< |
|
33 |
> |
|
34 |
|
virtual void integrateStep( int calcPot, int calcStress ); |
35 |
|
virtual void preMove( void ); |
36 |
|
virtual void moveA( 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 |
< |
|
41 |
< |
|
51 |
> |
double A[3][3] ); |
52 |
> |
|
53 |
|
ForceFields* myFF; |
54 |
|
|
55 |
|
SimInfo *info; // all the info we'll ever need |
60 |
|
int nMols; |
61 |
|
|
62 |
|
int isConstrained; // boolean to know whether the systems contains |
63 |
< |
// constraints. |
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 |
81 |
|
|
82 |
|
}; |
83 |
|
|
84 |
< |
class NVE : public Integrator{ |
84 |
> |
typedef Integrator<BaseIntegrator> RealIntegrator; |
85 |
|
|
86 |
+ |
template<typename T> class NVE : public T { |
87 |
+ |
|
88 |
|
public: |
89 |
|
NVE ( SimInfo *theInfo, ForceFields* the_ff ): |
90 |
< |
Integrator( theInfo, the_ff ){} |
91 |
< |
virtual ~NVE(){} |
79 |
< |
|
80 |
< |
|
81 |
< |
|
90 |
> |
T( theInfo, the_ff ){} |
91 |
> |
virtual ~NVE(){} |
92 |
|
}; |
93 |
|
|
84 |
– |
class NVT : public Integrator{ |
94 |
|
|
95 |
+ |
template<typename T> class NVT : public T { |
96 |
+ |
|
97 |
|
public: |
98 |
|
|
99 |
|
NVT ( SimInfo *theInfo, ForceFields* the_ff); |
100 |
< |
virtual ~NVT() {} |
100 |
> |
virtual ~NVT(); |
101 |
|
|
102 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
103 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
104 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol;} |
105 |
+ |
virtual double getConservedQuantity(void); |
106 |
|
|
107 |
|
protected: |
108 |
|
|
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; |
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 |
|
|
115 |
– |
class NPTi : public Integrator{ |
139 |
|
|
140 |
+ |
template<typename T> class NPT : public T{ |
141 |
+ |
|
142 |
|
public: |
143 |
|
|
144 |
< |
NPTi ( SimInfo *theInfo, ForceFields* the_ff); |
145 |
< |
virtual ~NPTi() {}; |
146 |
< |
|
144 |
> |
NPT ( SimInfo *theInfo, ForceFields* the_ff); |
145 |
> |
virtual ~NPT(); |
146 |
> |
|
147 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
148 |
|
calcStress = 1; |
149 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
149 |
> |
T::integrateStep( calcPot, calcStress ); |
150 |
|
} |
151 |
|
|
152 |
+ |
virtual double getConservedQuantity(void) = 0; |
153 |
+ |
|
154 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
155 |
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
156 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
157 |
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
158 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;} |
159 |
+ |
void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;} |
160 |
+ |
void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;} |
161 |
|
|
162 |
|
protected: |
163 |
|
|
166 |
|
|
167 |
|
virtual int readyCheck(); |
168 |
|
|
169 |
+ |
virtual void resetIntegrator( void ); |
170 |
+ |
|
171 |
+ |
virtual void getVelScaleA( double sc[3], double vel[3] ) = 0; |
172 |
+ |
virtual void getVelScaleB( double sc[3], int index ) = 0; |
173 |
+ |
virtual void getPosScale(double pos[3], double COM[3], |
174 |
+ |
int index, double sc[3]) = 0; |
175 |
+ |
|
176 |
+ |
virtual bool chiConverged( void ); |
177 |
+ |
virtual bool etaConverged( void ) = 0; |
178 |
+ |
|
179 |
+ |
virtual void evolveChiA( void ); |
180 |
+ |
virtual void evolveEtaA( void ) = 0; |
181 |
+ |
virtual void evolveChiB( void ); |
182 |
+ |
virtual void evolveEtaB( void ) = 0; |
183 |
+ |
|
184 |
+ |
virtual void scaleSimBox( void ) = 0; |
185 |
+ |
|
186 |
+ |
void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} |
187 |
+ |
|
188 |
|
// chi and eta are the propagated degrees of freedom |
189 |
|
|
190 |
+ |
double oldChi; |
191 |
+ |
double prevChi; |
192 |
|
double chi; |
142 |
– |
double eta; |
193 |
|
double NkBT; |
194 |
+ |
double fkBT; |
195 |
|
|
196 |
+ |
double tt2, tb2; |
197 |
+ |
double instaTemp, instaPress, instaVol; |
198 |
+ |
|
199 |
+ |
int Nparticles; |
200 |
+ |
|
201 |
+ |
double integralOfChidt; |
202 |
+ |
|
203 |
|
// targetTemp, targetPressure, and tauBarostat must be set. |
204 |
|
// One of qmass or tauThermostat must be set; |
205 |
|
|
211 |
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
212 |
|
short int have_target_pressure; |
213 |
|
|
214 |
+ |
double *oldPos; |
215 |
+ |
double *oldVel; |
216 |
+ |
double *oldJi; |
217 |
+ |
|
218 |
+ |
double chiTolerance; |
219 |
+ |
short int have_chi_tolerance; |
220 |
+ |
double posIterTolerance; |
221 |
+ |
short int have_pos_iter_tolerance; |
222 |
+ |
double etaTolerance; |
223 |
+ |
short int have_eta_tolerance; |
224 |
+ |
|
225 |
|
}; |
226 |
|
|
227 |
< |
class NPTim : public Integrator{ |
227 |
> |
template<typename T> class NPTi : public T{ |
228 |
> |
|
229 |
> |
public: |
230 |
> |
NPTi( SimInfo *theInfo, ForceFields* the_ff); |
231 |
> |
~NPTi(); |
232 |
> |
|
233 |
> |
virtual double getConservedQuantity(void); |
234 |
> |
virtual void resetIntegrator(void); |
235 |
> |
|
236 |
> |
protected: |
237 |
> |
|
238 |
> |
|
239 |
|
|
240 |
+ |
virtual void evolveEtaA(void); |
241 |
+ |
virtual void evolveEtaB(void); |
242 |
+ |
|
243 |
+ |
virtual bool etaConverged( void ); |
244 |
+ |
|
245 |
+ |
virtual void scaleSimBox( void ); |
246 |
+ |
|
247 |
+ |
virtual void getVelScaleA( double sc[3], double vel[3] ); |
248 |
+ |
virtual void getVelScaleB( double sc[3], int index ); |
249 |
+ |
virtual void getPosScale(double pos[3], double COM[3], |
250 |
+ |
int index, double sc[3]); |
251 |
+ |
|
252 |
+ |
double eta, oldEta, prevEta; |
253 |
+ |
}; |
254 |
+ |
|
255 |
+ |
|
256 |
+ |
template<typename T> class NPTim : public T{ |
257 |
+ |
|
258 |
|
public: |
259 |
|
|
260 |
|
NPTim ( SimInfo *theInfo, ForceFields* the_ff); |
261 |
< |
virtual ~NPTim() {}; |
261 |
> |
virtual ~NPTim() {} |
262 |
|
|
263 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
264 |
|
calcStress = 1; |
265 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
265 |
> |
T::integrateStep( calcPot, calcStress ); |
266 |
> |
accIntegralOfChidt(); |
267 |
|
} |
268 |
|
|
269 |
+ |
virtual double getConservedQuantity(void); |
270 |
+ |
|
271 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
272 |
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
273 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
274 |
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
275 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol;} |
276 |
+ |
void setPosIterTolerance(double tol) {posIterTolerance = tol;} |
277 |
|
|
278 |
|
protected: |
279 |
|
|
282 |
|
|
283 |
|
virtual int readyCheck(); |
284 |
|
|
285 |
+ |
virtual void resetIntegrator( void ); |
286 |
+ |
|
287 |
+ |
void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} |
288 |
+ |
|
289 |
|
Molecule* myMolecules; |
290 |
|
Atom** myAtoms; |
291 |
|
|
294 |
|
double chi; |
295 |
|
double eta; |
296 |
|
double NkBT; |
297 |
+ |
double integralOfChidt; |
298 |
|
|
299 |
|
// targetTemp, targetPressure, and tauBarostat must be set. |
300 |
|
// One of qmass or tauThermostat must be set; |
306 |
|
|
307 |
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
308 |
|
short int have_target_pressure; |
309 |
+ |
double chiTolerance; |
310 |
+ |
short int have_chi_tolerance; |
311 |
+ |
double posIterTolerance; |
312 |
+ |
short int have_pos_iter_tolerance; |
313 |
|
|
314 |
|
}; |
315 |
|
|
316 |
< |
class NPTf : public Integrator{ |
316 |
> |
template<typename T> class NPTzm : public T{ |
317 |
|
|
318 |
|
public: |
319 |
|
|
320 |
+ |
NPTzm ( SimInfo *theInfo, ForceFields* the_ff); |
321 |
+ |
virtual ~NPTzm() {}; |
322 |
+ |
|
323 |
+ |
virtual void integrateStep( int calcPot, int calcStress ){ |
324 |
+ |
calcStress = 1; |
325 |
+ |
T::integrateStep( calcPot, calcStress ); |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
329 |
+ |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
330 |
+ |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
331 |
+ |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
332 |
+ |
|
333 |
+ |
protected: |
334 |
+ |
|
335 |
+ |
virtual void moveA( void ); |
336 |
+ |
virtual void moveB( void ); |
337 |
+ |
|
338 |
+ |
virtual int readyCheck(); |
339 |
+ |
|
340 |
+ |
virtual void resetIntegrator( void ); |
341 |
+ |
|
342 |
+ |
Molecule* myMolecules; |
343 |
+ |
Atom** myAtoms; |
344 |
+ |
|
345 |
+ |
// chi and eta are the propagated degrees of freedom |
346 |
+ |
|
347 |
+ |
double chi; |
348 |
+ |
double eta; |
349 |
+ |
double etaZ; |
350 |
+ |
double NkBT; |
351 |
+ |
|
352 |
+ |
// targetTemp, targetPressure, and tauBarostat must be set. |
353 |
+ |
// One of qmass or tauThermostat must be set; |
354 |
+ |
|
355 |
+ |
double targetTemp; |
356 |
+ |
double targetPressure; |
357 |
+ |
double tauThermostat; |
358 |
+ |
double tauBarostat; |
359 |
+ |
|
360 |
+ |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
361 |
+ |
short int have_target_pressure; |
362 |
+ |
|
363 |
+ |
}; |
364 |
+ |
|
365 |
+ |
template<typename T> class NPTf : public T{ |
366 |
+ |
|
367 |
+ |
public: |
368 |
+ |
|
369 |
|
NPTf ( SimInfo *theInfo, ForceFields* the_ff); |
370 |
< |
virtual ~NPTf() {}; |
370 |
> |
virtual ~NPTf(); |
371 |
|
|
372 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
373 |
|
calcStress = 1; |
374 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
374 |
> |
T::integrateStep( calcPot, calcStress ); |
375 |
|
} |
376 |
+ |
|
377 |
+ |
virtual double getConservedQuantity(void); |
378 |
|
|
379 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
380 |
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
381 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
382 |
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
383 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol;} |
384 |
+ |
void setPosIterTolerance(double tol) {posIterTolerance = tol;} |
385 |
|
|
386 |
|
protected: |
387 |
|
|
388 |
|
virtual void moveA( void ); |
389 |
|
virtual void moveB( void ); |
390 |
|
|
391 |
+ |
virtual void resetIntegrator( void ); |
392 |
+ |
|
393 |
|
virtual int readyCheck(); |
394 |
|
|
395 |
+ |
|
396 |
|
// chi and eta are the propagated degrees of freedom |
397 |
|
|
398 |
|
double chi; |
399 |
|
double eta[3][3]; |
400 |
|
double NkBT; |
401 |
+ |
double fkBT; |
402 |
|
|
403 |
+ |
int Nparticles; |
404 |
+ |
|
405 |
+ |
double *oldPos; |
406 |
+ |
double *oldVel; |
407 |
+ |
double *oldJi; |
408 |
+ |
|
409 |
+ |
double integralOfChidt; |
410 |
+ |
|
411 |
|
// targetTemp, targetPressure, and tauBarostat must be set. |
412 |
|
// One of qmass or tauThermostat must be set; |
413 |
|
|
418 |
|
|
419 |
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
420 |
|
short int have_target_pressure; |
421 |
+ |
double chiTolerance; |
422 |
+ |
short int have_chi_tolerance; |
423 |
+ |
double posIterTolerance; |
424 |
+ |
short int have_pos_iter_tolerance; |
425 |
+ |
double etaTolerance; |
426 |
+ |
short int have_eta_tolerance; |
427 |
+ |
}; |
428 |
|
|
429 |
+ |
template<typename T> class NPTxym : public T{ |
430 |
+ |
|
431 |
+ |
public: |
432 |
+ |
|
433 |
+ |
NPTxym ( SimInfo *theInfo, ForceFields* the_ff); |
434 |
+ |
virtual ~NPTxym() {}; |
435 |
+ |
|
436 |
+ |
virtual void integrateStep( int calcPot, int calcStress ){ |
437 |
+ |
calcStress = 1; |
438 |
+ |
T::integrateStep( calcPot, calcStress ); |
439 |
+ |
} |
440 |
+ |
|
441 |
+ |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
442 |
+ |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
443 |
+ |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
444 |
+ |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
445 |
+ |
|
446 |
+ |
protected: |
447 |
+ |
|
448 |
+ |
virtual void moveA( void ); |
449 |
+ |
virtual void moveB( void ); |
450 |
+ |
|
451 |
+ |
virtual int readyCheck(); |
452 |
+ |
|
453 |
+ |
virtual void resetIntegrator( void ); |
454 |
+ |
|
455 |
+ |
Molecule* myMolecules; |
456 |
+ |
Atom** myAtoms; |
457 |
+ |
|
458 |
+ |
// chi and eta are the propagated degrees of freedom |
459 |
+ |
|
460 |
+ |
double chi; |
461 |
+ |
double eta; |
462 |
+ |
double etaX; |
463 |
+ |
double etaY; |
464 |
+ |
double NkBT; |
465 |
+ |
|
466 |
+ |
// targetTemp, targetPressure, and tauBarostat must be set. |
467 |
+ |
// One of qmass or tauThermostat must be set; |
468 |
+ |
|
469 |
+ |
double targetTemp; |
470 |
+ |
double targetPressure; |
471 |
+ |
double tauThermostat; |
472 |
+ |
double tauBarostat; |
473 |
+ |
|
474 |
+ |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
475 |
+ |
short int have_target_pressure; |
476 |
+ |
|
477 |
|
}; |
478 |
|
|
247 |
– |
class NPTfm : public Integrator{ |
479 |
|
|
480 |
+ |
template<typename T> class NPTfm : public T{ |
481 |
+ |
|
482 |
|
public: |
483 |
|
|
484 |
|
NPTfm ( SimInfo *theInfo, ForceFields* the_ff); |
486 |
|
|
487 |
|
virtual void integrateStep( int calcPot, int calcStress ){ |
488 |
|
calcStress = 1; |
489 |
< |
Integrator::integrateStep( calcPot, calcStress ); |
489 |
> |
T::integrateStep( calcPot, calcStress ); |
490 |
> |
accIntegralOfChidt(); |
491 |
|
} |
492 |
|
|
493 |
+ |
virtual double getConservedQuantity(void); |
494 |
+ |
|
495 |
|
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
496 |
|
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
497 |
|
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
498 |
|
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
499 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol;} |
500 |
+ |
void setPosIterTolerance(double tol) {posIterTolerance = tol;} |
501 |
|
|
502 |
|
protected: |
503 |
|
|
504 |
|
virtual void moveA( void ); |
505 |
|
virtual void moveB( void ); |
506 |
|
|
507 |
+ |
virtual void resetIntegrator( void ); |
508 |
+ |
|
509 |
|
virtual int readyCheck(); |
510 |
|
|
511 |
+ |
void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} |
512 |
+ |
|
513 |
|
Molecule* myMolecules; |
514 |
|
Atom** myAtoms; |
515 |
|
|
518 |
|
double chi; |
519 |
|
double eta[3][3]; |
520 |
|
double NkBT; |
521 |
+ |
double integralOfChidt; |
522 |
|
|
523 |
|
// targetTemp, targetPressure, and tauBarostat must be set. |
524 |
|
// One of qmass or tauThermostat must be set; |
530 |
|
|
531 |
|
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
532 |
|
short int have_target_pressure; |
533 |
+ |
double chiTolerance; |
534 |
+ |
short int have_chi_tolerance; |
535 |
+ |
double posIterTolerance; |
536 |
+ |
short int have_pos_iter_tolerance; |
537 |
|
|
538 |
|
}; |
539 |
|
|
540 |
+ |
|
541 |
+ |
template<typename T> class NPTpr : public T{ |
542 |
+ |
|
543 |
+ |
public: |
544 |
+ |
|
545 |
+ |
NPTpr ( SimInfo *theInfo, ForceFields* the_ff); |
546 |
+ |
virtual ~NPTpr() {}; |
547 |
+ |
|
548 |
+ |
virtual void integrateStep( int calcPot, int calcStress ){ |
549 |
+ |
calcStress = 1; |
550 |
+ |
T::integrateStep( calcPot, calcStress ); |
551 |
+ |
} |
552 |
+ |
|
553 |
+ |
void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} |
554 |
+ |
void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} |
555 |
+ |
void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} |
556 |
+ |
void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} |
557 |
+ |
void setChiTolerance(double tol) {chiTolerance = tol;} |
558 |
+ |
void setPosIterTolerance(double tol) {posIterTolerance = tol;} |
559 |
+ |
|
560 |
+ |
protected: |
561 |
+ |
|
562 |
+ |
virtual void moveA( void ); |
563 |
+ |
virtual void moveB( void ); |
564 |
+ |
|
565 |
+ |
virtual int readyCheck(); |
566 |
+ |
|
567 |
+ |
virtual void resetIntegrator( void ); |
568 |
+ |
|
569 |
+ |
// chi and eta are the propagated degrees of freedom |
570 |
+ |
|
571 |
+ |
double chi; |
572 |
+ |
double eta[3][3]; |
573 |
+ |
double NkBT; |
574 |
+ |
|
575 |
+ |
// targetTemp, targetPressure, and tauBarostat must be set. |
576 |
+ |
// One of qmass or tauThermostat must be set; |
577 |
+ |
|
578 |
+ |
double targetTemp; |
579 |
+ |
double targetPressure; |
580 |
+ |
double tauThermostat; |
581 |
+ |
double tauBarostat; |
582 |
+ |
|
583 |
+ |
short int have_tau_thermostat, have_tau_barostat, have_target_temp; |
584 |
+ |
short int have_target_pressure; |
585 |
+ |
double chiTolerance; |
586 |
+ |
short int have_chi_tolerance; |
587 |
+ |
double posIterTolerance; |
588 |
+ |
short int have_pos_iter_tolerance; |
589 |
+ |
|
590 |
+ |
}; |
591 |
+ |
|
592 |
+ |
|
593 |
+ |
template<typename T> class ZConstraint : public T { |
594 |
+ |
|
595 |
+ |
public: |
596 |
+ |
class ForceSubtractionPolicy{ |
597 |
+ |
public: |
598 |
+ |
ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;} |
599 |
+ |
|
600 |
+ |
virtual void update() = 0; |
601 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
602 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0; |
603 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; |
604 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0; |
605 |
+ |
|
606 |
+ |
protected: |
607 |
+ |
ZConstraint<T>* zconsIntegrator;; |
608 |
+ |
}; |
609 |
+ |
|
610 |
+ |
class PolicyByNumber : public ForceSubtractionPolicy{ |
611 |
+ |
|
612 |
+ |
public: |
613 |
+ |
PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
614 |
+ |
virtual void update(); |
615 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
616 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
617 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
618 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce); |
619 |
+ |
|
620 |
+ |
private: |
621 |
+ |
int totNumOfMovingAtoms; |
622 |
+ |
}; |
623 |
+ |
|
624 |
+ |
class PolicyByMass : public ForceSubtractionPolicy{ |
625 |
+ |
|
626 |
+ |
public: |
627 |
+ |
PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} |
628 |
+ |
|
629 |
+ |
virtual void update(); |
630 |
+ |
virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; |
631 |
+ |
virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; |
632 |
+ |
virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); |
633 |
+ |
virtual double getHFOfUnconsMols(Atom* atom, double totalForce); |
634 |
+ |
|
635 |
+ |
private: |
636 |
+ |
double totMassOfMovingAtoms; |
637 |
+ |
}; |
638 |
+ |
|
639 |
+ |
public: |
640 |
+ |
|
641 |
+ |
ZConstraint( SimInfo *theInfo, ForceFields* the_ff); |
642 |
+ |
~ZConstraint(); |
643 |
+ |
|
644 |
+ |
void setZConsTime(double time) {this->zconsTime = time;} |
645 |
+ |
void getZConsTime() {return zconsTime;} |
646 |
+ |
|
647 |
+ |
void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} |
648 |
+ |
void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} |
649 |
+ |
|
650 |
+ |
void setZConsOutput(const char * fileName) {zconsOutput = fileName;} |
651 |
+ |
string getZConsOutput() {return zconsOutput;} |
652 |
+ |
|
653 |
+ |
virtual void integrate(); |
654 |
+ |
|
655 |
+ |
|
656 |
+ |
#ifdef IS_MPI |
657 |
+ |
virtual void update(); //which is called to indicate the molecules' migration |
658 |
|
#endif |
659 |
+ |
|
660 |
+ |
protected: |
661 |
+ |
|
662 |
+ |
enum ZConsState {zcsMoving, zcsFixed}; |
663 |
+ |
|
664 |
+ |
virtual void calcForce( int calcPot, int calcStress ); |
665 |
+ |
virtual void thermalize(void); |
666 |
+ |
|
667 |
+ |
void zeroOutVel(); |
668 |
+ |
void doZconstraintForce(); |
669 |
+ |
void doHarmonic(); |
670 |
+ |
bool checkZConsState(); |
671 |
+ |
|
672 |
+ |
bool haveFixedZMols(); |
673 |
+ |
bool haveMovingZMols(); |
674 |
+ |
|
675 |
+ |
double calcZSys(); |
676 |
+ |
|
677 |
+ |
int isZConstraintMol(Molecule* mol); |
678 |
+ |
|
679 |
+ |
|
680 |
+ |
double zconsTime; //sample time |
681 |
+ |
double zconsTol; //tolerance of z-contratint |
682 |
+ |
double zForceConst; //base force constant term |
683 |
+ |
//which is estimate by OOPSE |
684 |
+ |
|
685 |
+ |
vector<Molecule*> zconsMols; //z-constraint molecules array |
686 |
+ |
vector<double> massOfZConsMols; //mass of z-constraint molecule |
687 |
+ |
vector<double> kz; //force constant array |
688 |
+ |
vector<ZConsState> states; //state of z-constraint molecules |
689 |
+ |
vector<double> zPos; // |
690 |
+ |
|
691 |
+ |
|
692 |
+ |
vector<Molecule*> unconsMols; //unconstraint molecules array |
693 |
+ |
vector<double> massOfUnconsMols; //mass array of unconstraint molecules |
694 |
+ |
double totalMassOfUncons; //total mas of unconstraint molecules |
695 |
+ |
|
696 |
+ |
vector<ZConsParaItem>* parameters; // |
697 |
+ |
|
698 |
+ |
vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels |
699 |
+ |
|
700 |
+ |
int* indexOfZConsMols; //index of local Z-Constraint Molecules |
701 |
+ |
double* fz; |
702 |
+ |
double* curZPos; |
703 |
+ |
|
704 |
+ |
int totNumOfUnconsAtoms; //total number of uncontraint atoms |
705 |
+ |
|
706 |
+ |
int whichDirection; //constraint direction |
707 |
+ |
|
708 |
+ |
private: |
709 |
+ |
|
710 |
+ |
string zconsOutput; //filename of zconstraint output |
711 |
+ |
ZConsWriter* fzOut; //z-constraint writer |
712 |
+ |
|
713 |
+ |
double curZconsTime; |
714 |
+ |
|
715 |
+ |
double calcMovingMolsCOMVel(); |
716 |
+ |
double calcSysCOMVel(); |
717 |
+ |
double calcTotalForce(); |
718 |
+ |
|
719 |
+ |
ForceSubtractionPolicy* forcePolicy; //force subtraction policy |
720 |
+ |
friend class ForceSubtractionPolicy; |
721 |
+ |
|
722 |
+ |
}; |
723 |
+ |
|
724 |
+ |
#endif |