| 1 |
< |
#include <cmath> |
| 1 |
> |
#include <math.h> |
| 2 |
|
#include <iostream> |
| 3 |
|
using namespace std; |
| 4 |
|
|
| 16 |
|
#include "mpiSimulation.hpp" |
| 17 |
|
#endif // is_mpi |
| 18 |
|
|
| 19 |
< |
|
| 20 |
< |
#define BASE_SEED 123456789 |
| 21 |
< |
|
| 22 |
< |
Thermo::Thermo( SimInfo* the_entry_plug ) { |
| 23 |
< |
entry_plug = the_entry_plug; |
| 24 |
< |
int baseSeed = BASE_SEED; |
| 19 |
> |
Thermo::Thermo( SimInfo* the_info ) { |
| 20 |
> |
info = the_info; |
| 21 |
> |
int baseSeed = the_info->getSeed(); |
| 22 |
|
|
| 23 |
|
gaussStream = new gaussianSPRNG( baseSeed ); |
| 24 |
|
} |
| 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 |
|
|
| 41 |
– |
DirectionalAtom *dAtom; |
| 42 |
– |
|
| 43 |
– |
int n_atoms; |
| 38 |
|
double kinetic_global; |
| 39 |
< |
Atom** atoms; |
| 46 |
< |
|
| 39 |
> |
vector<StuntDouble *> integrableObjects = info->integrableObjects; |
| 40 |
|
|
| 48 |
– |
n_atoms = entry_plug->n_atoms; |
| 49 |
– |
atoms = entry_plug->atoms; |
| 50 |
– |
|
| 41 |
|
kinetic = 0.0; |
| 42 |
|
kinetic_global = 0.0; |
| 53 |
– |
for( kl=0; kl < n_atoms; kl++ ){ |
| 54 |
– |
|
| 55 |
– |
atoms[kl]->getVel(aVel); |
| 56 |
– |
amass = atoms[kl]->getMass(); |
| 57 |
– |
|
| 58 |
– |
for (j=0; j < 3; j++) |
| 59 |
– |
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 |
< |
|
| 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 |
| 82 |
|
int el, nSRI; |
| 83 |
|
Molecule* molecules; |
| 84 |
|
|
| 85 |
< |
molecules = entry_plug->molecules; |
| 86 |
< |
nSRI = entry_plug->n_SRI; |
| 85 |
> |
molecules = info->molecules; |
| 86 |
> |
nSRI = info->n_SRI; |
| 87 |
|
|
| 88 |
|
potential_local = 0.0; |
| 89 |
|
potential = 0.0; |
| 90 |
< |
potential_local += entry_plug->lrPot; |
| 90 |
> |
potential_local += info->lrPot; |
| 91 |
|
|
| 92 |
< |
for( el=0; el<entry_plug->n_mol; el++ ){ |
| 92 |
> |
for( el=0; el<info->n_mol; el++ ){ |
| 93 |
|
potential_local += molecules[el].getPotential(); |
| 94 |
|
} |
| 95 |
|
|
| 101 |
|
potential = potential_local; |
| 102 |
|
#endif // is_mpi |
| 103 |
|
|
| 110 |
– |
#ifdef IS_MPI |
| 111 |
– |
/* |
| 112 |
– |
std::cerr << "node " << worldRank << ": after pot = " << potential << "\n"; |
| 113 |
– |
*/ |
| 114 |
– |
#endif |
| 115 |
– |
|
| 104 |
|
return potential; |
| 105 |
|
} |
| 106 |
|
|
| 114 |
|
|
| 115 |
|
double Thermo::getTemperature(){ |
| 116 |
|
|
| 117 |
< |
const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) |
| 117 |
> |
const double kb = 1.9872156E-3; // boltzman's constant in kcal/(mol K) |
| 118 |
|
double temperature; |
| 119 |
< |
|
| 120 |
< |
temperature = ( 2.0 * this->getKinetic() ) / ((double)entry_plug->ndf * kb ); |
| 119 |
> |
|
| 120 |
> |
temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb ); |
| 121 |
|
return temperature; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
< |
double Thermo::getEnthalpy() { |
| 124 |
> |
double Thermo::getVolume() { |
| 125 |
|
|
| 126 |
< |
const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 |
| 127 |
< |
double u, p, v; |
| 140 |
< |
double press[3][3]; |
| 126 |
> |
return info->boxVol; |
| 127 |
> |
} |
| 128 |
|
|
| 129 |
< |
u = this->getTotalE(); |
| 129 |
> |
double Thermo::getPressure() { |
| 130 |
|
|
| 131 |
+ |
// Relies on the calculation of the full molecular pressure tensor |
| 132 |
+ |
|
| 133 |
+ |
const double p_convert = 1.63882576e8; |
| 134 |
+ |
double press[3][3]; |
| 135 |
+ |
double pressure; |
| 136 |
+ |
|
| 137 |
|
this->getPressureTensor(press); |
| 145 |
– |
p = (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
| 138 |
|
|
| 139 |
< |
v = this->getVolume(); |
| 139 |
> |
pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
| 140 |
|
|
| 141 |
< |
return (u + (p*v)/e_convert); |
| 141 |
> |
return pressure; |
| 142 |
|
} |
| 143 |
|
|
| 144 |
< |
double Thermo::getVolume() { |
| 144 |
> |
double Thermo::getPressureX() { |
| 145 |
|
|
| 146 |
< |
return entry_plug->boxVol; |
| 146 |
> |
// Relies on the calculation of the full molecular pressure tensor |
| 147 |
> |
|
| 148 |
> |
const double p_convert = 1.63882576e8; |
| 149 |
> |
double press[3][3]; |
| 150 |
> |
double pressureX; |
| 151 |
> |
|
| 152 |
> |
this->getPressureTensor(press); |
| 153 |
> |
|
| 154 |
> |
pressureX = p_convert * press[0][0]; |
| 155 |
> |
|
| 156 |
> |
return pressureX; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
< |
double Thermo::getPressure() { |
| 159 |
> |
double Thermo::getPressureY() { |
| 160 |
|
|
| 161 |
|
// Relies on the calculation of the full molecular pressure tensor |
| 162 |
|
|
| 163 |
|
const double p_convert = 1.63882576e8; |
| 164 |
|
double press[3][3]; |
| 165 |
< |
double pressure; |
| 165 |
> |
double pressureY; |
| 166 |
|
|
| 167 |
|
this->getPressureTensor(press); |
| 168 |
|
|
| 169 |
< |
pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
| 169 |
> |
pressureY = p_convert * press[1][1]; |
| 170 |
|
|
| 171 |
< |
return pressure; |
| 171 |
> |
return pressureY; |
| 172 |
|
} |
| 173 |
|
|
| 174 |
+ |
double Thermo::getPressureZ() { |
| 175 |
|
|
| 176 |
+ |
// Relies on the calculation of the full molecular pressure tensor |
| 177 |
+ |
|
| 178 |
+ |
const double p_convert = 1.63882576e8; |
| 179 |
+ |
double press[3][3]; |
| 180 |
+ |
double pressureZ; |
| 181 |
+ |
|
| 182 |
+ |
this->getPressureTensor(press); |
| 183 |
+ |
|
| 184 |
+ |
pressureZ = p_convert * press[2][2]; |
| 185 |
+ |
|
| 186 |
+ |
return pressureZ; |
| 187 |
+ |
} |
| 188 |
+ |
|
| 189 |
+ |
|
| 190 |
|
void Thermo::getPressureTensor(double press[3][3]){ |
| 191 |
|
// returns pressure tensor in units amu*fs^-2*Ang^-1 |
| 192 |
|
// routine derived via viral theorem description in: |
| 197 |
|
double molmass, volume; |
| 198 |
|
double vcom[3]; |
| 199 |
|
double p_local[9], p_global[9]; |
| 200 |
< |
int i, j, k, l, nMols; |
| 200 |
> |
int i, j, k, nMols; |
| 201 |
|
Molecule* molecules; |
| 202 |
|
|
| 203 |
< |
nMols = entry_plug->n_mol; |
| 204 |
< |
molecules = entry_plug->molecules; |
| 205 |
< |
//tau = entry_plug->tau; |
| 203 |
> |
nMols = info->n_mol; |
| 204 |
> |
molecules = info->molecules; |
| 205 |
> |
//tau = info->tau; |
| 206 |
|
|
| 207 |
|
// use velocities of molecular centers of mass and molecular masses: |
| 208 |
|
for (i=0; i < 9; i++) { |
| 234 |
|
} |
| 235 |
|
#endif // is_mpi |
| 236 |
|
|
| 237 |
< |
volume = entry_plug->boxVol; |
| 237 |
> |
volume = this->getVolume(); |
| 238 |
|
|
| 239 |
|
for(i = 0; i < 3; i++) { |
| 240 |
|
for (j = 0; j < 3; j++) { |
| 241 |
|
k = 3*i + j; |
| 242 |
< |
l = 3*j + i; |
| 243 |
< |
press[i][j] = (p_global[k] - entry_plug->tau[l]*e_convert) / volume; |
| 242 |
> |
press[i][j] = (p_global[k] + info->tau[k]*e_convert) / volume; |
| 243 |
> |
|
| 244 |
|
} |
| 245 |
|
} |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
void Thermo::velocitize() { |
| 249 |
|
|
| 233 |
– |
double x,y; |
| 250 |
|
double aVel[3], aJ[3], I[3][3]; |
| 251 |
|
int i, j, vr, vd; // velocity randomizer loop counters |
| 252 |
|
double vdrift[3]; |
| 261 |
|
int n_oriented; |
| 262 |
|
int n_constraints; |
| 263 |
|
|
| 264 |
< |
atoms = entry_plug->atoms; |
| 265 |
< |
n_atoms = entry_plug->n_atoms; |
| 266 |
< |
temperature = entry_plug->target_temp; |
| 267 |
< |
n_oriented = entry_plug->n_oriented; |
| 268 |
< |
n_constraints = entry_plug->n_constraints; |
| 264 |
> |
atoms = info->atoms; |
| 265 |
> |
n_atoms = info->n_atoms; |
| 266 |
> |
temperature = info->target_temp; |
| 267 |
> |
n_oriented = info->n_oriented; |
| 268 |
> |
n_constraints = info->n_constraints; |
| 269 |
|
|
| 270 |
< |
kebar = kb * temperature * (double)entry_plug->ndf / |
| 271 |
< |
( 2.0 * (double)entry_plug->ndfRaw ); |
| 270 |
> |
kebar = kb * temperature * (double)info->ndfRaw / |
| 271 |
> |
( 2.0 * (double)info->ndf ); |
| 272 |
|
|
| 273 |
|
for(vr = 0; vr < n_atoms; vr++){ |
| 274 |
|
|
| 276 |
|
|
| 277 |
|
av2 = 2.0 * kebar / atoms[vr]->getMass(); |
| 278 |
|
vbar = sqrt( av2 ); |
| 279 |
< |
|
| 264 |
< |
// vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() ); |
| 265 |
< |
|
| 279 |
> |
|
| 280 |
|
// picks random velocities from a gaussian distribution |
| 281 |
|
// centered on vbar |
| 282 |
|
|
| 337 |
|
// We are very careless here with the distinction between n_atoms and n_local |
| 338 |
|
// We should really fix this before someone pokes an eye out. |
| 339 |
|
|
| 340 |
< |
n_atoms = entry_plug->n_atoms; |
| 341 |
< |
atoms = entry_plug->atoms; |
| 340 |
> |
n_atoms = info->n_atoms; |
| 341 |
> |
atoms = info->atoms; |
| 342 |
|
|
| 343 |
|
mtot_local = 0.0; |
| 344 |
|
vdrift_local[0] = 0.0; |
| 372 |
|
|
| 373 |
|
} |
| 374 |
|
|
| 375 |
+ |
void Thermo::getCOM(double COM[3]){ |
| 376 |
+ |
|
| 377 |
+ |
double mtot, mtot_local; |
| 378 |
+ |
double aPos[3], amass; |
| 379 |
+ |
double COM_local[3]; |
| 380 |
+ |
int i, n_atoms, j; |
| 381 |
+ |
Atom** atoms; |
| 382 |
+ |
|
| 383 |
+ |
// We are very careless here with the distinction between n_atoms and n_local |
| 384 |
+ |
// We should really fix this before someone pokes an eye out. |
| 385 |
+ |
|
| 386 |
+ |
n_atoms = info->n_atoms; |
| 387 |
+ |
atoms = info->atoms; |
| 388 |
+ |
|
| 389 |
+ |
mtot_local = 0.0; |
| 390 |
+ |
COM_local[0] = 0.0; |
| 391 |
+ |
COM_local[1] = 0.0; |
| 392 |
+ |
COM_local[2] = 0.0; |
| 393 |
+ |
|
| 394 |
+ |
for(i = 0; i < n_atoms; i++){ |
| 395 |
+ |
|
| 396 |
+ |
amass = atoms[i]->getMass(); |
| 397 |
+ |
atoms[i]->getPos( aPos ); |
| 398 |
+ |
|
| 399 |
+ |
for(j = 0; j < 3; j++) |
| 400 |
+ |
COM_local[j] += aPos[j] * amass; |
| 401 |
+ |
|
| 402 |
+ |
mtot_local += amass; |
| 403 |
+ |
} |
| 404 |
+ |
|
| 405 |
+ |
#ifdef IS_MPI |
| 406 |
+ |
MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
| 407 |
+ |
MPI_Allreduce(COM_local,COM,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
| 408 |
+ |
#else |
| 409 |
+ |
mtot = mtot_local; |
| 410 |
+ |
for(i = 0; i < 3; i++) { |
| 411 |
+ |
COM[i] = COM_local[i]; |
| 412 |
+ |
} |
| 413 |
+ |
#endif |
| 414 |
+ |
|
| 415 |
+ |
for (i = 0; i < 3; i++) { |
| 416 |
+ |
COM[i] = COM[i] / mtot; |
| 417 |
+ |
} |
| 418 |
+ |
} |