ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
Revision: 1248
Committed: Fri Jun 4 19:30:05 2004 UTC (20 years, 1 month ago) by tim
File size: 13266 byte(s)
Log Message:
constraint algorithm for minimization is working

File Contents

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