51#include "utils/Constants.hpp"
52#include "utils/simError.h"
58 Globals* simParams = info_->getSimParams();
60 if (!simParams->getUseIntialExtendedSystemState()) {
61 Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot();
62 snap->setThermostat(make_pair(0.0, 0.0));
65 if (!simParams->haveTargetTemp()) {
66 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
67 "You can't use the NVT integrator without a targetTemp_!\n");
69 painCave.severity = OPENMD_ERROR;
72 targetTemp_ = simParams->getTargetTemp();
77 if (!simParams->haveTauThermostat()) {
78 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
79 "If you use the constant temperature\n"
80 "\tintegrator, you must set tauThermostat.\n");
82 painCave.severity = OPENMD_ERROR;
86 tauThermostat_ = simParams->getTauThermostat();
92 void NVT::doUpdateSizes() {
93 oldVel_.resize(info_->getNIntegrableObjects());
94 oldJi_.resize(info_->getNIntegrableObjects());
98 SimInfo::MoleculeIterator i;
99 Molecule::IntegrableObjectIterator j;
109 pair<RealType, RealType> thermostat = snap->getThermostat();
113 RealType instTemp = thermo.getTemperature();
115 for (mol = info_->beginMolecule(i); mol != NULL;
116 mol = info_->nextMolecule(i)) {
117 for (sd = mol->beginIntegrableObject(j); sd != NULL;
118 sd = mol->nextIntegrableObject(j)) {
123 mass = sd->getMass();
126 vel += dt2 * Constants::energyConvert / mass * frc -
127 dt2 * thermostat.first * vel;
135 if (sd->isDirectional()) {
137 Tb = sd->lab2Body(sd->getTrq());
144 dt2 * Constants::energyConvert * Tb - dt2 * thermostat.first * ji;
146 rotAlgo_->rotate(sd, ji, dt);
154 rattle_->constraintA();
159 thermostat.first += dt2 * (instTemp / targetTemp_ - 1.0) /
160 (tauThermostat_ * tauThermostat_);
161 thermostat.second += thermostat.first * dt2;
163 snap->setThermostat(thermostat);
167 SimInfo::MoleculeIterator i;
168 Molecule::IntegrableObjectIterator j;
181 pair<RealType, RealType> thermostat = snap->getThermostat();
182 RealType oldChi = thermostat.first;
186 for (mol = info_->beginMolecule(i); mol != NULL;
187 mol = info_->nextMolecule(i)) {
188 for (sd = mol->beginIntegrableObject(j); sd != NULL;
189 sd = mol->nextIntegrableObject(j)) {
190 oldVel_[index] = sd->getVel();
192 if (sd->isDirectional()) oldJi_[index] = sd->getJ();
200 for (
int k = 0; k < maxIterNum_; k++) {
202 instTemp = thermo.getTemperature();
206 prevChi = thermostat.first;
207 thermostat.first = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) /
208 (tauThermostat_ * tauThermostat_);
210 for (mol = info_->beginMolecule(i); mol != NULL;
211 mol = info_->nextMolecule(i)) {
212 for (sd = mol->beginIntegrableObject(j); sd != NULL;
213 sd = mol->nextIntegrableObject(j)) {
215 mass = sd->getMass();
219 vel = oldVel_[index] + dt2 / mass * Constants::energyConvert * frc -
220 dt2 * thermostat.first * oldVel_[index];
224 if (sd->isDirectional()) {
227 Tb = sd->lab2Body(sd->getTrq());
229 ji = oldJi_[index] + dt2 * Constants::energyConvert * Tb -
230 dt2 * thermostat.first * oldJi_[index];
239 rattle_->constraintB();
241 if (fabs(prevChi - thermostat.first) <= chiTolerance_)
break;
246 thermostat.second += dt2 * thermostat.first;
247 snap->setThermostat(thermostat);
250 void NVT::resetIntegrator() { snap->setThermostat(make_pair(0.0, 0.0)); }
252 RealType NVT::calcConservedQuantity() {
253 pair<RealType, RealType> thermostat = snap->getThermostat();
254 RealType conservedQuantity;
257 RealType thermostat_kinetic;
258 RealType thermostat_potential;
260 fkBT = info_->getNdf() * Constants::kB * targetTemp_;
262 Energy = thermo.getTotalEnergy();
264 thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ *
265 thermostat.first * thermostat.first /
266 (2.0 * Constants::energyConvert);
268 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
270 conservedQuantity = Energy + thermostat_kinetic + thermostat_potential;
272 return conservedQuantity;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.