53#include "brains/Thermo.hpp"
56#include "utils/Constants.hpp"
57#include "utils/simError.h"
74 Globals* simParams = info_->getSimParams();
76 if (!simParams->getUseIntialExtendedSystemState()) {
77 Snapshot* currSnapshot =
78 info_->getSnapshotManager()->getCurrentSnapshot();
79 currSnapshot->setThermostat(make_pair(0.0, 0.0));
80 currSnapshot->setBarostat(Mat3x3d(0.0));
83 if (!simParams->haveTargetTemp()) {
84 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
85 "You can't use the NVT integrator without a targetTemp!\n");
87 painCave.severity = OPENMD_ERROR;
90 targetTemp = simParams->getTargetTemp();
94 if (!simParams->haveTauThermostat()) {
95 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
96 "If you use the constant temperature\n"
97 "\tintegrator, you must set tauThermostat.\n");
99 painCave.severity = OPENMD_ERROR;
100 painCave.isFatal = 1;
103 tauThermostat = simParams->getTauThermostat();
106 if (!simParams->haveTargetPressure()) {
107 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
108 "NPT error: You can't use the NPT integrator\n"
109 " without a targetPressure!\n");
111 painCave.isFatal = 1;
114 targetPressure = simParams->getTargetPressure();
117 if (!simParams->haveTauBarostat()) {
118 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
119 "If you use the NPT integrator, you must set tauBarostat.\n");
120 painCave.severity = OPENMD_ERROR;
121 painCave.isFatal = 1;
124 tauBarostat = simParams->getTauBarostat();
127 tt2 = tauThermostat * tauThermostat;
128 tb2 = tauBarostat * tauBarostat;
133 void NPT::doUpdateSizes() {
134 oldPos.resize(info_->getNIntegrableObjects());
135 oldVel.resize(info_->getNIntegrableObjects());
136 oldJi.resize(info_->getNIntegrableObjects());
140 SimInfo::MoleculeIterator i;
141 Molecule::IntegrableObjectIterator j;
152 thermostat = snap->getThermostat();
155 instaTemp = thermo.getTemperature();
156 press = thermo.getPressureTensor();
157 instaPress = Constants::pressureConvert *
158 (press(0, 0) + press(1, 1) + press(2, 2)) / 3.0;
159 instaVol = thermo.getVolume();
161 Vector3d COM = thermo.getCom();
167 for (mol = info_->beginMolecule(i); mol != NULL;
168 mol = info_->nextMolecule(i)) {
169 for (sd = mol->beginIntegrableObject(j); sd != NULL;
170 sd = mol->nextIntegrableObject(j)) {
174 mass = sd->getMass();
176 getVelScaleA(sc, vel);
180 vel += dt2 * Constants::energyConvert / mass * frc - dt2 * sc;
183 if (sd->isDirectional()) {
186 Tb = sd->lab2Body(sd->getTrq());
193 dt2 * Constants::energyConvert * Tb - dt2 * thermostat.first * ji;
195 rotAlgo_->rotate(sd, ji, dt);
203 thermostat.first += dt2 * (instaTemp / targetTemp - 1.0) / tt2;
208 thermostat.second += dt2 * thermostat.first;
213 for (mol = info_->beginMolecule(i); mol != NULL;
214 mol = info_->nextMolecule(i)) {
215 for (sd = mol->beginIntegrableObject(j); sd != NULL;
216 sd = mol->nextIntegrableObject(j)) {
217 oldPos[index++] = sd->getPos();
223 for (
int k = 0; k < maxIterNum_; k++) {
225 for (mol = info_->beginMolecule(i); mol != NULL;
226 mol = info_->nextMolecule(i)) {
227 for (sd = mol->beginIntegrableObject(j); sd != NULL;
228 sd = mol->nextIntegrableObject(j)) {
232 this->getPosScale(pos, COM, index, sc);
234 pos = oldPos[index] + dt * (vel + sc);
241 rattle_->constraintA();
248 snap->setThermostat(thermostat);
253 void NPT::moveB(
void) {
254 SimInfo::MoleculeIterator i;
255 Molecule::IntegrableObjectIterator j;
266 thermostat = snap->getThermostat();
267 RealType oldChi = thermostat.first;
274 for (mol = info_->beginMolecule(i); mol != NULL;
275 mol = info_->nextMolecule(i)) {
276 for (sd = mol->beginIntegrableObject(j); sd != NULL;
277 sd = mol->nextIntegrableObject(j)) {
278 oldVel[index] = sd->getVel();
280 if (sd->isDirectional()) oldJi[index] = sd->getJ();
287 instaVol = thermo.getVolume();
289 for (
int k = 0; k < maxIterNum_; k++) {
290 instaTemp = thermo.getTemperature();
291 instaPress = thermo.getPressure();
294 prevChi = thermostat.first;
295 thermostat.first = oldChi + dt2 * (instaTemp / targetTemp - 1.0) / tt2;
299 this->calcVelScale();
302 for (mol = info_->beginMolecule(i); mol != NULL;
303 mol = info_->nextMolecule(i)) {
304 for (sd = mol->beginIntegrableObject(j); sd != NULL;
305 sd = mol->nextIntegrableObject(j)) {
307 mass = sd->getMass();
309 getVelScaleB(sc, index);
312 vel = oldVel[index] + dt2 * Constants::energyConvert / mass * frc -
317 if (sd->isDirectional()) {
319 Tb = sd->lab2Body(sd->getTrq());
321 ji = oldJi[index] + dt2 * Constants::energyConvert * Tb -
322 dt2 * thermostat.first * oldJi[index];
331 rattle_->constraintB();
333 if ((fabs(prevChi - thermostat.first) <= chiTolerance) &&
334 this->etaConverged())
339 thermostat.second += dt2 * thermostat.first;
341 snap->setThermostat(thermostat);
347 void NPT::resetIntegrator() {
348 snap->setThermostat(make_pair(0.0, 0.0));
352 void NPT::resetEta() {
354 snap->setBarostat(etaMat);
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.