48#include "brains/Thermo.hpp"
49#include "integrators/IntegratorCreator.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
66 void NPTf::evolveEtaA() {
69 for (i = 0; i < 3; i++) {
70 for (j = 0; j < 3; j++) {
74 (press(i, j) - targetPressure / Constants::pressureConvert) /
77 eta(i, j) += dt2 * instaVol * press(i, j) / (NkBT * tb2);
82 for (i = 0; i < 3; i++) {
83 for (j = 0; j < 3; j++) {
84 oldEta(i, j) = eta(i, j);
89 void NPTf::evolveEtaB() {
93 for (i = 0; i < 3; i++) {
94 for (j = 0; j < 3; j++) {
95 prevEta(i, j) = eta(i, j);
99 for (i = 0; i < 3; i++) {
100 for (j = 0; j < 3; j++) {
105 (press(i, j) - targetPressure / Constants::pressureConvert) /
109 oldEta(i, j) + dt2 * instaVol * press(i, j) / (NkBT * tb2);
115 void NPTf::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; }
129 void NPTf::getVelScaleB(
Vector3d& sc,
int index) {
130 sc = vScale * oldVel[index];
136 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
140 void NPTf::scaleSimBox() {
146 RealType bigScale, smallScale, offDiagMax;
159 for (i = 0; i < 3; i++) {
160 for (j = 0; j < 3; j++) {
165 for (k = 0; k < 3; k++) {
166 eta2ij += eta(i, k) * eta(k, j);
169 scaleMat(i, j) = 0.0;
171 if (i == j) scaleMat(i, j) = 1.0;
173 scaleMat(i, j) += dt * eta(i, j) + 0.5 * dt * dt * eta2ij;
176 if (fabs(scaleMat(i, j)) > offDiagMax)
177 offDiagMax = fabs(scaleMat(i, j));
180 if (scaleMat(i, i) > bigScale) bigScale = scaleMat(i, i);
181 if (scaleMat(i, i) < smallScale) smallScale = scaleMat(i, i);
184 if ((bigScale > 1.01) || (smallScale < 0.99)) {
185 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
186 "NPTf error: Attempting a Box scaling of more than 1 percent.\n"
187 " Check your tauBarostat, as it is probably too small!\n\n"
188 " scaleMat = [%lf\t%lf\t%lf]\n"
191 " eta = [%lf\t%lf\t%lf]\n"
193 " [%lf\t%lf\t%lf]\n",
194 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
195 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
196 scaleMat(2, 2), eta(0, 0), eta(0, 1), eta(0, 2), eta(1, 0),
197 eta(1, 1), eta(1, 2), eta(2, 0), eta(2, 1), eta(2, 2));
198 painCave.isFatal = 1;
200 }
else if (offDiagMax > 0.01) {
202 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
203 "NPTf error: Attempting an off-diagonal Box scaling of more than 1 "
205 " Check your tauBarostat, as it is probably too small!\n\n"
206 " scaleMat = [%lf\t%lf\t%lf]\n"
209 " eta = [%lf\t%lf\t%lf]\n"
211 " [%lf\t%lf\t%lf]\n",
212 scaleMat(0, 0), scaleMat(0, 1), scaleMat(0, 2), scaleMat(1, 0),
213 scaleMat(1, 1), scaleMat(1, 2), scaleMat(2, 0), scaleMat(2, 1),
214 scaleMat(2, 2), eta(0, 0), eta(0, 1), eta(0, 2), eta(1, 0), eta(1, 1),
215 eta(1, 2), eta(2, 0), eta(2, 1), eta(2, 2));
216 painCave.isFatal = 1;
220 hmat = hmat * scaleMat;
225 bool NPTf::etaConverged() {
227 RealType diffEta, sumEta;
230 for (i = 0; i < 3; i++) {
231 sumEta += pow(prevEta(i, i) - eta(i, i), 2);
234 diffEta = sqrt(sumEta / 3.0);
236 return (diffEta <= etaTolerance);
239 RealType NPTf::calcConservedQuantity() {
240 thermostat = snap->getThermostat();
251 fkBT = info_->
getNdf() * Constants::kB * targetTemp;
253 RealType conservedQuantity;
254 RealType totalEnergy;
255 RealType thermostat_kinetic;
256 RealType thermostat_potential;
257 RealType barostat_kinetic;
258 RealType barostat_potential;
261 totalEnergy = thermo.getTotalEnergy();
263 thermostat_kinetic = fkBT * tt2 * thermostat.first * thermostat.first /
264 (2.0 * Constants::energyConvert);
266 thermostat_potential = fkBT * thermostat.second / Constants::energyConvert;
271 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
274 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
275 Constants::energyConvert;
277 conservedQuantity = totalEnergy + thermostat_kinetic +
278 thermostat_potential + barostat_kinetic +
281 return conservedQuantity;
284 void NPTf::loadEta() {
285 eta = snap->getBarostat();
296 void NPTf::saveEta() { snap->setBarostat(eta); }
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.