| 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); |
| 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 |
|
|
| 219 |
– |
|
| 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) / |
| 257 |
< |
(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 |
|
|
| 298 |
|
} |
| 299 |
|
|
| 300 |
|
if (fabs(prevChi - chi) <= |
| 301 |
< |
chiTolerance && fabs(preEta -eta) <= etaTolerance) |
| 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 |
|
|
| 305 |
– |
|
| 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 LkBT; |
| 393 |
< |
double fkBT; |
| 394 |
< |
double f1kBT; |
| 395 |
< |
double f2kBT; |
| 396 |
< |
double NkBT; |
| 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; |
| 410 |
> |
double eta2; |
| 411 |
|
|
| 405 |
– |
LkBT = (double)(info->getNDF() + 4) * kB * targetTemp; // 3N + 1 |
| 406 |
– |
fkBT = (double)(info->getNDF() ) * kB * targetTemp; // 3N - 3 |
| 407 |
– |
f1kBT = (double)(info->getNDF()+ 1) * kB * targetTemp; // 3N - 3 + 1 |
| 408 |
– |
NkBT = (double)(info->getNDF() + 3) * kB * targetTemp; // 3N |
| 409 |
– |
f2kBT = (double)(info->getNDF()+ 2) * kB * targetTemp; // 3N - 3 + 1 |
| 410 |
– |
|
| 412 |
|
Energy = tStats->getTotalE(); |
| 413 |
|
|
| 414 |
|
thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi / |
| 417 |
|
thermostat_potential = fkBT* integralOfChidt / eConvert; |
| 418 |
|
|
| 419 |
|
|
| 420 |
< |
barostat_kinetic = fkBT * tauBarostat * tauBarostat * eta * eta / |
| 420 |
> |
barostat_kinetic = 3.0 * NkBT * tauBarostat * tauBarostat * eta * eta / |
| 421 |
|
(2.0 * eConvert); |
| 422 |
|
|
| 423 |
|
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |