1 |
+ |
#include <cmath> |
2 |
|
#include "Atom.hpp" |
3 |
|
#include "Molecule.hpp" |
4 |
|
#include "SRI.hpp" |
10 |
|
#include "Integrator.hpp" |
11 |
|
#include "simError.h" |
12 |
|
|
13 |
+ |
|
14 |
|
// Basic non-isotropic thermostating and barostating via the Melchionna |
15 |
|
// modification of the Hoover algorithm: |
16 |
|
// |
24 |
|
// The NPTfm variant scales the molecular center-of-mass coordinates |
25 |
|
// instead of the atomic coordinates |
26 |
|
|
27 |
< |
NPTfm::NPTfm ( SimInfo *theInfo, ForceFields* the_ff): |
28 |
< |
Integrator( theInfo, the_ff ) |
27 |
> |
template<typename T> NPTfm<T>::NPTfm ( SimInfo *theInfo, ForceFields* the_ff): |
28 |
> |
T( theInfo, the_ff ) |
29 |
|
{ |
30 |
|
int i, j; |
31 |
|
chi = 0.0; |
40 |
|
have_target_pressure = 0; |
41 |
|
} |
42 |
|
|
43 |
< |
void NPTfm::moveA() { |
43 |
> |
template<typename T> void NPTfm<T>::moveA() { |
44 |
|
|
45 |
|
int i, j, k; |
46 |
|
DirectionalAtom* dAtom; |
53 |
|
double instaTemp, instaPress, instaVol; |
54 |
|
double tt2, tb2; |
55 |
|
double sc[3]; |
56 |
< |
double eta2ij; |
56 |
> |
double eta2ij, smallScale, bigScale, offDiagMax; |
57 |
|
double press[3][3], vScale[3][3], hm[3][3], hmnew[3][3], scaleMat[3][3]; |
58 |
|
|
59 |
|
int nInMol; |
129 |
|
|
130 |
|
for (k = 0; k < 3; k++ ) |
131 |
|
pos[k] += dt * (vel[k] + sc[k]); |
132 |
+ |
|
133 |
+ |
myAtoms[j]->setPos( pos ); |
134 |
|
|
135 |
|
if( myAtoms[j]->isDirectional() ){ |
136 |
|
|
187 |
|
// Hmat = Hmat . ( Ident + dt * etaMat + dt^2 * etaMat*etaMat / 2) |
188 |
|
|
189 |
|
|
190 |
+ |
bigScale = 1.0; |
191 |
+ |
smallScale = 1.0; |
192 |
+ |
offDiagMax = 0.0; |
193 |
+ |
|
194 |
|
for(i=0; i<3; i++){ |
195 |
|
for(j=0; j<3; j++){ |
196 |
|
|
207 |
|
if (i == j) scaleMat[i][j] = 1.0; |
208 |
|
// Taylor expansion for the exponential truncated at second order: |
209 |
|
scaleMat[i][j] += dt*eta[i][j] + 0.5*dt*dt*eta2ij; |
210 |
< |
|
210 |
> |
|
211 |
> |
if (i != j) |
212 |
> |
if (fabs(scaleMat[i][j]) > offDiagMax) |
213 |
> |
offDiagMax = fabs(scaleMat[i][j]); |
214 |
|
} |
215 |
+ |
if (scaleMat[i][i] > bigScale) bigScale = scaleMat[i][i]; |
216 |
+ |
if (scaleMat[i][i] < smallScale) smallScale = scaleMat[i][i]; |
217 |
|
} |
218 |
|
|
219 |
< |
info->getBoxM(hm); |
220 |
< |
info->matMul3(hm, scaleMat, hmnew); |
221 |
< |
info->setBoxM(hmnew); |
222 |
< |
|
219 |
> |
if ((bigScale > 1.1) || (smallScale < 0.9)) { |
220 |
> |
sprintf( painCave.errMsg, |
221 |
> |
"NPTf error: Attempting a Box scaling of more than 10 percent.\n" |
222 |
> |
" Check your tauBarostat, as it is probably too small!\n\n" |
223 |
> |
" scaleMat = [%lf\t%lf\t%lf]\n" |
224 |
> |
" [%lf\t%lf\t%lf]\n" |
225 |
> |
" [%lf\t%lf\t%lf]\n", |
226 |
> |
scaleMat[0][0],scaleMat[0][1],scaleMat[0][2], |
227 |
> |
scaleMat[1][0],scaleMat[1][1],scaleMat[1][2], |
228 |
> |
scaleMat[2][0],scaleMat[2][1],scaleMat[2][2]); |
229 |
> |
painCave.isFatal = 1; |
230 |
> |
simError(); |
231 |
> |
} else if (offDiagMax > 0.1) { |
232 |
> |
sprintf( painCave.errMsg, |
233 |
> |
"NPTf error: Attempting an off-diagonal Box scaling of more than 10 percent.\n" |
234 |
> |
" Check your tauBarostat, as it is probably too small!\n\n" |
235 |
> |
" scaleMat = [%lf\t%lf\t%lf]\n" |
236 |
> |
" [%lf\t%lf\t%lf]\n" |
237 |
> |
" [%lf\t%lf\t%lf]\n", |
238 |
> |
scaleMat[0][0],scaleMat[0][1],scaleMat[0][2], |
239 |
> |
scaleMat[1][0],scaleMat[1][1],scaleMat[1][2], |
240 |
> |
scaleMat[2][0],scaleMat[2][1],scaleMat[2][2]); |
241 |
> |
painCave.isFatal = 1; |
242 |
> |
simError(); |
243 |
> |
} else { |
244 |
> |
info->getBoxM(hm); |
245 |
> |
info->matMul3(hm, scaleMat, hmnew); |
246 |
> |
info->setBoxM(hmnew); |
247 |
> |
} |
248 |
|
} |
249 |
|
|
250 |
< |
void NPTfm::moveB( void ){ |
250 |
> |
template<typename T> void NPTfm<T>::moveB( void ){ |
251 |
|
|
252 |
|
int i, j; |
253 |
|
DirectionalAtom* dAtom; |
329 |
|
} |
330 |
|
} |
331 |
|
|
332 |
< |
int NPTfm::readyCheck() { |
333 |
< |
|
332 |
> |
template<typename T> void NPTfm<T>::resetIntegrator() { |
333 |
> |
int i,j; |
334 |
> |
|
335 |
> |
chi = 0.0; |
336 |
> |
|
337 |
> |
for(i = 0; i < 3; i++) |
338 |
> |
for (j = 0; j < 3; j++) |
339 |
> |
eta[i][j] = 0.0; |
340 |
> |
} |
341 |
> |
|
342 |
> |
template<typename T> int NPTfm<T>::readyCheck() { |
343 |
> |
|
344 |
> |
//check parent's readyCheck() first |
345 |
> |
if (T::readyCheck() == -1) |
346 |
> |
return -1; |
347 |
> |
|
348 |
|
// First check to see if we have a target temperature. |
349 |
|
// Not having one is fatal. |
350 |
|
|