1 |
#include <math.h> |
2 |
#include "primitives/Atom.hpp" |
3 |
#include "primitives/SRI.hpp" |
4 |
#include "primitives/AbstractClasses.hpp" |
5 |
#include "brains/SimInfo.hpp" |
6 |
#include "UseTheForce/ForceFields.hpp" |
7 |
#include "brains/Thermo.hpp" |
8 |
#include "io/ReadWrite.hpp" |
9 |
#include "integrators/Integrator.hpp" |
10 |
#include "utils/simError.h" |
11 |
|
12 |
#ifdef IS_MPI |
13 |
#include "brains/mpiSimulation.hpp" |
14 |
#endif |
15 |
|
16 |
// Basic isotropic thermostating and barostating via the Melchionna |
17 |
// modification of the Hoover algorithm: |
18 |
// |
19 |
// Melchionna, S., Ciccotti, G., and Holian, B. L., 1993, |
20 |
// Molec. Phys., 78, 533. |
21 |
// |
22 |
// and |
23 |
// |
24 |
// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. |
25 |
|
26 |
NPTi::NPTi ( SimInfo *theInfo, ForceFields* the_ff): |
27 |
T( theInfo, the_ff ) |
28 |
{ |
29 |
GenericData* data; |
30 |
DoubleVectorGenericData * etaValue; |
31 |
vector<double> etaArray; |
32 |
|
33 |
eta = 0.0; |
34 |
oldEta = 0.0; |
35 |
|
36 |
if( theInfo->useInitXSstate ){ |
37 |
// retrieve eta from simInfo if |
38 |
data = info->getPropertyByName(ETAVALUE_ID); |
39 |
if(data){ |
40 |
etaValue = dynamic_cast<DoubleVectorGenericData*>(data); |
41 |
|
42 |
if(etaValue){ |
43 |
eta = (*etaValue)[0]; |
44 |
oldEta = eta; |
45 |
} |
46 |
} |
47 |
} |
48 |
} |
49 |
|
50 |
NPTi::~NPTi() { |
51 |
//nothing for now |
52 |
} |
53 |
|
54 |
void NPTi::evolveEtaA() { |
55 |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
56 |
(p_convert*NkBT*tb2)); |
57 |
oldEta = eta; |
58 |
} |
59 |
|
60 |
void NPTi::evolveEtaB() { |
61 |
|
62 |
prevEta = eta; |
63 |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
64 |
(p_convert*NkBT*tb2)); |
65 |
} |
66 |
|
67 |
void NPTi::calcVelScale() { |
68 |
vScale = chi + eta; |
69 |
} |
70 |
|
71 |
void NPTi::getVelScaleA(Vector3d& sc, const Vector3d& vel) { |
72 |
sc = vel * vScale; |
73 |
} |
74 |
|
75 |
void NPTi::getVelScaleB(Vector3d& sc, int index ){ |
76 |
sc = oldVel[index] * vScale; |
77 |
} |
78 |
|
79 |
|
80 |
void NPTi::getPosScale(const Vector3d& pos, const Vector3d& COM, |
81 |
int index, Vector3d& sc){ |
82 |
/**@todo*/ |
83 |
sc = oldPos[index] + pos/2.0 -COM; |
84 |
sc *= eta; |
85 |
} |
86 |
|
87 |
void NPTi::scaleSimBox(){ |
88 |
|
89 |
double scaleFactor; |
90 |
|
91 |
scaleFactor = exp(dt*eta); |
92 |
|
93 |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
94 |
sprintf( painCave.errMsg, |
95 |
"NPTi error: Attempting a Box scaling of more than 10 percent" |
96 |
" check your tauBarostat, as it is probably too small!\n" |
97 |
" eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
98 |
); |
99 |
painCave.isFatal = 1; |
100 |
simError(); |
101 |
} else { |
102 |
info->scaleBox(scaleFactor); |
103 |
} |
104 |
|
105 |
} |
106 |
|
107 |
bool NPTi::etaConverged() { |
108 |
|
109 |
return ( fabs(prevEta - eta) <= etaTolerance ); |
110 |
} |
111 |
|
112 |
double NPTi::calcConservedQuantity(){ |
113 |
|
114 |
double conservedQuantity; |
115 |
double Energy; |
116 |
double thermostat_kinetic; |
117 |
double thermostat_potential; |
118 |
double barostat_kinetic; |
119 |
double barostat_potential; |
120 |
|
121 |
Energy = tStats->getTotalE(); |
122 |
|
123 |
thermostat_kinetic = fkBT* tt2 * chi * chi / |
124 |
(2.0 * eConvert); |
125 |
|
126 |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
127 |
|
128 |
|
129 |
barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta / |
130 |
(2.0 * eConvert); |
131 |
|
132 |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
133 |
eConvert; |
134 |
|
135 |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
136 |
barostat_kinetic + barostat_potential; |
137 |
|
138 |
return conservedQuantity; |
139 |
} |
140 |
|