| 1 |
< |
#include <cmath> |
| 1 |
> |
#include <math.h> |
| 2 |
|
#include <iostream> |
| 3 |
|
using namespace std; |
| 4 |
|
|
| 33 |
|
double kinetic; |
| 34 |
|
double amass; |
| 35 |
|
double aVel[3], aJ[3], I[3][3]; |
| 36 |
< |
int j, kl; |
| 36 |
> |
int i, j, k, kl; |
| 37 |
|
|
| 38 |
– |
DirectionalAtom *dAtom; |
| 39 |
– |
|
| 40 |
– |
int n_atoms; |
| 38 |
|
double kinetic_global; |
| 39 |
< |
Atom** atoms; |
| 43 |
< |
|
| 39 |
> |
vector<StuntDouble *> integrableObjects = info->integrableObjects; |
| 40 |
|
|
| 45 |
– |
n_atoms = info->n_atoms; |
| 46 |
– |
atoms = info->atoms; |
| 47 |
– |
|
| 41 |
|
kinetic = 0.0; |
| 42 |
|
kinetic_global = 0.0; |
| 50 |
– |
for( kl=0; kl < n_atoms; kl++ ){ |
| 51 |
– |
|
| 52 |
– |
atoms[kl]->getVel(aVel); |
| 53 |
– |
amass = atoms[kl]->getMass(); |
| 54 |
– |
|
| 55 |
– |
for (j=0; j < 3; j++) |
| 56 |
– |
kinetic += amass * aVel[j] * aVel[j]; |
| 43 |
|
|
| 44 |
< |
if( atoms[kl]->isDirectional() ){ |
| 45 |
< |
|
| 46 |
< |
dAtom = (DirectionalAtom *)atoms[kl]; |
| 44 |
> |
for (kl=0; kl<integrableObjects.size(); kl++) { |
| 45 |
> |
integrableObjects[kl]->getVel(aVel); |
| 46 |
> |
amass = integrableObjects[kl]->getMass(); |
| 47 |
|
|
| 48 |
< |
dAtom->getJ( aJ ); |
| 49 |
< |
dAtom->getI( I ); |
| 50 |
< |
|
| 51 |
< |
for (j=0; j<3; j++) |
| 52 |
< |
kinetic += aJ[j]*aJ[j] / I[j][j]; |
| 53 |
< |
|
| 54 |
< |
} |
| 48 |
> |
for(j=0; j<3; j++) |
| 49 |
> |
kinetic += amass*aVel[j]*aVel[j]; |
| 50 |
> |
|
| 51 |
> |
if (integrableObjects[kl]->isDirectional()){ |
| 52 |
> |
|
| 53 |
> |
integrableObjects[kl]->getJ( aJ ); |
| 54 |
> |
integrableObjects[kl]->getI( I ); |
| 55 |
> |
|
| 56 |
> |
if (integrableObjects[kl]->isLinear()) { |
| 57 |
> |
i = integrableObjects[kl]->linearAxis(); |
| 58 |
> |
j = (i+1)%3; |
| 59 |
> |
k = (i+2)%3; |
| 60 |
> |
kinetic += aJ[j]*aJ[j]/I[j][j] + aJ[k]*aJ[k]/I[k][k]; |
| 61 |
> |
} else { |
| 62 |
> |
for (j=0; j<3; j++) |
| 63 |
> |
kinetic += aJ[j]*aJ[j] / I[j][j]; |
| 64 |
> |
} |
| 65 |
> |
} |
| 66 |
|
} |
| 67 |
|
#ifdef IS_MPI |
| 68 |
|
MPI_Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE, |
| 69 |
|
MPI_SUM, MPI_COMM_WORLD); |
| 70 |
|
kinetic = kinetic_global; |
| 71 |
|
#endif //is_mpi |
| 72 |
< |
|
| 72 |
> |
|
| 73 |
|
kinetic = kinetic * 0.5 / e_convert; |
| 74 |
|
|
| 75 |
|
return kinetic; |
| 101 |
|
potential = potential_local; |
| 102 |
|
#endif // is_mpi |
| 103 |
|
|
| 107 |
– |
#ifdef IS_MPI |
| 108 |
– |
/* |
| 109 |
– |
std::cerr << "node " << worldRank << ": after pot = " << potential << "\n"; |
| 110 |
– |
*/ |
| 111 |
– |
#endif |
| 112 |
– |
|
| 104 |
|
return potential; |
| 105 |
|
} |
| 106 |
|
|
| 116 |
|
|
| 117 |
|
const double kb = 1.9872156E-3; // boltzman's constant in kcal/(mol K) |
| 118 |
|
double temperature; |
| 119 |
< |
|
| 119 |
> |
|
| 120 |
|
temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb ); |
| 121 |
|
return temperature; |
| 122 |
|
} |
| 123 |
|
|
| 133 |
– |
double Thermo::getEnthalpy() { |
| 134 |
– |
|
| 135 |
– |
const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 |
| 136 |
– |
double u, p, v; |
| 137 |
– |
double press[3][3]; |
| 138 |
– |
|
| 139 |
– |
u = this->getTotalE(); |
| 140 |
– |
|
| 141 |
– |
this->getPressureTensor(press); |
| 142 |
– |
p = (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
| 143 |
– |
|
| 144 |
– |
v = this->getVolume(); |
| 145 |
– |
|
| 146 |
– |
return (u + (p*v)/e_convert); |
| 147 |
– |
} |
| 148 |
– |
|
| 124 |
|
double Thermo::getVolume() { |
| 125 |
|
|
| 126 |
|
return info->boxVol; |
| 247 |
|
|
| 248 |
|
void Thermo::velocitize() { |
| 249 |
|
|
| 275 |
– |
double x,y; |
| 250 |
|
double aVel[3], aJ[3], I[3][3]; |
| 251 |
< |
int i, j, vr, vd; // velocity randomizer loop counters |
| 251 |
> |
int i, j, l, m, n, vr, vd; // velocity randomizer loop counters |
| 252 |
|
double vdrift[3]; |
| 253 |
|
double vbar; |
| 254 |
|
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
| 255 |
|
double av2; |
| 256 |
|
double kebar; |
| 283 |
– |
int n_atoms; |
| 284 |
– |
Atom** atoms; |
| 285 |
– |
DirectionalAtom* dAtom; |
| 257 |
|
double temperature; |
| 258 |
< |
int n_oriented; |
| 288 |
< |
int n_constraints; |
| 258 |
> |
int nobj; |
| 259 |
|
|
| 260 |
< |
atoms = info->atoms; |
| 261 |
< |
n_atoms = info->n_atoms; |
| 260 |
> |
nobj = info->integrableObjects.size(); |
| 261 |
> |
|
| 262 |
|
temperature = info->target_temp; |
| 293 |
– |
n_oriented = info->n_oriented; |
| 294 |
– |
n_constraints = info->n_constraints; |
| 263 |
|
|
| 264 |
|
kebar = kb * temperature * (double)info->ndfRaw / |
| 265 |
|
( 2.0 * (double)info->ndf ); |
| 266 |
|
|
| 267 |
< |
for(vr = 0; vr < n_atoms; vr++){ |
| 267 |
> |
for(vr = 0; vr < nobj; vr++){ |
| 268 |
|
|
| 269 |
|
// uses equipartition theory to solve for vbar in angstrom/fs |
| 270 |
|
|
| 271 |
< |
av2 = 2.0 * kebar / atoms[vr]->getMass(); |
| 271 |
> |
av2 = 2.0 * kebar / info->integrableObjects[vr]->getMass(); |
| 272 |
|
vbar = sqrt( av2 ); |
| 273 |
< |
|
| 306 |
< |
// vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() ); |
| 307 |
< |
|
| 273 |
> |
|
| 274 |
|
// picks random velocities from a gaussian distribution |
| 275 |
|
// centered on vbar |
| 276 |
|
|
| 277 |
|
for (j=0; j<3; j++) |
| 278 |
|
aVel[j] = vbar * gaussStream->getGaussian(); |
| 279 |
|
|
| 280 |
< |
atoms[vr]->setVel( aVel ); |
| 280 |
> |
info->integrableObjects[vr]->setVel( aVel ); |
| 281 |
> |
|
| 282 |
> |
if(info->integrableObjects[vr]->isDirectional()){ |
| 283 |
> |
|
| 284 |
> |
info->integrableObjects[vr]->getI( I ); |
| 285 |
> |
|
| 286 |
> |
if (info->integrableObjects[vr]->isLinear()) { |
| 287 |
> |
|
| 288 |
> |
l= info->integrableObjects[vr]->linearAxis(); |
| 289 |
> |
m = (l+1)%3; |
| 290 |
> |
n = (l+2)%3; |
| 291 |
|
|
| 292 |
+ |
aJ[l] = 0.0; |
| 293 |
+ |
vbar = sqrt( 2.0 * kebar * I[m][m] ); |
| 294 |
+ |
aJ[m] = vbar * gaussStream->getGaussian(); |
| 295 |
+ |
vbar = sqrt( 2.0 * kebar * I[n][n] ); |
| 296 |
+ |
aJ[n] = vbar * gaussStream->getGaussian(); |
| 297 |
+ |
|
| 298 |
+ |
} else { |
| 299 |
+ |
for (j = 0 ; j < 3; j++) { |
| 300 |
+ |
vbar = sqrt( 2.0 * kebar * I[j][j] ); |
| 301 |
+ |
aJ[j] = vbar * gaussStream->getGaussian(); |
| 302 |
+ |
} |
| 303 |
+ |
} // else isLinear |
| 304 |
+ |
|
| 305 |
+ |
info->integrableObjects[vr]->setJ( aJ ); |
| 306 |
+ |
|
| 307 |
+ |
}//isDirectional |
| 308 |
+ |
|
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
// Get the Center of Mass drift velocity. |
| 315 |
|
// Corrects for the center of mass drift. |
| 316 |
|
// sums all the momentum and divides by total mass. |
| 317 |
|
|
| 318 |
< |
for(vd = 0; vd < n_atoms; vd++){ |
| 318 |
> |
for(vd = 0; vd < nobj; vd++){ |
| 319 |
|
|
| 320 |
< |
atoms[vd]->getVel(aVel); |
| 320 |
> |
info->integrableObjects[vd]->getVel(aVel); |
| 321 |
|
|
| 322 |
|
for (j=0; j < 3; j++) |
| 323 |
|
aVel[j] -= vdrift[j]; |
| 324 |
|
|
| 325 |
< |
atoms[vd]->setVel( aVel ); |
| 325 |
> |
info->integrableObjects[vd]->setVel( aVel ); |
| 326 |
|
} |
| 334 |
– |
if( n_oriented ){ |
| 335 |
– |
|
| 336 |
– |
for( i=0; i<n_atoms; i++ ){ |
| 337 |
– |
|
| 338 |
– |
if( atoms[i]->isDirectional() ){ |
| 339 |
– |
|
| 340 |
– |
dAtom = (DirectionalAtom *)atoms[i]; |
| 341 |
– |
dAtom->getI( I ); |
| 342 |
– |
|
| 343 |
– |
for (j = 0 ; j < 3; j++) { |
| 327 |
|
|
| 345 |
– |
vbar = sqrt( 2.0 * kebar * I[j][j] ); |
| 346 |
– |
aJ[j] = vbar * gaussStream->getGaussian(); |
| 347 |
– |
|
| 348 |
– |
} |
| 349 |
– |
|
| 350 |
– |
dAtom->setJ( aJ ); |
| 351 |
– |
|
| 352 |
– |
} |
| 353 |
– |
} |
| 354 |
– |
} |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
void Thermo::getCOMVel(double vdrift[3]){ |
| 332 |
|
double mtot, mtot_local; |
| 333 |
|
double aVel[3], amass; |
| 334 |
|
double vdrift_local[3]; |
| 335 |
< |
int vd, n_atoms, j; |
| 336 |
< |
Atom** atoms; |
| 335 |
> |
int vd, j; |
| 336 |
> |
int nobj; |
| 337 |
|
|
| 338 |
< |
// We are very careless here with the distinction between n_atoms and n_local |
| 366 |
< |
// We should really fix this before someone pokes an eye out. |
| 338 |
> |
nobj = info->integrableObjects.size(); |
| 339 |
|
|
| 368 |
– |
n_atoms = info->n_atoms; |
| 369 |
– |
atoms = info->atoms; |
| 370 |
– |
|
| 340 |
|
mtot_local = 0.0; |
| 341 |
|
vdrift_local[0] = 0.0; |
| 342 |
|
vdrift_local[1] = 0.0; |
| 343 |
|
vdrift_local[2] = 0.0; |
| 344 |
|
|
| 345 |
< |
for(vd = 0; vd < n_atoms; vd++){ |
| 345 |
> |
for(vd = 0; vd < nobj; vd++){ |
| 346 |
|
|
| 347 |
< |
amass = atoms[vd]->getMass(); |
| 348 |
< |
atoms[vd]->getVel( aVel ); |
| 347 |
> |
amass = info->integrableObjects[vd]->getMass(); |
| 348 |
> |
info->integrableObjects[vd]->getVel( aVel ); |
| 349 |
|
|
| 350 |
|
for(j = 0; j < 3; j++) |
| 351 |
|
vdrift_local[j] += aVel[j] * amass; |
| 374 |
|
double mtot, mtot_local; |
| 375 |
|
double aPos[3], amass; |
| 376 |
|
double COM_local[3]; |
| 377 |
< |
int i, n_atoms, j; |
| 378 |
< |
Atom** atoms; |
| 377 |
> |
int i, j; |
| 378 |
> |
int nobj; |
| 379 |
|
|
| 411 |
– |
// We are very careless here with the distinction between n_atoms and n_local |
| 412 |
– |
// We should really fix this before someone pokes an eye out. |
| 413 |
– |
|
| 414 |
– |
n_atoms = info->n_atoms; |
| 415 |
– |
atoms = info->atoms; |
| 416 |
– |
|
| 380 |
|
mtot_local = 0.0; |
| 381 |
|
COM_local[0] = 0.0; |
| 382 |
|
COM_local[1] = 0.0; |
| 383 |
|
COM_local[2] = 0.0; |
| 384 |
< |
|
| 385 |
< |
for(i = 0; i < n_atoms; i++){ |
| 384 |
> |
|
| 385 |
> |
nobj = info->integrableObjects.size(); |
| 386 |
> |
for(i = 0; i < nobj; i++){ |
| 387 |
|
|
| 388 |
< |
amass = atoms[i]->getMass(); |
| 389 |
< |
atoms[i]->getPos( aPos ); |
| 388 |
> |
amass = info->integrableObjects[i]->getMass(); |
| 389 |
> |
info->integrableObjects[i]->getPos( aPos ); |
| 390 |
|
|
| 391 |
|
for(j = 0; j < 3; j++) |
| 392 |
|
COM_local[j] += aPos[j] * amass; |
| 408 |
|
COM[i] = COM[i] / mtot; |
| 409 |
|
} |
| 410 |
|
} |
| 411 |
+ |
|
| 412 |
+ |
void Thermo::removeCOMdrift() { |
| 413 |
+ |
double vdrift[3], aVel[3]; |
| 414 |
+ |
int vd, j, nobj; |
| 415 |
+ |
|
| 416 |
+ |
nobj = info->integrableObjects.size(); |
| 417 |
+ |
|
| 418 |
+ |
// Get the Center of Mass drift velocity. |
| 419 |
+ |
|
| 420 |
+ |
getCOMVel(vdrift); |
| 421 |
+ |
|
| 422 |
+ |
// Corrects for the center of mass drift. |
| 423 |
+ |
// sums all the momentum and divides by total mass. |
| 424 |
+ |
|
| 425 |
+ |
for(vd = 0; vd < nobj; vd++){ |
| 426 |
+ |
|
| 427 |
+ |
info->integrableObjects[vd]->getVel(aVel); |
| 428 |
+ |
|
| 429 |
+ |
for (j=0; j < 3; j++) |
| 430 |
+ |
aVel[j] -= vdrift[j]; |
| 431 |
+ |
|
| 432 |
+ |
info->integrableObjects[vd]->setVel( aVel ); |
| 433 |
+ |
} |
| 434 |
+ |
} |