| 17 |
|
#include "mpiSimulation.hpp" |
| 18 |
|
#endif // is_mpi |
| 19 |
|
|
| 20 |
+ |
inline double roundMe( double x ){ |
| 21 |
+ |
return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); |
| 22 |
+ |
} |
| 23 |
+ |
|
| 24 |
|
Thermo::Thermo( SimInfo* the_info ) { |
| 25 |
|
info = the_info; |
| 26 |
|
int baseSeed = the_info->getSeed(); |
| 200 |
|
const double e_convert = 4.184e-4; |
| 201 |
|
|
| 202 |
|
double molmass, volume; |
| 203 |
< |
double vcom[3], pcom[3], fcom[3], scaled[3]; |
| 203 |
> |
double vcom[3]; |
| 204 |
|
double p_local[9], p_global[9]; |
| 205 |
< |
int i, j, k, nMols; |
| 202 |
< |
Molecule* molecules; |
| 205 |
> |
int i, j, k; |
| 206 |
|
|
| 204 |
– |
nMols = info->n_mol; |
| 205 |
– |
molecules = info->molecules; |
| 206 |
– |
//tau = info->tau; |
| 207 |
|
|
| 208 |
< |
// use velocities of molecular centers of mass and molecular masses: |
| 208 |
> |
|
| 209 |
|
for (i=0; i < 9; i++) { |
| 210 |
|
p_local[i] = 0.0; |
| 211 |
|
p_global[i] = 0.0; |
| 212 |
|
} |
| 213 |
|
|
| 214 |
+ |
// use velocities of integrableObjects and their masses: |
| 215 |
+ |
|
| 216 |
|
for (i=0; i < info->integrableObjects.size(); i++) { |
| 217 |
|
|
| 218 |
|
molmass = info->integrableObjects[i]->getMass(); |
| 219 |
|
|
| 220 |
|
info->integrableObjects[i]->getVel(vcom); |
| 221 |
< |
info->integrableObjects[i]->getPos(pcom); |
| 222 |
< |
info->integrableObjects[i]->getFrc(fcom); |
| 223 |
< |
|
| 224 |
< |
matVecMul3(info->HmatInv, pcom, scaled); |
| 225 |
< |
|
| 226 |
< |
for(j=0; j<3; j++) |
| 227 |
< |
scaled[j] -= roundMe(scaled[j]); |
| 228 |
< |
|
| 229 |
< |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
| 230 |
< |
|
| 229 |
< |
matVecMul3(info->Hmat, scaled, pcom); |
| 221 |
> |
|
| 222 |
> |
p_local[0] += molmass * (vcom[0] * vcom[0]); |
| 223 |
> |
p_local[1] += molmass * (vcom[0] * vcom[1]); |
| 224 |
> |
p_local[2] += molmass * (vcom[0] * vcom[2]); |
| 225 |
> |
p_local[3] += molmass * (vcom[1] * vcom[0]); |
| 226 |
> |
p_local[4] += molmass * (vcom[1] * vcom[1]); |
| 227 |
> |
p_local[5] += molmass * (vcom[1] * vcom[2]); |
| 228 |
> |
p_local[6] += molmass * (vcom[2] * vcom[0]); |
| 229 |
> |
p_local[7] += molmass * (vcom[2] * vcom[1]); |
| 230 |
> |
p_local[8] += molmass * (vcom[2] * vcom[2]); |
| 231 |
|
|
| 231 |
– |
p_local[0] += molmass * (vcom[0] * vcom[0]) + fcom[0]*pcom[0]*eConvert; |
| 232 |
– |
p_local[1] += molmass * (vcom[0] * vcom[1]) + fcom[0]*pcom[1]*eConvert; |
| 233 |
– |
p_local[2] += molmass * (vcom[0] * vcom[2]) + fcom[0]*pcom[2]*eConvert; |
| 234 |
– |
p_local[3] += molmass * (vcom[1] * vcom[0]) + fcom[1]*pcom[0]*eConvert; |
| 235 |
– |
p_local[4] += molmass * (vcom[1] * vcom[1]) + fcom[1]*pcom[1]*eConvert; |
| 236 |
– |
p_local[5] += molmass * (vcom[1] * vcom[2]) + fcom[1]*pcom[2]*eConvert; |
| 237 |
– |
p_local[6] += molmass * (vcom[2] * vcom[0]) + fcom[2]*pcom[0]*eConvert; |
| 238 |
– |
p_local[7] += molmass * (vcom[2] * vcom[1]) + fcom[2]*pcom[1]*eConvert; |
| 239 |
– |
p_local[8] += molmass * (vcom[2] * vcom[2]) + fcom[2]*pcom[2]*eConvert; |
| 240 |
– |
|
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
// Get total for entire system from MPI. |
| 235 |
< |
|
| 235 |
> |
|
| 236 |
|
#ifdef IS_MPI |
| 237 |
|
MPI_Allreduce(p_local,p_global,9,MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); |
| 238 |
|
#else |
| 246 |
|
for(i = 0; i < 3; i++) { |
| 247 |
|
for (j = 0; j < 3; j++) { |
| 248 |
|
k = 3*i + j; |
| 249 |
< |
press[i][j] = p_global[k] / volume; |
| 259 |
< |
|
| 249 |
> |
press[i][j] = (p_global[k] + info->tau[k]*e_convert) / volume; |
| 250 |
|
} |
| 251 |
|
} |
| 252 |
|
} |
| 437 |
|
|
| 438 |
|
info->integrableObjects[vd]->setVel( aVel ); |
| 439 |
|
} |
| 440 |
< |
} |
| 440 |
> |
} |