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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines