51#include "brains/Thermo.hpp"
52#include "integrators/IntegratorCreator.hpp"
54#include "utils/Constants.hpp"
55#include "utils/simError.h"
69 void NPTf::evolveEtaA() {
72 for (i = 0; i < 3; i++) {
73 for (j = 0; j < 3; j++) {
77 (press(i, j) - targetPressure / Constants::pressureConvert) /
80 eta(i, j) += dt2 * instaVol * press(i, j) / (NkBT * tb2);
85 for (i = 0; i < 3; i++) {
86 for (j = 0; j < 3; j++) {
87 oldEta(i, j) = eta(i, j);
92 void NPTf::evolveEtaB() {
96 for (i = 0; i < 3; i++) {
97 for (j = 0; j < 3; j++) {
98 prevEta(i, j) = eta(i, j);
102 for (i = 0; i < 3; i++) {
103 for (j = 0; j < 3; j++) {
108 (press(i, j) - targetPressure / Constants::pressureConvert) /
112 oldEta(i, j) + dt2 * instaVol * press(i, j) / (NkBT * tb2);
118 void NPTf::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; }
128 void NPTf::getVelScaleA(Vector3d& sc,
const Vector3d& vel) {
132 void NPTf::getVelScaleB(Vector3d& sc,
int index) {
133 sc = vScale * oldVel[index];
136 void NPTf::getPosScale(
const Vector3d& pos,
const Vector3d& COM,
int index,
139 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
143 void NPTf::scaleSimBox() {
149 RealType bigScale, smallScale, offDiagMax;
162 for (i = 0; i < 3; i++) {
163 for (j = 0; j < 3; j++) {
168 for (k = 0; k < 3; k++) {
169 eta2ij += eta(i, k) * eta(k, j);
172 scaleMat(i, j) = 0.0;
174 if (i == j) scaleMat(i, j) = 1.0;
176 scaleMat(i, j) += dt * eta(i, j) + 0.5 * dt * dt * eta2ij;
179 if (fabs(scaleMat(i, j)) > offDiagMax)
180 offDiagMax = fabs(scaleMat(i, j));
183 if (scaleMat(i, i) > bigScale) bigScale = scaleMat(i, i);
184 if (scaleMat(i, i) < smallScale) smallScale = scaleMat(i, i);
187 if ((bigScale > 1.01) || (smallScale < 0.99)) {
188 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
189 "NPTf error: Attempting a Box scaling of more than 1 percent.\n"
190 " Check your tauBarostat, as it is probably too small!\n\n"
191 " scaleMat = [%lf\t%lf\t%lf]\n"
194 " eta = [%lf\t%lf\t%lf]\n"
196 " [%lf\t%lf\t%lf]\n",
197 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
198 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
199 scaleMat(2, 2), eta(0, 0), eta(0, 1), eta(0, 2), eta(1, 0),
200 eta(1, 1), eta(1, 2), eta(2, 0), eta(2, 1), eta(2, 2));
201 painCave.isFatal = 1;
203 }
else if (offDiagMax > 0.01) {
205 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
206 "NPTf error: Attempting an off-diagonal Box scaling of more than 1 "
208 " Check your tauBarostat, as it is probably too small!\n\n"
209 " scaleMat = [%lf\t%lf\t%lf]\n"
212 " eta = [%lf\t%lf\t%lf]\n"
214 " [%lf\t%lf\t%lf]\n",
215 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
216 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
217 scaleMat(2, 2), eta(0, 0), eta(0, 1), eta(0, 2), eta(1, 0), eta(1, 1),
218 eta(1, 2), eta(2, 0), eta(2, 1), eta(2, 2));
219 painCave.isFatal = 1;
222 Mat3x3d hmat = snap->getHmat();
223 hmat = hmat * scaleMat;
228 bool NPTf::etaConverged() {
230 RealType diffEta, sumEta;
233 for (i = 0; i < 3; i++) {
234 sumEta += pow(prevEta(i, i) - eta(i, i), 2);
237 diffEta = sqrt(sumEta / 3.0);
239 return (diffEta <= etaTolerance);
242 RealType NPTf::calcConservedQuantity() {
243 thermostat = snap->getThermostat();
249 NkBT = info_->getNGlobalIntegrableObjects() * Constants::kB * targetTemp;
254 fkBT = info_->getNdf() * Constants::kB * targetTemp;
256 RealType conservedQuantity;
257 RealType totalEnergy;
258 RealType thermostat_kinetic;
259 RealType thermostat_potential;
260 RealType barostat_kinetic;
261 RealType barostat_potential;
264 totalEnergy = thermo.getTotalEnergy();
266 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
267 (2.0 * Constants::energyConvert);
269 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
271 SquareMatrix<RealType, 3> tmp = eta.transpose() * eta;
274 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
277 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
278 Constants::energyConvert;
280 conservedQuantity = totalEnergy + thermostat_kinetic +
281 thermostat_potential + barostat_kinetic +
284 return conservedQuantity;
287 void NPTf::loadEta() {
288 eta = snap->getBarostat();
299 void NPTf::saveEta() { snap->setBarostat(eta); }
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.