| 1 | mmeineke | 377 | #ifndef _INTEGRATOR_H_ | 
| 2 |  |  | #define _INTEGRATOR_H_ | 
| 3 |  |  |  | 
| 4 | tim | 658 | #include <string> | 
| 5 |  |  | #include <vector> | 
| 6 | mmeineke | 377 | #include "Atom.hpp" | 
| 7 | gezelter | 604 | #include "Molecule.hpp" | 
| 8 | mmeineke | 377 | #include "SRI.hpp" | 
| 9 |  |  | #include "AbstractClasses.hpp" | 
| 10 |  |  | #include "SimInfo.hpp" | 
| 11 |  |  | #include "ForceFields.hpp" | 
| 12 | mmeineke | 540 | #include "Thermo.hpp" | 
| 13 |  |  | #include "ReadWrite.hpp" | 
| 14 | tim | 658 | #include "ZConsWriter.hpp" | 
| 15 | mmeineke | 377 |  | 
| 16 | tim | 658 | using namespace std; | 
| 17 | mmeineke | 561 | 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 | mmeineke | 586 | const double p_convert = 1.63882576e8; //converts amu*fs^-2*Ang^-1 -> atm | 
| 20 | mmeineke | 561 | const int maxIteration = 300; | 
| 21 |  |  | const double tol = 1.0e-6; | 
| 22 |  |  |  | 
| 23 | mmeineke | 377 |  | 
| 24 | tim | 645 | template<typename T = BaseIntegrator> class Integrator : public T { | 
| 25 |  |  |  | 
| 26 | mmeineke | 377 | public: | 
| 27 | mmeineke | 561 | Integrator( SimInfo *theInfo, ForceFields* the_ff ); | 
| 28 | mmeineke | 548 | virtual ~Integrator(); | 
| 29 | mmeineke | 377 | void integrate( void ); | 
| 30 | tim | 763 | virtual double  getConservedQuantity(void); | 
| 31 | mmeineke | 377 |  | 
| 32 | mmeineke | 540 | protected: | 
| 33 | mmeineke | 377 |  | 
| 34 | mmeineke | 540 | virtual void integrateStep( int calcPot, int calcStress ); | 
| 35 | mmeineke | 548 | virtual void preMove( void ); | 
| 36 | mmeineke | 540 | virtual void moveA( void ); | 
| 37 |  |  | virtual void moveB( void ); | 
| 38 |  |  | virtual void constrainA( void ); | 
| 39 |  |  | virtual void constrainB( void ); | 
| 40 | mmeineke | 559 | virtual int  readyCheck( void ) { return 1; } | 
| 41 | tim | 677 |  | 
| 42 | mmeineke | 746 | virtual void resetIntegrator( void ) { } | 
| 43 | tim | 763 |  | 
| 44 | tim | 677 | virtual void calcForce( int calcPot, int calcStress ); | 
| 45 |  |  | virtual void thermalize(); | 
| 46 | mmeineke | 377 |  | 
| 47 | mmeineke | 540 | void checkConstraints( void ); | 
| 48 | mmeineke | 377 | void rotate( int axes1, int axes2, double angle, double j[3], | 
| 49 | tim | 701 | double A[3][3] ); | 
| 50 |  |  |  | 
| 51 | mmeineke | 377 | ForceFields* myFF; | 
| 52 |  |  |  | 
| 53 | mmeineke | 540 | SimInfo *info; // all the info we'll ever need | 
| 54 |  |  | int nAtoms;  /* the number of atoms */ | 
| 55 | mmeineke | 548 | int oldAtoms; | 
| 56 | mmeineke | 540 | Atom **atoms; /* array of atom pointers */ | 
| 57 | mmeineke | 423 | Molecule* molecules; | 
| 58 |  |  | int nMols; | 
| 59 |  |  |  | 
| 60 | mmeineke | 548 | int isConstrained; // boolean to know whether the systems contains | 
| 61 | tim | 701 | // constraints. | 
| 62 | mmeineke | 548 | 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 | 
| 65 |  |  | double *constrainedDsqr; // the square of the constraint distance | 
| 66 |  |  |  | 
| 67 |  |  | int* moving; // tells whether we are moving atom i | 
| 68 |  |  | int* moved;  // tells whether we have moved atom i | 
| 69 | mmeineke | 561 | double* oldPos; // pre constrained positions | 
| 70 | mmeineke | 548 |  | 
| 71 | mmeineke | 540 | short isFirst; /*boolean for the first time integrate is called */ | 
| 72 |  |  |  | 
| 73 |  |  | double dt; | 
| 74 | mmeineke | 541 | double dt2; | 
| 75 | gezelter | 560 |  | 
| 76 | mmeineke | 540 | Thermo *tStats; | 
| 77 |  |  | StatWriter*  statOut; | 
| 78 |  |  | DumpWriter*  dumpOut; | 
| 79 | mmeineke | 377 |  | 
| 80 |  |  | }; | 
| 81 |  |  |  | 
| 82 | tim | 645 | typedef Integrator<BaseIntegrator> RealIntegrator; | 
| 83 | mmeineke | 540 |  | 
| 84 | tim | 645 | template<typename T> class NVE : public T { | 
| 85 |  |  |  | 
| 86 | mmeineke | 561 | public: | 
| 87 |  |  | NVE ( SimInfo *theInfo, ForceFields* the_ff ): | 
| 88 | tim | 645 | T( theInfo, the_ff ){} | 
| 89 |  |  | virtual ~NVE(){} | 
| 90 |  |  | }; | 
| 91 | mmeineke | 555 |  | 
| 92 |  |  |  | 
| 93 | tim | 645 | template<typename T> class NVT : public T { | 
| 94 | mmeineke | 555 |  | 
| 95 | gezelter | 560 | public: | 
| 96 |  |  |  | 
| 97 | mmeineke | 561 | NVT ( SimInfo *theInfo, ForceFields* the_ff); | 
| 98 | tim | 763 | virtual ~NVT(); | 
| 99 | mmeineke | 540 |  | 
| 100 | gezelter | 560 | void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} | 
| 101 |  |  | void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} | 
| 102 | tim | 763 | void setChiTolerance(double tol) {chiTolerance = tol;} | 
| 103 |  |  | virtual double  getConservedQuantity(void); | 
| 104 | gezelter | 560 |  | 
| 105 | mmeineke | 540 | protected: | 
| 106 | gezelter | 560 |  | 
| 107 | mmeineke | 561 | virtual void moveA( void ); | 
| 108 |  |  | virtual void moveB( void ); | 
| 109 | mmeineke | 540 |  | 
| 110 | mmeineke | 561 | virtual int readyCheck(); | 
| 111 | gezelter | 560 |  | 
| 112 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 113 |  |  |  | 
| 114 | gezelter | 565 | // chi is a propagated degree of freedom. | 
| 115 | gezelter | 560 |  | 
| 116 | gezelter | 565 | double chi; | 
| 117 | gezelter | 560 |  | 
| 118 | tim | 763 | //integral of chi(t)dt | 
| 119 |  |  | double integralOfChidt; | 
| 120 |  |  |  | 
| 121 | gezelter | 565 | // targetTemp must be set.  tauThermostat must also be set; | 
| 122 | gezelter | 560 |  | 
| 123 |  |  | double targetTemp; | 
| 124 |  |  | double tauThermostat; | 
| 125 | mmeineke | 561 |  | 
| 126 | gezelter | 565 | short int have_tau_thermostat, have_target_temp; | 
| 127 | gezelter | 560 |  | 
| 128 | tim | 763 | double *oldVel; | 
| 129 |  |  | double *oldJi; | 
| 130 |  |  |  | 
| 131 |  |  | double chiTolerance; | 
| 132 |  |  | short int have_chi_tolerance; | 
| 133 |  |  |  | 
| 134 | mmeineke | 540 | }; | 
| 135 |  |  |  | 
| 136 |  |  |  | 
| 137 |  |  |  | 
| 138 | tim | 645 | template<typename T> class NPTi : public T{ | 
| 139 |  |  |  | 
| 140 | gezelter | 560 | public: | 
| 141 |  |  |  | 
| 142 | gezelter | 574 | NPTi ( SimInfo *theInfo, ForceFields* the_ff); | 
| 143 | tim | 763 | virtual ~NPTi(); | 
| 144 |  |  |  | 
| 145 | mmeineke | 594 | virtual void integrateStep( int calcPot, int calcStress ){ | 
| 146 |  |  | calcStress = 1; | 
| 147 | tim | 645 | T::integrateStep( calcPot, calcStress ); | 
| 148 | tim | 763 | /* accIntegralOfChidt(); */ | 
| 149 | mmeineke | 594 | } | 
| 150 |  |  |  | 
| 151 | tim | 763 | virtual double getConservedQuantity(void); | 
| 152 |  |  |  | 
| 153 | gezelter | 560 | 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 | tim | 763 | 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 | gezelter | 560 |  | 
| 161 |  |  | protected: | 
| 162 |  |  |  | 
| 163 | mmeineke | 561 | virtual void  moveA( void ); | 
| 164 |  |  | virtual void moveB( void ); | 
| 165 | gezelter | 560 |  | 
| 166 | mmeineke | 561 | virtual int readyCheck(); | 
| 167 | gezelter | 560 |  | 
| 168 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 169 |  |  |  | 
| 170 | tim | 763 | void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} | 
| 171 |  |  |  | 
| 172 | gezelter | 565 | // chi and eta are the propagated degrees of freedom | 
| 173 | gezelter | 560 |  | 
| 174 | gezelter | 565 | double chi; | 
| 175 |  |  | double eta; | 
| 176 | gezelter | 574 | double NkBT; | 
| 177 | tim | 763 | double fkBT; | 
| 178 | gezelter | 560 |  | 
| 179 | tim | 763 | int Nparticles; | 
| 180 |  |  |  | 
| 181 |  |  | double integralOfChidt; | 
| 182 |  |  |  | 
| 183 | gezelter | 560 | // targetTemp, targetPressure, and tauBarostat must be set. | 
| 184 |  |  | // One of qmass or tauThermostat must be set; | 
| 185 |  |  |  | 
| 186 |  |  | double targetTemp; | 
| 187 |  |  | double targetPressure; | 
| 188 |  |  | double tauThermostat; | 
| 189 |  |  | double tauBarostat; | 
| 190 |  |  |  | 
| 191 |  |  | short int have_tau_thermostat, have_tau_barostat, have_target_temp; | 
| 192 | gezelter | 565 | short int have_target_pressure; | 
| 193 | gezelter | 560 |  | 
| 194 | tim | 763 | 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 | gezelter | 560 | }; | 
| 208 |  |  |  | 
| 209 | tim | 645 | template<typename T> class NPTim : public T{ | 
| 210 | gezelter | 596 |  | 
| 211 |  |  | public: | 
| 212 |  |  |  | 
| 213 |  |  | NPTim ( SimInfo *theInfo, ForceFields* the_ff); | 
| 214 | tim | 763 | virtual ~NPTim() {} | 
| 215 | gezelter | 596 |  | 
| 216 |  |  | virtual void integrateStep( int calcPot, int calcStress ){ | 
| 217 |  |  | calcStress = 1; | 
| 218 | tim | 645 | T::integrateStep( calcPot, calcStress ); | 
| 219 | tim | 763 | accIntegralOfChidt(); | 
| 220 | gezelter | 596 | } | 
| 221 |  |  |  | 
| 222 | tim | 763 | virtual double getConservedQuantity(void); | 
| 223 |  |  |  | 
| 224 | gezelter | 596 | 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 | tim | 763 | void setChiTolerance(double tol) {chiTolerance = tol;} | 
| 229 |  |  | void setPosIterTolerance(double tol) {posIterTolerance = tol;} | 
| 230 | gezelter | 596 |  | 
| 231 |  |  | protected: | 
| 232 |  |  |  | 
| 233 | gezelter | 604 | virtual void moveA( void ); | 
| 234 | gezelter | 596 | virtual void moveB( void ); | 
| 235 |  |  |  | 
| 236 |  |  | virtual int readyCheck(); | 
| 237 |  |  |  | 
| 238 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 239 |  |  |  | 
| 240 | tim | 763 | void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} | 
| 241 |  |  |  | 
| 242 | gezelter | 604 | Molecule* myMolecules; | 
| 243 |  |  | Atom** myAtoms; | 
| 244 |  |  |  | 
| 245 | gezelter | 596 | // chi and eta are the propagated degrees of freedom | 
| 246 |  |  |  | 
| 247 |  |  | double chi; | 
| 248 |  |  | double eta; | 
| 249 |  |  | double NkBT; | 
| 250 | tim | 763 | double integralOfChidt; | 
| 251 | gezelter | 596 |  | 
| 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 | tim | 763 | double chiTolerance; | 
| 263 |  |  | short int have_chi_tolerance; | 
| 264 |  |  | double posIterTolerance; | 
| 265 |  |  | short int have_pos_iter_tolerance; | 
| 266 | gezelter | 596 |  | 
| 267 |  |  | }; | 
| 268 |  |  |  | 
| 269 | mmeineke | 755 | 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 ); | 
| 279 |  |  | } | 
| 280 |  |  |  | 
| 281 |  |  | void setTauThermostat(double tt) {tauThermostat = tt; have_tau_thermostat=1;} | 
| 282 |  |  | void setTauBarostat(double tb) {tauBarostat = tb; have_tau_barostat=1;} | 
| 283 |  |  | void setTargetTemp(double tt) {targetTemp = tt; have_target_temp = 1;} | 
| 284 |  |  | void setTargetPressure(double tp) {targetPressure = tp; have_target_pressure = 1;} | 
| 285 |  |  |  | 
| 286 |  |  | protected: | 
| 287 |  |  |  | 
| 288 |  |  | virtual void moveA( void ); | 
| 289 |  |  | virtual void moveB( void ); | 
| 290 |  |  |  | 
| 291 |  |  | virtual int readyCheck(); | 
| 292 |  |  |  | 
| 293 |  |  | virtual void resetIntegrator( void ); | 
| 294 |  |  |  | 
| 295 |  |  | Molecule* myMolecules; | 
| 296 |  |  | Atom** myAtoms; | 
| 297 |  |  |  | 
| 298 |  |  | // chi and eta are the propagated degrees of freedom | 
| 299 |  |  |  | 
| 300 |  |  | double chi; | 
| 301 |  |  | double eta; | 
| 302 |  |  | double etaZ; | 
| 303 |  |  | double NkBT; | 
| 304 |  |  |  | 
| 305 |  |  | // targetTemp, targetPressure, and tauBarostat must be set. | 
| 306 |  |  | // One of qmass or tauThermostat must be set; | 
| 307 |  |  |  | 
| 308 |  |  | double targetTemp; | 
| 309 |  |  | double targetPressure; | 
| 310 |  |  | double tauThermostat; | 
| 311 |  |  | double tauBarostat; | 
| 312 |  |  |  | 
| 313 |  |  | short int have_tau_thermostat, have_tau_barostat, have_target_temp; | 
| 314 |  |  | short int have_target_pressure; | 
| 315 |  |  |  | 
| 316 |  |  | }; | 
| 317 |  |  |  | 
| 318 | tim | 645 | template<typename T> class NPTf : public T{ | 
| 319 | gezelter | 576 |  | 
| 320 |  |  | public: | 
| 321 |  |  |  | 
| 322 |  |  | NPTf ( SimInfo *theInfo, ForceFields* the_ff); | 
| 323 |  |  | virtual ~NPTf() {}; | 
| 324 |  |  |  | 
| 325 | mmeineke | 594 | virtual void integrateStep( int calcPot, int calcStress ){ | 
| 326 |  |  | calcStress = 1; | 
| 327 | tim | 645 | T::integrateStep( calcPot, calcStress ); | 
| 328 | tim | 763 | accIntegralOfChidt(); | 
| 329 | mmeineke | 594 | } | 
| 330 | tim | 763 |  | 
| 331 |  |  | virtual double getConservedQuantity(void); | 
| 332 | mmeineke | 594 |  | 
| 333 | gezelter | 576 | 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 | tim | 763 | void setChiTolerance(double tol) {chiTolerance = tol;} | 
| 338 |  |  | void setPosIterTolerance(double tol) {posIterTolerance = tol;} | 
| 339 | gezelter | 576 |  | 
| 340 |  |  | protected: | 
| 341 |  |  |  | 
| 342 |  |  | virtual void  moveA( void ); | 
| 343 |  |  | virtual void moveB( void ); | 
| 344 |  |  |  | 
| 345 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 346 |  |  |  | 
| 347 | gezelter | 576 | virtual int readyCheck(); | 
| 348 |  |  |  | 
| 349 | tim | 763 | void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} | 
| 350 |  |  |  | 
| 351 | gezelter | 576 | // chi and eta are the propagated degrees of freedom | 
| 352 |  |  |  | 
| 353 |  |  | double chi; | 
| 354 | gezelter | 588 | double eta[3][3]; | 
| 355 | gezelter | 576 | double NkBT; | 
| 356 |  |  |  | 
| 357 | tim | 763 | double integralOfChidt; | 
| 358 |  |  |  | 
| 359 | gezelter | 576 | // targetTemp, targetPressure, and tauBarostat must be set. | 
| 360 |  |  | // One of qmass or tauThermostat must be set; | 
| 361 |  |  |  | 
| 362 |  |  | double targetTemp; | 
| 363 |  |  | double targetPressure; | 
| 364 |  |  | double tauThermostat; | 
| 365 |  |  | double tauBarostat; | 
| 366 |  |  |  | 
| 367 |  |  | short int have_tau_thermostat, have_tau_barostat, have_target_temp; | 
| 368 |  |  | short int have_target_pressure; | 
| 369 | tim | 763 | double chiTolerance; | 
| 370 |  |  | short int have_chi_tolerance; | 
| 371 |  |  | double posIterTolerance; | 
| 372 |  |  | short int have_pos_iter_tolerance; | 
| 373 | gezelter | 576 |  | 
| 374 |  |  | }; | 
| 375 |  |  |  | 
| 376 | mmeineke | 755 | 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 | tim | 645 | template<typename T> class NPTfm : public T{ | 
| 428 | gezelter | 596 |  | 
| 429 |  |  | public: | 
| 430 |  |  |  | 
| 431 |  |  | NPTfm ( SimInfo *theInfo, ForceFields* the_ff); | 
| 432 |  |  | virtual ~NPTfm() {}; | 
| 433 |  |  |  | 
| 434 |  |  | virtual void integrateStep( int calcPot, int calcStress ){ | 
| 435 |  |  | calcStress = 1; | 
| 436 | tim | 645 | T::integrateStep( calcPot, calcStress ); | 
| 437 | tim | 763 | accIntegralOfChidt(); | 
| 438 | gezelter | 596 | } | 
| 439 |  |  |  | 
| 440 | tim | 763 | virtual double getConservedQuantity(void); | 
| 441 |  |  |  | 
| 442 | gezelter | 596 | 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 | tim | 763 | void setChiTolerance(double tol) {chiTolerance = tol;} | 
| 447 |  |  | void setPosIterTolerance(double tol) {posIterTolerance = tol;} | 
| 448 | gezelter | 596 |  | 
| 449 |  |  | protected: | 
| 450 |  |  |  | 
| 451 |  |  | virtual void  moveA( void ); | 
| 452 |  |  | virtual void moveB( void ); | 
| 453 |  |  |  | 
| 454 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 455 |  |  |  | 
| 456 | gezelter | 596 | virtual int readyCheck(); | 
| 457 |  |  |  | 
| 458 | tim | 763 | void accIntegralOfChidt(void) { integralOfChidt += dt * chi;} | 
| 459 |  |  |  | 
| 460 | gezelter | 605 | Molecule* myMolecules; | 
| 461 |  |  | Atom** myAtoms; | 
| 462 |  |  |  | 
| 463 | gezelter | 596 | // chi and eta are the propagated degrees of freedom | 
| 464 |  |  |  | 
| 465 |  |  | double chi; | 
| 466 |  |  | double eta[3][3]; | 
| 467 |  |  | double NkBT; | 
| 468 | tim | 763 | double integralOfChidt; | 
| 469 | gezelter | 596 |  | 
| 470 |  |  | // targetTemp, targetPressure, and tauBarostat must be set. | 
| 471 |  |  | // One of qmass or tauThermostat must be set; | 
| 472 |  |  |  | 
| 473 |  |  | double targetTemp; | 
| 474 |  |  | double targetPressure; | 
| 475 |  |  | double tauThermostat; | 
| 476 |  |  | double tauBarostat; | 
| 477 |  |  |  | 
| 478 |  |  | short int have_tau_thermostat, have_tau_barostat, have_target_temp; | 
| 479 |  |  | short int have_target_pressure; | 
| 480 | tim | 763 | double chiTolerance; | 
| 481 |  |  | short int have_chi_tolerance; | 
| 482 |  |  | double posIterTolerance; | 
| 483 |  |  | short int have_pos_iter_tolerance; | 
| 484 | gezelter | 596 |  | 
| 485 |  |  | }; | 
| 486 |  |  |  | 
| 487 | gezelter | 718 |  | 
| 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 | tim | 763 | void setChiTolerance(double tol) {chiTolerance = tol;} | 
| 505 |  |  | void setPosIterTolerance(double tol) {posIterTolerance = tol;} | 
| 506 | gezelter | 718 |  | 
| 507 |  |  | protected: | 
| 508 |  |  |  | 
| 509 |  |  | virtual void  moveA( void ); | 
| 510 |  |  | virtual void moveB( void ); | 
| 511 |  |  |  | 
| 512 |  |  | virtual int readyCheck(); | 
| 513 |  |  |  | 
| 514 | mmeineke | 746 | virtual void resetIntegrator( void ); | 
| 515 |  |  |  | 
| 516 | gezelter | 718 | // 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 | tim | 763 | double chiTolerance; | 
| 533 |  |  | short int have_chi_tolerance; | 
| 534 |  |  | double posIterTolerance; | 
| 535 |  |  | short int have_pos_iter_tolerance; | 
| 536 | gezelter | 718 |  | 
| 537 |  |  | }; | 
| 538 |  |  |  | 
| 539 |  |  |  | 
| 540 | tim | 658 | template<typename T> class ZConstraint : public T { | 
| 541 | tim | 701 |  | 
| 542 |  |  | public: | 
| 543 | tim | 738 | class ForceSubtractionPolicy{ | 
| 544 | tim | 699 | public: | 
| 545 | tim | 738 | ForceSubtractionPolicy(ZConstraint<T>* integrator) {zconsIntegrator = integrator;} | 
| 546 | tim | 658 |  | 
| 547 | tim | 701 | virtual void update() = 0; | 
| 548 | tim | 699 | virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) = 0; | 
| 549 |  |  | virtual double getZFOfMovingMols(Atom* atom, double totalForce) = 0; | 
| 550 | tim | 701 | 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 | tim | 699 | }; | 
| 556 |  |  |  | 
| 557 | tim | 738 | class PolicyByNumber : public ForceSubtractionPolicy{ | 
| 558 | gezelter | 747 |  | 
| 559 | tim | 699 | public: | 
| 560 | tim | 738 | PolicyByNumber(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} | 
| 561 | tim | 701 | virtual void update(); | 
| 562 | tim | 699 | virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; | 
| 563 |  |  | virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; | 
| 564 | tim | 701 | virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); | 
| 565 |  |  | virtual double getHFOfUnconsMols(Atom* atom, double totalForce); | 
| 566 |  |  |  | 
| 567 | tim | 699 | private: | 
| 568 | tim | 763 | int totNumOfMovingAtoms; | 
| 569 | tim | 699 | }; | 
| 570 |  |  |  | 
| 571 | tim | 738 | class PolicyByMass : public ForceSubtractionPolicy{ | 
| 572 | gezelter | 747 |  | 
| 573 | tim | 699 | public: | 
| 574 | tim | 738 | PolicyByMass(ZConstraint<T>* integrator) :ForceSubtractionPolicy(integrator) {} | 
| 575 | tim | 701 |  | 
| 576 |  |  | virtual void update(); | 
| 577 | tim | 699 | virtual double getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce) ; | 
| 578 |  |  | virtual double getZFOfMovingMols(Atom* atom, double totalForce) ; | 
| 579 | tim | 701 | virtual double getHFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce); | 
| 580 |  |  | virtual double getHFOfUnconsMols(Atom* atom, double totalForce); | 
| 581 | tim | 699 |  | 
| 582 | tim | 701 | private: | 
| 583 |  |  | double totMassOfMovingAtoms; | 
| 584 | tim | 699 | }; | 
| 585 |  |  |  | 
| 586 | tim | 658 | public: | 
| 587 |  |  |  | 
| 588 |  |  | ZConstraint( SimInfo *theInfo, ForceFields* the_ff); | 
| 589 |  |  | ~ZConstraint(); | 
| 590 | tim | 677 |  | 
| 591 | tim | 658 | void setZConsTime(double time)                  {this->zconsTime = time;} | 
| 592 |  |  | void getZConsTime()                             {return zconsTime;} | 
| 593 |  |  |  | 
| 594 | tim | 701 | void setIndexOfAllZConsMols(vector<int> index) {indexOfAllZConsMols = index;} | 
| 595 |  |  | void getIndexOfAllZConsMols()                  {return indexOfAllZConsMols;} | 
| 596 | tim | 658 |  | 
| 597 | tim | 701 | void setZConsOutput(const char * fileName)          {zconsOutput = fileName;} | 
| 598 | tim | 658 | string getZConsOutput()                         {return zconsOutput;} | 
| 599 | tim | 677 |  | 
| 600 |  |  | virtual void integrate(); | 
| 601 |  |  |  | 
| 602 | tim | 658 |  | 
| 603 |  |  | #ifdef IS_MPI | 
| 604 | tim | 701 | virtual void update();                      //which is called to indicate the molecules' migration | 
| 605 | mmeineke | 377 | #endif | 
| 606 | tim | 658 |  | 
| 607 |  |  | protected: | 
| 608 |  |  |  | 
| 609 | tim | 701 | enum ZConsState {zcsMoving, zcsFixed}; | 
| 610 | tim | 677 |  | 
| 611 |  |  | virtual void calcForce( int calcPot, int calcStress ); | 
| 612 |  |  | virtual void thermalize(void); | 
| 613 |  |  |  | 
| 614 |  |  | void zeroOutVel(); | 
| 615 |  |  | void doZconstraintForce(); | 
| 616 | tim | 682 | void doHarmonic(); | 
| 617 | tim | 677 | bool checkZConsState(); | 
| 618 |  |  |  | 
| 619 |  |  | bool haveFixedZMols(); | 
| 620 |  |  | bool haveMovingZMols(); | 
| 621 |  |  |  | 
| 622 |  |  | double calcZSys(); | 
| 623 |  |  |  | 
| 624 |  |  | int isZConstraintMol(Molecule* mol); | 
| 625 |  |  |  | 
| 626 |  |  |  | 
| 627 | tim | 701 | 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 | tim | 658 |  | 
| 632 | tim | 701 | 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 | tim | 658 |  | 
| 638 | tim | 677 |  | 
| 639 | tim | 701 | vector<Molecule*> unconsMols;           //unconstraint molecules array | 
| 640 |  |  | vector<double> massOfUnconsMols;    //mass array of unconstraint molecules | 
| 641 |  |  | double totalMassOfUncons;                //total mas of unconstraint molecules | 
| 642 | tim | 682 |  | 
| 643 | tim | 701 | vector<ZConsParaItem>* parameters; // | 
| 644 | tim | 658 |  | 
| 645 |  |  | vector<int> indexOfAllZConsMols;     //index of All Z-Constraint Molecuels | 
| 646 | tim | 677 |  | 
| 647 |  |  | int* indexOfZConsMols;                   //index of local Z-Constraint Molecules | 
| 648 | tim | 658 | double* fz; | 
| 649 | tim | 699 | double* curZPos; | 
| 650 | tim | 658 |  | 
| 651 | tim | 701 | int totNumOfUnconsAtoms;              //total number of uncontraint atoms | 
| 652 | tim | 677 |  | 
| 653 |  |  | int whichDirection;                           //constraint direction | 
| 654 |  |  |  | 
| 655 | tim | 658 | private: | 
| 656 | tim | 677 |  | 
| 657 | tim | 701 | string zconsOutput;                         //filename of zconstraint output | 
| 658 |  |  | ZConsWriter* fzOut;                         //z-constraint writer | 
| 659 | tim | 677 |  | 
| 660 | tim | 701 | double curZconsTime; | 
| 661 | tim | 699 |  | 
| 662 | tim | 696 | double calcMovingMolsCOMVel(); | 
| 663 |  |  | double calcSysCOMVel(); | 
| 664 |  |  | double calcTotalForce(); | 
| 665 | tim | 701 |  | 
| 666 | gezelter | 747 | ForceSubtractionPolicy* forcePolicy; //force subtraction policy | 
| 667 | tim | 738 | friend class ForceSubtractionPolicy; | 
| 668 | tim | 677 |  | 
| 669 | tim | 658 | }; | 
| 670 |  |  |  | 
| 671 |  |  | #endif |