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 NgammaT integrator, you must "
63 "set a surface tension.\n");
64 painCave.severity = OPENMD_ERROR;
68 surfaceTension_ = simParams->getSurfaceTension() *
69 Constants::surfaceTensionConvert *
70 Constants::energyConvert;
73 if (simParams->getPrivilegedAxis() ==
"x")
75 else if (simParams->getPrivilegedAxis() ==
"y")
77 else if (simParams->getPrivilegedAxis() ==
"z")
81 axis1_ = (axis_ + 1) % 3;
82 axis2_ = (axis_ + 2) % 3;
85 void NgammaT::evolveEtaA() {
86 Mat3x3d hmat = snap->getHmat();
87 RealType hz = hmat(axis_, axis_);
88 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
89 RealType sx = -hz * (press(axis1_, axis1_) -
90 targetPressure / Constants::pressureConvert);
91 RealType sy = -hz * (press(axis2_, axis2_) -
92 targetPressure / Constants::pressureConvert);
93 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
94 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
95 eta(axis_, axis_) = 0.0;
99 void NgammaT::evolveEtaB() {
100 Mat3x3d hmat = snap->getHmat();
101 RealType hz = hmat(axis_, axis_);
102 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
104 RealType sx = -hz * (press(axis1_, axis1_) -
105 targetPressure / Constants::pressureConvert);
106 RealType sy = -hz * (press(axis2_, axis2_) -
107 targetPressure / Constants::pressureConvert);
108 eta(axis_, axis_) = oldEta_(axis_, axis_) -
109 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
110 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
111 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
112 eta(axis_, axis_) = 0.0;
115 void NgammaT::calcVelScale() {
116 for (
int i = 0; i < 3; i++) {
117 for (
int j = 0; j < 3; j++) {
118 vScale_(i, j) = eta(i, j);
120 if (i == j) { vScale_(i, j) += thermostat.first; }
125 void NgammaT::getVelScaleA(Vector3d& sc,
const Vector3d& vel) {
129 void NgammaT::getVelScaleB(Vector3d& sc,
int index) {
130 sc = vScale_ * oldVel[index];
133 void NgammaT::getPosScale(
const Vector3d& pos,
const Vector3d& COM,
int index,
136 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
140 void NgammaT::scaleSimBox() {
143 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
144 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
145 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
146 Mat3x3d hmat = snap->getHmat();
147 hmat = hmat * scaleMat;
151 bool NgammaT::etaConverged() {
153 RealType diffEta, sumEta;
156 for (i = 0; i < 3; i++) {
157 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
160 diffEta = sqrt(sumEta / 3.0);
162 return (diffEta <= etaTolerance);
165 RealType NgammaT::calcConservedQuantity() {
166 thermostat = snap->getThermostat();
172 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
177 fkBT = info_->getNdf() * Constants::kB * targetTemp;
179 RealType totalEnergy = thermo.getTotalEnergy();
181 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
183 (2.0 * Constants::energyConvert);
185 RealType thermostat_potential =
186 fkBT * thermostat.second / Constants::energyConvert;
188 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
189 RealType trEta = tmp.trace();
191 RealType barostat_kinetic =
192 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
194 RealType barostat_potential =
195 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
196 Constants::energyConvert;
198 Mat3x3d hmat = snap->getHmat();
199 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
201 RealType conservedQuantity =
202 totalEnergy + thermostat_kinetic + thermostat_potential +
203 barostat_kinetic + barostat_potential -
204 surfaceTension_ * area / Constants::energyConvert;
206 return conservedQuantity;
209 void NgammaT::loadEta() {
210 eta = snap->getBarostat();
221 void NgammaT::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.