| 1 |
|
#include <cmath> |
| 2 |
|
|
| 3 |
+ |
#ifdef IS_MPI |
| 4 |
+ |
#include <mpi++.h> |
| 5 |
+ |
#endif //is_mpi |
| 6 |
+ |
|
| 7 |
|
#include "Thermo.hpp" |
| 8 |
|
#include "SRI.hpp" |
| 9 |
|
#include "LRI.hpp" |
| 10 |
|
#include "Integrator.hpp" |
| 11 |
|
|
| 12 |
+ |
#define BASE_SEED 123456789 |
| 13 |
|
|
| 14 |
+ |
Thermo::Thermo( SimInfo* the_entry_plug ) { |
| 15 |
+ |
entry_plug = the_entry_plug; |
| 16 |
+ |
int baseSeed = BASE_SEED; |
| 17 |
+ |
gaussStream = new gaussianSPRNG( baseSeed ); |
| 18 |
+ |
} |
| 19 |
+ |
|
| 20 |
+ |
Thermo::~Thermo(){ |
| 21 |
+ |
delete gaussStream; |
| 22 |
+ |
} |
| 23 |
+ |
|
| 24 |
|
double Thermo::getKinetic(){ |
| 25 |
|
|
| 26 |
|
const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 |
| 32 |
|
DirectionalAtom *dAtom; |
| 33 |
|
|
| 34 |
|
int n_atoms; |
| 35 |
+ |
double kinetic_global; |
| 36 |
|
Atom** atoms; |
| 37 |
+ |
|
| 38 |
|
|
| 39 |
|
n_atoms = entry_plug->n_atoms; |
| 40 |
|
atoms = entry_plug->atoms; |
| 41 |
|
|
| 42 |
|
kinetic = 0.0; |
| 43 |
+ |
kinetic_global = 0.0; |
| 44 |
|
for( kl=0; kl < n_atoms; kl++ ){ |
| 45 |
|
|
| 46 |
|
vx2 = atoms[kl]->get_vx() * atoms[kl]->get_vx(); |
| 62 |
|
+ (jz2 / dAtom->getIzz()); |
| 63 |
|
} |
| 64 |
|
} |
| 65 |
< |
|
| 65 |
> |
#ifdef IS_MPI |
| 66 |
> |
MPI_COMM_WORLD.Allreduce(&kinetic,&kinetic_global,1,MPI_DOUBLE,MPI_SUM); |
| 67 |
> |
kinetic = kinetic_global; |
| 68 |
> |
#endif //is_mpi |
| 69 |
> |
|
| 70 |
|
kinetic = kinetic * 0.5 / e_convert; |
| 71 |
|
|
| 72 |
|
return kinetic; |
| 75 |
|
double Thermo::getPotential(){ |
| 76 |
|
|
| 77 |
|
double potential; |
| 78 |
+ |
double potential_global; |
| 79 |
|
int el, nSRI; |
| 80 |
|
SRI** sris; |
| 81 |
|
|
| 83 |
|
nSRI = entry_plug->n_SRI; |
| 84 |
|
|
| 85 |
|
potential = 0.0; |
| 86 |
+ |
potential_global = 0.0; |
| 87 |
+ |
potential += entry_plug->lrPot; |
| 88 |
|
|
| 64 |
– |
potential += entry_plug->longRange->get_potential();; |
| 65 |
– |
|
| 89 |
|
// std::cerr << "long range potential: " << potential << "\n"; |
| 67 |
– |
|
| 90 |
|
for( el=0; el<nSRI; el++ ){ |
| 91 |
|
|
| 92 |
|
potential += sris[el]->get_potential(); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
+ |
// Get total potential for entire system from MPI. |
| 96 |
+ |
#ifdef IS_MPI |
| 97 |
+ |
MPI_COMM_WORLD.Allreduce(&potential,&potential_global,1,MPI_DOUBLE,MPI_SUM); |
| 98 |
+ |
potential = potential_global; |
| 99 |
+ |
#endif // is_mpi |
| 100 |
+ |
|
| 101 |
|
return potential; |
| 102 |
|
} |
| 103 |
|
|
| 123 |
|
|
| 124 |
|
double Thermo::getPressure(){ |
| 125 |
|
|
| 126 |
< |
const double conv_Pa_atm = 9.901E-6; // convert Pa -> atm |
| 127 |
< |
const double conv_internal_Pa = 1.661E-7; //convert amu/(fs^2 A) -> Pa |
| 128 |
< |
const double conv_A_m = 1.0E-10; //convert A -> m |
| 126 |
> |
// const double conv_Pa_atm = 9.901E-6; // convert Pa -> atm |
| 127 |
> |
// const double conv_internal_Pa = 1.661E-7; //convert amu/(fs^2 A) -> Pa |
| 128 |
> |
// const double conv_A_m = 1.0E-10; //convert A -> m |
| 129 |
|
|
| 130 |
|
return 0.0; |
| 131 |
|
} |
| 173 |
|
|
| 174 |
|
// picks random velocities from a gaussian distribution |
| 175 |
|
// centered on vbar |
| 176 |
< |
|
| 176 |
> |
#ifndef USE_SPRNG |
| 177 |
> |
/* If we are using mpi, we need to use the SPRNG random |
| 178 |
> |
generator. The non drand48 generator will just repeat |
| 179 |
> |
the same numbers for every node creating a non-gaussian |
| 180 |
> |
distribution for the simulation. drand48 is fine for the |
| 181 |
> |
single processor version of the code, but SPRNG should |
| 182 |
> |
still be preferred for consistency. |
| 183 |
> |
*/ |
| 184 |
> |
|
| 185 |
> |
#ifdef IS_MPI |
| 186 |
> |
#error "SPRNG random number generator must be used for MPI" |
| 187 |
> |
#else |
| 188 |
> |
#warning "Using drand48 for random number generation" |
| 189 |
> |
#endif // is_mpi |
| 190 |
> |
|
| 191 |
|
x = drand48(); |
| 192 |
|
y = drand48(); |
| 193 |
|
vx = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y); |
| 199 |
|
x = drand48(); |
| 200 |
|
y = drand48(); |
| 201 |
|
vz = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y); |
| 202 |
< |
|
| 202 |
> |
#endif // use_spring |
| 203 |
> |
|
| 204 |
> |
#ifdef USE_SPRNG |
| 205 |
> |
vx = vbar * gaussStream->getGaussian(); |
| 206 |
> |
vy = vbar * gaussStream->getGaussian(); |
| 207 |
> |
vz = vbar * gaussStream->getGaussian(); |
| 208 |
> |
#endif // use_spring |
| 209 |
> |
|
| 210 |
|
atoms[vr]->set_vx( vx ); |
| 211 |
|
atoms[vr]->set_vy( vy ); |
| 212 |
|
atoms[vr]->set_vz( vz ); |
| 254 |
|
if( atoms[i]->isDirectional() ){ |
| 255 |
|
|
| 256 |
|
dAtom = (DirectionalAtom *)atoms[i]; |
| 257 |
+ |
|
| 258 |
+ |
#ifndef USE_SPRNG |
| 259 |
+ |
|
| 260 |
+ |
#ifdef IS_MPI |
| 261 |
+ |
#error "SPRNG random number generator must be used for MPI" |
| 262 |
+ |
#else // is_mpi |
| 263 |
+ |
#warning "Using drand48 for random number generation" |
| 264 |
+ |
#endif // is_MPI |
| 265 |
|
|
| 266 |
|
vbar = sqrt( 2.0 * kebar * dAtom->getIxx() ); |
| 267 |
|
x = drand48(); |
| 277 |
|
x = drand48(); |
| 278 |
|
y = drand48(); |
| 279 |
|
jz = vbar * sqrt( -2.0 * log(x)) * cos(2 * M_PI * y); |
| 280 |
+ |
|
| 281 |
+ |
#else //use_sprng |
| 282 |
+ |
|
| 283 |
+ |
vbar = sqrt( 2.0 * kebar * dAtom->getIxx() ); |
| 284 |
+ |
jx = vbar * gaussStream->getGaussian(); |
| 285 |
+ |
|
| 286 |
+ |
vbar = sqrt( 2.0 * kebar * dAtom->getIyy() ); |
| 287 |
+ |
jy = vbar * gaussStream->getGaussian(); |
| 288 |
+ |
|
| 289 |
+ |
vbar = sqrt( 2.0 * kebar * dAtom->getIzz() ); |
| 290 |
+ |
jz = vbar * gaussStream->getGaussian(); |
| 291 |
+ |
#endif //use_sprng |
| 292 |
|
|
| 293 |
|
dAtom->setJx( jx ); |
| 294 |
|
dAtom->setJy( jy ); |