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 658 by tim, Thu Jul 31 15:35:07 2003 UTC vs.
Revision 763 by tim, Mon Sep 15 16:52:02 2003 UTC

# Line 27 | 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  
31
32   protected:
33    
34    virtual void integrateStep( int calcPot, int calcStress );
# Line 38 | Line 38 | template<typename T = BaseIntegrator> class Integrator
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 <
46 <
49 >         double A[3][3] );
50 >        
51    ForceFields* myFF;
52  
53    SimInfo *info; // all the info we'll ever need
# Line 54 | Line 58 | template<typename T = BaseIntegrator> class Integrator
58    int nMols;
59  
60    int isConstrained; // boolean to know whether the systems contains
61 <                     // constraints.
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
# Line 91 | Line 95 | template<typename T> class NVT : public T { (public)
95   public:
96  
97    NVT ( SimInfo *theInfo, ForceFields* the_ff);
98 <  virtual ~NVT() {}
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 +  void setChiTolerance(double tol) {chiTolerance = tol;}
103 +  virtual double  getConservedQuantity(void);
104  
105   protected:
106  
# Line 103 | Line 109 | template<typename T> class NVT : public T { (public)
109  
110    virtual int readyCheck();
111  
112 +  virtual void resetIntegrator( void );
113 +
114    // chi is a propagated degree of freedom.
115  
116    double chi;
117  
118 +  //integral of chi(t)dt
119 +  double integralOfChidt;
120 +
121    // targetTemp must be set.  tauThermostat must also be set;
122  
123    double targetTemp;
# Line 114 | Line 125 | template<typename T> class NVT : public T { (public)
125    
126    short int have_tau_thermostat, have_target_temp;
127  
128 +  double *oldVel;
129 +  double *oldJi;
130 +
131 +  double chiTolerance;
132 +  short int have_chi_tolerance;
133 +
134   };
135  
136  
# Line 123 | Line 140 | template<typename T> class NPTi : public T{ (public)
140   public:
141  
142    NPTi ( SimInfo *theInfo, ForceFields* the_ff);
143 <  virtual ~NPTi() {};
144 <
143 >  virtual ~NPTi();
144 >  
145    virtual void integrateStep( int calcPot, int calcStress ){
146      calcStress = 1;
147      T::integrateStep( calcPot, calcStress );
148 +    /* accIntegralOfChidt(); */
149    }
150  
151 +  virtual double getConservedQuantity(void);
152 +
153    void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
154    void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
155    void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
156    void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
157 +  void setChiTolerance(double tol) {chiTolerance = tol; have_chi_tolerance = 1;}
158 +  void setPosIterTolerance(double tol) {posIterTolerance = tol; have_pos_iter_tolerance = 1;}
159 +  void setEtaTolerance(double tol) {etaTolerance = tol; have_eta_tolerance = 1;}
160  
161   protected:
162  
# Line 142 | Line 165 | template<typename T> class NPTi : public T{ (public)
165  
166    virtual int readyCheck();
167  
168 +  virtual void resetIntegrator( void );
169 +
170 +  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
171 +
172    // chi and eta are the propagated degrees of freedom
173  
174    double chi;
175    double eta;
176    double NkBT;
177 +  double fkBT;
178  
179 +  int Nparticles;
180 +
181 +  double integralOfChidt;
182 +
183    // targetTemp, targetPressure, and tauBarostat must be set.  
184    // One of qmass or tauThermostat must be set;
185  
# Line 159 | Line 191 | template<typename T> class NPTi : public T{ (public)
191    short int have_tau_thermostat, have_tau_barostat, have_target_temp;
192    short int have_target_pressure;
193  
194 +  double *oldPos;
195 +  double *oldVel;
196 +  double *oldJi;
197 +
198 +  double chiTolerance;
199 +  short int have_chi_tolerance;
200 +  double posIterTolerance;
201 +  short int have_pos_iter_tolerance;
202 +  double etaTolerance;
203 +  short int have_eta_tolerance;
204 +
205 +  double volume;
206 +
207   };
208  
209   template<typename T> class NPTim : public T{
# Line 166 | Line 211 | template<typename T> class NPTim : public T{ (public)
211   public:
212  
213    NPTim ( SimInfo *theInfo, ForceFields* the_ff);
214 <  virtual ~NPTim() {};
214 >  virtual ~NPTim() {}
215 >
216 >  virtual void integrateStep( int calcPot, int calcStress ){
217 >    calcStress = 1;
218 >    T::integrateStep( calcPot, calcStress );
219 >    accIntegralOfChidt();  
220 >  }
221 >
222 >  virtual double getConservedQuantity(void);
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 >  void setChiTolerance(double tol) {chiTolerance = tol;}
229 >  void setPosIterTolerance(double tol) {posIterTolerance = tol;}
230 >
231 > protected:
232 >
233 >  virtual void moveA( void );
234 >  virtual void moveB( void );
235 >
236 >  virtual int readyCheck();
237 >
238 >  virtual void resetIntegrator( void );
239 >
240 >  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
241 >  
242 >  Molecule* myMolecules;
243 >  Atom** myAtoms;
244 >
245 >  // chi and eta are the propagated degrees of freedom
246 >
247 >  double chi;
248 >  double eta;
249 >  double NkBT;
250 >  double integralOfChidt;
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 +  double chiTolerance;
263 +  short int have_chi_tolerance;
264 +  double posIterTolerance;
265 +  short int have_pos_iter_tolerance;
266 +
267 + };
268 +
269 + template<typename T> class NPTzm : public T{
270 +
271 + public:
272 +
273 +  NPTzm ( SimInfo *theInfo, ForceFields* the_ff);
274 +  virtual ~NPTzm() {};
275 +
276    virtual void integrateStep( int calcPot, int calcStress ){
277      calcStress = 1;
278      T::integrateStep( calcPot, calcStress );
# Line 185 | Line 290 | template<typename T> class NPTim : public T{ (public)
290  
291    virtual int readyCheck();
292  
293 +  virtual void resetIntegrator( void );
294 +
295    Molecule* myMolecules;
296    Atom** myAtoms;
297  
# Line 192 | Line 299 | template<typename T> class NPTim : public T{ (public)
299  
300    double chi;
301    double eta;
302 +  double etaZ;
303    double NkBT;
304  
305    // targetTemp, targetPressure, and tauBarostat must be set.  
# Line 217 | Line 325 | template<typename T> class NPTf : public T{ (public)
325    virtual void integrateStep( int calcPot, int calcStress ){
326      calcStress = 1;
327      T::integrateStep( calcPot, calcStress );
328 +    accIntegralOfChidt();
329    }
330 +  
331 +  virtual double getConservedQuantity(void);
332  
333    void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
334    void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
335    void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
336    void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
337 +  void setChiTolerance(double tol) {chiTolerance = tol;}
338 +  void setPosIterTolerance(double tol) {posIterTolerance = tol;}
339  
340   protected:
341  
342    virtual void  moveA( void );
343    virtual void moveB( void );
344  
345 +  virtual void resetIntegrator( void );
346 +
347    virtual int readyCheck();
348  
349 +  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
350 +
351    // chi and eta are the propagated degrees of freedom
352  
353    double chi;
354    double eta[3][3];
355    double NkBT;
356  
357 +  double integralOfChidt;
358 +  
359    // targetTemp, targetPressure, and tauBarostat must be set.  
360    // One of qmass or tauThermostat must be set;
361  
# Line 247 | Line 366 | template<typename T> class NPTf : public T{ (public)
366  
367    short int have_tau_thermostat, have_tau_barostat, have_target_temp;
368    short int have_target_pressure;
369 +  double chiTolerance;
370 +  short int have_chi_tolerance;
371 +  double posIterTolerance;
372 +  short int have_pos_iter_tolerance;
373  
374   };
375  
376 + template<typename T> class NPTxym : public T{
377 +
378 + public:
379 +
380 +  NPTxym ( SimInfo *theInfo, ForceFields* the_ff);
381 +  virtual ~NPTxym() {};
382 +
383 +  virtual void integrateStep( int calcPot, int calcStress ){
384 +    calcStress = 1;
385 +    T::integrateStep( calcPot, calcStress );
386 +  }
387 +
388 +  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
389 +  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
390 +  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
391 +  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
392 +
393 + protected:
394 +
395 +  virtual void moveA( void );
396 +  virtual void moveB( void );
397 +
398 +  virtual int readyCheck();
399 +
400 +  virtual void resetIntegrator( void );
401 +
402 +  Molecule* myMolecules;
403 +  Atom** myAtoms;
404 +
405 +  // chi and eta are the propagated degrees of freedom
406 +
407 +  double chi;
408 +  double eta;
409 +  double etaX;
410 +  double etaY;
411 +  double NkBT;
412 +
413 +  // targetTemp, targetPressure, and tauBarostat must be set.  
414 +  // One of qmass or tauThermostat must be set;
415 +
416 +  double targetTemp;
417 +  double targetPressure;
418 +  double tauThermostat;
419 +  double tauBarostat;
420 +
421 +  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
422 +  short int have_target_pressure;
423 +
424 + };
425 +
426 +
427   template<typename T> class NPTfm : public T{
428  
429   public:
# Line 260 | Line 434 | template<typename T> class NPTfm : public T{ (public)
434    virtual void integrateStep( int calcPot, int calcStress ){
435      calcStress = 1;
436      T::integrateStep( calcPot, calcStress );
437 +    accIntegralOfChidt();
438    }
439  
440 +  virtual double getConservedQuantity(void);
441 +  
442    void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
443    void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
444    void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
445    void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
446 +  void setChiTolerance(double tol) {chiTolerance = tol;}
447 +  void setPosIterTolerance(double tol) {posIterTolerance = tol;}
448  
449   protected:
450  
451    virtual void  moveA( void );
452    virtual void moveB( void );
453  
454 +  virtual void resetIntegrator( void );
455 +
456    virtual int readyCheck();
457  
458 +  void accIntegralOfChidt(void) { integralOfChidt += dt * chi;}
459 +
460    Molecule* myMolecules;
461    Atom** myAtoms;
462  
# Line 282 | Line 465 | template<typename T> class NPTfm : public T{ (public)
465    double chi;
466    double eta[3][3];
467    double NkBT;
468 +  double integralOfChidt;
469  
470    // targetTemp, targetPressure, and tauBarostat must be set.  
471    // One of qmass or tauThermostat must be set;
# Line 293 | Line 477 | template<typename T> class NPTfm : public T{ (public)
477  
478    short int have_tau_thermostat, have_tau_barostat, have_target_temp;
479    short int have_target_pressure;
480 +  double chiTolerance;
481 +  short int have_chi_tolerance;
482 +  double posIterTolerance;
483 +  short int have_pos_iter_tolerance;
484  
485   };
486  
487 +
488 + template<typename T> class NPTpr : public T{
489 +
490 + public:
491 +
492 +  NPTpr ( SimInfo *theInfo, ForceFields* the_ff);
493 +  virtual ~NPTpr() {};
494 +
495 +  virtual void integrateStep( int calcPot, int calcStress ){
496 +    calcStress = 1;
497 +    T::integrateStep( calcPot, calcStress );
498 +  }
499 +
500 +  void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;}
501 +  void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;}
502 +  void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;}
503 +  void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;}
504 +  void setChiTolerance(double tol) {chiTolerance = tol;}
505 +  void setPosIterTolerance(double tol) {posIterTolerance = tol;}
506 +
507 + protected:
508 +
509 +  virtual void  moveA( void );
510 +  virtual void moveB( void );
511 +
512 +  virtual int readyCheck();
513 +
514 +  virtual void resetIntegrator( void );
515 +
516 +  // chi and eta are the propagated degrees of freedom
517 +
518 +  double chi;
519 +  double eta[3][3];
520 +  double NkBT;
521 +
522 +  // targetTemp, targetPressure, and tauBarostat must be set.  
523 +  // One of qmass or tauThermostat must be set;
524 +
525 +  double targetTemp;
526 +  double targetPressure;
527 +  double tauThermostat;
528 +  double tauBarostat;
529 +
530 +  short int have_tau_thermostat, have_tau_barostat, have_target_temp;
531 +  short int have_target_pressure;
532 +  double chiTolerance;
533 +  short int have_chi_tolerance;
534 +  double posIterTolerance;
535 +  short int have_pos_iter_tolerance;
536 +
537 + };
538 +
539 +
540   template<typename T> class ZConstraint : public T {
541 +  
542 +  public:
543 +  class ForceSubtractionPolicy{
544 +    public:
545 +      ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;}
546  
547 +      virtual void update() = 0;    
548 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
549 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0;
550 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0;
551 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0;
552 +    
553 +   protected:
554 +     ZConstraint<T>* zconsIntegrator;;
555 +  };
556 +
557 +  class PolicyByNumber : public ForceSubtractionPolicy{
558 +
559 +    public:
560 +      PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}    
561 +      virtual void update();    
562 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
563 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
564 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
565 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
566 +    
567 +    private:
568 +      int totNumOfMovingAtoms;
569 +  };
570 +
571 +  class PolicyByMass : public ForceSubtractionPolicy{
572 +
573 +    public:
574 +      PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {}  
575 +      
576 +      virtual void update();    
577 +      virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ;
578 +      virtual double getZFOfMovingMols(Atom* atom, double totalForce) ;
579 +      virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce);
580 +      virtual double getHFOfUnconsMols(Atom* atom, double totalForce);
581 +
582 +   private:
583 +     double totMassOfMovingAtoms;
584 +  };
585 +
586   public:
587  
588    ZConstraint( SimInfo *theInfo, ForceFields* the_ff);
589    ~ZConstraint();
590 <
306 <  virtual void integrateStep( int calcPot, int calcStress );
307 <  
308 <  
590 >    
591    void setZConsTime(double time)                  {this->zconsTime = time;}
592    void getZConsTime()                             {return zconsTime;}
593    
594 <  void setIndexOfAllZConsMols(vector<int> index)  {indexOfAllZConsMols = index;}
595 <  void getIndexOfAllZConsMols()                   {return indexOfAllZConsMols;}
594 >  void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;}
595 >  void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;}
596    
597 <  void setZConsOutput(const char * fileName)      {zconsOutput = fileName;}
597 >  void setZConsOutput(const char * fileName)          {zconsOutput = fileName;}
598    string getZConsOutput()                         {return zconsOutput;}
599 +  
600 +  virtual void integrate();
601 +  
602  
603   #ifdef IS_MPI
604 <  virtual void update(); //which is called to indicate the molecules' migration
604 >  virtual void update();                      //which is called to indicate the molecules' migration
605   #endif
606  
607   protected:
608  
609 <  double zconsTime;
609 >  enum ZConsState {zcsMoving, zcsFixed};  
610 >
611 >  virtual void calcForce( int calcPot, int calcStress );
612 >  virtual void thermalize(void);
613    
614 <  void resetZ(void);
614 >  void zeroOutVel();
615 >  void doZconstraintForce();
616 >  void doHarmonic();
617 >  bool checkZConsState();
618 >
619 >  bool haveFixedZMols();
620 >  bool haveMovingZMols();
621 >
622 >  double calcZSys();
623 >
624 >  int isZConstraintMol(Molecule* mol);
625 >
626 >
627 >  double zconsTime;                              //sample time
628 >  double zconsTol;                                 //tolerance of z-contratint
629 >  double zForceConst;                           //base force constant term
630 >                                                          //which is estimate by OOPSE
631    
632 <  vector<Molecule*> zconsMols;
633 <  vector<double> massOfZConsMols;
632 >  vector<Molecule*> zconsMols;              //z-constraint molecules array
633 >  vector<double> massOfZConsMols;       //mass of z-constraint molecule
634 >  vector<double> kz;                              //force constant array
635 >  vector<ZConsState> states;                 //state of z-constraint molecules
636 >  vector<double> zPos;                          //
637    
638 <  vector<Molecule*> unconsMols;
639 <  vector<double> massOfUnconsMols;
640 <  double totalMassOfUncons;
638 >  
639 >  vector<Molecule*> unconsMols;           //unconstraint molecules array
640 >  vector<double> massOfUnconsMols;    //mass array of unconstraint molecules
641 >  double totalMassOfUncons;                //total mas of unconstraint molecules
642  
643 <  vector<double> allRefZ;    
336 <  vector<double> refZ;
643 >  vector<ZConsParaItem>* parameters; //
644    
645    vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels
646 <  int* indexOfZConsMols;               //index of local Z-Constraint Molecules
647 <    
646 >
647 >  int* indexOfZConsMols;                   //index of local Z-Constraint Molecules  
648    double* fz;
649 +  double* curZPos;
650    
651 +  int totNumOfUnconsAtoms;              //total number of uncontraint atoms
652 +
653 +  int whichDirection;                           //constraint direction
654 +  
655   private:
656 +  
657 +  string zconsOutput;                         //filename of zconstraint output
658 +  ZConsWriter* fzOut;                         //z-constraint writer
659  
660 <  int isZConstraintMol(Molecule* mol);
661 <  string zconsOutput;
662 <  ZConsWriter* fzOut;
660 >  double curZconsTime;                      
661 >
662 >  double calcMovingMolsCOMVel();
663 >  double calcSysCOMVel();
664 >  double calcTotalForce();
665 >  
666 >  ForceSubtractionPolicy* forcePolicy; //force subtraction policy
667 >  friend class ForceSubtractionPolicy;
668 >
669   };
670  
671   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines