13 |
|
#include "mpiSimulation.hpp" |
14 |
|
#endif |
15 |
|
|
16 |
– |
|
16 |
|
// Basic isotropic thermostating and barostating via the Melchionna |
17 |
|
// modification of the Hoover algorithm: |
18 |
|
// |
87 |
|
mass = atoms[i]->getMass(); |
88 |
|
|
89 |
|
for (j=0; j < 3; j++) { |
90 |
< |
// velocity half step (use chi from previous step here): |
90 |
> |
// velocity half step |
91 |
|
vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi + eta)); |
93 |
– |
|
92 |
|
} |
93 |
|
|
94 |
|
atoms[i]->setVel( vel ); |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
< |
// evolve chi and eta half step |
143 |
> |
// advance chi half step |
144 |
|
|
145 |
|
chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
148 |
– |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / (p_convert*NkBT*tb2)); |
146 |
|
|
147 |
< |
//calculate the integral of chidt |
147 |
> |
// calculate the integral of chidt |
148 |
> |
|
149 |
|
integralOfChidt += dt2*chi; |
150 |
|
|
151 |
+ |
// advance eta half step |
152 |
+ |
|
153 |
+ |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / (p_convert*NkBT*tb2)); |
154 |
+ |
|
155 |
|
//save the old positions |
156 |
|
for(i = 0; i < nAtoms; i++){ |
157 |
|
atoms[i]->getPos(pos); |
175 |
|
pos[j] = oldPos[i*3 + j] + dt*(vel[j] + eta*rj[j]); |
176 |
|
|
177 |
|
atoms[i]->setPos( pos ); |
176 |
– |
|
178 |
|
} |
179 |
< |
|
179 |
> |
|
180 |
> |
if (nConstrained){ |
181 |
> |
constrainA(); |
182 |
> |
} |
183 |
|
} |
184 |
|
|
185 |
|
|
210 |
|
double vel[3], frc[3]; |
211 |
|
double mass; |
212 |
|
|
213 |
< |
double instTemp, instPress, instVol; |
213 |
> |
double instaTemp, instaPress, instaVol; |
214 |
|
double tt2, tb2; |
215 |
|
double oldChi, prevChi; |
216 |
< |
double oldEta, preEta; |
216 |
> |
double oldEta, prevEta; |
217 |
|
|
218 |
|
tt2 = tauThermostat * tauThermostat; |
219 |
|
tb2 = tauBarostat * tauBarostat; |
220 |
|
|
217 |
– |
|
221 |
|
// Set things up for the iteration: |
222 |
|
|
223 |
|
oldChi = chi; |
244 |
|
|
245 |
|
// do the iteration: |
246 |
|
|
247 |
< |
instVol = tStats->getVolume(); |
247 |
> |
instaVol = tStats->getVolume(); |
248 |
|
|
249 |
|
for (k=0; k < 4; k++) { |
250 |
|
|
251 |
< |
instTemp = tStats->getTemperature(); |
252 |
< |
instPress = tStats->getPressure(); |
251 |
> |
instaTemp = tStats->getTemperature(); |
252 |
> |
instaPress = tStats->getPressure(); |
253 |
|
|
254 |
|
// evolve chi another half step using the temperature at t + dt/2 |
255 |
|
|
256 |
|
prevChi = chi; |
257 |
< |
chi = oldChi + dt2 * ( instTemp / targetTemp - 1.0) / |
255 |
< |
(tauThermostat*tauThermostat); |
257 |
> |
chi = oldChi + dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
258 |
|
|
259 |
< |
preEta = eta; |
260 |
< |
eta = oldEta + dt2 * ( instVol * (instPress - targetPressure) / |
259 |
> |
prevEta = eta; |
260 |
> |
|
261 |
> |
// advance eta half step and calculate scale factor for velocity |
262 |
> |
|
263 |
> |
eta = oldEta + dt2 * ( instaVol * (instaPress - targetPressure) / |
264 |
|
(p_convert*NkBT*tb2)); |
265 |
|
|
266 |
|
|
292 |
|
dAtom->setJ( ji ); |
293 |
|
} |
294 |
|
} |
295 |
< |
|
296 |
< |
if (fabs(prevChi - chi) <= chiTolerance && fabs(preEta -eta) <= etaTolerance) |
295 |
> |
|
296 |
> |
if (nConstrained){ |
297 |
> |
constrainB(); |
298 |
> |
} |
299 |
> |
|
300 |
> |
if (fabs(prevChi - chi) <= |
301 |
> |
chiTolerance && fabs(prevEta -eta) <= etaTolerance) |
302 |
|
break; |
303 |
|
} |
304 |
|
|
305 |
< |
//calculate integral of chida |
305 |
> |
//calculate integral of chidt |
306 |
|
integralOfChidt += dt2*chi; |
307 |
|
|
298 |
– |
|
308 |
|
} |
309 |
|
|
310 |
|
template<typename T> void NPTi<T>::resetIntegrator() { |
372 |
|
simError(); |
373 |
|
} |
374 |
|
|
375 |
< |
if (!have_eta_tolerance) { |
375 |
> |
if (!have_eta_tolerance) { |
376 |
|
sprintf( painCave.errMsg, |
377 |
|
"NPTi warning: setting eta tolerance to 1e-6\n"); |
378 |
|
etaTolerance = 1e-6; |
380 |
|
painCave.isFatal = 0; |
381 |
|
simError(); |
382 |
|
} |
383 |
< |
// We need NkBT a lot, so just set it here: |
384 |
< |
|
383 |
> |
|
384 |
> |
|
385 |
> |
// We need NkBT a lot, so just set it here: This is the RAW number |
386 |
> |
// of particles, so no subtraction or addition of constraints or |
387 |
> |
// orientational degrees of freedom: |
388 |
> |
|
389 |
|
NkBT = (double)Nparticles * kB * targetTemp; |
390 |
+ |
|
391 |
+ |
// fkBT is used because the thermostat operates on more degrees of freedom |
392 |
+ |
// than the barostat (when there are particles with orientational degrees |
393 |
+ |
// of freedom). ndf = 3 * (n_atoms + n_oriented -1) - n_constraint - nZcons |
394 |
+ |
|
395 |
|
fkBT = (double)info->ndf * kB * targetTemp; |
396 |
|
|
397 |
|
return 1; |
400 |
|
template<typename T> double NPTi<T>::getConservedQuantity(void){ |
401 |
|
|
402 |
|
double conservedQuantity; |
403 |
+ |
double Three_NkBT; |
404 |
+ |
double Energy; |
405 |
+ |
double thermostat_kinetic; |
406 |
+ |
double thermostat_potential; |
407 |
+ |
double barostat_kinetic; |
408 |
+ |
double barostat_potential; |
409 |
|
double tb2; |
410 |
< |
double eta2; |
387 |
< |
double E_NPT; |
388 |
< |
double U; |
389 |
< |
double TS; |
390 |
< |
double PV; |
391 |
< |
double extra; |
410 |
> |
double eta2; |
411 |
|
|
412 |
< |
U = tStats->getTotalE(); |
412 |
> |
Energy = tStats->getTotalE(); |
413 |
|
|
414 |
< |
TS = fkBT * |
415 |
< |
(integralOfChidt + tauThermostat * tauThermostat * chi * chi / 2.0) / eConvert; |
414 |
> |
thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi / |
415 |
> |
(2.0 * eConvert); |
416 |
|
|
417 |
< |
PV = (targetPressure * tStats->getVolume() / p_convert) / eConvert; |
417 |
> |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
418 |
|
|
400 |
– |
tb2 = tauBarostat * tauBarostat; |
401 |
– |
eta2 = eta * eta; |
419 |
|
|
420 |
+ |
barostat_kinetic = 3.0 * NkBT * tauBarostat * tauBarostat * eta * eta / |
421 |
+ |
(2.0 * eConvert); |
422 |
+ |
|
423 |
+ |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
424 |
+ |
eConvert; |
425 |
|
|
426 |
< |
extra = ((double)info->ndfTrans * kB * targetTemp * tb2 * eta2 / 2.0) / eConvert; |
427 |
< |
|
426 |
> |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
427 |
> |
barostat_kinetic + barostat_potential; |
428 |
> |
|
429 |
|
cout.width(8); |
430 |
|
cout.precision(8); |
431 |
|
|
432 |
< |
|
433 |
< |
cout << info->getTime() << "\t" |
434 |
< |
<< chi << "\t" |
412 |
< |
<< eta << "\t" |
413 |
< |
<< U << "\t" |
414 |
< |
<< TS << "\t" |
415 |
< |
<< PV << "\t" |
416 |
< |
<< extra << "\t" |
417 |
< |
<< U+TS+PV+extra << endl; |
432 |
> |
cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
433 |
> |
"\t" << thermostat_potential << "\t" << barostat_kinetic << |
434 |
> |
"\t" << barostat_potential << "\t" << conservedQuantity << endl; |
435 |
|
|
419 |
– |
conservedQuantity = U+TS+PV+extra; |
436 |
|
return conservedQuantity; |
437 |
|
} |