48#include "brains/Thermo.hpp"
49#include "integrators/IntegratorCreator.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
56 Globals* simParams = info_->getSimParams();
57 if (!simParams->haveSurfaceTension()) {
58 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
59 "If you use the NPT integrator, you must set tauBarostat.\n");
60 painCave.severity = OPENMD_ERROR;
64 surfaceTension_ = simParams->getSurfaceTension() *
65 Constants::surfaceTensionConvert *
66 Constants::energyConvert;
69 if (simParams->getPrivilegedAxis() ==
"x")
71 else if (simParams->getPrivilegedAxis() ==
"y")
73 else if (simParams->getPrivilegedAxis() ==
"z")
77 axis1_ = (axis_ + 1) % 3;
78 axis2_ = (axis_ + 2) % 3;
81 void NPrT::evolveEtaA() {
83 RealType hz = hmat(axis_, axis_);
84 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
85 RealType sx = -hz * (press(axis1_, axis1_) -
86 targetPressure / Constants::pressureConvert);
87 RealType sy = -hz * (press(axis2_, axis2_) -
88 targetPressure / Constants::pressureConvert);
89 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
90 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
93 (press(axis_, axis_) - targetPressure / Constants::pressureConvert) /
98 void NPrT::evolveEtaB() {
100 RealType hz = hmat(axis_, axis_);
101 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
103 RealType sx = -hz * (press(axis1_, axis1_) -
104 targetPressure / Constants::pressureConvert);
105 RealType sy = -hz * (press(axis2_, axis2_) -
106 targetPressure / Constants::pressureConvert);
107 eta(axis1_, axis1_) = oldEta_(axis1_, axis1_) -
108 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
109 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
110 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
111 eta(axis_, axis_) = oldEta_(axis_, axis_) +
113 (press(axis_, axis_) -
114 targetPressure / Constants::pressureConvert) /
118 void NPrT::calcVelScale() {
119 for (
int i = 0; i < 3; i++) {
120 for (
int j = 0; j < 3; j++) {
121 vScale_(i, j) = eta(i, j);
123 if (i == j) { vScale_(i, j) += thermostat.first; }
132 void NPrT::getVelScaleB(
Vector3d& sc,
int index) {
133 sc = vScale_ * oldVel[index];
139 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
143 void NPrT::scaleSimBox() {
146 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
147 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
148 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
150 hmat = hmat * scaleMat;
154 bool NPrT::etaConverged() {
156 RealType diffEta, sumEta;
159 for (i = 0; i < 3; i++) {
160 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
163 diffEta = sqrt(sumEta / 3.0);
165 return (diffEta <= etaTolerance);
168 RealType NPrT::calcConservedQuantity() {
169 thermostat = snap->getThermostat();
180 fkBT = info_->
getNdf() * Constants::kB * targetTemp;
182 RealType totalEnergy = thermo.getTotalEnergy();
184 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
186 (2.0 * Constants::energyConvert);
188 RealType thermostat_potential =
189 fkBT * thermostat.second / Constants::energyConvert;
192 RealType trEta = tmp.
trace();
194 RealType barostat_kinetic =
195 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
197 RealType barostat_potential =
198 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
199 Constants::energyConvert;
202 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
204 RealType conservedQuantity =
205 totalEnergy + thermostat_kinetic + thermostat_potential +
206 barostat_kinetic + barostat_potential -
207 surfaceTension_ * area / Constants::energyConvert;
209 return conservedQuantity;
212 void NPrT::loadEta() {
213 eta = snap->getBarostat();
224 void NPrT::saveEta() { snap->setBarostat(eta); }
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.
int getNGlobalIntegrableObjects()
Returns the total number of integrable objects (total number of rigid bodies plus the total number of...
Mat3x3d getHmat()
Returns the H-Matrix.
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Real trace() const
Returns the trace of this matrix.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.