--- branches/mmeineke/OOPSE/libmdtools/Integrator.hpp 2003/03/21 17:42:12 377 +++ trunk/OOPSE/libmdtools/Integrator.hpp 2003/09/04 21:48:35 746 @@ -1,74 +1,489 @@ #ifndef _INTEGRATOR_H_ #define _INTEGRATOR_H_ +#include +#include #include "Atom.hpp" +#include "Molecule.hpp" #include "SRI.hpp" #include "AbstractClasses.hpp" #include "SimInfo.hpp" #include "ForceFields.hpp" +#include "Thermo.hpp" +#include "ReadWrite.hpp" +#include "ZConsWriter.hpp" -class Verlet : public Integrator { +using namespace std; +const double kB = 8.31451e-7;// boltzmann constant amu*Ang^2*fs^-2/K +const double eConvert = 4.184e-4; // converts kcal/mol -> amu*A^2/fs^2 +const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm +const int maxIteration = 300; +const double tol = 1.0e-6; + +template class Integrator : public T { + public: - Verlet( SimInfo &info, ForceFields* the_ff ); - ~Verlet(); + Integrator( SimInfo *theInfo, ForceFields* the_ff ); + virtual ~Integrator(); void integrate( void ); -private: + +protected: - void move_a( double dt ); - void move_b( double dt ); + virtual void integrateStep( int calcPot, int calcStress ); + virtual void preMove( void ); + virtual void moveA( void ); + virtual void moveB( void ); + virtual void constrainA( void ); + virtual void constrainB( void ); + virtual int readyCheck( void ) { return 1; } + virtual void resetIntegrator( void ) { } + + virtual void calcForce( int calcPot, int calcStress ); + virtual void thermalize(); + + void checkConstraints( void ); + void rotate( int axes1, int axes2, double angle, double j[3], + double A[3][3] ); + ForceFields* myFF; - SimInfo *entry_plug; // all the info we'll ever need - int c_natoms; /* the number of atoms */ - Atom **c_atoms; /* array of atom pointers */ - SRI **c_sr_interactions; /* array of SRI pointers */ - int c_n_SRI; /* the number of short range interactions */ + SimInfo *info; // all the info we'll ever need + int nAtoms; /* the number of atoms */ + int oldAtoms; + Atom **atoms; /* array of atom pointers */ + Molecule* molecules; + int nMols; - int c_is_constrained; /*boolean to know whether the systems contains - constraints. */ - int c_n_constrained; /*counter for number of constraints */ - int *c_constrained_i; /* the i of a constraint pair */ - int *c_constrained_j; /* the j of a constraint pair */ - double *c_constrained_dsqr; /* the square of the constraint distance */ - double *c_mass; /* the array of masses */ - short is_first; /*boolean for the first time integrate is called */ - double c_box_x; - double c_box_y; - double c_box_z; -}; + int isConstrained; // boolean to know whether the systems contains + // constraints. + int nConstrained; // counter for number of constraints + int *constrainedA; // the i of a constraint pair + int *constrainedB; // the j of a constraint pair + double *constrainedDsqr; // the square of the constraint distance + + int* moving; // tells whether we are moving atom i + int* moved; // tells whether we have moved atom i + double* oldPos; // pre constrained positions -class Symplectic : public Integrator { + short isFirst; /*boolean for the first time integrate is called */ + double dt; + double dt2; + + Thermo *tStats; + StatWriter* statOut; + DumpWriter* dumpOut; + +}; + +typedef Integrator RealIntegrator; + +template class NVE : public T { + public: - Symplectic( SimInfo* the_entry_plug, ForceFields* the_ff ); - ~Symplectic(); + NVE ( SimInfo *theInfo, ForceFields* the_ff ): + T( theInfo, the_ff ){} + virtual ~NVE(){} +}; + + +template class NVT : public T { + +public: + + NVT ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NVT() {} + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual int readyCheck(); + + virtual void resetIntegrator( void ); + + // chi is a propagated degree of freedom. + + double chi; + + // targetTemp must be set. tauThermostat must also be set; + + double targetTemp; + double tauThermostat; - void integrate( void ); + short int have_tau_thermostat, have_target_temp; -private: +}; - void rotate( int axes1, int axes2, double angle, double j[3], - double A[3][3] ); - SimInfo* entry_plug; - ForceFields* myFF; - int is_constrained; /*boolean to know whether the systems contains - constraints. */ - int n_constrained; /*counter for number of constraints */ - int *constrained_i; /* the i of a constraint pair */ - int *constrained_j; /* the j of a constraint pair */ - double *constrained_dsqr; /* the square of the constraint distance */ - double *mass; /* the array of masses */ +template class NPTi : public T{ - short int isFirst; +public: - SRI **srInteractions; /* array of SRI pointers */ - int nSRI; /* the number of short range interactions */ + NPTi ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTi() {}; + + virtual void integrateStep( int calcPot, int calcStress ){ + calcStress = 1; + T::integrateStep( calcPot, calcStress ); + } + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual int readyCheck(); + + virtual void resetIntegrator( void ); + + // chi and eta are the propagated degrees of freedom + + double chi; + double eta; + double NkBT; + + // targetTemp, targetPressure, and tauBarostat must be set. + // One of qmass or tauThermostat must be set; + + double targetTemp; + double targetPressure; + double tauThermostat; + double tauBarostat; + + short int have_tau_thermostat, have_tau_barostat, have_target_temp; + short int have_target_pressure; + +}; + +template class NPTim : public T{ + +public: + + NPTim ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTim() {}; + + virtual void integrateStep( int calcPot, int calcStress ){ + calcStress = 1; + T::integrateStep( calcPot, calcStress ); + } + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual int readyCheck(); + + virtual void resetIntegrator( void ); + + Molecule* myMolecules; + Atom** myAtoms; + + // chi and eta are the propagated degrees of freedom + + double chi; + double eta; + double NkBT; + + // targetTemp, targetPressure, and tauBarostat must be set. + // One of qmass or tauThermostat must be set; + + double targetTemp; + double targetPressure; + double tauThermostat; + double tauBarostat; + + short int have_tau_thermostat, have_tau_barostat, have_target_temp; + short int have_target_pressure; + +}; + +template class NPTf : public T{ + +public: + + NPTf ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTf() {}; + + virtual void integrateStep( int calcPot, int calcStress ){ + calcStress = 1; + T::integrateStep( calcPot, calcStress ); + } + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual void resetIntegrator( void ); + + virtual int readyCheck(); + + // chi and eta are the propagated degrees of freedom + + double chi; + double eta[3][3]; + double NkBT; + + // targetTemp, targetPressure, and tauBarostat must be set. + // One of qmass or tauThermostat must be set; + + double targetTemp; + double targetPressure; + double tauThermostat; + double tauBarostat; + + short int have_tau_thermostat, have_tau_barostat, have_target_temp; + short int have_target_pressure; + +}; + +template class NPTfm : public T{ + +public: + + NPTfm ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTfm() {}; + + virtual void integrateStep( int calcPot, int calcStress ){ + calcStress = 1; + T::integrateStep( calcPot, calcStress ); + } + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual void resetIntegrator( void ); + + virtual int readyCheck(); + + Molecule* myMolecules; + Atom** myAtoms; + + // chi and eta are the propagated degrees of freedom + + double chi; + double eta[3][3]; + double NkBT; + + // targetTemp, targetPressure, and tauBarostat must be set. + // One of qmass or tauThermostat must be set; + + double targetTemp; + double targetPressure; + double tauThermostat; + double tauBarostat; + + short int have_tau_thermostat, have_tau_barostat, have_target_temp; + short int have_target_pressure; + +}; + + +template class NPTpr : public T{ + +public: + + NPTpr ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTpr() {}; + + virtual void integrateStep( int calcPot, int calcStress ){ + calcStress = 1; + T::integrateStep( calcPot, calcStress ); + } + + void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} + void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} + void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} + void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} + +protected: + + virtual void moveA( void ); + virtual void moveB( void ); + + virtual int readyCheck(); + + virtual void resetIntegrator( void ); + + // chi and eta are the propagated degrees of freedom + + double chi; + double eta[3][3]; + double NkBT; + + // targetTemp, targetPressure, and tauBarostat must be set. + // One of qmass or tauThermostat must be set; + + double targetTemp; + double targetPressure; + double tauThermostat; + double tauBarostat; + + short int have_tau_thermostat, have_tau_barostat, have_target_temp; + short int have_target_pressure; + +}; + + +template class ZConstraint : public T { + public: + class ForceSubtractionPolicy{ + public: + ForceSubtractionPolicy(ZConstraint* integrator) {zconsIntegrator = integrator;} + + virtual void update() = 0; + virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; + virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0; + virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; + virtual double getHFOfUnconsMols(Atom* atom, double totalForce) = 0; + + protected: + ZConstraint* zconsIntegrator;; + }; + + class PolicyByNumber : public ForceSubtractionPolicy{ + public: + PolicyByNumber(ZConstraint* integrator) :ForceSubtractionPolicy(integrator) {} + virtual void update(); + virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; + virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; + virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); + virtual double getHFOfUnconsMols(Atom* atom, double totalForce); + + private: + int totNumOfMovingAtoms; + }; + + class PolicyByMass : public ForceSubtractionPolicy{ + public: + PolicyByMass(ZConstraint* integrator) :ForceSubtractionPolicy(integrator) {} + + virtual void update(); + virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; + virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; + virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); + virtual double getHFOfUnconsMols(Atom* atom, double totalForce); + + private: + double totMassOfMovingAtoms; + }; + +public: + + ZConstraint( SimInfo *theInfo, ForceFields* the_ff); + ~ZConstraint(); + + void setZConsTime(double time) {this->zconsTime = time;} + void getZConsTime() {return zconsTime;} + + void setIndexOfAllZConsMols(vector index) {indexOfAllZConsMols = index;} + void getIndexOfAllZConsMols() {return indexOfAllZConsMols;} + + void setZConsOutput(const char * fileName) {zconsOutput = fileName;} + string getZConsOutput() {return zconsOutput;} + + virtual void integrate(); + + +#ifdef IS_MPI + virtual void update(); //which is called to indicate the molecules' migration +#endif + +protected: + + enum ZConsState {zcsMoving, zcsFixed}; + + virtual void calcForce( int calcPot, int calcStress ); + virtual void thermalize(void); + + void zeroOutVel(); + void doZconstraintForce(); + void doHarmonic(); + bool checkZConsState(); + + bool haveFixedZMols(); + bool haveMovingZMols(); + + double calcZSys(); + + int isZConstraintMol(Molecule* mol); + + + double zconsTime; //sample time + double zconsTol; //tolerance of z-contratint + double zForceConst; //base force constant term + //which is estimate by OOPSE + + vector zconsMols; //z-constraint molecules array + vector massOfZConsMols; //mass of z-constraint molecule + vector kz; //force constant array + vector states; //state of z-constraint molecules + vector zPos; // + + + vector unconsMols; //unconstraint molecules array + vector massOfUnconsMols; //mass array of unconstraint molecules + double totalMassOfUncons; //total mas of unconstraint molecules + + vector* parameters; // + + vector indexOfAllZConsMols; //index of All Z-Constraint Molecuels + + int* indexOfZConsMols; //index of local Z-Constraint Molecules + double* fz; + double* curZPos; + + int totNumOfUnconsAtoms; //total number of uncontraint atoms + + int whichDirection; //constraint direction + +private: + + string zconsOutput; //filename of zconstraint output + ZConsWriter* fzOut; //z-constraint writer + + double curZconsTime; + + double calcMovingMolsCOMVel(); + double calcSysCOMVel(); + double calcTotalForce(); + + ForceSubtractionPolicy* forcePolicy; //force substration policy + friend class ForceSubtractionPolicy; + }; #endif