ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.hpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Integrator.hpp (file contents):
Revision 645 by tim, Tue Jul 22 19:54:52 2003 UTC vs.
Revision 1093 by tim, Wed Mar 17 14:22:59 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines