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), chiTolerance(1e-6), etaTolerance(1e-6), maxIterNum_(4) { |
67 |
|
|
68 |
< |
chi = 0.0; |
69 |
< |
integralOfChidt = 0.0; |
70 |
< |
have_tau_thermostat = 0; |
71 |
< |
have_tau_barostat = 0; |
72 |
< |
have_target_temp = 0; |
73 |
< |
have_target_pressure = 0; |
74 |
< |
have_chi_tolerance = 0; |
75 |
< |
have_eta_tolerance = 0; |
76 |
< |
have_pos_iter_tolerance = 0; |
68 |
> |
Globals* simParams = info_->getSimParams(); |
69 |
> |
|
70 |
> |
if (!simParams->getUseIntialExtendedSystemState()) { |
71 |
> |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
72 |
> |
currSnapshot->setThermostat(make_pair(0.0, 0.0)); |
73 |
> |
currSnapshot->setBarostat(Mat3x3d(0.0)); |
74 |
> |
} |
75 |
> |
|
76 |
> |
if (!simParams->haveTargetTemp()) { |
77 |
> |
sprintf(painCave.errMsg, "You can't use the NVT integrator without a targetTemp!\n"); |
78 |
> |
painCave.isFatal = 1; |
79 |
> |
painCave.severity = OPENMD_ERROR; |
80 |
> |
simError(); |
81 |
> |
} else { |
82 |
> |
targetTemp = simParams->getTargetTemp(); |
83 |
> |
} |
84 |
|
|
85 |
< |
// retrieve chi and integralOfChidt from simInfo |
86 |
< |
data = info->getProperty(CHIVALUE_ID); |
87 |
< |
if(data){ |
88 |
< |
chiValue = dynamic_cast<DoubleData*>(data); |
52 |
< |
} |
85 |
> |
// We must set tauThermostat |
86 |
> |
if (!simParams->haveTauThermostat()) { |
87 |
> |
sprintf(painCave.errMsg, "If you use the constant temperature\n" |
88 |
> |
"\tintegrator, you must set tauThermostat.\n"); |
89 |
|
|
90 |
< |
data = info->getProperty(INTEGRALOFCHIDT_ID); |
91 |
< |
if(data){ |
92 |
< |
integralOfChidtValue = dynamic_cast<DoubleData*>(data); |
90 |
> |
painCave.severity = OPENMD_ERROR; |
91 |
> |
painCave.isFatal = 1; |
92 |
> |
simError(); |
93 |
> |
} else { |
94 |
> |
tauThermostat = simParams->getTauThermostat(); |
95 |
> |
} |
96 |
> |
|
97 |
> |
if (!simParams->haveTargetPressure()) { |
98 |
> |
sprintf(painCave.errMsg, "NPT error: You can't use the NPT integrator\n" |
99 |
> |
" without a targetPressure!\n"); |
100 |
> |
|
101 |
> |
painCave.isFatal = 1; |
102 |
> |
simError(); |
103 |
> |
} else { |
104 |
> |
targetPressure = simParams->getTargetPressure(); |
105 |
> |
} |
106 |
> |
|
107 |
> |
if (!simParams->haveTauBarostat()) { |
108 |
> |
sprintf(painCave.errMsg, |
109 |
> |
"If you use the NPT integrator, you must set tauBarostat.\n"); |
110 |
> |
painCave.severity = OPENMD_ERROR; |
111 |
> |
painCave.isFatal = 1; |
112 |
> |
simError(); |
113 |
> |
} else { |
114 |
> |
tauBarostat = simParams->getTauBarostat(); |
115 |
> |
} |
116 |
> |
|
117 |
> |
tt2 = tauThermostat * tauThermostat; |
118 |
> |
tb2 = tauBarostat * tauBarostat; |
119 |
> |
|
120 |
> |
updateSizes(); |
121 |
> |
} |
122 |
> |
|
123 |
> |
NPT::~NPT() { |
124 |
|
} |
125 |
|
|
126 |
< |
// chi and integralOfChidt should appear by pair |
127 |
< |
if(chiValue && integralOfChidtValue){ |
128 |
< |
chi = chiValue->getData(); |
129 |
< |
integralOfChidt = integralOfChidtValue->getData(); |
126 |
> |
void NPT::doUpdateSizes() { |
127 |
> |
|
128 |
> |
oldPos.resize(info_->getNIntegrableObjects()); |
129 |
> |
oldVel.resize(info_->getNIntegrableObjects()); |
130 |
> |
oldJi.resize(info_->getNIntegrableObjects()); |
131 |
> |
|
132 |
|
} |
133 |
|
|
134 |
< |
oldPos = new double[3*integrableObjects.size()]; |
135 |
< |
oldVel = new double[3*integrableObjects.size()]; |
136 |
< |
oldJi = new double[3*integrableObjects.size()]; |
134 |
> |
void NPT::moveA() { |
135 |
> |
SimInfo::MoleculeIterator i; |
136 |
> |
Molecule::IntegrableObjectIterator j; |
137 |
> |
Molecule* mol; |
138 |
> |
StuntDouble* sd; |
139 |
> |
Vector3d Tb, ji; |
140 |
> |
RealType mass; |
141 |
> |
Vector3d vel; |
142 |
> |
Vector3d pos; |
143 |
> |
Vector3d frc; |
144 |
> |
Vector3d sc; |
145 |
> |
int index; |
146 |
|
|
147 |
< |
} |
147 |
> |
thermostat = snap->getThermostat(); |
148 |
> |
loadEta(); |
149 |
> |
|
150 |
> |
instaTemp =thermo.getTemperature(); |
151 |
> |
press = thermo.getPressureTensor(); |
152 |
> |
instaPress = PhysicalConstants::pressureConvert* (press(0, 0) + press(1, 1) + press(2, 2)) / 3.0; |
153 |
> |
instaVol =thermo.getVolume(); |
154 |
|
|
155 |
< |
template<typename T> NPT<T>::~NPT() { |
72 |
< |
delete[] oldPos; |
73 |
< |
delete[] oldVel; |
74 |
< |
delete[] oldJi; |
75 |
< |
} |
155 |
> |
Vector3d COM = thermo.getCom(); |
156 |
|
|
157 |
< |
template<typename T> void NPT<T>::moveA() { |
157 |
> |
//evolve velocity half step |
158 |
|
|
159 |
< |
//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]; |
159 |
> |
calcVelScale(); |
160 |
|
|
161 |
< |
instaTemp = tStats->getTemperature(); |
162 |
< |
tStats->getPressureTensor( press ); |
89 |
< |
instaPress = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
90 |
< |
instaVol = tStats->getVolume(); |
161 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
162 |
> |
mol = info_->nextMolecule(i)) { |
163 |
|
|
164 |
< |
tStats->getCOM(COM); |
164 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
165 |
> |
sd = mol->nextIntegrableObject(j)) { |
166 |
> |
|
167 |
> |
vel = sd->getVel(); |
168 |
> |
frc = sd->getFrc(); |
169 |
|
|
170 |
< |
//evolve velocity half step |
170 |
> |
mass = sd->getMass(); |
171 |
|
|
172 |
< |
calcVelScale(); |
97 |
< |
|
98 |
< |
for( i=0; i<integrableObjects.size(); i++ ){ |
172 |
> |
getVelScaleA(sc, vel); |
173 |
|
|
174 |
< |
integrableObjects[i]->getVel( vel ); |
101 |
< |
integrableObjects[i]->getFrc( frc ); |
174 |
> |
// velocity half step (use chi from previous step here): |
175 |
|
|
176 |
< |
mass = integrableObjects[i]->getMass(); |
176 |
> |
vel += dt2*PhysicalConstants::energyConvert/mass* frc - dt2*sc; |
177 |
> |
sd->setVel(vel); |
178 |
|
|
179 |
< |
getVelScaleA( sc, vel ); |
179 |
> |
if (sd->isDirectional()) { |
180 |
|
|
181 |
< |
for (j=0; j < 3; j++) { |
181 |
> |
// get and convert the torque to body frame |
182 |
|
|
183 |
< |
// velocity half step (use chi from previous step here): |
110 |
< |
vel[j] += dt2 * ((frc[j] / mass ) * eConvert - sc[j]); |
183 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
184 |
|
|
185 |
< |
} |
185 |
> |
// get the angular momentum, and propagate a half step |
186 |
|
|
187 |
< |
integrableObjects[i]->setVel( vel ); |
187 |
> |
ji = sd->getJ(); |
188 |
|
|
189 |
< |
if( integrableObjects[i]->isDirectional() ){ |
189 |
> |
ji += dt2*PhysicalConstants::energyConvert * Tb |
190 |
> |
- dt2*thermostat.first* ji; |
191 |
> |
|
192 |
> |
rotAlgo_->rotate(sd, ji, dt); |
193 |
|
|
194 |
< |
// get and convert the torque to body frame |
194 |
> |
sd->setJ(ji); |
195 |
> |
} |
196 |
> |
|
197 |
> |
} |
198 |
> |
} |
199 |
> |
// evolve chi and eta half step |
200 |
|
|
201 |
< |
integrableObjects[i]->getTrq( Tb ); |
202 |
< |
integrableObjects[i]->lab2Body( Tb ); |
201 |
> |
thermostat.first += dt2 * (instaTemp / targetTemp - 1.0) / tt2; |
202 |
> |
|
203 |
> |
evolveEtaA(); |
204 |
|
|
205 |
< |
// get the angular momentum, and propagate a half step |
205 |
> |
//calculate the integral of chidt |
206 |
> |
thermostat.second += dt2 * thermostat.first; |
207 |
> |
|
208 |
> |
flucQ_->moveA(); |
209 |
|
|
125 |
– |
integrableObjects[i]->getJ( ji ); |
210 |
|
|
211 |
< |
for (j=0; j < 3; j++) |
212 |
< |
ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
211 |
> |
index = 0; |
212 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
213 |
> |
mol = info_->nextMolecule(i)) { |
214 |
|
|
215 |
< |
this->rotationPropagation( integrableObjects[i], ji ); |
215 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
216 |
> |
sd = mol->nextIntegrableObject(j)) { |
217 |
|
|
218 |
< |
integrableObjects[i]->setJ( ji ); |
218 |
> |
oldPos[index++] = sd->getPos(); |
219 |
> |
|
220 |
> |
} |
221 |
|
} |
222 |
< |
} |
222 |
> |
|
223 |
> |
//the first estimation of r(t+dt) is equal to r(t) |
224 |
|
|
225 |
< |
// evolve chi and eta half step |
225 |
> |
for(int k = 0; k < maxIterNum_; k++) { |
226 |
> |
index = 0; |
227 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
228 |
> |
mol = info_->nextMolecule(i)) { |
229 |
|
|
230 |
< |
evolveChiA(); |
231 |
< |
evolveEtaA(); |
230 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
231 |
> |
sd = mol->nextIntegrableObject(j)) { |
232 |
|
|
233 |
< |
//calculate the integral of chidt |
234 |
< |
integralOfChidt += dt2*chi; |
233 |
> |
vel = sd->getVel(); |
234 |
> |
pos = sd->getPos(); |
235 |
|
|
236 |
< |
//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 |
< |
} |
236 |
> |
this->getPosScale(pos, COM, index, sc); |
237 |
|
|
238 |
< |
//the first estimation of r(t+dt) is equal to r(t) |
238 |
> |
pos = oldPos[index] + dt * (vel + sc); |
239 |
> |
sd->setPos(pos); |
240 |
|
|
241 |
< |
for(k = 0; k < 5; k ++){ |
241 |
> |
++index; |
242 |
> |
} |
243 |
> |
} |
244 |
|
|
245 |
< |
for(i =0 ; i < integrableObjects.size(); i++){ |
245 |
> |
rattle_->constraintA(); |
246 |
> |
} |
247 |
|
|
248 |
< |
integrableObjects[i]->getVel(vel); |
158 |
< |
integrableObjects[i]->getPos(pos); |
248 |
> |
// Scale the box after all the positions have been moved: |
249 |
|
|
250 |
< |
this->getPosScale( pos, COM, i, sc ); |
250 |
> |
this->scaleSimBox(); |
251 |
|
|
252 |
< |
for(j = 0; j < 3; j++) |
163 |
< |
pos[j] = oldPos[i*3 + j] + dt*(vel[j] + sc[j]); |
252 |
> |
snap->setThermostat(thermostat); |
253 |
|
|
254 |
< |
integrableObjects[i]->setPos( pos ); |
166 |
< |
} |
167 |
< |
|
168 |
< |
if(nConstrained) |
169 |
< |
constrainA(); |
254 |
> |
saveEta(); |
255 |
|
} |
256 |
|
|
257 |
+ |
void NPT::moveB(void) { |
258 |
+ |
SimInfo::MoleculeIterator i; |
259 |
+ |
Molecule::IntegrableObjectIterator j; |
260 |
+ |
Molecule* mol; |
261 |
+ |
StuntDouble* sd; |
262 |
+ |
int index; |
263 |
+ |
Vector3d Tb; |
264 |
+ |
Vector3d ji; |
265 |
+ |
Vector3d sc; |
266 |
+ |
Vector3d vel; |
267 |
+ |
Vector3d frc; |
268 |
+ |
RealType mass; |
269 |
|
|
270 |
< |
// Scale the box after all the positions have been moved: |
270 |
> |
thermostat = snap->getThermostat(); |
271 |
> |
RealType oldChi = thermostat.first; |
272 |
> |
RealType prevChi; |
273 |
|
|
274 |
< |
this->scaleSimBox(); |
275 |
< |
} |
274 |
> |
loadEta(); |
275 |
> |
|
276 |
> |
//save velocity and angular momentum |
277 |
> |
index = 0; |
278 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
279 |
> |
mol = info_->nextMolecule(i)) { |
280 |
|
|
281 |
< |
template<typename T> void NPT<T>::moveB( void ){ |
281 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
282 |
> |
sd = mol->nextIntegrableObject(j)) { |
283 |
> |
|
284 |
> |
oldVel[index] = sd->getVel(); |
285 |
|
|
286 |
< |
//new version of NPT |
287 |
< |
int i, j, k; |
182 |
< |
double Tb[3], ji[3], sc[3]; |
183 |
< |
double vel[3], frc[3]; |
184 |
< |
double mass; |
286 |
> |
if (sd->isDirectional()) |
287 |
> |
oldJi[index] = sd->getJ(); |
288 |
|
|
289 |
< |
// Set things up for the iteration: |
290 |
< |
|
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 |
< |
|
289 |
> |
++index; |
290 |
> |
} |
291 |
|
} |
203 |
– |
} |
292 |
|
|
293 |
< |
// do the iteration: |
293 |
> |
// do the iteration: |
294 |
> |
instaVol =thermo.getVolume(); |
295 |
|
|
296 |
< |
instaVol = tStats->getVolume(); |
296 |
> |
for(int k = 0; k < maxIterNum_; k++) { |
297 |
> |
instaTemp =thermo.getTemperature(); |
298 |
> |
instaPress =thermo.getPressure(); |
299 |
|
|
300 |
< |
for (k=0; k < 4; k++) { |
300 |
> |
// evolve chi another half step using the temperature at t + dt/2 |
301 |
> |
prevChi = thermostat.first; |
302 |
> |
thermostat.first = oldChi + dt2 * (instaTemp / targetTemp - 1.0) / tt2; |
303 |
|
|
304 |
< |
instaTemp = tStats->getTemperature(); |
305 |
< |
instaPress = tStats->getPressure(); |
304 |
> |
//evolve eta |
305 |
> |
this->evolveEtaB(); |
306 |
> |
this->calcVelScale(); |
307 |
|
|
308 |
< |
// evolve chi another half step using the temperature at t + dt/2 |
308 |
> |
index = 0; |
309 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
310 |
> |
mol = info_->nextMolecule(i)) { |
311 |
|
|
312 |
< |
this->evolveChiB(); |
313 |
< |
this->evolveEtaB(); |
218 |
< |
this->calcVelScale(); |
312 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
313 |
> |
sd = mol->nextIntegrableObject(j)) { |
314 |
|
|
315 |
< |
for( i=0; i<integrableObjects.size(); i++ ){ |
315 |
> |
frc = sd->getFrc(); |
316 |
> |
mass = sd->getMass(); |
317 |
|
|
318 |
< |
integrableObjects[i]->getFrc( frc ); |
223 |
< |
integrableObjects[i]->getVel(vel); |
318 |
> |
getVelScaleB(sc, index); |
319 |
|
|
320 |
< |
mass = integrableObjects[i]->getMass(); |
320 |
> |
// velocity half step |
321 |
> |
vel = oldVel[index] |
322 |
> |
+ dt2*PhysicalConstants::energyConvert/mass* frc |
323 |
> |
- dt2*sc; |
324 |
|
|
325 |
< |
getVelScaleB( sc, i ); |
325 |
> |
sd->setVel(vel); |
326 |
|
|
327 |
< |
// velocity half step |
328 |
< |
for (j=0; j < 3; j++) |
329 |
< |
vel[j] = oldVel[3*i+j] + dt2 * ((frc[j] / mass ) * eConvert - sc[j]); |
327 |
> |
if (sd->isDirectional()) { |
328 |
> |
// get and convert the torque to body frame |
329 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
330 |
|
|
331 |
< |
integrableObjects[i]->setVel( vel ); |
331 |
> |
ji = oldJi[index] |
332 |
> |
+ dt2*PhysicalConstants::energyConvert*Tb |
333 |
> |
- dt2*thermostat.first*oldJi[index]; |
334 |
|
|
335 |
< |
if( integrableObjects[i]->isDirectional() ){ |
335 |
> |
sd->setJ(ji); |
336 |
> |
} |
337 |
|
|
338 |
< |
// get and convert the torque to body frame |
339 |
< |
|
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 ); |
338 |
> |
++index; |
339 |
> |
} |
340 |
|
} |
341 |
+ |
|
342 |
+ |
rattle_->constraintB(); |
343 |
+ |
|
344 |
+ |
if ((fabs(prevChi - thermostat.first) <= chiTolerance) && |
345 |
+ |
this->etaConverged()) |
346 |
+ |
break; |
347 |
|
} |
348 |
|
|
349 |
< |
if(nConstrained) |
350 |
< |
constrainB(); |
349 |
> |
//calculate integral of chidt |
350 |
> |
thermostat.second += dt2 * thermostat.first; |
351 |
|
|
352 |
< |
if ( this->chiConverged() && this->etaConverged() ) break; |
253 |
< |
} |
352 |
> |
snap->setThermostat(thermostat); |
353 |
|
|
354 |
< |
//calculate integral of chida |
355 |
< |
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; |
354 |
> |
flucQ_->moveB(); |
355 |
> |
saveEta(); |
356 |
|
} |
357 |
|
|
358 |
< |
if (!have_target_pressure) { |
359 |
< |
sprintf( painCave.errMsg, |
360 |
< |
"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; |
358 |
> |
void NPT::resetIntegrator(){ |
359 |
> |
snap->setThermostat(make_pair(0.0, 0.0)); |
360 |
> |
resetEta(); |
361 |
|
} |
362 |
|
|
363 |
< |
// We must set tauThermostat. |
364 |
< |
|
365 |
< |
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; |
363 |
> |
void NPT::resetEta() { |
364 |
> |
Mat3x3d etaMat(0.0); |
365 |
> |
snap->setBarostat(etaMat); |
366 |
|
} |
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; |
367 |
|
} |