1 |
+ |
/* |
2 |
+ |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
+ |
* |
4 |
+ |
* The University of Notre Dame grants you ("Licensee") a |
5 |
+ |
* non-exclusive, royalty free, license to use, modify and |
6 |
+ |
* redistribute this software in source and binary code form, provided |
7 |
+ |
* that the following conditions are met: |
8 |
+ |
* |
9 |
+ |
* 1. Redistributions of source code must retain the above copyright |
10 |
+ |
* notice, this list of conditions and the following disclaimer. |
11 |
+ |
* |
12 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
+ |
* notice, this list of conditions and the following disclaimer in the |
14 |
+ |
* documentation and/or other materials provided with the |
15 |
+ |
* distribution. |
16 |
+ |
* |
17 |
+ |
* This software is provided "AS IS," without a warranty of any |
18 |
+ |
* kind. All express or implied conditions, representations and |
19 |
+ |
* warranties, including any implied warranty of merchantability, |
20 |
+ |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
+ |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
+ |
* be liable for any damages suffered by licensee as a result of |
23 |
+ |
* using, modifying or distributing the software or its |
24 |
+ |
* derivatives. In no event will the University of Notre Dame or its |
25 |
+ |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
+ |
* direct, indirect, special, consequential, incidental or punitive |
27 |
+ |
* damages, however caused and regardless of the theory of liability, |
28 |
+ |
* arising out of the use of or inability to use software, even if the |
29 |
+ |
* University of Notre Dame has been advised of the possibility of |
30 |
+ |
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
+ |
*/ |
42 |
+ |
|
43 |
|
#include <math.h> |
44 |
|
|
3 |
– |
#include "primitives/Atom.hpp" |
4 |
– |
#include "primitives/SRI.hpp" |
5 |
– |
#include "primitives/AbstractClasses.hpp" |
45 |
|
#include "brains/SimInfo.hpp" |
7 |
– |
#include "UseTheForce/ForceFields.hpp" |
46 |
|
#include "brains/Thermo.hpp" |
47 |
< |
#include "io/ReadWrite.hpp" |
48 |
< |
#include "integrators/Integrator.hpp" |
47 |
> |
#include "integrators/NPT.hpp" |
48 |
> |
#include "math/SquareMatrix3.hpp" |
49 |
> |
#include "primitives/Molecule.hpp" |
50 |
> |
#include "utils/PhysicalConstants.hpp" |
51 |
|
#include "utils/simError.h" |
52 |
|
|
13 |
– |
#ifdef IS_MPI |
14 |
– |
#include "brains/mpiSimulation.hpp" |
15 |
– |
#endif |
16 |
– |
|
17 |
– |
|
53 |
|
// Basic isotropic thermostating and barostating via the Melchionna |
54 |
|
// modification of the Hoover algorithm: |
55 |
|
// |
60 |
|
// |
61 |
|
// Hoover, W. G., 1986, Phys. Rev. A, 34, 2499. |
62 |
|
|
63 |
< |
template<typename T> NPT<T>::NPT ( SimInfo *theInfo, ForceFields* the_ff): |
29 |
< |
T( theInfo, the_ff ) |
30 |
< |
{ |
31 |
< |
GenericData* data; |
32 |
< |
DoubleData * chiValue; |
33 |
< |
DoubleData * integralOfChidtValue; |
63 |
> |
namespace OpenMD { |
64 |
|
|
65 |
< |
chiValue = NULL; |
66 |
< |
integralOfChidtValue = NULL; |
65 |
> |
NPT::NPT(SimInfo* info) : |
66 |
> |
VelocityVerletIntegrator(info), etaTolerance(1e-6), chiTolerance(1e-6), |
67 |
> |
maxIterNum_(4) { |
68 |
|
|
69 |
< |
chi = 0.0; |
70 |
< |
integralOfChidt = 0.0; |
71 |
< |
have_tau_thermostat = 0; |
72 |
< |
have_tau_barostat = 0; |
73 |
< |
have_target_temp = 0; |
74 |
< |
have_target_pressure = 0; |
75 |
< |
have_chi_tolerance = 0; |
76 |
< |
have_eta_tolerance = 0; |
77 |
< |
have_pos_iter_tolerance = 0; |
69 |
> |
Globals* simParams = info_->getSimParams(); |
70 |
> |
|
71 |
> |
if (!simParams->getUseIntialExtendedSystemState()) { |
72 |
> |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
73 |
> |
currSnapshot->setThermostat(make_pair(0.0, 0.0)); |
74 |
> |
currSnapshot->setBarostat(Mat3x3d(0.0)); |
75 |
> |
} |
76 |
> |
|
77 |
> |
if (!simParams->haveTargetTemp()) { |
78 |
> |
sprintf(painCave.errMsg, "You can't use the NVT integrator without a targetTemp!\n"); |
79 |
> |
painCave.isFatal = 1; |
80 |
> |
painCave.severity = OPENMD_ERROR; |
81 |
> |
simError(); |
82 |
> |
} else { |
83 |
> |
targetTemp = simParams->getTargetTemp(); |
84 |
> |
} |
85 |
|
|
86 |
< |
// retrieve chi and integralOfChidt from simInfo |
87 |
< |
data = info->getProperty(CHIVALUE_ID); |
88 |
< |
if(data){ |
89 |
< |
chiValue = dynamic_cast<DoubleData*>(data); |
52 |
< |
} |
86 |
> |
// We must set tauThermostat |
87 |
> |
if (!simParams->haveTauThermostat()) { |
88 |
> |
sprintf(painCave.errMsg, "If you use the constant temperature\n" |
89 |
> |
"\tintegrator, you must set tauThermostat.\n"); |
90 |
|
|
91 |
< |
data = info->getProperty(INTEGRALOFCHIDT_ID); |
92 |
< |
if(data){ |
93 |
< |
integralOfChidtValue = dynamic_cast<DoubleData*>(data); |
91 |
> |
painCave.severity = OPENMD_ERROR; |
92 |
> |
painCave.isFatal = 1; |
93 |
> |
simError(); |
94 |
> |
} else { |
95 |
> |
tauThermostat = simParams->getTauThermostat(); |
96 |
> |
} |
97 |
> |
|
98 |
> |
if (!simParams->haveTargetPressure()) { |
99 |
> |
sprintf(painCave.errMsg, "NPT error: You can't use the NPT integrator\n" |
100 |
> |
" without a targetPressure!\n"); |
101 |
> |
|
102 |
> |
painCave.isFatal = 1; |
103 |
> |
simError(); |
104 |
> |
} else { |
105 |
> |
targetPressure = simParams->getTargetPressure(); |
106 |
> |
} |
107 |
> |
|
108 |
> |
if (!simParams->haveTauBarostat()) { |
109 |
> |
sprintf(painCave.errMsg, |
110 |
> |
"If you use the NPT integrator, you must set tauBarostat.\n"); |
111 |
> |
painCave.severity = OPENMD_ERROR; |
112 |
> |
painCave.isFatal = 1; |
113 |
> |
simError(); |
114 |
> |
} else { |
115 |
> |
tauBarostat = simParams->getTauBarostat(); |
116 |
> |
} |
117 |
> |
|
118 |
> |
tt2 = tauThermostat * tauThermostat; |
119 |
> |
tb2 = tauBarostat * tauBarostat; |
120 |
> |
|
121 |
> |
updateSizes(); |
122 |
> |
} |
123 |
> |
|
124 |
> |
NPT::~NPT() { |
125 |
|
} |
126 |
|
|
127 |
< |
// chi and integralOfChidt should appear by pair |
128 |
< |
if(chiValue && integralOfChidtValue){ |
129 |
< |
chi = chiValue->getData(); |
130 |
< |
integralOfChidt = integralOfChidtValue->getData(); |
127 |
> |
void NPT::doUpdateSizes() { |
128 |
> |
|
129 |
> |
oldPos.resize(info_->getNIntegrableObjects()); |
130 |
> |
oldVel.resize(info_->getNIntegrableObjects()); |
131 |
> |
oldJi.resize(info_->getNIntegrableObjects()); |
132 |
> |
|
133 |
|
} |
134 |
|
|
135 |
< |
oldPos = new double[3*integrableObjects.size()]; |
136 |
< |
oldVel = new double[3*integrableObjects.size()]; |
137 |
< |
oldJi = new double[3*integrableObjects.size()]; |
135 |
> |
void NPT::moveA() { |
136 |
> |
SimInfo::MoleculeIterator i; |
137 |
> |
Molecule::IntegrableObjectIterator j; |
138 |
> |
Molecule* mol; |
139 |
> |
StuntDouble* sd; |
140 |
> |
Vector3d Tb, ji; |
141 |
> |
RealType mass; |
142 |
> |
Vector3d vel; |
143 |
> |
Vector3d pos; |
144 |
> |
Vector3d frc; |
145 |
> |
Vector3d sc; |
146 |
> |
int index; |
147 |
|
|
148 |
< |
} |
148 |
> |
thermostat = snap->getThermostat(); |
149 |
> |
loadEta(); |
150 |
> |
|
151 |
> |
instaTemp =thermo.getTemperature(); |
152 |
> |
press = thermo.getPressureTensor(); |
153 |
> |
instaPress = PhysicalConstants::pressureConvert* (press(0, 0) + press(1, 1) + press(2, 2)) / 3.0; |
154 |
> |
instaVol =thermo.getVolume(); |
155 |
|
|
156 |
< |
template<typename T> NPT<T>::~NPT() { |
72 |
< |
delete[] oldPos; |
73 |
< |
delete[] oldVel; |
74 |
< |
delete[] oldJi; |
75 |
< |
} |
156 |
> |
Vector3d COM = thermo.getCom(); |
157 |
|
|
158 |
< |
template<typename T> void NPT<T>::moveA() { |
158 |
> |
//evolve velocity half step |
159 |
|
|
160 |
< |
//new version of NPT |
80 |
< |
int i, j, k; |
81 |
< |
double Tb[3], ji[3]; |
82 |
< |
double mass; |
83 |
< |
double vel[3], pos[3], frc[3]; |
84 |
< |
double sc[3]; |
85 |
< |
double COM[3]; |
160 |
> |
calcVelScale(); |
161 |
|
|
162 |
< |
instaTemp = tStats->getTemperature(); |
163 |
< |
tStats->getPressureTensor( press ); |
89 |
< |
instaPress = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
90 |
< |
instaVol = tStats->getVolume(); |
162 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
163 |
> |
mol = info_->nextMolecule(i)) { |
164 |
|
|
165 |
< |
tStats->getCOM(COM); |
165 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
166 |
> |
sd = mol->nextIntegrableObject(j)) { |
167 |
> |
|
168 |
> |
vel = sd->getVel(); |
169 |
> |
frc = sd->getFrc(); |
170 |
|
|
171 |
< |
//evolve velocity half step |
171 |
> |
mass = sd->getMass(); |
172 |
|
|
173 |
< |
calcVelScale(); |
97 |
< |
|
98 |
< |
for( i=0; i<integrableObjects.size(); i++ ){ |
173 |
> |
getVelScaleA(sc, vel); |
174 |
|
|
175 |
< |
integrableObjects[i]->getVel( vel ); |
101 |
< |
integrableObjects[i]->getFrc( frc ); |
175 |
> |
// velocity half step (use chi from previous step here): |
176 |
|
|
177 |
< |
mass = integrableObjects[i]->getMass(); |
177 |
> |
vel += dt2*PhysicalConstants::energyConvert/mass* frc - dt2*sc; |
178 |
> |
sd->setVel(vel); |
179 |
|
|
180 |
< |
getVelScaleA( sc, vel ); |
180 |
> |
if (sd->isDirectional()) { |
181 |
|
|
182 |
< |
for (j=0; j < 3; j++) { |
182 |
> |
// get and convert the torque to body frame |
183 |
|
|
184 |
< |
// velocity half step (use chi from previous step here): |
110 |
< |
vel[j] += dt2 * ((frc[j] / mass ) * eConvert - sc[j]); |
184 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
185 |
|
|
186 |
< |
} |
186 |
> |
// get the angular momentum, and propagate a half step |
187 |
|
|
188 |
< |
integrableObjects[i]->setVel( vel ); |
188 |
> |
ji = sd->getJ(); |
189 |
|
|
190 |
< |
if( integrableObjects[i]->isDirectional() ){ |
190 |
> |
ji += dt2*PhysicalConstants::energyConvert * Tb |
191 |
> |
- dt2*thermostat.first* ji; |
192 |
> |
|
193 |
> |
rotAlgo_->rotate(sd, ji, dt); |
194 |
|
|
195 |
< |
// get and convert the torque to body frame |
195 |
> |
sd->setJ(ji); |
196 |
> |
} |
197 |
> |
|
198 |
> |
} |
199 |
> |
} |
200 |
> |
// evolve chi and eta half step |
201 |
|
|
202 |
< |
integrableObjects[i]->getTrq( Tb ); |
203 |
< |
integrableObjects[i]->lab2Body( Tb ); |
202 |
> |
thermostat.first += dt2 * (instaTemp / targetTemp - 1.0) / tt2; |
203 |
> |
|
204 |
> |
evolveEtaA(); |
205 |
|
|
206 |
< |
// get the angular momentum, and propagate a half step |
206 |
> |
//calculate the integral of chidt |
207 |
> |
thermostat.second += dt2 * thermostat.first; |
208 |
> |
|
209 |
> |
flucQ_->moveA(); |
210 |
|
|
125 |
– |
integrableObjects[i]->getJ( ji ); |
211 |
|
|
212 |
< |
for (j=0; j < 3; j++) |
213 |
< |
ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
212 |
> |
index = 0; |
213 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
214 |
> |
mol = info_->nextMolecule(i)) { |
215 |
|
|
216 |
< |
this->rotationPropagation( integrableObjects[i], ji ); |
216 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
217 |
> |
sd = mol->nextIntegrableObject(j)) { |
218 |
|
|
219 |
< |
integrableObjects[i]->setJ( ji ); |
219 |
> |
oldPos[index++] = sd->getPos(); |
220 |
> |
|
221 |
> |
} |
222 |
|
} |
223 |
< |
} |
223 |
> |
|
224 |
> |
//the first estimation of r(t+dt) is equal to r(t) |
225 |
|
|
226 |
< |
// evolve chi and eta half step |
226 |
> |
for(int k = 0; k < maxIterNum_; k++) { |
227 |
> |
index = 0; |
228 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
229 |
> |
mol = info_->nextMolecule(i)) { |
230 |
|
|
231 |
< |
evolveChiA(); |
232 |
< |
evolveEtaA(); |
231 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
232 |
> |
sd = mol->nextIntegrableObject(j)) { |
233 |
|
|
234 |
< |
//calculate the integral of chidt |
235 |
< |
integralOfChidt += dt2*chi; |
234 |
> |
vel = sd->getVel(); |
235 |
> |
pos = sd->getPos(); |
236 |
|
|
237 |
< |
//save the old positions |
145 |
< |
for(i = 0; i < integrableObjects.size(); i++){ |
146 |
< |
integrableObjects[i]->getPos(pos); |
147 |
< |
for(j = 0; j < 3; j++) |
148 |
< |
oldPos[i*3 + j] = pos[j]; |
149 |
< |
} |
237 |
> |
this->getPosScale(pos, COM, index, sc); |
238 |
|
|
239 |
< |
//the first estimation of r(t+dt) is equal to r(t) |
239 |
> |
pos = oldPos[index] + dt * (vel + sc); |
240 |
> |
sd->setPos(pos); |
241 |
|
|
242 |
< |
for(k = 0; k < 5; k ++){ |
242 |
> |
++index; |
243 |
> |
} |
244 |
> |
} |
245 |
|
|
246 |
< |
for(i =0 ; i < integrableObjects.size(); i++){ |
246 |
> |
rattle_->constraintA(); |
247 |
> |
} |
248 |
|
|
249 |
< |
integrableObjects[i]->getVel(vel); |
158 |
< |
integrableObjects[i]->getPos(pos); |
249 |
> |
// Scale the box after all the positions have been moved: |
250 |
|
|
251 |
< |
this->getPosScale( pos, COM, i, sc ); |
251 |
> |
this->scaleSimBox(); |
252 |
|
|
253 |
< |
for(j = 0; j < 3; j++) |
163 |
< |
pos[j] = oldPos[i*3 + j] + dt*(vel[j] + sc[j]); |
253 |
> |
snap->setThermostat(thermostat); |
254 |
|
|
255 |
< |
integrableObjects[i]->setPos( pos ); |
166 |
< |
} |
167 |
< |
|
168 |
< |
if(nConstrained) |
169 |
< |
constrainA(); |
255 |
> |
saveEta(); |
256 |
|
} |
257 |
|
|
258 |
+ |
void NPT::moveB(void) { |
259 |
+ |
SimInfo::MoleculeIterator i; |
260 |
+ |
Molecule::IntegrableObjectIterator j; |
261 |
+ |
Molecule* mol; |
262 |
+ |
StuntDouble* sd; |
263 |
+ |
int index; |
264 |
+ |
Vector3d Tb; |
265 |
+ |
Vector3d ji; |
266 |
+ |
Vector3d sc; |
267 |
+ |
Vector3d vel; |
268 |
+ |
Vector3d frc; |
269 |
+ |
RealType mass; |
270 |
|
|
271 |
< |
// Scale the box after all the positions have been moved: |
271 |
> |
thermostat = snap->getThermostat(); |
272 |
> |
RealType oldChi = thermostat.first; |
273 |
> |
RealType prevChi; |
274 |
|
|
275 |
< |
this->scaleSimBox(); |
276 |
< |
} |
275 |
> |
loadEta(); |
276 |
> |
|
277 |
> |
//save velocity and angular momentum |
278 |
> |
index = 0; |
279 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
280 |
> |
mol = info_->nextMolecule(i)) { |
281 |
|
|
282 |
< |
template<typename T> void NPT<T>::moveB( void ){ |
282 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
283 |
> |
sd = mol->nextIntegrableObject(j)) { |
284 |
> |
|
285 |
> |
oldVel[index] = sd->getVel(); |
286 |
|
|
287 |
< |
//new version of NPT |
288 |
< |
int i, j, k; |
182 |
< |
double Tb[3], ji[3], sc[3]; |
183 |
< |
double vel[3], frc[3]; |
184 |
< |
double mass; |
287 |
> |
if (sd->isDirectional()) |
288 |
> |
oldJi[index] = sd->getJ(); |
289 |
|
|
290 |
< |
// Set things up for the iteration: |
291 |
< |
|
188 |
< |
for( i=0; i<integrableObjects.size(); i++ ){ |
189 |
< |
|
190 |
< |
integrableObjects[i]->getVel( vel ); |
191 |
< |
|
192 |
< |
for (j=0; j < 3; j++) |
193 |
< |
oldVel[3*i + j] = vel[j]; |
194 |
< |
|
195 |
< |
if( integrableObjects[i]->isDirectional() ){ |
196 |
< |
|
197 |
< |
integrableObjects[i]->getJ( ji ); |
198 |
< |
|
199 |
< |
for (j=0; j < 3; j++) |
200 |
< |
oldJi[3*i + j] = ji[j]; |
201 |
< |
|
290 |
> |
++index; |
291 |
> |
} |
292 |
|
} |
203 |
– |
} |
293 |
|
|
294 |
< |
// do the iteration: |
294 |
> |
// do the iteration: |
295 |
> |
instaVol =thermo.getVolume(); |
296 |
|
|
297 |
< |
instaVol = tStats->getVolume(); |
297 |
> |
for(int k = 0; k < maxIterNum_; k++) { |
298 |
> |
instaTemp =thermo.getTemperature(); |
299 |
> |
instaPress =thermo.getPressure(); |
300 |
|
|
301 |
< |
for (k=0; k < 4; k++) { |
301 |
> |
// evolve chi another half step using the temperature at t + dt/2 |
302 |
> |
prevChi = thermostat.first; |
303 |
> |
thermostat.first = oldChi + dt2 * (instaTemp / targetTemp - 1.0) / tt2; |
304 |
|
|
305 |
< |
instaTemp = tStats->getTemperature(); |
306 |
< |
instaPress = tStats->getPressure(); |
305 |
> |
//evolve eta |
306 |
> |
this->evolveEtaB(); |
307 |
> |
this->calcVelScale(); |
308 |
|
|
309 |
< |
// evolve chi another half step using the temperature at t + dt/2 |
309 |
> |
index = 0; |
310 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
311 |
> |
mol = info_->nextMolecule(i)) { |
312 |
|
|
313 |
< |
this->evolveChiB(); |
314 |
< |
this->evolveEtaB(); |
218 |
< |
this->calcVelScale(); |
313 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
314 |
> |
sd = mol->nextIntegrableObject(j)) { |
315 |
|
|
316 |
< |
for( i=0; i<integrableObjects.size(); i++ ){ |
316 |
> |
frc = sd->getFrc(); |
317 |
> |
mass = sd->getMass(); |
318 |
|
|
319 |
< |
integrableObjects[i]->getFrc( frc ); |
223 |
< |
integrableObjects[i]->getVel(vel); |
319 |
> |
getVelScaleB(sc, index); |
320 |
|
|
321 |
< |
mass = integrableObjects[i]->getMass(); |
321 |
> |
// velocity half step |
322 |
> |
vel = oldVel[index] |
323 |
> |
+ dt2*PhysicalConstants::energyConvert/mass* frc |
324 |
> |
- dt2*sc; |
325 |
|
|
326 |
< |
getVelScaleB( sc, i ); |
326 |
> |
sd->setVel(vel); |
327 |
|
|
328 |
< |
// velocity half step |
329 |
< |
for (j=0; j < 3; j++) |
330 |
< |
vel[j] = oldVel[3*i+j] + dt2 * ((frc[j] / mass ) * eConvert - sc[j]); |
328 |
> |
if (sd->isDirectional()) { |
329 |
> |
// get and convert the torque to body frame |
330 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
331 |
|
|
332 |
< |
integrableObjects[i]->setVel( vel ); |
332 |
> |
ji = oldJi[index] |
333 |
> |
+ dt2*PhysicalConstants::energyConvert*Tb |
334 |
> |
- dt2*thermostat.first*oldJi[index]; |
335 |
|
|
336 |
< |
if( integrableObjects[i]->isDirectional() ){ |
336 |
> |
sd->setJ(ji); |
337 |
> |
} |
338 |
|
|
339 |
< |
// get and convert the torque to body frame |
340 |
< |
|
239 |
< |
integrableObjects[i]->getTrq( Tb ); |
240 |
< |
integrableObjects[i]->lab2Body( Tb ); |
241 |
< |
|
242 |
< |
for (j=0; j < 3; j++) |
243 |
< |
ji[j] = oldJi[3*i + j] + dt2 * (Tb[j] * eConvert - oldJi[3*i+j]*chi); |
244 |
< |
|
245 |
< |
integrableObjects[i]->setJ( ji ); |
339 |
> |
++index; |
340 |
> |
} |
341 |
|
} |
342 |
+ |
|
343 |
+ |
rattle_->constraintB(); |
344 |
+ |
|
345 |
+ |
if ((fabs(prevChi - thermostat.first) <= chiTolerance) && |
346 |
+ |
this->etaConverged()) |
347 |
+ |
break; |
348 |
|
} |
349 |
|
|
350 |
< |
if(nConstrained) |
351 |
< |
constrainB(); |
350 |
> |
//calculate integral of chidt |
351 |
> |
thermostat.second += dt2 * thermostat.first; |
352 |
|
|
353 |
< |
if ( this->chiConverged() && this->etaConverged() ) break; |
253 |
< |
} |
353 |
> |
snap->setThermostat(thermostat); |
354 |
|
|
355 |
< |
//calculate integral of chida |
356 |
< |
integralOfChidt += dt2*chi; |
257 |
< |
|
258 |
< |
|
259 |
< |
} |
260 |
< |
|
261 |
< |
template<typename T> void NPT<T>::resetIntegrator() { |
262 |
< |
chi = 0.0; |
263 |
< |
T::resetIntegrator(); |
264 |
< |
} |
265 |
< |
|
266 |
< |
template<typename T> void NPT<T>::evolveChiA() { |
267 |
< |
chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
268 |
< |
oldChi = chi; |
269 |
< |
} |
270 |
< |
|
271 |
< |
template<typename T> void NPT<T>::evolveChiB() { |
272 |
< |
|
273 |
< |
prevChi = chi; |
274 |
< |
chi = oldChi + dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
275 |
< |
} |
276 |
< |
|
277 |
< |
template<typename T> bool NPT<T>::chiConverged() { |
278 |
< |
|
279 |
< |
return ( fabs( prevChi - chi ) <= chiTolerance ); |
280 |
< |
} |
281 |
< |
|
282 |
< |
template<typename T> int NPT<T>::readyCheck() { |
283 |
< |
|
284 |
< |
//check parent's readyCheck() first |
285 |
< |
if (T::readyCheck() == -1) |
286 |
< |
return -1; |
287 |
< |
|
288 |
< |
// First check to see if we have a target temperature. |
289 |
< |
// Not having one is fatal. |
290 |
< |
|
291 |
< |
if (!have_target_temp) { |
292 |
< |
sprintf( painCave.errMsg, |
293 |
< |
"NPT error: You can't use the NPT integrator\n" |
294 |
< |
" without a targetTemp!\n" |
295 |
< |
); |
296 |
< |
painCave.isFatal = 1; |
297 |
< |
simError(); |
298 |
< |
return -1; |
355 |
> |
flucQ_->moveB(); |
356 |
> |
saveEta(); |
357 |
|
} |
358 |
|
|
359 |
< |
if (!have_target_pressure) { |
360 |
< |
sprintf( painCave.errMsg, |
361 |
< |
"NPT error: You can't use the NPT integrator\n" |
304 |
< |
" without a targetPressure!\n" |
305 |
< |
); |
306 |
< |
painCave.isFatal = 1; |
307 |
< |
simError(); |
308 |
< |
return -1; |
359 |
> |
void NPT::resetIntegrator(){ |
360 |
> |
snap->setThermostat(make_pair(0.0, 0.0)); |
361 |
> |
resetEta(); |
362 |
|
} |
363 |
|
|
364 |
< |
// We must set tauThermostat. |
365 |
< |
|
366 |
< |
if (!have_tau_thermostat) { |
314 |
< |
sprintf( painCave.errMsg, |
315 |
< |
"NPT error: If you use the NPT\n" |
316 |
< |
" integrator, you must set tauThermostat.\n"); |
317 |
< |
painCave.isFatal = 1; |
318 |
< |
simError(); |
319 |
< |
return -1; |
364 |
> |
void NPT::resetEta() { |
365 |
> |
Mat3x3d etaMat(0.0); |
366 |
> |
snap->setBarostat(etaMat); |
367 |
|
} |
321 |
– |
|
322 |
– |
// We must set tauBarostat. |
323 |
– |
|
324 |
– |
if (!have_tau_barostat) { |
325 |
– |
sprintf( painCave.errMsg, |
326 |
– |
"If you use the NPT integrator, you must set tauBarostat.\n"); |
327 |
– |
painCave.severity = OOPSE_ERROR; |
328 |
– |
painCave.isFatal = 1; |
329 |
– |
simError(); |
330 |
– |
return -1; |
331 |
– |
} |
332 |
– |
|
333 |
– |
if (!have_chi_tolerance) { |
334 |
– |
sprintf( painCave.errMsg, |
335 |
– |
"Setting chi tolerance to 1e-6 in NPT integrator\n"); |
336 |
– |
chiTolerance = 1e-6; |
337 |
– |
have_chi_tolerance = 1; |
338 |
– |
painCave.severity = OOPSE_INFO; |
339 |
– |
painCave.isFatal = 0; |
340 |
– |
simError(); |
341 |
– |
} |
342 |
– |
|
343 |
– |
if (!have_eta_tolerance) { |
344 |
– |
sprintf( painCave.errMsg, |
345 |
– |
"Setting eta tolerance to 1e-6 in NPT integrator"); |
346 |
– |
etaTolerance = 1e-6; |
347 |
– |
have_eta_tolerance = 1; |
348 |
– |
painCave.severity = OOPSE_INFO; |
349 |
– |
painCave.isFatal = 0; |
350 |
– |
simError(); |
351 |
– |
} |
352 |
– |
|
353 |
– |
// We need NkBT a lot, so just set it here: This is the RAW number |
354 |
– |
// of integrableObjects, so no subtraction or addition of constraints or |
355 |
– |
// orientational degrees of freedom: |
356 |
– |
|
357 |
– |
NkBT = (double)(info->getTotIntegrableObjects()) * kB * targetTemp; |
358 |
– |
|
359 |
– |
// fkBT is used because the thermostat operates on more degrees of freedom |
360 |
– |
// than the barostat (when there are particles with orientational degrees |
361 |
– |
// of freedom). |
362 |
– |
|
363 |
– |
fkBT = (double)(info->getNDF()) * kB * targetTemp; |
364 |
– |
|
365 |
– |
tt2 = tauThermostat * tauThermostat; |
366 |
– |
tb2 = tauBarostat * tauBarostat; |
367 |
– |
|
368 |
– |
return 1; |
368 |
|
} |