1 |
#include <math.h> |
2 |
#include "Atom.hpp" |
3 |
#include "SRI.hpp" |
4 |
#include "AbstractClasses.hpp" |
5 |
#include "SimInfo.hpp" |
6 |
#include "ForceFields.hpp" |
7 |
#include "Thermo.hpp" |
8 |
#include "ReadWrite.hpp" |
9 |
#include "Integrator.hpp" |
10 |
#include "simError.h" |
11 |
|
12 |
#ifdef IS_MPI |
13 |
#include "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 |
Integrator( theInfo, the_ff ) |
28 |
{ |
29 |
GenericData* data; |
30 |
DoubleArrayData * etaValue; |
31 |
vector<double> etaArray; |
32 |
|
33 |
eta = 0.0; |
34 |
oldEta = 0.0; |
35 |
|
36 |
// retrieve eta from simInfo if |
37 |
data = info->getProperty(ETAVALUE_ID); |
38 |
if(data){ |
39 |
etaValue = dynamic_cast<DoubleArrayData*>(data); |
40 |
|
41 |
if(etaValue){ |
42 |
etaArray = etaValue->getData(); |
43 |
eta = etaArray[0]; |
44 |
oldEta = eta; |
45 |
} |
46 |
} |
47 |
|
48 |
} |
49 |
|
50 |
NPTi::~NPTi() { |
51 |
//nothing for now |
52 |
} |
53 |
|
54 |
void NPTi::resetIntegrator() { |
55 |
eta = 0.0; |
56 |
Integrator::resetIntegrator(); |
57 |
} |
58 |
|
59 |
void NPTi::evolveEtaA() { |
60 |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
61 |
(p_convert*NkBT*tb2)); |
62 |
oldEta = eta; |
63 |
} |
64 |
|
65 |
void NPTi::evolveEtaB() { |
66 |
|
67 |
prevEta = eta; |
68 |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
69 |
(p_convert*NkBT*tb2)); |
70 |
} |
71 |
|
72 |
void NPTi::getVelScaleA(double sc[3], double vel[3]) { |
73 |
int i; |
74 |
|
75 |
for(i=0; i<3; i++) sc[i] = vel[i] * ( chi + eta ); |
76 |
} |
77 |
|
78 |
void NPTi::getVelScaleB(double sc[3], int index ){ |
79 |
int i; |
80 |
|
81 |
for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * ( chi + eta ); |
82 |
} |
83 |
|
84 |
|
85 |
void NPTi::getPosScale(double pos[3], double COM[3], |
86 |
int index, double sc[3]){ |
87 |
int j; |
88 |
|
89 |
for(j=0; j<3; j++) |
90 |
sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j]; |
91 |
|
92 |
for(j=0; j<3; j++) |
93 |
sc[j] *= eta; |
94 |
} |
95 |
|
96 |
void NPTi::scaleSimBox( void ){ |
97 |
|
98 |
double scaleFactor; |
99 |
|
100 |
scaleFactor = exp(dt*eta); |
101 |
|
102 |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
103 |
sprintf( painCave.errMsg, |
104 |
"NPTi error: Attempting a Box scaling of more than 10 percent" |
105 |
" check your tauBarostat, as it is probably too small!\n" |
106 |
" eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
107 |
); |
108 |
painCave.isFatal = 1; |
109 |
simError(); |
110 |
} else { |
111 |
info->scaleBox(scaleFactor); |
112 |
} |
113 |
|
114 |
} |
115 |
|
116 |
bool NPTi::etaConverged() { |
117 |
|
118 |
return ( fabs(prevEta - eta) <= etaTolerance ); |
119 |
} |
120 |
|
121 |
double NPTi::getConservedQuantity(void){ |
122 |
|
123 |
double conservedQuantity; |
124 |
double Energy; |
125 |
double thermostat_kinetic; |
126 |
double thermostat_potential; |
127 |
double barostat_kinetic; |
128 |
double barostat_potential; |
129 |
|
130 |
Energy = tStats->getTotalE(); |
131 |
|
132 |
thermostat_kinetic = fkBT* tt2 * chi * chi / |
133 |
(2.0 * eConvert); |
134 |
|
135 |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
136 |
|
137 |
|
138 |
barostat_kinetic = 3.0 * NkBT * tb2 * eta * eta / |
139 |
(2.0 * eConvert); |
140 |
|
141 |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
142 |
eConvert; |
143 |
|
144 |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
145 |
barostat_kinetic + barostat_potential; |
146 |
|
147 |
// cout.width(8); |
148 |
// cout.precision(8); |
149 |
|
150 |
// cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
151 |
// "\t" << thermostat_potential << "\t" << barostat_kinetic << |
152 |
// "\t" << barostat_potential << "\t" << conservedQuantity << endl; |
153 |
return conservedQuantity; |
154 |
} |
155 |
|
156 |
string NPTi::getAdditionalParameters(void){ |
157 |
string parameters; |
158 |
const int BUFFERSIZE = 2000; // size of the read buffer |
159 |
char buffer[BUFFERSIZE]; |
160 |
|
161 |
sprintf(buffer,"\t%lf\t%lf;", chi, integralOfChidt); |
162 |
parameters += buffer; |
163 |
|
164 |
sprintf(buffer,"\t%lf\t0\t0;", eta); |
165 |
parameters += buffer; |
166 |
|
167 |
sprintf(buffer,"\t0\t%lf\t0;", eta); |
168 |
parameters += buffer; |
169 |
|
170 |
sprintf(buffer,"\t0\t0\t%lf;", eta); |
171 |
parameters += buffer; |
172 |
|
173 |
return parameters; |
174 |
|
175 |
} |