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 466 by gezelter, Mon Apr 7 14:30:36 2003 UTC vs.
Revision 747 by gezelter, Fri Sep 5 21:28:52 2003 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"
9   #include "AbstractClasses.hpp"
10   #include "SimInfo.hpp"
11   #include "ForceFields.hpp"
12 < #include "ExtendedSystem.hpp"
12 > #include "Thermo.hpp"
13 > #include "ReadWrite.hpp"
14 > #include "ZConsWriter.hpp"
15  
16 < class Verlet : public Integrator {
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 <  Verlet( SimInfo &info, ForceFields* the_ff, ExtendedSystem* the_es );
28 <  ~Verlet();
27 >  Integrator( SimInfo *theInfo, ForceFields* the_ff );
28 >  virtual ~Integrator();
29    void integrate( void );
30  
31 < private:
31 >
32 > protected:
33    
34 <  void move_a( double dt );
35 <  void move_b( double dt );
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;
24  ExtendedSystem* myES;
52  
53 <  SimInfo *entry_plug; // all the info we'll ever need
54 <  int c_natoms;  /* the number of atoms */
55 <  Atom **c_atoms; /* array of atom pointers */
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 c_is_constrained; /*boolean to know whether the systems contains
61 <                          constraints. */
62 <  int c_n_constrained; /*counter for number of constraints */
63 <  int *c_constrained_i; /* the i of a constraint pair */
64 <  int *c_constrained_j; /* the j of a constraint pair */
65 <  double *c_constrained_dsqr; /* the square of the constraint distance */
66 <  double *c_mass; /* the array of masses */
67 <  short is_first; /*boolean for the first time integrate is called */
68 <  double c_box_x;
69 <  double c_box_y;
42 <  double c_box_z;
43 < };
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 < class Symplectic : public Integrator {
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 <  Symplectic( SimInfo* the_entry_plug,  
88 <              ForceFields* the_ff,
89 <              ExtendedSystem* the_es);
90 <  ~Symplectic();
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 >
103 > protected:
104 >
105 >  virtual void moveA( void );
106 >  virtual void moveB( void );
107 >
108 >  virtual int readyCheck();
109 >
110 >  virtual void resetIntegrator( void );
111 >
112 >  // chi is a propagated degree of freedom.
113 >
114 >  double chi;
115 >
116 >  // targetTemp must be set.  tauThermostat must also be set;
117 >
118 >  double targetTemp;
119 >  double tauThermostat;
120    
121 <  void integrate( void );
121 >  short int have_tau_thermostat, have_target_temp;
122  
123 < private:
123 > };
124  
57  void rotate( int axes1, int axes2, double angle, double j[3],
58               double A[3][3] );
125  
60  SimInfo* entry_plug;
61  ForceFields* myFF;
62  ExtendedSystem* myES;
126  
127 <  Molecule* molecules;
65 <  int nMols;
127 > template<typename T> class NPTi : public T{
128  
129 <  int is_constrained; /*boolean to know whether the systems contains
68 <                          constraints. */
69 <  int n_constrained; /*counter for number of constraints */
70 <  int *constrained_i; /* the i of a constraint pair */
71 <  int *constrained_j; /* the j of a constraint pair */
72 <  double *constrained_dsqr; /* the square of the constraint distance */
73 <  double *mass; /* the array of masses */
129 > public:
130  
131 <  short int isFirst;
131 >  NPTi ( SimInfo *theInfo, ForceFields* the_ff);
132 >  virtual ~NPTi() {};
133  
134 <  SRI **srInteractions; /* array of SRI pointers */
135 <  int nSRI; /* the number of short range interactions */
134 >  virtual void integrateStep( int calcPot, int calcStress ){
135 >    calcStress = 1;
136 >    T::integrateStep( calcPot, calcStress );
137 >  }
138 >
139 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
140 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
141 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
142 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
143 >
144 > protected:
145 >
146 >  virtual void  moveA( void );
147 >  virtual void moveB( void );
148 >
149 >  virtual int readyCheck();
150 >
151 >  virtual void resetIntegrator( void );
152 >
153 >  // chi and eta are the propagated degrees of freedom
154 >
155 >  double chi;
156 >  double eta;
157 >  double NkBT;
158 >
159 >  // targetTemp, targetPressure, and tauBarostat must be set.  
160 >  // One of qmass or tauThermostat must be set;
161 >
162 >  double targetTemp;
163 >  double targetPressure;
164 >  double tauThermostat;
165 >  double tauBarostat;
166 >
167 >  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
168 >  short int have_target_pressure;
169 >
170 > };
171 >
172 > template<typename T> class NPTim : public T{
173 >
174 > public:
175 >
176 >  NPTim ( SimInfo *theInfo, ForceFields* the_ff);
177 >  virtual ~NPTim() {};
178 >
179 >  virtual void integrateStep( int calcPot, int calcStress ){
180 >    calcStress = 1;
181 >    T::integrateStep( calcPot, calcStress );
182 >  }
183 >
184 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
185 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
186 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
187 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
188 >
189 > protected:
190 >
191 >  virtual void moveA( void );
192 >  virtual void moveB( void );
193 >
194 >  virtual int readyCheck();
195 >
196 >  virtual void resetIntegrator( void );
197 >
198 >  Molecule* myMolecules;
199 >  Atom** myAtoms;
200 >
201 >  // chi and eta are the propagated degrees of freedom
202 >
203 >  double chi;
204 >  double eta;
205 >  double NkBT;
206 >
207 >  // targetTemp, targetPressure, and tauBarostat must be set.  
208 >  // One of qmass or tauThermostat must be set;
209 >
210 >  double targetTemp;
211 >  double targetPressure;
212 >  double tauThermostat;
213 >  double tauBarostat;
214 >
215 >  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
216 >  short int have_target_pressure;
217 >
218 > };
219 >
220 > template<typename T> class NPTf : public T{
221 >
222 > public:
223 >
224 >  NPTf ( SimInfo *theInfo, ForceFields* the_ff);
225 >  virtual ~NPTf() {};
226 >
227 >  virtual void integrateStep( int calcPot, int calcStress ){
228 >    calcStress = 1;
229 >    T::integrateStep( calcPot, calcStress );
230 >  }
231 >
232 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
233 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
234 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
235 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
236 >
237 > protected:
238 >
239 >  virtual void  moveA( void );
240 >  virtual void moveB( void );
241 >
242 >  virtual void resetIntegrator( void );
243 >
244 >  virtual int readyCheck();
245 >
246 >  // chi and eta are the propagated degrees of freedom
247 >
248 >  double chi;
249 >  double eta[3][3];
250 >  double NkBT;
251 >
252 >  // targetTemp, targetPressure, and tauBarostat must be set.  
253 >  // One of qmass or tauThermostat must be set;
254 >
255 >  double targetTemp;
256 >  double targetPressure;
257 >  double tauThermostat;
258 >  double tauBarostat;
259 >
260 >  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
261 >  short int have_target_pressure;
262 >
263 > };
264 >
265 > template<typename T> class NPTfm : public T{
266 >
267 > public:
268 >
269 >  NPTfm ( SimInfo *theInfo, ForceFields* the_ff);
270 >  virtual ~NPTfm() {};
271 >
272 >  virtual void integrateStep( int calcPot, int calcStress ){
273 >    calcStress = 1;
274 >    T::integrateStep( calcPot, calcStress );
275 >  }
276 >
277 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
278 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
279 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
280 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
281 >
282 > protected:
283 >
284 >  virtual void  moveA( void );
285 >  virtual void moveB( void );
286 >
287 >  virtual void resetIntegrator( void );
288 >
289 >  virtual int readyCheck();
290 >
291 >  Molecule* myMolecules;
292 >  Atom** myAtoms;
293 >
294 >  // chi and eta are the propagated degrees of freedom
295 >
296 >  double chi;
297 >  double eta[3][3];
298 >  double NkBT;
299 >
300 >  // targetTemp, targetPressure, and tauBarostat must be set.  
301 >  // One of qmass or tauThermostat must be set;
302 >
303 >  double targetTemp;
304 >  double targetPressure;
305 >  double tauThermostat;
306 >  double tauBarostat;
307 >
308 >  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
309 >  short int have_target_pressure;
310 >
311 > };
312 >
313 >
314 > template<typename T> class NPTpr : public T{
315 >
316 > public:
317 >
318 >  NPTpr ( SimInfo *theInfo, ForceFields* the_ff);
319 >  virtual ~NPTpr() {};
320 >
321 >  virtual void integrateStep( int calcPot, int calcStress ){
322 >    calcStress = 1;
323 >    T::integrateStep( calcPot, calcStress );
324 >  }
325 >
326 >  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
327 >  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
328 >  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
329 >  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
330 >
331 > protected:
332 >
333 >  virtual void  moveA( void );
334 >  virtual void moveB( void );
335 >
336 >  virtual int readyCheck();
337 >
338 >  virtual void resetIntegrator( void );
339 >
340 >  // chi and eta are the propagated degrees of freedom
341 >
342 >  double chi;
343 >  double eta[3][3];
344 >  double NkBT;
345 >
346 >  // targetTemp, targetPressure, and tauBarostat must be set.  
347 >  // One of qmass or tauThermostat must be set;
348 >
349 >  double targetTemp;
350 >  double targetPressure;
351 >  double tauThermostat;
352 >  double tauBarostat;
353 >
354 >  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
355 >  short int have_target_pressure;
356 >
357 > };
358 >
359 >
360 > template<typename T> class ZConstraint : public T {
361    
362 +  public:
363 +  class ForceSubtractionPolicy{
364 +    public:
365 +      ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
366 +
367 +      virtual void update() = 0;    
368 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
369 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
370 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
371 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
372 +    
373 +   protected:
374 +     ZConstraint<T>* zconsIntegrator;;
375 +  };
376 +
377 +  class PolicyByNumber : public ForceSubtractionPolicy{
378 +
379 +    public:
380 +      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}    
381 +      virtual void update();    
382 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
383 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
384 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
385 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
386 +    
387 +    private:
388 +    int totNumOfMovingAtoms;
389 +  };
390 +
391 +  class PolicyByMass : public ForceSubtractionPolicy{
392 +
393 +    public:
394 +      PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}  
395 +      
396 +      virtual void update();    
397 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
398 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
399 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
400 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
401 +
402 +   private:
403 +     double totMassOfMovingAtoms;
404 +  };
405 +
406 + public:
407 +
408 +  ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
409 +  ~ZConstraint();
410 +    
411 +  void setZConsTime(double time)                  {this->zconsTime = time;}
412 +  void getZConsTime()                             {return zconsTime;}
413 +  
414 +  void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
415 +  void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
416 +  
417 +  void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
418 +  string getZConsOutput()                         {return zconsOutput;}
419 +  
420 +  virtual void integrate();
421 +  
422 +
423 + #ifdef IS_MPI
424 +  virtual void update();                      //which is called to indicate the molecules' migration
425 + #endif
426 +
427 + protected:
428 +
429 +  enum ZConsState {zcsMoving, zcsFixed};  
430 +
431 +  virtual void calcForce( int calcPot, int calcStress );
432 +  virtual void thermalize(void);
433 +  
434 +  void zeroOutVel();
435 +  void doZconstraintForce();
436 +  void doHarmonic();
437 +  bool checkZConsState();
438 +
439 +  bool haveFixedZMols();
440 +  bool haveMovingZMols();
441 +
442 +  double calcZSys();
443 +
444 +  int isZConstraintMol(Molecule* mol);
445 +
446 +
447 +  double zconsTime;                              //sample time
448 +  double zconsTol;                                 //tolerance of z-contratint
449 +  double zForceConst;                           //base force constant term
450 +                                                          //which is estimate by OOPSE
451 +  
452 +  vector<Molecule*> zconsMols;              //z-constraint molecules array
453 +  vector<double> massOfZConsMols;       //mass of z-constraint molecule
454 +  vector<double> kz;                              //force constant array
455 +  vector<ZConsState> states;                 //state of z-constraint molecules
456 +  vector<double> zPos;                          //
457 +  
458 +  
459 +  vector<Molecule*> unconsMols;           //unconstraint molecules array
460 +  vector<double> massOfUnconsMols;    //mass array of unconstraint molecules
461 +  double totalMassOfUncons;                //total mas of unconstraint molecules
462 +
463 +  vector<ZConsParaItem>* parameters; //
464 +  
465 +  vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
466 +
467 +  int* indexOfZConsMols;                   //index of local Z-Constraint Molecules  
468 +  double* fz;
469 +  double* curZPos;
470 +  
471 +  int totNumOfUnconsAtoms;              //total number of uncontraint atoms
472 +
473 +  int whichDirection;                           //constraint direction
474 +  
475 + private:
476 +  
477 +  string zconsOutput;                         //filename of zconstraint output
478 +  ZConsWriter* fzOut;                         //z-constraint writer
479 +
480 +  double curZconsTime;                      
481 +
482 +  double calcMovingMolsCOMVel();
483 +  double calcSysCOMVel();
484 +  double calcTotalForce();
485 +  
486 +  ForceSubtractionPolicy* forcePolicy; //force subtraction policy
487 +  friend class ForceSubtractionPolicy;
488 +
489   };
490  
491   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines