| 9 |
|
#include "Integrator.hpp" |
| 10 |
|
#include "simError.h" |
| 11 |
|
|
| 12 |
+ |
#ifdef IS_MPI |
| 13 |
+ |
#include "mpiSimulation.hpp" |
| 14 |
+ |
#endif |
| 15 |
|
|
| 16 |
|
// Basic non-isotropic thermostating and barostating via the Melchionna |
| 17 |
|
// modification of the Hoover algorithm: |
| 51 |
|
#else |
| 52 |
|
Nparticles = theInfo->n_atoms; |
| 53 |
|
#endif |
| 54 |
+ |
|
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
template<typename T> NPTf<T>::~NPTf() { |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
template<typename T> void NPTf<T>::moveA() { |
| 64 |
< |
|
| 64 |
> |
|
| 65 |
> |
// new version of NPTf |
| 66 |
|
int i, j, k; |
| 67 |
|
DirectionalAtom* dAtom; |
| 68 |
|
double Tb[3], ji[3]; |
| 69 |
< |
double A[3][3], I[3][3]; |
| 70 |
< |
double angle, mass; |
| 69 |
> |
|
| 70 |
> |
double mass; |
| 71 |
|
double vel[3], pos[3], frc[3]; |
| 72 |
|
|
| 73 |
|
double rj[3]; |
| 110 |
|
info->matVecMul3( vScale, vel, sc ); |
| 111 |
|
|
| 112 |
|
for (j=0; j < 3; j++) { |
| 113 |
< |
// velocity half step (use chi from previous step here): |
| 113 |
> |
// velocity half step |
| 114 |
|
vel[j] += dt2 * ((frc[j] / mass) * eConvert - sc[j]); |
| 110 |
– |
|
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
atoms[i]->setVel( vel ); |
| 132 |
|
for (j=0; j < 3; j++) |
| 133 |
|
ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
| 134 |
|
|
| 135 |
< |
// use the angular velocities to propagate the rotation matrix a |
| 136 |
< |
// full time step |
| 133 |
< |
|
| 134 |
< |
dAtom->getA(A); |
| 135 |
< |
dAtom->getI(I); |
| 136 |
< |
|
| 137 |
< |
// rotate about the x-axis |
| 138 |
< |
angle = dt2 * ji[0] / I[0][0]; |
| 139 |
< |
this->rotate( 1, 2, angle, ji, A ); |
| 140 |
< |
|
| 141 |
< |
// rotate about the y-axis |
| 142 |
< |
angle = dt2 * ji[1] / I[1][1]; |
| 143 |
< |
this->rotate( 2, 0, angle, ji, A ); |
| 144 |
< |
|
| 145 |
< |
// rotate about the z-axis |
| 146 |
< |
angle = dt * ji[2] / I[2][2]; |
| 147 |
< |
this->rotate( 0, 1, angle, ji, A); |
| 148 |
< |
|
| 149 |
< |
// rotate about the y-axis |
| 150 |
< |
angle = dt2 * ji[1] / I[1][1]; |
| 151 |
< |
this->rotate( 2, 0, angle, ji, A ); |
| 152 |
< |
|
| 153 |
< |
// rotate about the x-axis |
| 154 |
< |
angle = dt2 * ji[0] / I[0][0]; |
| 155 |
< |
this->rotate( 1, 2, angle, ji, A ); |
| 156 |
< |
|
| 135 |
> |
this->rotationPropagation( dAtom, ji ); |
| 136 |
> |
|
| 137 |
|
dAtom->setJ( ji ); |
| 158 |
– |
dAtom->setA( A ); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
// advance chi half step |
| 142 |
|
chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
| 143 |
|
|
| 144 |
< |
//calculate the integral of chidt |
| 144 |
> |
// calculate the integral of chidt |
| 145 |
|
integralOfChidt += dt2*chi; |
| 146 |
|
|
| 147 |
< |
//advance eta half step |
| 147 |
> |
// advance eta half step |
| 148 |
> |
|
| 149 |
|
for(i = 0; i < 3; i ++) |
| 150 |
|
for(j = 0; j < 3; j++){ |
| 151 |
|
if( i == j) |
| 152 |
|
eta[i][j] += dt2 * instaVol * |
| 153 |
|
(press[i][j] - targetPressure/p_convert) / (NkBT*tb2); |
| 154 |
|
else |
| 155 |
< |
eta[i][j] += dt2 * instaVol * press[i][j] / ( NkBT*tb2); |
| 155 |
> |
eta[i][j] += dt2 * instaVol * press[i][j] / (NkBT*tb2); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
//save the old positions |
| 183 |
|
|
| 184 |
|
} |
| 185 |
|
|
| 186 |
+ |
if (nConstrained) { |
| 187 |
+ |
constrainA(); |
| 188 |
+ |
} |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 258 |
|
|
| 259 |
|
template<typename T> void NPTf<T>::moveB( void ){ |
| 260 |
|
|
| 261 |
+ |
//new version of NPTf |
| 262 |
|
int i, j, k; |
| 263 |
|
DirectionalAtom* dAtom; |
| 264 |
|
double Tb[3], ji[3]; |
| 265 |
< |
double vel[3], frc[3]; |
| 265 |
> |
double vel[3], myVel[3], frc[3]; |
| 266 |
|
double mass; |
| 267 |
|
|
| 268 |
|
double instaTemp, instaPress, instaVol; |
| 270 |
|
double sc[3]; |
| 271 |
|
double press[3][3], vScale[3][3]; |
| 272 |
|
double oldChi, prevChi; |
| 273 |
< |
double oldEta[3][3], preEta[3][3], diffEta; |
| 273 |
> |
double oldEta[3][3], prevEta[3][3], diffEta; |
| 274 |
|
|
| 275 |
|
tt2 = tauThermostat * tauThermostat; |
| 276 |
|
tb2 = tauBarostat * tauBarostat; |
| 277 |
|
|
| 294 |
– |
|
| 278 |
|
// Set things up for the iteration: |
| 279 |
|
|
| 280 |
|
oldChi = chi; |
| 318 |
|
|
| 319 |
|
for(i = 0; i < 3; i++) |
| 320 |
|
for(j = 0; j < 3; j++) |
| 321 |
< |
preEta[i][j] = eta[i][j]; |
| 321 |
> |
prevEta[i][j] = eta[i][j]; |
| 322 |
|
|
| 323 |
|
//advance eta half step and calculate scale factor for velocity |
| 324 |
+ |
|
| 325 |
|
for(i = 0; i < 3; i ++) |
| 326 |
|
for(j = 0; j < 3; j++){ |
| 327 |
< |
if( i == j){ |
| 327 |
> |
if( i == j) { |
| 328 |
|
eta[i][j] = oldEta[i][j] + dt2 * instaVol * |
| 329 |
< |
(press[i][j] - targetPressure/p_convert) / (NkBT*tb2); |
| 329 |
> |
(press[i][j] - targetPressure/p_convert) / (NkBT*tb2); |
| 330 |
|
vScale[i][j] = eta[i][j] + chi; |
| 331 |
< |
} |
| 348 |
< |
else |
| 349 |
< |
{ |
| 331 |
> |
} else { |
| 332 |
|
eta[i][j] = oldEta[i][j] + dt2 * instaVol * press[i][j] / (NkBT*tb2); |
| 333 |
|
vScale[i][j] = eta[i][j]; |
| 334 |
|
} |
| 335 |
< |
} |
| 336 |
< |
|
| 355 |
< |
//advance velocity half step |
| 335 |
> |
} |
| 336 |
> |
|
| 337 |
|
for( i=0; i<nAtoms; i++ ){ |
| 338 |
|
|
| 339 |
|
atoms[i]->getFrc( frc ); |
| 340 |
|
atoms[i]->getVel(vel); |
| 341 |
|
|
| 342 |
|
mass = atoms[i]->getMass(); |
| 343 |
+ |
|
| 344 |
+ |
for (j = 0; j < 3; j++) |
| 345 |
+ |
myVel[j] = oldVel[3*i + j]; |
| 346 |
|
|
| 347 |
< |
info->matVecMul3( vScale, vel, sc ); |
| 348 |
< |
|
| 347 |
> |
info->matVecMul3( vScale, myVel, sc ); |
| 348 |
> |
|
| 349 |
> |
// velocity half step |
| 350 |
|
for (j=0; j < 3; j++) { |
| 351 |
|
// velocity half step (use chi from previous step here): |
| 352 |
|
vel[j] = oldVel[3*i+j] + dt2 * ((frc[j] / mass) * eConvert - sc[j]); |
| 370 |
|
} |
| 371 |
|
} |
| 372 |
|
|
| 373 |
+ |
if (nConstrained) { |
| 374 |
+ |
constrainB(); |
| 375 |
+ |
} |
| 376 |
|
|
| 377 |
|
diffEta = 0; |
| 378 |
|
for(i = 0; i < 3; i++) |
| 379 |
< |
diffEta += pow(preEta[i][i] - eta[i][i], 2); |
| 379 |
> |
diffEta += pow(prevEta[i][i] - eta[i][i], 2); |
| 380 |
|
|
| 381 |
|
if (fabs(prevChi - chi) <= chiTolerance && sqrt(diffEta / 3) <= etaTolerance) |
| 382 |
|
break; |
| 383 |
|
} |
| 384 |
|
|
| 385 |
< |
//calculate integral of chida |
| 385 |
> |
//calculate integral of chidt |
| 386 |
|
integralOfChidt += dt2*chi; |
| 399 |
– |
|
| 387 |
|
|
| 388 |
|
} |
| 389 |
|
|
| 449 |
|
return -1; |
| 450 |
|
} |
| 451 |
|
|
| 452 |
< |
// We need NkBT a lot, so just set it here: |
| 453 |
< |
|
| 452 |
> |
|
| 453 |
> |
// We need NkBT a lot, so just set it here: This is the RAW number |
| 454 |
> |
// of particles, so no subtraction or addition of constraints or |
| 455 |
> |
// orientational degrees of freedom: |
| 456 |
> |
|
| 457 |
|
NkBT = (double)Nparticles * kB * targetTemp; |
| 458 |
+ |
|
| 459 |
+ |
// fkBT is used because the thermostat operates on more degrees of freedom |
| 460 |
+ |
// than the barostat (when there are particles with orientational degrees |
| 461 |
+ |
// of freedom). ndf = 3 * (n_atoms + n_oriented -1) - n_constraint - nZcons |
| 462 |
+ |
|
| 463 |
|
fkBT = (double)info->ndf * kB * targetTemp; |
| 464 |
|
|
| 465 |
|
return 1; |
| 468 |
|
template<typename T> double NPTf<T>::getConservedQuantity(void){ |
| 469 |
|
|
| 470 |
|
double conservedQuantity; |
| 471 |
< |
double tb2; |
| 472 |
< |
double trEta; |
| 473 |
< |
double U; |
| 474 |
< |
double thermo; |
| 475 |
< |
double integral; |
| 476 |
< |
double baro; |
| 477 |
< |
double PV; |
| 471 |
> |
double Energy; |
| 472 |
> |
double thermostat_kinetic; |
| 473 |
> |
double thermostat_potential; |
| 474 |
> |
double barostat_kinetic; |
| 475 |
> |
double barostat_potential; |
| 476 |
> |
double trEta; |
| 477 |
> |
double a[3][3], b[3][3]; |
| 478 |
|
|
| 479 |
< |
U = tStats->getTotalE(); |
| 485 |
< |
thermo = (fkBT * tauThermostat * tauThermostat * chi * chi / 2.0) / eConvert; |
| 479 |
> |
Energy = tStats->getTotalE(); |
| 480 |
|
|
| 481 |
< |
tb2 = tauBarostat * tauBarostat; |
| 482 |
< |
trEta = info->matTrace3(eta); |
| 489 |
< |
baro = ((double)info->ndfTrans * kB * targetTemp * tb2 * trEta * trEta / 2.0) / eConvert; |
| 481 |
> |
thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi / |
| 482 |
> |
(2.0 * eConvert); |
| 483 |
|
|
| 484 |
< |
integral = ((double)(info->ndf + 1) * kB * targetTemp * integralOfChidt) /eConvert; |
| 484 |
> |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
| 485 |
|
|
| 486 |
< |
PV = (targetPressure * tStats->getVolume() / p_convert) / eConvert; |
| 486 |
> |
info->transposeMat3(eta, a); |
| 487 |
> |
info->matMul3(a, eta, b); |
| 488 |
> |
trEta = info->matTrace3(b); |
| 489 |
|
|
| 490 |
+ |
barostat_kinetic = NkBT * tauBarostat * tauBarostat * trEta / |
| 491 |
+ |
(2.0 * eConvert); |
| 492 |
+ |
|
| 493 |
+ |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
| 494 |
+ |
eConvert; |
| 495 |
|
|
| 496 |
+ |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
| 497 |
+ |
barostat_kinetic + barostat_potential; |
| 498 |
+ |
|
| 499 |
|
cout.width(8); |
| 500 |
|
cout.precision(8); |
| 498 |
– |
|
| 499 |
– |
cout << info->getTime() << "\t" |
| 500 |
– |
<< chi << "\t" |
| 501 |
– |
<< trEta << "\t" |
| 502 |
– |
<< U << "\t" |
| 503 |
– |
<< thermo << "\t" |
| 504 |
– |
<< baro << "\t" |
| 505 |
– |
<< integral << "\t" |
| 506 |
– |
<< PV << "\t" |
| 507 |
– |
<< U+thermo+integral+PV+baro << endl; |
| 501 |
|
|
| 502 |
< |
conservedQuantity = U+thermo+integral+PV+baro; |
| 503 |
< |
return conservedQuantity; |
| 504 |
< |
|
| 502 |
> |
cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
| 503 |
> |
"\t" << thermostat_potential << "\t" << barostat_kinetic << |
| 504 |
> |
"\t" << barostat_potential << "\t" << conservedQuantity << endl; |
| 505 |
> |
|
| 506 |
> |
return conservedQuantity; |
| 507 |
|
} |