48#include "utils/Constants.hpp"
49#include "utils/simError.h"
55 Globals* simParams = info_->getSimParams();
57 if (!simParams->getUseIntialExtendedSystemState()) {
58 Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
59 snap->setThermostat(make_pair(0.0, 0.0));
62 if (!simParams->haveTargetTemp()) {
63 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
64 "You can't use the NVT integrator without a targetTemp_!\n");
66 painCave.severity = OPENMD_ERROR;
69 targetTemp_ = simParams->getTargetTemp();
74 if (!simParams->haveTauThermostat()) {
75 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
76 "If you use the constant temperature\n"
77 "\tintegrator, you must set tauThermostat.\n");
79 painCave.severity = OPENMD_ERROR;
83 tauThermostat_ = simParams->getTauThermostat();
89 void NVT::doUpdateSizes() {
95 SimInfo::MoleculeIterator i;
96 Molecule::IntegrableObjectIterator j;
106 pair<RealType, RealType> thermostat = snap->getThermostat();
110 RealType instTemp = thermo.getTemperature();
114 for (sd = mol->beginIntegrableObject(j); sd != NULL;
115 sd = mol->nextIntegrableObject(j)) {
123 vel += dt2 * Constants::energyConvert / mass * frc -
124 dt2 * thermostat.first * vel;
141 dt2 * Constants::energyConvert * Tb - dt2 * thermostat.first * ji;
143 rotAlgo_->rotate(sd, ji, dt);
151 rattle_->constraintA();
156 thermostat.first += dt2 * (instTemp / targetTemp_ - 1.0) /
157 (tauThermostat_ * tauThermostat_);
158 thermostat.second += thermostat.first * dt2;
160 snap->setThermostat(thermostat);
164 SimInfo::MoleculeIterator i;
165 Molecule::IntegrableObjectIterator j;
178 pair<RealType, RealType> thermostat = snap->getThermostat();
179 RealType oldChi = thermostat.first;
185 for (sd = mol->beginIntegrableObject(j); sd != NULL;
186 sd = mol->nextIntegrableObject(j)) {
187 oldVel_[index] = sd->
getVel();
197 for (
int k = 0; k < maxIterNum_; k++) {
199 instTemp = thermo.getTemperature();
203 prevChi = thermostat.first;
204 thermostat.first = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) /
205 (tauThermostat_ * tauThermostat_);
209 for (sd = mol->beginIntegrableObject(j); sd != NULL;
210 sd = mol->nextIntegrableObject(j)) {
216 vel = oldVel_[index] + dt2 / mass * Constants::energyConvert * frc -
217 dt2 * thermostat.first * oldVel_[index];
226 ji = oldJi_[index] + dt2 * Constants::energyConvert * Tb -
227 dt2 * thermostat.first * oldJi_[index];
236 rattle_->constraintB();
238 if (fabs(prevChi - thermostat.first) <= chiTolerance_)
break;
243 thermostat.second += dt2 * thermostat.first;
244 snap->setThermostat(thermostat);
247 void NVT::resetIntegrator() { snap->setThermostat(make_pair(0.0, 0.0)); }
249 RealType NVT::calcConservedQuantity() {
250 pair<RealType, RealType> thermostat = snap->getThermostat();
251 RealType conservedQuantity;
254 RealType thermostat_kinetic;
255 RealType thermostat_potential;
257 fkBT = info_->
getNdf() * Constants::kB * targetTemp_;
259 Energy = thermo.getTotalEnergy();
261 thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ *
262 thermostat.first * thermostat.first /
263 (2.0 * Constants::energyConvert);
265 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
267 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential;
269 return conservedQuantity;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
int getNdf()
Returns the number of degrees of freedom.
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).
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.