1 |
#include "NPTi.hpp" |
2 |
#include "brains/SimInfo.hpp" |
3 |
#include "brains/Thermo.hpp" |
4 |
#include "integrators/IntegratorCreator.hpp" |
5 |
#include "integrators/NPT.hpp" |
6 |
#include "primitives/Molecule.hpp" |
7 |
#include "utils/OOPSEConstant.hpp" |
8 |
#include "utils/simError.h" |
9 |
|
10 |
namespace oopse { |
11 |
|
12 |
static IntegratorBuilder<NPTi>* NPTiCreator = new IntegratorBuilder<NPTi>("NPTi"); |
13 |
|
14 |
// Basic isotropic thermostating and barostating via the Melchionna |
15 |
// modification of the Hoover algorithm: |
16 |
// |
17 |
// Melchionna, S., Ciccotti, G., and Holian, B. L., 1993, |
18 |
// Molec. Phys., 78, 533. |
19 |
// |
20 |
// and |
21 |
// |
22 |
// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. |
23 |
|
24 |
NPTi::NPTi ( SimInfo *info) : NPT(info){ |
25 |
|
26 |
Globals* globals = info_->getGlobals(); |
27 |
|
28 |
} |
29 |
|
30 |
void NPTi::evolveEtaA() { |
31 |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
32 |
(OOPSEConstant::pressureConvert*NkBT*tb2)); |
33 |
oldEta = eta; |
34 |
} |
35 |
|
36 |
void NPTi::evolveEtaB() { |
37 |
|
38 |
prevEta = eta; |
39 |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
40 |
(OOPSEConstant::pressureConvert*NkBT*tb2)); |
41 |
} |
42 |
|
43 |
void NPTi::calcVelScale() { |
44 |
vScale = chi + eta; |
45 |
} |
46 |
|
47 |
void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) { |
48 |
sc = vel * vScale; |
49 |
} |
50 |
|
51 |
void NPTi::getVelScaleB(Vector3d& sc, int index ){ |
52 |
sc = oldVel[index] * vScale; |
53 |
} |
54 |
|
55 |
|
56 |
void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM, |
57 |
int index, Vector3d& sc){ |
58 |
/**@todo*/ |
59 |
sc = oldPos[index] + pos/2.0 -COM; |
60 |
sc *= eta; |
61 |
} |
62 |
|
63 |
void NPTi::scaleSimBox(){ |
64 |
|
65 |
double scaleFactor; |
66 |
|
67 |
scaleFactor = exp(dt*eta); |
68 |
|
69 |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
70 |
sprintf( painCave.errMsg, |
71 |
"NPTi error: Attempting a Box scaling of more than 10 percent" |
72 |
" check your tauBarostat, as it is probably too small!\n" |
73 |
" eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
74 |
); |
75 |
painCave.isFatal = 1; |
76 |
simError(); |
77 |
} else { |
78 |
Mat3x3d hmat = currentSnapshot_->getHmat(); |
79 |
hmat *= scaleFactor; |
80 |
currentSnapshot_->setHmat(hmat); |
81 |
} |
82 |
|
83 |
} |
84 |
|
85 |
bool NPTi::etaConverged() { |
86 |
|
87 |
return ( fabs(prevEta - eta) <= etaTolerance ); |
88 |
} |
89 |
|
90 |
double NPTi::calcConservedQuantity(){ |
91 |
|
92 |
double conservedQuantity; |
93 |
double Energy; |
94 |
double thermostat_kinetic; |
95 |
double thermostat_potential; |
96 |
double barostat_kinetic; |
97 |
double barostat_potential; |
98 |
|
99 |
Energy =thermo.getTotalE(); |
100 |
|
101 |
thermostat_kinetic = fkBT* tt2 * chi * chi / (2.0 * OOPSEConstant::energyConvert); |
102 |
|
103 |
thermostat_potential = fkBT* integralOfChidt / OOPSEConstant::energyConvert; |
104 |
|
105 |
|
106 |
barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta /(2.0 * OOPSEConstant::energyConvert); |
107 |
|
108 |
barostat_potential = (targetPressure * thermo.getVolume() / OOPSEConstant::pressureConvert) / |
109 |
OOPSEConstant::energyConvert; |
110 |
|
111 |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
112 |
barostat_kinetic + barostat_potential; |
113 |
|
114 |
return conservedQuantity; |
115 |
} |
116 |
|
117 |
void NPTi::loadEta() { |
118 |
Mat3x3d etaMat = currentSnapshot_->getEta(); |
119 |
eta = etaMat(0,0); |
120 |
if (fabs(etaMat(1,1) - eta) >= oopse::epsilon || fabs(etaMat(1,1) - eta) >= oopse::epsilon || etaMat.isDiagonal()) { |
121 |
sprintf( painCave.errMsg, |
122 |
"NPTi error: the diagonal elements of are eta matrix is not same or etaMat is not a diagonal matrix"); |
123 |
painCave.isFatal = 1; |
124 |
simError(); |
125 |
} |
126 |
} |
127 |
|
128 |
void NPTi::saveEta() { |
129 |
Mat3x3d etaMat(0.0); |
130 |
etaMat(0, 0) = eta; |
131 |
etaMat(1, 1) = eta; |
132 |
etaMat(2, 2) = eta; |
133 |
currentSnapshot_->setEta(etaMat); |
134 |
} |
135 |
|
136 |
} |