51#include "brains/Thermo.hpp"
52#include "integrators/IntegratorCreator.hpp"
54#include "utils/Constants.hpp"
55#include "utils/simError.h"
59 Globals* simParams = info_->getSimParams();
60 if (!simParams->haveSurfaceTension()) {
61 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
62 "If you use the NPT integrator, you must set tauBarostat.\n");
63 painCave.severity = OPENMD_ERROR;
67 surfaceTension_ = simParams->getSurfaceTension() *
68 Constants::surfaceTensionConvert *
69 Constants::energyConvert;
72 if (simParams->getPrivilegedAxis() ==
"x")
74 else if (simParams->getPrivilegedAxis() ==
"y")
76 else if (simParams->getPrivilegedAxis() ==
"z")
80 axis1_ = (axis_ + 1) % 3;
81 axis2_ = (axis_ + 2) % 3;
84 void NPrT::evolveEtaA() {
85 Mat3x3d hmat = snap->getHmat();
86 RealType hz = hmat(axis_, axis_);
87 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
88 RealType sx = -hz * (press(axis1_, axis1_) -
89 targetPressure / Constants::pressureConvert);
90 RealType sy = -hz * (press(axis2_, axis2_) -
91 targetPressure / Constants::pressureConvert);
92 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
93 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
96 (press(axis_, axis_) - targetPressure / Constants::pressureConvert) /
101 void NPrT::evolveEtaB() {
102 Mat3x3d hmat = snap->getHmat();
103 RealType hz = hmat(axis_, axis_);
104 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
106 RealType sx = -hz * (press(axis1_, axis1_) -
107 targetPressure / Constants::pressureConvert);
108 RealType sy = -hz * (press(axis2_, axis2_) -
109 targetPressure / Constants::pressureConvert);
110 eta(axis1_, axis1_) = oldEta_(axis1_, axis1_) -
111 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
112 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
113 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
114 eta(axis_, axis_) = oldEta_(axis_, axis_) +
116 (press(axis_, axis_) -
117 targetPressure / Constants::pressureConvert) /
121 void NPrT::calcVelScale() {
122 for (
int i = 0; i < 3; i++) {
123 for (
int j = 0; j < 3; j++) {
124 vScale_(i, j) = eta(i, j);
126 if (i == j) { vScale_(i, j) += thermostat.first; }
131 void NPrT::getVelScaleA(Vector3d& sc,
const Vector3d& vel) {
135 void NPrT::getVelScaleB(Vector3d& sc,
int index) {
136 sc = vScale_ * oldVel[index];
139 void NPrT::getPosScale(
const Vector3d& pos,
const Vector3d& COM,
int index,
142 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
146 void NPrT::scaleSimBox() {
149 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
150 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
151 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
152 Mat3x3d hmat = snap->getHmat();
153 hmat = hmat * scaleMat;
157 bool NPrT::etaConverged() {
159 RealType diffEta, sumEta;
162 for (i = 0; i < 3; i++) {
163 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
166 diffEta = sqrt(sumEta / 3.0);
168 return (diffEta <= etaTolerance);
171 RealType NPrT::calcConservedQuantity() {
172 thermostat = snap->getThermostat();
178 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
183 fkBT = info_->getNdf() * Constants::kB * targetTemp;
185 RealType totalEnergy = thermo.getTotalEnergy();
187 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
189 (2.0 * Constants::energyConvert);
191 RealType thermostat_potential =
192 fkBT * thermostat.second / Constants::energyConvert;
194 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
195 RealType trEta = tmp.trace();
197 RealType barostat_kinetic =
198 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
200 RealType barostat_potential =
201 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
202 Constants::energyConvert;
204 Mat3x3d hmat = snap->getHmat();
205 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
207 RealType conservedQuantity =
208 totalEnergy + thermostat_kinetic + thermostat_potential +
209 barostat_kinetic + barostat_potential -
210 surfaceTension_ * area / Constants::energyConvert;
212 return conservedQuantity;
215 void NPrT::loadEta() {
216 eta = snap->getBarostat();
227 void NPrT::saveEta() { snap->setBarostat(eta); }
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.