1 |
#include <cmath> |
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 |
template<typename T> NPTi<T>::NPTi ( SimInfo *theInfo, ForceFields* the_ff): |
27 |
T( theInfo, the_ff ) |
28 |
{ |
29 |
eta = 0.0; |
30 |
oldEta = 0.0; |
31 |
} |
32 |
|
33 |
template<typename T> NPTi<T>::~NPTi() { |
34 |
//nothing for now |
35 |
} |
36 |
|
37 |
template<typename T> void NPTi<T>::resetIntegrator() { |
38 |
eta = 0.0; |
39 |
T::resetIntegrator(); |
40 |
} |
41 |
|
42 |
template<typename T> void NPTi<T>::evolveEtaA() { |
43 |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
44 |
(p_convert*NkBT*tb2)); |
45 |
oldEta = eta; |
46 |
} |
47 |
|
48 |
template<typename T> void NPTi<T>::evolveEtaB() { |
49 |
|
50 |
prevEta = eta; |
51 |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
52 |
(p_convert*NkBT*tb2)); |
53 |
} |
54 |
|
55 |
template<typename T> void NPTi<T>::getVelScaleA(double sc[3], double vel[3]) { |
56 |
int i; |
57 |
|
58 |
for(i=0; i<3; i++) sc[i] = vel[i] * ( chi + eta ); |
59 |
} |
60 |
|
61 |
template<typename T> void NPTi<T>::getVelScaleB(double sc[3], int index ){ |
62 |
int i; |
63 |
|
64 |
for(i=0; i<3; i++) sc[i] = oldVel[index*3 + i] * ( chi + eta ); |
65 |
} |
66 |
|
67 |
|
68 |
template<typename T> void NPTi<T>::getPosScale(double pos[3], double COM[3], |
69 |
int index, double sc[3]){ |
70 |
int j; |
71 |
|
72 |
for(j=0; j<3; j++) |
73 |
sc[j] = ( oldPos[index*3+j] + pos[j]) / 2.0 - COM[j]; |
74 |
|
75 |
for(j=0; j<3; j++) |
76 |
sc[j] *= eta; |
77 |
} |
78 |
|
79 |
template<typename T> void NPTi<T>::scaleSimBox( void ){ |
80 |
|
81 |
double scaleFactor; |
82 |
|
83 |
scaleFactor = exp(dt*eta); |
84 |
|
85 |
if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
86 |
sprintf( painCave.errMsg, |
87 |
"NPTi error: Attempting a Box scaling of more than 10 percent" |
88 |
" check your tauBarostat, as it is probably too small!\n" |
89 |
" eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
90 |
); |
91 |
painCave.isFatal = 1; |
92 |
simError(); |
93 |
} else { |
94 |
info->scaleBox(scaleFactor); |
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
template<typename T> bool NPTi<T>::etaConverged() { |
100 |
|
101 |
return ( fabs(prevEta - eta) <= etaTolerance ); |
102 |
} |
103 |
|
104 |
template<typename T> double NPTi<T>::getConservedQuantity(void){ |
105 |
|
106 |
double conservedQuantity; |
107 |
double Three_NkBT; |
108 |
double Energy; |
109 |
double thermostat_kinetic; |
110 |
double thermostat_potential; |
111 |
double barostat_kinetic; |
112 |
double barostat_potential; |
113 |
double tb2; |
114 |
double eta2; |
115 |
|
116 |
Energy = tStats->getTotalE(); |
117 |
|
118 |
thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi / |
119 |
(2.0 * eConvert); |
120 |
|
121 |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
122 |
|
123 |
|
124 |
barostat_kinetic = 3.0 * NkBT * tauBarostat * tauBarostat * eta * eta / |
125 |
(2.0 * eConvert); |
126 |
|
127 |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
128 |
eConvert; |
129 |
|
130 |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
131 |
barostat_kinetic + barostat_potential; |
132 |
|
133 |
// cout.width(8); |
134 |
// cout.precision(8); |
135 |
|
136 |
// cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
137 |
// "\t" << thermostat_potential << "\t" << barostat_kinetic << |
138 |
// "\t" << barostat_potential << "\t" << conservedQuantity << endl; |
139 |
return conservedQuantity; |
140 |
} |