--- trunk/OOPSE/libmdtools/Integrator.hpp 2003/09/22 21:23:25 780 +++ trunk/OOPSE/libmdtools/Integrator.hpp 2004/01/27 19:15:20 987 @@ -28,6 +28,7 @@ template class Integrator virtual ~Integrator(); void integrate( void ); virtual double getConservedQuantity(void); + virtual string getAdditionalParameters(void); protected: @@ -40,16 +41,16 @@ template class Integrator virtual int readyCheck( void ) { return 1; } virtual void resetIntegrator( void ) { } - - virtual void calcForce( int calcPot, int calcStress ); + + virtual void calcForce( int calcPot, int calcStress ); virtual void thermalize(); - + virtual void rotationPropagation( DirectionalAtom* dAtom, double ji[3] ); void checkConstraints( void ); - void rotate( int axes1, int axes2, double angle, double j[3], + void rotate( int axes1, int axes2, double angle, double j[3], double A[3][3] ); - + ForceFields* myFF; SimInfo *info; // all the info we'll ever need @@ -61,24 +62,24 @@ template class Integrator 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 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 + double* oldPos; // pre constrained positions short isFirst; /*boolean for the first time integrate is called */ - + double dt; double dt2; Thermo *tStats; StatWriter* statOut; DumpWriter* dumpOut; - + }; typedef Integrator RealIntegrator; @@ -88,7 +89,7 @@ template class NVE : public T { (public) public: NVE ( SimInfo *theInfo, ForceFields* the_ff ): T( theInfo, the_ff ){} - virtual ~NVE(){} + virtual ~NVE(){} }; @@ -103,6 +104,7 @@ template class NVT : public T { (public) void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} void setChiTolerance(double tol) {chiTolerance = tol;} virtual double getConservedQuantity(void); + virtual string getAdditionalParameters(void); protected: @@ -124,7 +126,7 @@ template class NVT : public T { (public) double targetTemp; double tauThermostat; - + short int have_tau_thermostat, have_target_temp; double *oldVel; @@ -143,13 +145,17 @@ template class NPT : public T{ (public) NPT ( SimInfo *theInfo, ForceFields* the_ff); virtual ~NPT(); - + virtual void integrateStep( int calcPot, int calcStress ){ calcStress = 1; T::integrateStep( calcPot, calcStress ); } virtual double getConservedQuantity(void) = 0; + virtual string getAdditionalParameters(void) = 0; + + double myTauThermo( void ) { return tauThermostat; } + double myTauBaro( void ) { return tauBarostat; } void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} @@ -170,12 +176,14 @@ template class NPT : public T{ (public) virtual void getVelScaleA( double sc[3], double vel[3] ) = 0; virtual void getVelScaleB( double sc[3], int index ) = 0; - virtual void getPosScale(double pos[3], double COM[3], + virtual void getPosScale(double pos[3], double COM[3], int index, double sc[3]) = 0; + virtual void calcVelScale( void ) = 0; + virtual bool chiConverged( void ); virtual bool etaConverged( void ) = 0; - + virtual void evolveChiA( void ); virtual void evolveEtaA( void ) = 0; virtual void evolveChiB( void ); @@ -201,7 +209,7 @@ template class NPT : public T{ (public) double integralOfChidt; - // targetTemp, targetPressure, and tauBarostat must be set. + // targetTemp, targetPressure, and tauBarostat must be set. // One of qmass or tauThermostat must be set; double targetTemp; @@ -226,18 +234,18 @@ template class NPTi : public T{ }; template class NPTi : public T{ - + public: NPTi( SimInfo *theInfo, ForceFields* the_ff); ~NPTi(); virtual double getConservedQuantity(void); virtual void resetIntegrator(void); - + virtual string getAdditionalParameters(void); protected: - + virtual void evolveEtaA(void); virtual void evolveEtaB(void); @@ -247,59 +255,13 @@ template class NPTi : public T{ virtual void getVelScaleA( double sc[3], double vel[3] ); virtual void getVelScaleB( double sc[3], int index ); - virtual void getPosScale(double pos[3], double COM[3], + virtual void getPosScale(double pos[3], double COM[3], int index, double sc[3]); - double eta, oldEta, prevEta; -}; + virtual void calcVelScale( void ); -template class NPTzm : public T{ - -public: - - NPTzm ( SimInfo *theInfo, ForceFields* the_ff); - virtual ~NPTzm() {}; - - 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 etaZ; - 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; - + double eta, oldEta, prevEta; + double vScale; }; template class NPTf : public T{ @@ -310,6 +272,7 @@ template class NPTf : public T{ (public) virtual ~NPTf(); virtual double getConservedQuantity(void); + virtual string getAdditionalParameters(void); virtual void resetIntegrator(void); protected: @@ -323,205 +286,78 @@ template class NPTf : public T{ (public) virtual void getVelScaleA( double sc[3], double vel[3] ); virtual void getVelScaleB( double sc[3], int index ); - virtual void getPosScale(double pos[3], double COM[3], + virtual void getPosScale(double pos[3], double COM[3], int index, double sc[3]); + virtual void calcVelScale( void ); + double eta[3][3]; double oldEta[3][3]; double prevEta[3][3]; + double vScale[3][3]; }; -template class NPTxym : public T{ +template class NPTxyz : public T{ public: - NPTxym ( SimInfo *theInfo, ForceFields* the_ff); - virtual ~NPTxym() {}; + NPTxyz ( SimInfo *theInfo, ForceFields* the_ff); + virtual ~NPTxyz(); - 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 etaX; - double etaY; - 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 ); - accIntegralOfChidt(); - } - virtual double getConservedQuantity(void); - - 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;} - void setChiTolerance(double tol) {chiTolerance = tol;} - void setPosIterTolerance(double tol) {posIterTolerance = tol;} + virtual string getAdditionalParameters(void); + virtual void resetIntegrator(void); protected: - virtual void moveA( void ); - virtual void moveB( void ); + virtual void evolveEtaA(void); + virtual void evolveEtaB(void); - virtual void resetIntegrator( void ); + virtual bool etaConverged( void ); - virtual int readyCheck(); + virtual void scaleSimBox( void ); - void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} - - Molecule* myMolecules; - Atom** myAtoms; - - // chi and eta are the propagated degrees of freedom + virtual void getVelScaleA( double sc[3], double vel[3] ); + virtual void getVelScaleB( double sc[3], int index ); + virtual void getPosScale(double pos[3], double COM[3], + int index, double sc[3]); - double chi; - double eta[3][3]; - double NkBT; - double integralOfChidt; + virtual void calcVelScale( void ); - // 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; - double chiTolerance; - short int have_chi_tolerance; - double posIterTolerance; - short int have_pos_iter_tolerance; - -}; - - -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;} - void setChiTolerance(double tol) {chiTolerance = tol;} - void setPosIterTolerance(double tol) {posIterTolerance = tol;} - -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; - double chiTolerance; - short int have_chi_tolerance; - double posIterTolerance; - short int have_pos_iter_tolerance; - + double oldEta[3][3]; + double prevEta[3][3]; + double vScale[3][3]; }; template class ZConstraint : public T { - - public: + + public: class ForceSubtractionPolicy{ public: ForceSubtractionPolicy(ZConstraint* integrator) {zconsIntegrator = integrator;} - virtual void update() = 0; + 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;; + ZConstraint* zconsIntegrator; }; class PolicyByNumber : public ForceSubtractionPolicy{ public: - PolicyByNumber(ZConstraint* integrator) :ForceSubtractionPolicy(integrator) {} - virtual void update(); + 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; }; @@ -529,9 +365,9 @@ template class ZConstraint : public T { class PolicyByMass : public ForceSubtractionPolicy{ public: - PolicyByMass(ZConstraint* integrator) :ForceSubtractionPolicy(integrator) {} - - virtual void update(); + 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); @@ -545,30 +381,41 @@ template class ZConstraint : public T { 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 + enum ZConsState {zcsMoving, zcsFixed}; + + vector zconsMols; //z-constraint molecules array + vector states; //state of z-constraint molecules + + + + int totNumOfUnconsAtoms; //total number of uncontraint atoms + double totalMassOfUncons; //total mas of unconstraint molecules + + protected: - enum ZConsState {zcsMoving, zcsFixed}; - - virtual void calcForce( int calcPot, int calcStress ); + + + virtual void calcForce( int calcPot, int calcStress ); virtual void thermalize(void); - + void zeroOutVel(); void doZconstraintForce(); void doHarmonic(); @@ -586,44 +433,62 @@ template class ZConstraint : public T { 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 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 + int* indexOfZConsMols; //index of local Z-Constraint Molecules double* fz; double* curZPos; - - int totNumOfUnconsAtoms; //total number of uncontraint atoms - int whichDirection; //constraint direction - + + + int whichDirection; //constraint direction + private: - + string zconsOutput; //filename of zconstraint output ZConsWriter* fzOut; //z-constraint writer - double curZconsTime; + double curZconsTime; double calcMovingMolsCOMVel(); double calcSysCOMVel(); double calcTotalForce(); - + ForceSubtractionPolicy* forcePolicy; //force subtraction policy friend class ForceSubtractionPolicy; }; +class OOPSEMinimizerBase : public RealIntegrator { + public: + + OOPSEMinimizerBase ( SimInfo *theInfo, ForceFields* the_ff ); + virtual ~OOPSEMinimizerBase(); + + double calcGradient(const vector& x, vector& grad); + void setOptCoor(vector& x); + void getOptCoor(vector& x); + void output(); + +}; + +template class OOPSEMinimizer : public OOPSEMinimizerBase, TMinimizer{ + public: + void writeOutput(); +}; + #endif