ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 767
Committed: Tue Sep 16 20:02:11 2003 UTC (20 years, 9 months ago) by tim
File size: 18246 byte(s)
Log Message:
fixed ecr grow in SimInfo

fixed conserved quantity in NPT (Still some small bug)

NPTi appears very stable.

File Contents

# Content
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 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
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 void checkConstraints( void );
48 void rotate( int axes1, int axes2, double angle, double j[3],
49 double A[3][3] );
50
51 ForceFields* myFF;
52
53 SimInfo *info; // all the info we'll ever need
54 int nAtoms; /* the number of atoms */
55 int oldAtoms;
56 Atom **atoms; /* array of atom pointers */
57 Molecule* molecules;
58 int nMols;
59
60 int isConstrained; // boolean to know whether the systems contains
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
65 double *constrainedDsqr; // the square of the constraint distance
66
67 int* moving; // tells whether we are moving atom i
68 int* moved; // tells whether we have moved atom i
69 double* oldPos; // pre constrained positions
70
71 short isFirst; /*boolean for the first time integrate is called */
72
73 double dt;
74 double dt2;
75
76 Thermo *tStats;
77 StatWriter* statOut;
78 DumpWriter* dumpOut;
79
80 };
81
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 T( theInfo, the_ff ){}
89 virtual ~NVE(){}
90 };
91
92
93 template<typename T> class NVT : public T {
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 template<typename T> class NPTi : public T{
139
140 public:
141
142 NPTi ( SimInfo *theInfo, ForceFields* the_ff);
143 virtual ~NPTi();
144
145 virtual void integrateStep( int calcPot, int calcStress ){
146 calcStress = 1;
147 T::integrateStep( calcPot, calcStress );
148 /* accIntegralOfChidt(); */
149 }
150
151 virtual double getConservedQuantity(void);
152
153 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
154 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
155 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
156 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
157 void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;}
158 void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;}
159 void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;}
160
161 protected:
162
163 virtual void moveA( void );
164 virtual void moveB( void );
165
166 virtual int readyCheck();
167
168 virtual void resetIntegrator( void );
169
170 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
171
172 // chi and eta are the propagated degrees of freedom
173
174 double chi;
175 double eta;
176 double NkBT;
177 double fkBT;
178
179 int Nparticles;
180
181 double integralOfChidt;
182
183 // targetTemp, targetPressure, and tauBarostat must be set.
184 // One of qmass or tauThermostat must be set;
185
186 double targetTemp;
187 double targetPressure;
188 double tauThermostat;
189 double tauBarostat;
190
191 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
192 short int have_target_pressure;
193
194 double *oldPos;
195 double *oldVel;
196 double *oldJi;
197
198 double chiTolerance;
199 short int have_chi_tolerance;
200 double posIterTolerance;
201 short int have_pos_iter_tolerance;
202 double etaTolerance;
203 short int have_eta_tolerance;
204
205 };
206
207 template<typename T> class NPTim : public T{
208
209 public:
210
211 NPTim ( SimInfo *theInfo, ForceFields* the_ff);
212 virtual ~NPTim() {}
213
214 virtual void integrateStep( int calcPot, int calcStress ){
215 calcStress = 1;
216 T::integrateStep( calcPot, calcStress );
217 accIntegralOfChidt();
218 }
219
220 virtual double getConservedQuantity(void);
221
222 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
223 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
224 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
225 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
226 void setChiTolerance(double tol) {chiTolerance = tol;}
227 void setPosIterTolerance(double tol) {posIterTolerance = tol;}
228
229 protected:
230
231 virtual void moveA( void );
232 virtual void moveB( void );
233
234 virtual int readyCheck();
235
236 virtual void resetIntegrator( void );
237
238 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
239
240 Molecule* myMolecules;
241 Atom** myAtoms;
242
243 // chi and eta are the propagated degrees of freedom
244
245 double chi;
246 double eta;
247 double NkBT;
248 double integralOfChidt;
249
250 // targetTemp, targetPressure, and tauBarostat must be set.
251 // One of qmass or tauThermostat must be set;
252
253 double targetTemp;
254 double targetPressure;
255 double tauThermostat;
256 double tauBarostat;
257
258 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
259 short int have_target_pressure;
260 double chiTolerance;
261 short int have_chi_tolerance;
262 double posIterTolerance;
263 short int have_pos_iter_tolerance;
264
265 };
266
267 template<typename T> class NPTzm : public T{
268
269 public:
270
271 NPTzm ( SimInfo *theInfo, ForceFields* the_ff);
272 virtual ~NPTzm() {};
273
274 virtual void integrateStep( int calcPot, int calcStress ){
275 calcStress = 1;
276 T::integrateStep( calcPot, calcStress );
277 }
278
279 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
280 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
281 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
282 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
283
284 protected:
285
286 virtual void moveA( void );
287 virtual void moveB( void );
288
289 virtual int readyCheck();
290
291 virtual void resetIntegrator( void );
292
293 Molecule* myMolecules;
294 Atom** myAtoms;
295
296 // chi and eta are the propagated degrees of freedom
297
298 double chi;
299 double eta;
300 double etaZ;
301 double NkBT;
302
303 // targetTemp, targetPressure, and tauBarostat must be set.
304 // One of qmass or tauThermostat must be set;
305
306 double targetTemp;
307 double targetPressure;
308 double tauThermostat;
309 double tauBarostat;
310
311 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
312 short int have_target_pressure;
313
314 };
315
316 template<typename T> class NPTf : public T{
317
318 public:
319
320 NPTf ( SimInfo *theInfo, ForceFields* the_ff);
321 virtual ~NPTf();
322
323 virtual void integrateStep( int calcPot, int calcStress ){
324 calcStress = 1;
325 T::integrateStep( calcPot, calcStress );
326 }
327
328 virtual double getConservedQuantity(void);
329
330 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
331 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
332 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
333 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
334 void setChiTolerance(double tol) {chiTolerance = tol;}
335 void setPosIterTolerance(double tol) {posIterTolerance = tol;}
336
337 protected:
338
339 virtual void moveA( void );
340 virtual void moveB( void );
341
342 virtual void resetIntegrator( void );
343
344 virtual int readyCheck();
345
346
347 // chi and eta are the propagated degrees of freedom
348
349 double chi;
350 double eta[3][3];
351 double NkBT;
352 double fkBT;
353
354 int Nparticles;
355
356 double *oldPos;
357 double *oldVel;
358 double *oldJi;
359
360 double integralOfChidt;
361
362 // targetTemp, targetPressure, and tauBarostat must be set.
363 // One of qmass or tauThermostat must be set;
364
365 double targetTemp;
366 double targetPressure;
367 double tauThermostat;
368 double tauBarostat;
369
370 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
371 short int have_target_pressure;
372 double chiTolerance;
373 short int have_chi_tolerance;
374 double posIterTolerance;
375 short int have_pos_iter_tolerance;
376 double etaTolerance;
377 short int have_eta_tolerance;
378 };
379
380 template<typename T> class NPTxym : public T{
381
382 public:
383
384 NPTxym ( SimInfo *theInfo, ForceFields* the_ff);
385 virtual ~NPTxym() {};
386
387 virtual void integrateStep( int calcPot, int calcStress ){
388 calcStress = 1;
389 T::integrateStep( calcPot, calcStress );
390 }
391
392 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
393 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
394 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
395 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
396
397 protected:
398
399 virtual void moveA( void );
400 virtual void moveB( void );
401
402 virtual int readyCheck();
403
404 virtual void resetIntegrator( void );
405
406 Molecule* myMolecules;
407 Atom** myAtoms;
408
409 // chi and eta are the propagated degrees of freedom
410
411 double chi;
412 double eta;
413 double etaX;
414 double etaY;
415 double NkBT;
416
417 // targetTemp, targetPressure, and tauBarostat must be set.
418 // One of qmass or tauThermostat must be set;
419
420 double targetTemp;
421 double targetPressure;
422 double tauThermostat;
423 double tauBarostat;
424
425 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
426 short int have_target_pressure;
427
428 };
429
430
431 template<typename T> class NPTfm : public T{
432
433 public:
434
435 NPTfm ( SimInfo *theInfo, ForceFields* the_ff);
436 virtual ~NPTfm() {};
437
438 virtual void integrateStep( int calcPot, int calcStress ){
439 calcStress = 1;
440 T::integrateStep( calcPot, calcStress );
441 accIntegralOfChidt();
442 }
443
444 virtual double getConservedQuantity(void);
445
446 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
447 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
448 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
449 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
450 void setChiTolerance(double tol) {chiTolerance = tol;}
451 void setPosIterTolerance(double tol) {posIterTolerance = tol;}
452
453 protected:
454
455 virtual void moveA( void );
456 virtual void moveB( void );
457
458 virtual void resetIntegrator( void );
459
460 virtual int readyCheck();
461
462 void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
463
464 Molecule* myMolecules;
465 Atom** myAtoms;
466
467 // chi and eta are the propagated degrees of freedom
468
469 double chi;
470 double eta[3][3];
471 double NkBT;
472 double integralOfChidt;
473
474 // targetTemp, targetPressure, and tauBarostat must be set.
475 // One of qmass or tauThermostat must be set;
476
477 double targetTemp;
478 double targetPressure;
479 double tauThermostat;
480 double tauBarostat;
481
482 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
483 short int have_target_pressure;
484 double chiTolerance;
485 short int have_chi_tolerance;
486 double posIterTolerance;
487 short int have_pos_iter_tolerance;
488
489 };
490
491
492 template<typename T> class NPTpr : public T{
493
494 public:
495
496 NPTpr ( SimInfo *theInfo, ForceFields* the_ff);
497 virtual ~NPTpr() {};
498
499 virtual void integrateStep( int calcPot, int calcStress ){
500 calcStress = 1;
501 T::integrateStep( calcPot, calcStress );
502 }
503
504 void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
505 void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
506 void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
507 void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
508 void setChiTolerance(double tol) {chiTolerance = tol;}
509 void setPosIterTolerance(double tol) {posIterTolerance = tol;}
510
511 protected:
512
513 virtual void moveA( void );
514 virtual void moveB( void );
515
516 virtual int readyCheck();
517
518 virtual void resetIntegrator( void );
519
520 // chi and eta are the propagated degrees of freedom
521
522 double chi;
523 double eta[3][3];
524 double NkBT;
525
526 // targetTemp, targetPressure, and tauBarostat must be set.
527 // One of qmass or tauThermostat must be set;
528
529 double targetTemp;
530 double targetPressure;
531 double tauThermostat;
532 double tauBarostat;
533
534 short int have_tau_thermostat, have_tau_barostat, have_target_temp;
535 short int have_target_pressure;
536 double chiTolerance;
537 short int have_chi_tolerance;
538 double posIterTolerance;
539 short int have_pos_iter_tolerance;
540
541 };
542
543
544 template<typename T> class ZConstraint : public T {
545
546 public:
547 class ForceSubtractionPolicy{
548 public:
549 ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
550
551 virtual void update() = 0;
552 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
553 virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
554 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
555 virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
556
557 protected:
558 ZConstraint<T>* zconsIntegrator;;
559 };
560
561 class PolicyByNumber : public ForceSubtractionPolicy{
562
563 public:
564 PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
565 virtual void update();
566 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
567 virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
568 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
569 virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
570
571 private:
572 int totNumOfMovingAtoms;
573 };
574
575 class PolicyByMass : public ForceSubtractionPolicy{
576
577 public:
578 PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}
579
580 virtual void update();
581 virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
582 virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
583 virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
584 virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
585
586 private:
587 double totMassOfMovingAtoms;
588 };
589
590 public:
591
592 ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
593 ~ZConstraint();
594
595 void setZConsTime(double time) {this->zconsTime = time;}
596 void getZConsTime() {return zconsTime;}
597
598 void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
599 void getIndexOfAllZConsMols() {return indexOfAllZConsMols;}
600
601 void setZConsOutput(const char * fileName) {zconsOutput = fileName;}
602 string getZConsOutput() {return zconsOutput;}
603
604 virtual void integrate();
605
606
607 #ifdef IS_MPI
608 virtual void update(); //which is called to indicate the molecules' migration
609 #endif
610
611 protected:
612
613 enum ZConsState {zcsMoving, zcsFixed};
614
615 virtual void calcForce( int calcPot, int calcStress );
616 virtual void thermalize(void);
617
618 void zeroOutVel();
619 void doZconstraintForce();
620 void doHarmonic();
621 bool checkZConsState();
622
623 bool haveFixedZMols();
624 bool haveMovingZMols();
625
626 double calcZSys();
627
628 int isZConstraintMol(Molecule* mol);
629
630
631 double zconsTime; //sample time
632 double zconsTol; //tolerance of z-contratint
633 double zForceConst; //base force constant term
634 //which is estimate by OOPSE
635
636 vector<Molecule*> zconsMols; //z-constraint molecules array
637 vector<double> massOfZConsMols; //mass of z-constraint molecule
638 vector<double> kz; //force constant array
639 vector<ZConsState> states; //state of z-constraint molecules
640 vector<double> zPos; //
641
642
643 vector<Molecule*> unconsMols; //unconstraint molecules array
644 vector<double> massOfUnconsMols; //mass array of unconstraint molecules
645 double totalMassOfUncons; //total mas of unconstraint molecules
646
647 vector<ZConsParaItem>* parameters; //
648
649 vector<int> indexOfAllZConsMols; //index of All Z-Constraint Molecuels
650
651 int* indexOfZConsMols; //index of local Z-Constraint Molecules
652 double* fz;
653 double* curZPos;
654
655 int totNumOfUnconsAtoms; //total number of uncontraint atoms
656
657 int whichDirection; //constraint direction
658
659 private:
660
661 string zconsOutput; //filename of zconstraint output
662 ZConsWriter* fzOut; //z-constraint writer
663
664 double curZconsTime;
665
666 double calcMovingMolsCOMVel();
667 double calcSysCOMVel();
668 double calcTotalForce();
669
670 ForceSubtractionPolicy* forcePolicy; //force subtraction policy
671 friend class ForceSubtractionPolicy;
672
673 };
674
675 #endif