48#include "brains/Thermo.hpp"
49#include "integrators/IntegratorCreator.hpp"
51#include "utils/Constants.hpp"
52#include "utils/simError.h"
57 SimInfo::MoleculeIterator i;
58 Molecule::IntegrableObjectIterator j;
71 instaTemp = thermo.getTemperature();
73 instaPress = Constants::pressureConvert *
74 (press(0, 0) + press(1, 1) + press(2, 2)) / 3.0;
75 instaVol = thermo.getVolume();
85 for (sd = mol->beginIntegrableObject(j); sd != NULL;
86 sd = mol->nextIntegrableObject(j)) {
92 getVelScaleA(sc, vel);
96 vel += dt2 * Constants::energyConvert / mass * frc - dt2 * sc;
108 ji += dt2 * Constants::energyConvert * Tb;
110 rotAlgo_->rotate(sd, ji, dt);
124 for (sd = mol->beginIntegrableObject(j); sd != NULL;
125 sd = mol->nextIntegrableObject(j)) {
126 oldPos[index++] = sd->
getPos();
132 for (
int k = 0; k < maxIterNum_; k++) {
136 for (sd = mol->beginIntegrableObject(j); sd != NULL;
137 sd = mol->nextIntegrableObject(j)) {
141 this->getPosScale(pos, COM, index, sc);
143 pos = oldPos[index] + dt * (vel + sc);
150 rattle_->constraintA();
160 void NPA::moveB(
void) {
161 SimInfo::MoleculeIterator i;
162 Molecule::IntegrableObjectIterator j;
179 for (sd = mol->beginIntegrableObject(j); sd != NULL;
180 sd = mol->nextIntegrableObject(j)) {
181 oldVel[index] = sd->
getVel();
189 instaVol = thermo.getVolume();
190 for (
int k = 0; k < maxIterNum_; k++) {
191 instaTemp = thermo.getTemperature();
192 instaPress = thermo.getPressure();
196 this->calcVelScale();
201 for (sd = mol->beginIntegrableObject(j); sd != NULL;
202 sd = mol->nextIntegrableObject(j)) {
206 getVelScaleB(sc, index);
209 vel = oldVel[index] + dt2 * Constants::energyConvert / mass * frc -
218 ji = oldJi[index] + dt2 * Constants::energyConvert * Tb;
227 rattle_->constraintB();
229 if (this->etaConverged())
break;
236 void NPA::evolveEtaA() {
237 eta(2, 2) += dt2 * instaVol *
238 (press(2, 2) - targetPressure / Constants::pressureConvert) /
243 void NPA::evolveEtaB() {
248 (press(2, 2) - targetPressure / Constants::pressureConvert) /
252 void NPA::calcVelScale() {
253 for (
int i = 0; i < 3; i++) {
254 for (
int j = 0; j < 3; j++) {
255 vScale(i, j) = eta(i, j);
264 void NPA::getVelScaleB(
Vector3d& sc,
int index) {
265 sc = vScale * oldVel[index];
270 Vector3d rj = (oldPos[index] + pos) / (RealType)2.0 - COM;
274 void NPA::scaleSimBox() {
277 for (
int i = 0; i < 3; i++) {
278 for (
int j = 0; j < 3; j++) {
279 scaleMat(i, j) = 0.0;
280 if (i == j) { scaleMat(i, j) = 1.0; }
284 scaleMat(2, 2) = exp(dt * eta(2, 2));
286 hmat = hmat * scaleMat;
290 bool NPA::etaConverged() {
292 RealType diffEta, sumEta;
295 for (i = 0; i < 3; i++) {
296 sumEta += pow(prevEta(i, i) - eta(i, i), 2);
299 diffEta = sqrt(sumEta / 3.0);
301 return (diffEta <= etaTolerance);
304 RealType NPA::calcConservedQuantity() {
312 RealType conservedQuantity;
313 RealType totalEnergy;
314 RealType barostat_kinetic;
315 RealType barostat_potential;
318 totalEnergy = thermo.getTotalEnergy();
323 barostat_kinetic = NkBT * tb2 * trEta / (2.0 * Constants::energyConvert);
326 (targetPressure * thermo.getVolume() / Constants::pressureConvert) /
327 Constants::energyConvert;
329 conservedQuantity = totalEnergy + barostat_kinetic + barostat_potential;
331 return conservedQuantity;
334 void NPA::loadEta() { eta = snap->getBarostat(); }
336 void NPA::saveEta() { snap->setBarostat(eta); }
int getNGlobalIntegrableObjects()
Returns the total number of integrable objects (total number of rigid bodies plus the total number of...
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
Mat3x3d getHmat()
Returns the H-Matrix.
void setHmat(const Mat3x3d &m)
Sets the H-Matrix.
Real trace() const
Returns the trace of this matrix.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Vector3d getTrq()
Returns the current torque of this stuntDouble.
Vector3d lab2Body(const Vector3d &v)
Converts a lab fixed vector to a body fixed vector.
Vector3d getVel()
Returns the current velocity of this stuntDouble.
RealType getMass()
Returns the mass of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
void setVel(const Vector3d &vel)
Sets the current velocity of this stuntDouble.
Vector3d getJ()
Returns the current angular momentum of this stuntDouble (body -fixed).
bool isDirectional()
Tests if this stuntDouble is a directional one.
Vector3d getFrc()
Returns the current force of this stuntDouble.
void setJ(const Vector3d &angMom)
Sets the current angular momentum of this stuntDouble (body-fixed).
Mat3x3d getPressureTensor()
gives the pressure tensor in amu*fs^-2*Ang^-1
Vector3d getCom()
Returns the center of the mass of the whole system.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.