50#include "brains/Thermo.hpp"
53#include "utils/Constants.hpp"
54#include "utils/simError.h"
71 Globals* simParams = info_->getSimParams();
73 if (!simParams->getUseIntialExtendedSystemState()) {
75 info_->getSnapshotManager()->getCurrentSnapshot();
76 currSnapshot->setThermostat(make_pair(0.0, 0.0));
77 currSnapshot->setBarostat(
Mat3x3d(0.0));
80 if (!simParams->haveTargetTemp()) {
81 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
82 "You can't use the NVT integrator without a targetTemp!\n");
84 painCave.severity = OPENMD_ERROR;
87 targetTemp = simParams->getTargetTemp();
91 if (!simParams->haveTauThermostat()) {
92 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
93 "If you use the constant temperature\n"
94 "\tintegrator, you must set tauThermostat.\n");
96 painCave.severity = OPENMD_ERROR;
100 tauThermostat = simParams->getTauThermostat();
103 if (!simParams->haveTargetPressure()) {
104 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
105 "NPT error: You can't use the NPT integrator\n"
106 " without a targetPressure!\n");
108 painCave.isFatal = 1;
111 targetPressure = simParams->getTargetPressure();
114 if (!simParams->haveTauBarostat()) {
115 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
116 "If you use the NPT integrator, you must set tauBarostat.\n");
117 painCave.severity = OPENMD_ERROR;
118 painCave.isFatal = 1;
121 tauBarostat = simParams->getTauBarostat();
124 tt2 = tauThermostat * tauThermostat;
125 tb2 = tauBarostat * tauBarostat;
130 void NPT::doUpdateSizes() {
137 SimInfo::MoleculeIterator i;
138 Molecule::IntegrableObjectIterator j;
149 thermostat = snap->getThermostat();
152 instaTemp = thermo.getTemperature();
154 instaPress = Constants::pressureConvert *
155 (press(0, 0) + press(1, 1) + press(2, 2)) / 3.0;
156 instaVol = thermo.getVolume();
166 for (sd = mol->beginIntegrableObject(j); sd != NULL;
167 sd = mol->nextIntegrableObject(j)) {
173 getVelScaleA(sc, vel);
177 vel += dt2 * Constants::energyConvert / mass * frc - dt2 * sc;
190 dt2 * Constants::energyConvert * Tb - dt2 * thermostat.first * ji;
192 rotAlgo_->rotate(sd, ji, dt);
200 thermostat.first += dt2 * (instaTemp / targetTemp - 1.0) / tt2;
205 thermostat.second += dt2 * thermostat.first;
212 for (sd = mol->beginIntegrableObject(j); sd != NULL;
213 sd = mol->nextIntegrableObject(j)) {
214 oldPos[index++] = sd->
getPos();
220 for (
int k = 0; k < maxIterNum_; k++) {
224 for (sd = mol->beginIntegrableObject(j); sd != NULL;
225 sd = mol->nextIntegrableObject(j)) {
229 this->getPosScale(pos, COM, index, sc);
231 pos = oldPos[index] + dt * (vel + sc);
238 rattle_->constraintA();
245 snap->setThermostat(thermostat);
250 void NPT::moveB(
void) {
251 SimInfo::MoleculeIterator i;
252 Molecule::IntegrableObjectIterator j;
263 thermostat = snap->getThermostat();
264 RealType oldChi = thermostat.first;
273 for (sd = mol->beginIntegrableObject(j); sd != NULL;
274 sd = mol->nextIntegrableObject(j)) {
275 oldVel[index] = sd->
getVel();
284 instaVol = thermo.getVolume();
286 for (
int k = 0; k < maxIterNum_; k++) {
287 instaTemp = thermo.getTemperature();
288 instaPress = thermo.getPressure();
291 prevChi = thermostat.first;
292 thermostat.first = oldChi + dt2 * (instaTemp / targetTemp - 1.0) / tt2;
296 this->calcVelScale();
301 for (sd = mol->beginIntegrableObject(j); sd != NULL;
302 sd = mol->nextIntegrableObject(j)) {
306 getVelScaleB(sc, index);
309 vel = oldVel[index] + dt2 * Constants::energyConvert / mass * frc -
318 ji = oldJi[index] + dt2 * Constants::energyConvert * Tb -
319 dt2 * thermostat.first * oldJi[index];
328 rattle_->constraintB();
330 if ((fabs(prevChi - thermostat.first) <= chiTolerance) &&
331 this->etaConverged())
336 thermostat.second += dt2 * thermostat.first;
338 snap->setThermostat(thermostat);
344 void NPT::resetIntegrator() {
345 snap->setThermostat(make_pair(0.0, 0.0));
349 void NPT::resetEta() {
351 snap->setBarostat(etaMat);
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
unsigned int getNIntegrableObjects()
Returns the number of local integrable objects.
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
The Snapshot class is a repository storing dynamic data during a Simulation.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Vector3d getTrq()
Returns the current torque of this stuntDouble.
Vector3d lab2Body(const Vector3d &v)
Converts a lab fixed vector to a body fixed vector.
Vector3d getVel()
Returns the current velocity of this stuntDouble.
RealType getMass()
Returns the mass of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
void setVel(const Vector3d &vel)
Sets the current velocity of this stuntDouble.
Vector3d getJ()
Returns the current angular momentum of this stuntDouble (body -fixed).
bool isDirectional()
Tests if this stuntDouble is a directional one.
Vector3d getFrc()
Returns the current force of this stuntDouble.
void setJ(const Vector3d &angMom)
Sets the current angular momentum of this stuntDouble (body-fixed).
Mat3x3d getPressureTensor()
gives the pressure tensor in amu*fs^-2*Ang^-1
Vector3d getCom()
Returns the center of the mass of the whole system.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.