| 56 |
|
} |
| 57 |
|
|
| 58 |
|
template<typename T> void NPTi<T>::moveA() { |
| 59 |
– |
|
| 60 |
– |
|
| 61 |
– |
// int i, j; |
| 62 |
– |
// DirectionalAtom* dAtom; |
| 63 |
– |
// double Tb[3], ji[3]; |
| 64 |
– |
// double A[3][3], I[3][3]; |
| 65 |
– |
// double angle, mass; |
| 66 |
– |
// double vel[3], pos[3], frc[3]; |
| 67 |
– |
|
| 68 |
– |
// double rj[3]; |
| 69 |
– |
// double instaTemp, instaPress, instaVol; |
| 70 |
– |
// double tt2, tb2, scaleFactor; |
| 71 |
– |
|
| 72 |
– |
// tt2 = tauThermostat * tauThermostat; |
| 73 |
– |
// tb2 = tauBarostat * tauBarostat; |
| 74 |
– |
|
| 75 |
– |
// instaTemp = tStats->getTemperature(); |
| 76 |
– |
// instaPress = tStats->getPressure(); |
| 77 |
– |
// instaVol = tStats->getVolume(); |
| 78 |
– |
|
| 79 |
– |
// // first evolve chi a half step |
| 80 |
– |
|
| 81 |
– |
// chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
| 82 |
– |
// eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
| 83 |
– |
// (p_convert*NkBT*tb2)); |
| 84 |
– |
|
| 85 |
– |
// integralOfChidt += dt2* chi; |
| 86 |
– |
|
| 87 |
– |
// for( i=0; i<nAtoms; i++ ){ |
| 88 |
– |
// atoms[i]->getVel( vel ); |
| 89 |
– |
// atoms[i]->getPos( pos ); |
| 90 |
– |
// atoms[i]->getFrc( frc ); |
| 91 |
– |
|
| 92 |
– |
// mass = atoms[i]->getMass(); |
| 93 |
– |
|
| 94 |
– |
// for (j=0; j < 3; j++) { |
| 95 |
– |
// vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta)); |
| 96 |
– |
// rj[j] = pos[j]; |
| 97 |
– |
// } |
| 98 |
– |
|
| 99 |
– |
// atoms[i]->setVel( vel ); |
| 100 |
– |
|
| 101 |
– |
// info->wrapVector(rj); |
| 102 |
– |
|
| 103 |
– |
// for (j = 0; j < 3; j++) |
| 104 |
– |
// pos[j] += dt * (vel[j] + eta*rj[j]); |
| 105 |
– |
|
| 106 |
– |
// atoms[i]->setPos( pos ); |
| 107 |
– |
|
| 108 |
– |
// if( atoms[i]->isDirectional() ){ |
| 109 |
– |
|
| 110 |
– |
// dAtom = (DirectionalAtom *)atoms[i]; |
| 111 |
– |
|
| 112 |
– |
// // get and convert the torque to body frame |
| 113 |
– |
|
| 114 |
– |
// dAtom->getTrq( Tb ); |
| 115 |
– |
// dAtom->lab2Body( Tb ); |
| 116 |
– |
|
| 117 |
– |
// // get the angular momentum, and propagate a half step |
| 118 |
– |
|
| 119 |
– |
// dAtom->getJ( ji ); |
| 120 |
– |
|
| 121 |
– |
// for (j=0; j < 3; j++) |
| 122 |
– |
// ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
| 123 |
– |
|
| 124 |
– |
// // use the angular velocities to propagate the rotation matrix a |
| 125 |
– |
// // full time step |
| 126 |
– |
|
| 127 |
– |
// dAtom->getA(A); |
| 128 |
– |
// dAtom->getI(I); |
| 129 |
– |
|
| 130 |
– |
// // rotate about the x-axis |
| 131 |
– |
// angle = dt2 * ji[0] / I[0][0]; |
| 132 |
– |
// this->rotate( 1, 2, angle, ji, A ); |
| 133 |
– |
|
| 134 |
– |
// // rotate about the y-axis |
| 135 |
– |
// angle = dt2 * ji[1] / I[1][1]; |
| 136 |
– |
// this->rotate( 2, 0, angle, ji, A ); |
| 137 |
– |
|
| 138 |
– |
// // rotate about the z-axis |
| 139 |
– |
// angle = dt * ji[2] / I[2][2]; |
| 140 |
– |
// this->rotate( 0, 1, angle, ji, A); |
| 141 |
– |
|
| 142 |
– |
// // rotate about the y-axis |
| 143 |
– |
// angle = dt2 * ji[1] / I[1][1]; |
| 144 |
– |
// this->rotate( 2, 0, angle, ji, A ); |
| 145 |
– |
|
| 146 |
– |
// // rotate about the x-axis |
| 147 |
– |
// angle = dt2 * ji[0] / I[0][0]; |
| 148 |
– |
// this->rotate( 1, 2, angle, ji, A ); |
| 149 |
– |
|
| 150 |
– |
// dAtom->setJ( ji ); |
| 151 |
– |
// dAtom->setA( A ); |
| 152 |
– |
// } |
| 153 |
– |
|
| 154 |
– |
// } |
| 155 |
– |
|
| 156 |
– |
// // Scale the box after all the positions have been moved: |
| 157 |
– |
|
| 158 |
– |
// scaleFactor = exp(dt*eta); |
| 159 |
– |
|
| 160 |
– |
// if ((scaleFactor > 1.1) || (scaleFactor < 0.9)) { |
| 161 |
– |
// sprintf( painCave.errMsg, |
| 162 |
– |
// "NPTi error: Attempting a Box scaling of more than 10 percent" |
| 163 |
– |
// " check your tauBarostat, as it is probably too small!\n" |
| 164 |
– |
// " eta = %lf, scaleFactor = %lf\n", eta, scaleFactor |
| 165 |
– |
// ); |
| 166 |
– |
// painCave.isFatal = 1; |
| 167 |
– |
// simError(); |
| 168 |
– |
// } else { |
| 169 |
– |
// info->scaleBox(exp(dt*eta)); |
| 170 |
– |
// } |
| 171 |
– |
|
| 59 |
|
|
| 60 |
|
//new version of NPTi |
| 61 |
|
int i, j, k; |
| 167 |
|
atoms[i]->getPos(pos); |
| 168 |
|
|
| 169 |
|
for(j = 0; j < 3; j++) |
| 170 |
< |
rj[j] = (oldPos[i*3 + j] + pos[j])/2 - COM[j]; |
| 284 |
< |
|
| 170 |
> |
rj[j] = (oldPos[i*3 + j] + pos[j])/2 - COM[j]; |
| 171 |
|
|
| 286 |
– |
//wrapVector(r(t)) = r(t)-R0 |
| 287 |
– |
//info->wrapVector(rj); |
| 288 |
– |
|
| 172 |
|
for(j = 0; j < 3; j++) |
| 173 |
|
pos[j] = oldPos[i*3 + j] + dt*(vel[j] + eta*rj[j]); |
| 174 |
|
|
| 175 |
|
atoms[i]->setPos( pos ); |
| 293 |
– |
|
| 176 |
|
} |
| 177 |
< |
|
| 177 |
> |
|
| 178 |
> |
if (nConstrained){ |
| 179 |
> |
constrainA(); |
| 180 |
> |
} |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
|
| 197 |
|
info->scaleBox(scaleFactor); |
| 198 |
|
} |
| 199 |
|
|
| 315 |
– |
//advance volume; |
| 316 |
– |
volume = volume * exp(dt*eta); |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
template<typename T> void NPTi<T>::moveB( void ){ |
| 320 |
– |
|
| 321 |
– |
/* |
| 322 |
– |
int i, j; |
| 323 |
– |
DirectionalAtom* dAtom; |
| 324 |
– |
double Tb[3], ji[3]; |
| 325 |
– |
double vel[3], frc[3]; |
| 326 |
– |
double mass; |
| 327 |
– |
|
| 328 |
– |
double instaTemp, instaPress, instaVol; |
| 329 |
– |
double tt2, tb2; |
| 203 |
|
|
| 331 |
– |
tt2 = tauThermostat * tauThermostat; |
| 332 |
– |
tb2 = tauBarostat * tauBarostat; |
| 333 |
– |
|
| 334 |
– |
instaTemp = tStats->getTemperature(); |
| 335 |
– |
instaPress = tStats->getPressure(); |
| 336 |
– |
instaVol = tStats->getVolume(); |
| 337 |
– |
|
| 338 |
– |
chi += dt2 * ( instaTemp / targetTemp - 1.0) / tt2; |
| 339 |
– |
eta += dt2 * ( instaVol * (instaPress - targetPressure) / |
| 340 |
– |
(p_convert*NkBT*tb2)); |
| 341 |
– |
integralOfChidt += dt2*chi; |
| 342 |
– |
|
| 343 |
– |
for( i=0; i<nAtoms; i++ ){ |
| 344 |
– |
|
| 345 |
– |
atoms[i]->getVel( vel ); |
| 346 |
– |
atoms[i]->getFrc( frc ); |
| 347 |
– |
|
| 348 |
– |
mass = atoms[i]->getMass(); |
| 349 |
– |
|
| 350 |
– |
// velocity half step |
| 351 |
– |
for (j=0; j < 3; j++) |
| 352 |
– |
vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*(chi+eta)); |
| 353 |
– |
|
| 354 |
– |
atoms[i]->setVel( vel ); |
| 355 |
– |
|
| 356 |
– |
if( atoms[i]->isDirectional() ){ |
| 357 |
– |
|
| 358 |
– |
dAtom = (DirectionalAtom *)atoms[i]; |
| 359 |
– |
|
| 360 |
– |
// get and convert the torque to body frame |
| 361 |
– |
|
| 362 |
– |
dAtom->getTrq( Tb ); |
| 363 |
– |
dAtom->lab2Body( Tb ); |
| 364 |
– |
|
| 365 |
– |
// get the angular momentum, and propagate a half step |
| 366 |
– |
|
| 367 |
– |
dAtom->getJ( ji ); |
| 368 |
– |
|
| 369 |
– |
for (j=0; j < 3; j++) |
| 370 |
– |
ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
| 371 |
– |
|
| 372 |
– |
dAtom->setJ( ji ); |
| 373 |
– |
} |
| 374 |
– |
} |
| 375 |
– |
|
| 376 |
– |
*/ |
| 377 |
– |
|
| 204 |
|
//new version of NPTi |
| 205 |
|
int i, j, k; |
| 206 |
|
DirectionalAtom* dAtom; |
| 216 |
|
tt2 = tauThermostat * tauThermostat; |
| 217 |
|
tb2 = tauBarostat * tauBarostat; |
| 218 |
|
|
| 393 |
– |
|
| 219 |
|
// Set things up for the iteration: |
| 220 |
|
|
| 221 |
|
oldChi = chi; |
| 288 |
|
dAtom->setJ( ji ); |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
< |
|
| 292 |
< |
if (fabs(prevChi - chi) <= chiTolerance && fabs(preEta -eta) <= etaTolerance) |
| 291 |
> |
|
| 292 |
> |
if (nConstrained){ |
| 293 |
> |
constrainB(); |
| 294 |
> |
} |
| 295 |
> |
|
| 296 |
> |
if (fabs(prevChi - chi) <= |
| 297 |
> |
chiTolerance && fabs(preEta -eta) <= etaTolerance) |
| 298 |
|
break; |
| 299 |
|
} |
| 300 |
|
|
| 369 |
|
simError(); |
| 370 |
|
} |
| 371 |
|
|
| 372 |
< |
if (!have_eta_tolerance) { |
| 372 |
> |
if (!have_eta_tolerance) { |
| 373 |
|
sprintf( painCave.errMsg, |
| 374 |
|
"NPTi warning: setting eta tolerance to 1e-6\n"); |
| 375 |
|
etaTolerance = 1e-6; |
| 377 |
|
painCave.isFatal = 0; |
| 378 |
|
simError(); |
| 379 |
|
} |
| 380 |
< |
// We need NkBT a lot, so just set it here: |
| 381 |
< |
|
| 380 |
> |
|
| 381 |
> |
|
| 382 |
> |
// We need NkBT a lot, so just set it here: This is the RAW number |
| 383 |
> |
// of particles, so no subtraction or addition of constraints or |
| 384 |
> |
// orientational degrees of freedom: |
| 385 |
> |
|
| 386 |
|
NkBT = (double)Nparticles * kB * targetTemp; |
| 387 |
+ |
|
| 388 |
+ |
// fkBT is used because the thermostat operates on more degrees of freedom |
| 389 |
+ |
// than the barostat (when there are particles with orientational degrees |
| 390 |
+ |
// of freedom). ndf = 3 * (n_atoms + n_oriented -1) - n_constraint - nZcons |
| 391 |
+ |
|
| 392 |
|
fkBT = (double)info->ndf * kB * targetTemp; |
| 393 |
|
|
| 394 |
|
return 1; |
| 397 |
|
template<typename T> double NPTi<T>::getConservedQuantity(void){ |
| 398 |
|
|
| 399 |
|
double conservedQuantity; |
| 400 |
+ |
double Three_NkBT; |
| 401 |
+ |
double Energy; |
| 402 |
+ |
double thermostat_kinetic; |
| 403 |
+ |
double thermostat_potential; |
| 404 |
+ |
double barostat_kinetic; |
| 405 |
+ |
double barostat_potential; |
| 406 |
|
double tb2; |
| 407 |
< |
double eta2; |
| 563 |
< |
double E_NPT; |
| 564 |
< |
double U; |
| 565 |
< |
double TS; |
| 566 |
< |
double PV; |
| 567 |
< |
double extra; |
| 568 |
< |
|
| 569 |
< |
static double pre_U; |
| 570 |
< |
static double pre_TS; |
| 571 |
< |
static double pre_PV; |
| 572 |
< |
static double pre_extra; |
| 573 |
< |
static int hackCount = 0; |
| 407 |
> |
double eta2; |
| 408 |
|
|
| 409 |
< |
double delta_U; |
| 576 |
< |
double delta_TS; |
| 577 |
< |
double delta_PV; |
| 578 |
< |
double delta_extra; |
| 409 |
> |
Energy = tStats->getTotalE(); |
| 410 |
|
|
| 411 |
< |
U = tStats->getTotalE(); |
| 411 |
> |
thermostat_kinetic = fkBT* tauThermostat * tauThermostat * chi * chi / |
| 412 |
> |
(2.0 * eConvert); |
| 413 |
|
|
| 414 |
< |
TS = fkBT * |
| 583 |
< |
(integralOfChidt + tauThermostat * tauThermostat * chi * chi / 2.0) / eConvert; |
| 414 |
> |
thermostat_potential = fkBT* integralOfChidt / eConvert; |
| 415 |
|
|
| 585 |
– |
PV = (targetPressure * tStats->getVolume() / p_convert) / eConvert; |
| 416 |
|
|
| 417 |
< |
tb2 = tauBarostat * tauBarostat; |
| 418 |
< |
eta2 = eta * eta; |
| 417 |
> |
barostat_kinetic = 3.0 * NkBT * tauBarostat * tauBarostat * eta * eta / |
| 418 |
> |
(2.0 * eConvert); |
| 419 |
> |
|
| 420 |
> |
barostat_potential = (targetPressure * tStats->getVolume() / p_convert) / |
| 421 |
> |
eConvert; |
| 422 |
|
|
| 423 |
< |
extra = (fkBT * tb2 * eta2 / 2.0 ) / eConvert; |
| 424 |
< |
/* |
| 425 |
< |
if(hackCount == 0){ |
| 593 |
< |
pre_U = U; |
| 594 |
< |
pre_TS =TS; |
| 595 |
< |
pre_PV = PV; |
| 596 |
< |
pre_extra =extra; |
| 597 |
< |
hackCount ++; |
| 598 |
< |
} |
| 599 |
< |
|
| 600 |
< |
delta_U = U - pre_U; |
| 601 |
< |
delta_TS = TS - pre_TS; |
| 602 |
< |
delta_PV = PV - pre_PV; |
| 603 |
< |
delta_extra = extra - pre_extra; |
| 604 |
< |
*/ |
| 423 |
> |
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential + |
| 424 |
> |
barostat_kinetic + barostat_potential; |
| 425 |
> |
|
| 426 |
|
cout.width(8); |
| 427 |
|
cout.precision(8); |
| 428 |
|
|
| 429 |
< |
|
| 430 |
< |
cout << info->getTime() << "\t" |
| 431 |
< |
<< chi << "\t" |
| 611 |
< |
<< eta << "\t" |
| 612 |
< |
<< U << "\t" |
| 613 |
< |
<< TS << "\t" |
| 614 |
< |
<< PV << "\t" |
| 615 |
< |
<< extra << "\t" |
| 616 |
< |
<< U+TS+PV+extra << endl; |
| 429 |
> |
cerr << info->getTime() << "\t" << Energy << "\t" << thermostat_kinetic << |
| 430 |
> |
"\t" << thermostat_potential << "\t" << barostat_kinetic << |
| 431 |
> |
"\t" << barostat_potential << "\t" << conservedQuantity << endl; |
| 432 |
|
|
| 618 |
– |
/* |
| 619 |
– |
pre_U = U; |
| 620 |
– |
pre_TS =TS; |
| 621 |
– |
pre_PV = PV; |
| 622 |
– |
pre_extra =extra; |
| 623 |
– |
|
| 624 |
– |
|
| 625 |
– |
cout << info->getTime() << "\t" |
| 626 |
– |
<< U << "\t" |
| 627 |
– |
<< U+TS << "\t" |
| 628 |
– |
<< U+TS+PV << "\t" |
| 629 |
– |
<< U+TS+PV+extra << endl; |
| 630 |
– |
*/ |
| 631 |
– |
conservedQuantity = U+TS+PV+extra; |
| 433 |
|
return conservedQuantity; |
| 434 |
|
} |