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 561 by mmeineke, Fri Jun 20 20:29:36 2003 UTC vs.
Revision 701 by tim, Wed Aug 20 14:34:04 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 + 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  
17 class Integrator : public BaseIntegrator {
23  
24 + template<typename T = BaseIntegrator> class Integrator : public T {
25 +
26   public:
27    Integrator( SimInfo *theInfo, ForceFields* the_ff );
28    virtual ~Integrator();
# Line 31 | Line 38 | class Integrator : public BaseIntegrator { (protected)
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[9] );
48 <
39 <
47 >         double A[3][3] );
48 >        
49    ForceFields* myFF;
50  
51    SimInfo *info; // all the info we'll ever need
# Line 47 | Line 56 | class Integrator : public BaseIntegrator { (protected)
56    int nMols;
57  
58    int isConstrained; // boolean to know whether the systems contains
59 <                     // constraints.
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
# Line 62 | Line 71 | class Integrator : public BaseIntegrator { (protected)
71    double dt;
72    double dt2;
73  
65  double* pos;
66  double* vel;
67  double* frc;
68  double* trq;
69  double* Amat;
70
74    Thermo *tStats;
75    StatWriter*  statOut;
76    DumpWriter*  dumpOut;
77    
78   };
79  
80 < class NVE : public Integrator{
80 > typedef Integrator<BaseIntegrator> RealIntegrator;
81  
82 + template<typename T> class NVE : public T {
83 +
84   public:
85    NVE ( SimInfo *theInfo, ForceFields* the_ff ):
86 <    Integrator( theInfo, the_ff ){}
87 <  virtual ~NVE(){}
83 <
84 <  
85 <
86 >    T( theInfo, the_ff ){}
87 >  virtual ~NVE(){}  
88   };
89  
88 class NVT : public Integrator{
90  
91 + template<typename T> class NVT : public T {
92 +
93   public:
94  
95    NVT ( SimInfo *theInfo, ForceFields* the_ff);
96    virtual ~NVT() {}
97  
95  void setQmass(double q) {qmass = q; have_qmass = 1;}
98    void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
99    void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
100  
# Line 103 | Line 105 | class NVT : public Integrator{ (protected)
105  
106    virtual int readyCheck();
107  
108 <  // zeta is a propagated degree of freedom.
108 >  // chi is a propagated degree of freedom.
109  
110 <  double zeta;
110 >  double chi;
111  
112 <  // targetTemp must be set.  One of qmass or tauThermostat must be set;
112 >  // targetTemp must be set.  tauThermostat must also be set;
113  
112  double qmass;
114    double targetTemp;
115    double tauThermostat;
116 +  
117 +  short int have_tau_thermostat, have_target_temp;
118  
119 + };
120 +
121 +
122 +
123 + template<typename T> class NPTi : public T{
124 +
125 + public:
126 +
127 +  NPTi ( SimInfo *theInfo, ForceFields* the_ff);
128 +  virtual ~NPTi() {};
129 +
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;
117  
118  short int have_tau_thermostat, have_target_temp, have_qmass;
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 < class NPT : public Integrator{
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 <  NPT ( SimInfo *theInfo, ForceFields* the_ff);
217 <  virtual ~NPT();
216 >  NPTf ( SimInfo *theInfo, ForceFields* the_ff);
217 >  virtual ~NPTf() {};
218  
219 <  void setQmass(double q) {qmass = q; have_qmass = 1;}
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;}
# Line 140 | Line 233 | class NPT : public Integrator{ (protected)
233  
234    virtual int readyCheck();
235  
236 <  Atom** atoms;
236 >  // chi and eta are the propagated degrees of freedom
237  
238 <  // zeta and epsilonDot are the propagated degrees of freedom.
238 >  double chi;
239 >  double eta[3][3];
240 >  double NkBT;
241  
242 <  double zeta;
243 <  double epsilonDot;
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  
153  double qmass;
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, have_qmass;
297 >  short int have_target_pressure;
298  
299   };
300  
301 + template<typename T> class ZConstraint : public T {
302 +  
303 +  public:
304 +  class ForceSubstractionPolicy{
305 +    public:
306 +      ForceSubstractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
307 +
308 +      virtual void update() = 0;    
309 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
310 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
311 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
312 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
313 +    
314 +   protected:
315 +     ZConstraint<T>* zconsIntegrator;;
316 +  };
317 +
318 +  class PolicyByNumber : ForceSubstractionPolicy{
319 +    public:
320 +      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubstractionPolicy(integrator) {}    
321 +      virtual void update();    
322 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
323 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
324 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
325 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
326 +    
327 +    private:
328 +    int totNumOfMovingAtoms;
329 +  };
330 +
331 +  class PolicyByMass :ForceSubstractionPolicy{
332 +    public:
333 +      PolicyByMass(ZConstraint<T>* integrator) :ForceSubstractionPolicy(integrator) {}  
334 +      
335 +      virtual void update();    
336 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
337 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
338 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
339 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
340 +
341 +   private:
342 +     double totMassOfMovingAtoms;
343 +  };
344 +
345 + public:
346 +
347 +  ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
348 +  ~ZConstraint();
349 +    
350 +  void setZConsTime(double time)                  {this->zconsTime = time;}
351 +  void getZConsTime()                             {return zconsTime;}
352 +  
353 +  void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
354 +  void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
355 +  
356 +  void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
357 +  string getZConsOutput()                         {return zconsOutput;}
358 +  
359 +  virtual void integrate();
360 +  
361 +
362 + #ifdef IS_MPI
363 +  virtual void update();                      //which is called to indicate the molecules' migration
364   #endif
365 +
366 + protected:
367 +
368 +  enum ZConsState {zcsMoving, zcsFixed};  
369 +
370 +  virtual void calcForce( int calcPot, int calcStress );
371 +  virtual void thermalize(void);
372 +  
373 +  void zeroOutVel();
374 +  void doZconstraintForce();
375 +  void doHarmonic();
376 +  bool checkZConsState();
377 +
378 +  bool haveFixedZMols();
379 +  bool haveMovingZMols();
380 +
381 +  double calcZSys();
382 +
383 +  int isZConstraintMol(Molecule* mol);
384 +
385 +
386 +  double zconsTime;                              //sample time
387 +  double zconsTol;                                 //tolerance of z-contratint
388 +  double zForceConst;                           //base force constant term
389 +                                                          //which is estimate by OOPSE
390 +  
391 +  vector<Molecule*> zconsMols;              //z-constraint molecules array
392 +  vector<double> massOfZConsMols;       //mass of z-constraint molecule
393 +  vector<double> kz;                              //force constant array
394 +  vector<ZConsState> states;                 //state of z-constraint molecules
395 +  vector<double> zPos;                          //
396 +  
397 +  
398 +  vector<Molecule*> unconsMols;           //unconstraint molecules array
399 +  vector<double> massOfUnconsMols;    //mass array of unconstraint molecules
400 +  double totalMassOfUncons;                //total mas of unconstraint molecules
401 +
402 +  vector<ZConsParaItem>* parameters; //
403 +  
404 +  vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
405 +
406 +  int* indexOfZConsMols;                   //index of local Z-Constraint Molecules  
407 +  double* fz;
408 +  double* curZPos;
409 +  
410 +  int totNumOfUnconsAtoms;              //total number of uncontraint atoms
411 +
412 +  int whichDirection;                           //constraint direction
413 +  
414 + private:
415 +  
416 +  string zconsOutput;                         //filename of zconstraint output
417 +  ZConsWriter* fzOut;                         //z-constraint writer
418 +
419 +  double curZconsTime;                      
420 +
421 +  double calcMovingMolsCOMVel();
422 +  double calcSysCOMVel();
423 +  double calcTotalForce();
424 +  
425 +  ForceSubstractionPolicy* forcePolicy; //force substration policy
426 +  friend class ForceSubstractionPolicy;
427 +
428 + };
429 +
430 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines