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 NgammaT integrator, you must "
60 "set a surface tension.\n");
61 painCave.severity = OPENMD_ERROR;
65 surfaceTension_ = simParams->getSurfaceTension() *
66 Constants::surfaceTensionConvert *
67 Constants::energyConvert;
70 if (simParams->getPrivilegedAxis() ==
"x")
72 else if (simParams->getPrivilegedAxis() ==
"y")
74 else if (simParams->getPrivilegedAxis() ==
"z")
78 axis1_ = (axis_ + 1) % 3;
79 axis2_ = (axis_ + 2) % 3;
82 void NgammaT::evolveEtaA() {
84 RealType hz = hmat(axis_, axis_);
85 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
86 RealType sx = -hz * (press(axis1_, axis1_) -
87 targetPressure / Constants::pressureConvert);
88 RealType sy = -hz * (press(axis2_, axis2_) -
89 targetPressure / Constants::pressureConvert);
90 eta(axis1_, axis1_) -= dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
91 eta(axis2_, axis2_) -= dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
92 eta(axis_, axis_) = 0.0;
96 void NgammaT::evolveEtaB() {
98 RealType hz = hmat(axis_, axis_);
99 RealType Axy = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
101 RealType sx = -hz * (press(axis1_, axis1_) -
102 targetPressure / Constants::pressureConvert);
103 RealType sy = -hz * (press(axis2_, axis2_) -
104 targetPressure / Constants::pressureConvert);
105 eta(axis_, axis_) = oldEta_(axis_, axis_) -
106 dt2 * Axy * (sx - surfaceTension_) / (NkBT * tb2);
107 eta(axis2_, axis2_) = oldEta_(axis2_, axis2_) -
108 dt2 * Axy * (sy - surfaceTension_) / (NkBT * tb2);
109 eta(axis_, axis_) = 0.0;
112 void NgammaT::calcVelScale() {
113 for (
int i = 0; i < 3; i++) {
114 for (
int j = 0; j < 3; j++) {
115 vScale_(i, j) = eta(i, j);
117 if (i == j) { vScale_(i, j) += thermostat.first; }
126 void NgammaT::getVelScaleB(
Vector3d& sc,
int index) {
127 sc = vScale_ * oldVel[index];
130 void NgammaT::getPosScale(
const Vector3d& pos,
const Vector3d& COM,
int index,
133 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
137 void NgammaT::scaleSimBox() {
140 scaleMat(axis1_, axis1_) = exp(dt * eta(axis1_, axis1_));
141 scaleMat(axis2_, axis2_) = exp(dt * eta(axis2_, axis2_));
142 scaleMat(axis_, axis_) = exp(dt * eta(axis_, axis_));
144 hmat = hmat * scaleMat;
148 bool NgammaT::etaConverged() {
150 RealType diffEta, sumEta;
153 for (i = 0; i < 3; i++) {
154 sumEta += pow(prevEta_(i, i) - eta(i, i), 2);
157 diffEta = sqrt(sumEta / 3.0);
159 return (diffEta <= etaTolerance);
162 RealType NgammaT::calcConservedQuantity() {
163 thermostat = snap->getThermostat();
174 fkBT = info_->
getNdf() * Constants::kB * targetTemp;
176 RealType totalEnergy = thermo.getTotalEnergy();
178 RealType thermostat_kinetic = fkBT * tt2 * thermostat.first *
180 (2.0 * Constants::energyConvert);
182 RealType thermostat_potential =
183 fkBT * thermostat.second / Constants::energyConvert;
186 RealType trEta = tmp.
trace();
188 RealType barostat_kinetic =
189 NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
191 RealType barostat_potential =
192 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
193 Constants::energyConvert;
196 RealType area = hmat(axis1_, axis1_) * hmat(axis2_, axis2_);
198 RealType conservedQuantity =
199 totalEnergy + thermostat_kinetic + thermostat_potential +
200 barostat_kinetic + barostat_potential -
201 surfaceTension_ * area / Constants::energyConvert;
203 return conservedQuantity;
206 void NgammaT::loadEta() {
207 eta = snap->getBarostat();
218 void NgammaT::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.