1 |
< |
#include <math.h> |
2 |
< |
#include "math/MatVec3.h" |
3 |
< |
#include "primitives/Atom.hpp" |
4 |
< |
#include "primitives/SRI.hpp" |
5 |
< |
#include "primitives/AbstractClasses.hpp" |
6 |
< |
#include "brains/SimInfo.hpp" |
7 |
< |
#include "UseTheForce/ForceFields.hpp" |
8 |
< |
#include "brains/Thermo.hpp" |
9 |
< |
#include "io/ReadWrite.hpp" |
10 |
< |
#include "integrators/Integrator.hpp" |
11 |
< |
#include "utils/simError.h" |
1 |
> |
#include "integrators/NPTxyz.hpp" |
2 |
|
|
13 |
– |
#ifdef IS_MPI |
14 |
– |
#include "brains/mpiSimulation.hpp" |
15 |
– |
#endif |
16 |
– |
|
3 |
|
// Basic non-isotropic thermostating and barostating via the Melchionna |
4 |
|
// modification of the Hoover algorithm: |
5 |
|
// |
10 |
|
// |
11 |
|
// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. |
12 |
|
|
13 |
< |
template<typename T> NPTxyz<T>::NPTxyz ( SimInfo *theInfo, ForceFields* the_ff): |
14 |
< |
T( theInfo, the_ff ) |
15 |
< |
{ |
13 |
> |
namespace oopse { |
14 |
> |
/* |
15 |
> |
NPTxyz::NPTxyz (SimInfo* info): NPT(info) { |
16 |
|
GenericData* data; |
17 |
|
DoubleVectorGenericData * etaValue; |
18 |
|
int i,j; |
20 |
|
for(i = 0; i < 3; i++){ |
21 |
|
for (j = 0; j < 3; j++){ |
22 |
|
|
23 |
< |
eta[i][j] = 0.0; |
24 |
< |
oldEta[i][j] = 0.0; |
23 |
> |
eta(i, j) = 0.0; |
24 |
> |
oldEta(i, j) = 0.0; |
25 |
|
} |
26 |
|
} |
27 |
|
|
37 |
|
|
38 |
|
for(i = 0; i < 3; i++){ |
39 |
|
for (j = 0; j < 3; j++){ |
40 |
< |
eta[i][j] = (*etaValue)[3*i+j]; |
41 |
< |
oldEta[i][j] = eta[i][j]; |
40 |
> |
eta(i, j) = (*etaValue)[3*i+j]; |
41 |
> |
oldEta(i, j) = eta(i, j); |
42 |
|
} |
43 |
|
} |
44 |
|
} |
46 |
|
} |
47 |
|
} |
48 |
|
|
63 |
– |
template<typename T> NPTxyz<T>::~NPTxyz() { |
49 |
|
|
65 |
– |
// empty for now |
66 |
– |
} |
50 |
|
|
51 |
< |
template<typename T> void NPTxyz<T>::resetIntegrator() { |
51 |
> |
void NPTxyz::evolveEtaA() { |
52 |
|
|
53 |
|
int i, j; |
54 |
|
|
55 |
< |
for(i = 0; i < 3; i++) |
56 |
< |
for (j = 0; j < 3; j++) |
57 |
< |
eta[i][j] = 0.0; |
58 |
< |
|
59 |
< |
T::resetIntegrator(); |
60 |
< |
} |
61 |
< |
|
62 |
< |
template<typename T> void NPTxyz<T>::evolveEtaA() { |
80 |
< |
|
81 |
< |
int i, j; |
82 |
< |
|
83 |
< |
for(i = 0; i < 3; i ++){ |
84 |
< |
for(j = 0; j < 3; j++){ |
85 |
< |
if( i == j) |
86 |
< |
eta[i][j] += dt2 * instaVol * |
87 |
< |
(press[i][j] - targetPressure/p_convert) / (NkBT*tb2); |
88 |
< |
else |
89 |
< |
eta[i][j] = 0.0; |
55 |
> |
for(i = 0; i < 3; i ++){ |
56 |
> |
for(j = 0; j < 3; j++){ |
57 |
> |
if( i == j) { |
58 |
> |
eta(i, j) += dt2 * instaVol *(press(i, j) - targetPressure/p_convert) / (NkBT*tb2); |
59 |
> |
} else { |
60 |
> |
eta(i, j) = 0.0; |
61 |
> |
} |
62 |
> |
} |
63 |
|
} |
91 |
– |
} |
64 |
|
|
65 |
< |
for(i = 0; i < 3; i++) |
66 |
< |
for (j = 0; j < 3; j++) |
67 |
< |
oldEta[i][j] = eta[i][j]; |
65 |
> |
for(i = 0; i < 3; i++) { |
66 |
> |
for (j = 0; j < 3; j++) { |
67 |
> |
oldEta(i, j) = eta(i, j); |
68 |
> |
} |
69 |
> |
} |
70 |
> |
|
71 |
|
} |
72 |
|
|
73 |
< |
template<typename T> void NPTxyz<T>::evolveEtaB() { |
73 |
> |
void NPTxyz::evolveEtaB() { |
74 |
|
|
75 |
|
int i,j; |
76 |
|
|
77 |
|
for(i = 0; i < 3; i++) |
78 |
|
for (j = 0; j < 3; j++) |
79 |
< |
prevEta[i][j] = eta[i][j]; |
79 |
> |
prevEta(i, j) = eta(i, j); |
80 |
|
|
81 |
|
for(i = 0; i < 3; i ++){ |
82 |
|
for(j = 0; j < 3; j++){ |
83 |
|
if( i == j) { |
84 |
< |
eta[i][j] = oldEta[i][j] + dt2 * instaVol * |
85 |
< |
(press[i][j] - targetPressure/p_convert) / (NkBT*tb2); |
84 |
> |
eta(i, j) = oldEta(i, j) + dt2 * instaVol * |
85 |
> |
(press(i, j) - targetPressure/p_convert) / (NkBT*tb2); |
86 |
|
} else { |
87 |
< |
eta[i][j] = 0.0; |
87 |
> |
eta(i, j) = 0.0; |
88 |
|
} |
89 |
|
} |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
< |
template<typename T> void NPTxyz<T>::calcVelScale(void) { |
93 |
> |
void NPTxyz::calcVelScale(void) { |
94 |
|
int i,j; |
95 |
|
|
96 |
|
for (i = 0; i < 3; i++ ) { |
97 |
|
for (j = 0; j < 3; j++ ) { |
98 |
< |
vScale[i][j] = eta[i][j]; |
98 |
> |
vScale(i, j) = eta(i, j); |
99 |
|
|
100 |
|
if (i == j) { |
101 |
< |
vScale[i][j] += chi; |
101 |
> |
vScale(i, j) += chi; |
102 |
|
} |
103 |
|
} |
104 |
|
} |
105 |
|
} |
106 |
|
|
132 |
– |
template<typename T> void NPTxyz<T>::getVelScaleA(double sc[3], double vel[3]) { |
133 |
– |
matVecMul3( vScale, vel, sc ); |
134 |
– |
} |
107 |
|
|
108 |
< |
template<typename T> void NPTxyz<T>::getVelScaleB(double sc[3], int index ){ |
109 |
< |
int j; |
138 |
< |
double myVel[3]; |
139 |
< |
|
140 |
< |
for (j = 0; j < 3; j++) |
141 |
< |
myVel[j] = oldVel[3*index + j]; |
142 |
< |
|
143 |
< |
matVecMul3( vScale, myVel, sc ); |
108 |
> |
void NPTxyz::getVelScaleA(Vector3d& sc, const Vector3d& vel) { |
109 |
> |
sc = vScale * vel; |
110 |
|
} |
111 |
|
|
112 |
< |
template<typename T> void NPTxyz<T>::getPosScale(double pos[3], double COM[3], |
113 |
< |
int index, double sc[3]){ |
148 |
< |
int j; |
149 |
< |
double rj[3]; |
150 |
< |
|
151 |
< |
for(j=0; j<3; j++) |
152 |
< |
rj[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j]; |
153 |
< |
|
154 |
< |
matVecMul3( eta, rj, sc ); |
112 |
> |
void NPTxyz::getVelScaleB(Vector3d& sc, int index ) { |
113 |
> |
sc = vScale * oldVel[index]; |
114 |
|
} |
156 |
– |
|
157 |
– |
template<typename T> void NPTxyz<T>::scaleSimBox( void ){ |
158 |
– |
|
159 |
– |
int i,j,k; |
160 |
– |
double scaleMat[3][3]; |
161 |
– |
double eta2ij, scaleFactor; |
162 |
– |
double bigScale, smallScale, offDiagMax; |
163 |
– |
double hm[3][3], hmnew[3][3]; |
164 |
– |
|
165 |
– |
|
166 |
– |
|
167 |
– |
// Scale the box after all the positions have been moved: |
168 |
– |
|
169 |
– |
// Use a taylor expansion for eta products: Hmat = Hmat . exp(dt * etaMat) |
170 |
– |
// Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2) |
171 |
– |
|
172 |
– |
bigScale = 1.0; |
173 |
– |
smallScale = 1.0; |
174 |
– |
offDiagMax = 0.0; |
175 |
– |
|
176 |
– |
for(i=0; i<3; i++){ |
177 |
– |
for(j=0; j<3; j++){ |
178 |
– |
scaleMat[i][j] = 0.0; |
179 |
– |
if(i==j) scaleMat[i][j] = 1.0; |
180 |
– |
} |
181 |
– |
} |
182 |
– |
|
183 |
– |
for(i=0;i<3;i++){ |
184 |
– |
|
185 |
– |
// calculate the scaleFactors |
186 |
– |
|
187 |
– |
scaleFactor = exp(dt*eta[i][i]); |
115 |
|
|
116 |
< |
scaleMat[i][i] = scaleFactor; |
117 |
< |
|
118 |
< |
if (scaleMat[i][i] > bigScale) bigScale = scaleMat[i][i]; |
119 |
< |
if (scaleMat[i][i] < smallScale) smallScale = scaleMat[i][i]; |
120 |
< |
} |
194 |
< |
|
195 |
< |
// for(i=0; i<3; i++){ |
196 |
< |
// for(j=0; j<3; j++){ |
197 |
< |
|
198 |
< |
// // Calculate the matrix Product of the eta array (we only need |
199 |
< |
// // the ij element right now): |
200 |
< |
|
201 |
< |
// eta2ij = 0.0; |
202 |
< |
// for(k=0; k<3; k++){ |
203 |
< |
// eta2ij += eta[i][k] * eta[k][j]; |
204 |
< |
// } |
205 |
< |
|
206 |
< |
// scaleMat[i][j] = 0.0; |
207 |
< |
// // identity matrix (see above): |
208 |
< |
// if (i == j) scaleMat[i][j] = 1.0; |
209 |
< |
// // Taylor expansion for the exponential truncated at second order: |
210 |
< |
// scaleMat[i][j] += dt*eta[i][j] + 0.5*dt*dt*eta2ij; |
211 |
< |
|
212 |
< |
// if (i != j) |
213 |
< |
// if (fabs(scaleMat[i][j]) > offDiagMax) |
214 |
< |
// offDiagMax = fabs(scaleMat[i][j]); |
215 |
< |
// } |
216 |
< |
|
217 |
< |
// if (scaleMat[i][i] > bigScale) bigScale = scaleMat[i][i]; |
218 |
< |
// if (scaleMat[i][i] < smallScale) smallScale = scaleMat[i][i]; |
219 |
< |
// } |
220 |
< |
|
221 |
< |
if ((bigScale > 1.1) || (smallScale < 0.9)) { |
222 |
< |
sprintf( painCave.errMsg, |
223 |
< |
"NPTxyz error: Attempting a Box scaling of more than 10 percent.\n" |
224 |
< |
" Check your tauBarostat, as it is probably too small!\n\n" |
225 |
< |
" scaleMat = [%lf\t%lf\t%lf]\n" |
226 |
< |
" [%lf\t%lf\t%lf]\n" |
227 |
< |
" [%lf\t%lf\t%lf]\n", |
228 |
< |
scaleMat[0][0],scaleMat[0][1],scaleMat[0][2], |
229 |
< |
scaleMat[1][0],scaleMat[1][1],scaleMat[1][2], |
230 |
< |
scaleMat[2][0],scaleMat[2][1],scaleMat[2][2]); |
231 |
< |
painCave.isFatal = 1; |
232 |
< |
simError(); |
233 |
< |
} else { |
234 |
< |
info->getBoxM(hm); |
235 |
< |
matMul3(hm, scaleMat, hmnew); |
236 |
< |
info->setBoxM(hmnew); |
237 |
< |
} |
116 |
> |
void NPTxyz::getPosScale(const Vector3d& pos, const Vector3d& COM, |
117 |
> |
int index, Vector3d& sc) { |
118 |
> |
|
119 |
> |
Vector3d rj = (oldPos[index] + pos[j])/2.0 -COM; |
120 |
> |
sc = eta * rj; |
121 |
|
} |
122 |
|
|
123 |
< |
template<typename T> bool NPTxyz<T>::etaConverged() { |
123 |
> |
bool NPTxyz::etaConverged() { |
124 |
|
int i; |
125 |
|
double diffEta, sumEta; |
126 |
|
|
127 |
|
sumEta = 0; |
128 |
|
for(i = 0; i < 3; i++) |
129 |
< |
sumEta += pow(prevEta[i][i] - eta[i][i], 2); |
129 |
> |
sumEta += pow(prevEta(i, i) - eta(i, i), 2); |
130 |
|
|
131 |
|
diffEta = sqrt( sumEta / 3.0 ); |
132 |
|
|
133 |
|
return ( diffEta <= etaTolerance ); |
134 |
|
} |
135 |
|
|
136 |
< |
template<typename T> double NPTxyz<T>::getConservedQuantity(void){ |
136 |
> |
*/ |
137 |
> |
|
138 |
> |
double NPTxyz::calcConservedQuantity(){ |
139 |
|
|
140 |
|
double conservedQuantity; |
141 |
|
double totalEnergy; |
144 |
|
double barostat_kinetic; |
145 |
|
double barostat_potential; |
146 |
|
double trEta; |
147 |
< |
double a[3][3], b[3][3]; |
147 |
> |
Mat3x3d a; |
148 |
> |
Mat3x3d b; |
149 |
|
|
150 |
|
totalEnergy = tStats->getTotalE(); |
151 |
|
|
167 |
|
conservedQuantity = totalEnergy + thermostat_kinetic + thermostat_potential + |
168 |
|
barostat_kinetic + barostat_potential; |
169 |
|
|
284 |
– |
// cout.width(8); |
285 |
– |
// cout.precision(8); |
170 |
|
|
287 |
– |
// cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
288 |
– |
// "\t" << thermostat_potential << "\t" << barostat_kinetic << |
289 |
– |
// "\t" << barostat_potential << "\t" << conservedQuantity << endl; |
290 |
– |
|
171 |
|
return conservedQuantity; |
172 |
|
|
173 |
|
} |
174 |
|
|
175 |
< |
template<typename T> string NPTxyz<T>::getAdditionalParameters(void){ |
176 |
< |
string parameters; |
297 |
< |
const int BUFFERSIZE = 2000; // size of the read buffer |
298 |
< |
char buffer[BUFFERSIZE]; |
175 |
> |
|
176 |
> |
void NPTxyz::scaleSimBox(){ |
177 |
|
|
178 |
< |
sprintf(buffer,"\t%G\t%G;", chi, integralOfChidt); |
179 |
< |
parameters += buffer; |
178 |
> |
int i,j,k; |
179 |
> |
Mat3x3d scaleMat; |
180 |
> |
double eta2ij, scaleFactor; |
181 |
> |
double bigScale, smallScale, offDiagMax; |
182 |
> |
Mat3x3d hm; |
183 |
> |
Mat3x3d hmnew; |
184 |
|
|
185 |
< |
for(int i = 0; i < 3; i++){ |
186 |
< |
sprintf(buffer,"\t%G\t%G\t%G;", eta[i][0], eta[i][1], eta[i][2]); |
187 |
< |
parameters += buffer; |
185 |
> |
|
186 |
> |
|
187 |
> |
// Scale the box after all the positions have been moved: |
188 |
> |
|
189 |
> |
// Use a taylor expansion for eta products: Hmat = Hmat . exp(dt * etaMat) |
190 |
> |
// Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2) |
191 |
> |
|
192 |
> |
bigScale = 1.0; |
193 |
> |
smallScale = 1.0; |
194 |
> |
offDiagMax = 0.0; |
195 |
> |
|
196 |
> |
for(i=0; i<3; i++){ |
197 |
> |
for(j=0; j<3; j++){ |
198 |
> |
scaleMat(i, j) = 0.0; |
199 |
> |
if(i==j) scaleMat(i, j) = 1.0; |
200 |
> |
} |
201 |
|
} |
202 |
|
|
203 |
< |
return parameters; |
203 |
> |
for(i=0;i<3;i++){ |
204 |
|
|
205 |
+ |
// calculate the scaleFactors |
206 |
+ |
|
207 |
+ |
scaleFactor = exp(dt*eta(i, i)); |
208 |
+ |
|
209 |
+ |
scaleMat(i, i) = scaleFactor; |
210 |
+ |
|
211 |
+ |
if (scaleMat(i, i) > bigScale) bigScale = scaleMat(i, i); |
212 |
+ |
if (scaleMat(i, i) < smallScale) smallScale = scaleMat(i, i); |
213 |
+ |
} |
214 |
+ |
|
215 |
+ |
if ((bigScale > 1.1) || (smallScale < 0.9)) { |
216 |
+ |
sprintf( painCave.errMsg, |
217 |
+ |
"NPTxyz error: Attempting a Box scaling of more than 10 percent.\n" |
218 |
+ |
" Check your tauBarostat, as it is probably too small!\n\n" |
219 |
+ |
" scaleMat = [%lf\t%lf\t%lf]\n" |
220 |
+ |
" [%lf\t%lf\t%lf]\n" |
221 |
+ |
" [%lf\t%lf\t%lf]\n", |
222 |
+ |
scaleMat(0, 0),scaleMat(0, 1),scaleMat(0, 2), |
223 |
+ |
scaleMat(1, 0),scaleMat(1, 1),scaleMat(1, 2), |
224 |
+ |
scaleMat(2, 0),scaleMat(2, 1),scaleMat(2, 2)); |
225 |
+ |
painCave.isFatal = 1; |
226 |
+ |
simError(); |
227 |
+ |
} else { |
228 |
+ |
info->getBoxM(hm); |
229 |
+ |
matMul3(hm, scaleMat, hmnew); |
230 |
+ |
info->setBoxM(hmnew); |
231 |
+ |
} |
232 |
|
} |
233 |
+ |
|
234 |
+ |
} |