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 |
|
} |
30 |
|
double Thermo::getKinetic(){ |
31 |
|
|
32 |
|
const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 |
33 |
< |
double vx2, vy2, vz2; |
34 |
< |
double kinetic, v_sqr; |
35 |
< |
int kl; |
36 |
< |
double jx2, jy2, jz2; // the square of the angular momentums |
33 |
> |
double kinetic; |
34 |
> |
double amass; |
35 |
> |
double aVel[3], aJ[3], I[3][3]; |
36 |
> |
int j, kl; |
37 |
|
|
38 |
|
DirectionalAtom *dAtom; |
39 |
|
|
42 |
|
Atom** atoms; |
43 |
|
|
44 |
|
|
45 |
< |
n_atoms = entry_plug->n_atoms; |
46 |
< |
atoms = entry_plug->atoms; |
45 |
> |
n_atoms = info->n_atoms; |
46 |
> |
atoms = info->atoms; |
47 |
|
|
48 |
|
kinetic = 0.0; |
49 |
|
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]; |
57 |
|
|
55 |
– |
vx2 = atoms[kl]->get_vx() * atoms[kl]->get_vx(); |
56 |
– |
vy2 = atoms[kl]->get_vy() * atoms[kl]->get_vy(); |
57 |
– |
vz2 = atoms[kl]->get_vz() * atoms[kl]->get_vz(); |
58 |
– |
|
59 |
– |
v_sqr = vx2 + vy2 + vz2; |
60 |
– |
kinetic += atoms[kl]->getMass() * v_sqr; |
61 |
– |
|
58 |
|
if( atoms[kl]->isDirectional() ){ |
59 |
|
|
60 |
|
dAtom = (DirectionalAtom *)atoms[kl]; |
61 |
+ |
|
62 |
+ |
dAtom->getJ( aJ ); |
63 |
+ |
dAtom->getI( I ); |
64 |
|
|
65 |
< |
jx2 = dAtom->getJx() * dAtom->getJx(); |
66 |
< |
jy2 = dAtom->getJy() * dAtom->getJy(); |
68 |
< |
jz2 = dAtom->getJz() * dAtom->getJz(); |
65 |
> |
for (j=0; j<3; j++) |
66 |
> |
kinetic += aJ[j]*aJ[j] / I[j][j]; |
67 |
|
|
70 |
– |
kinetic += (jx2 / dAtom->getIxx()) + (jy2 / dAtom->getIyy()) |
71 |
– |
+ (jz2 / dAtom->getIzz()); |
68 |
|
} |
69 |
|
} |
70 |
|
#ifdef IS_MPI |
85 |
|
int el, nSRI; |
86 |
|
Molecule* molecules; |
87 |
|
|
88 |
< |
molecules = entry_plug->molecules; |
89 |
< |
nSRI = entry_plug->n_SRI; |
88 |
> |
molecules = info->molecules; |
89 |
> |
nSRI = info->n_SRI; |
90 |
|
|
91 |
|
potential_local = 0.0; |
92 |
|
potential = 0.0; |
93 |
< |
potential_local += entry_plug->lrPot; |
93 |
> |
potential_local += info->lrPot; |
94 |
|
|
95 |
< |
for( el=0; el<entry_plug->n_mol; el++ ){ |
95 |
> |
for( el=0; el<info->n_mol; el++ ){ |
96 |
|
potential_local += molecules[el].getPotential(); |
97 |
|
} |
98 |
|
|
126 |
|
const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) |
127 |
|
double temperature; |
128 |
|
|
129 |
< |
temperature = ( 2.0 * this->getKinetic() ) / ((double)entry_plug->ndf * kb ); |
129 |
> |
temperature = ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb ); |
130 |
|
return temperature; |
131 |
|
} |
132 |
|
|
148 |
|
|
149 |
|
double Thermo::getVolume() { |
150 |
|
|
151 |
< |
return entry_plug->boxVol; |
151 |
> |
return info->boxVol; |
152 |
|
} |
153 |
|
|
154 |
|
double Thermo::getPressure() { |
177 |
|
double molmass, volume; |
178 |
|
double vcom[3]; |
179 |
|
double p_local[9], p_global[9]; |
180 |
< |
int i, j, k, l, nMols; |
180 |
> |
int i, j, k, nMols; |
181 |
|
Molecule* molecules; |
182 |
|
|
183 |
< |
nMols = entry_plug->n_mol; |
184 |
< |
molecules = entry_plug->molecules; |
185 |
< |
//tau = entry_plug->tau; |
183 |
> |
nMols = info->n_mol; |
184 |
> |
molecules = info->molecules; |
185 |
> |
//tau = info->tau; |
186 |
|
|
187 |
|
// use velocities of molecular centers of mass and molecular masses: |
188 |
|
for (i=0; i < 9; i++) { |
214 |
|
} |
215 |
|
#endif // is_mpi |
216 |
|
|
217 |
< |
volume = entry_plug->boxVol; |
217 |
> |
volume = this->getVolume(); |
218 |
|
|
219 |
|
for(i = 0; i < 3; i++) { |
220 |
|
for (j = 0; j < 3; j++) { |
221 |
|
k = 3*i + j; |
222 |
< |
l = 3*j + i; |
223 |
< |
press[i][j] = (p_global[k] - entry_plug->tau[l]*e_convert) / volume; |
222 |
> |
press[i][j] = (p_global[k] + info->tau[k]*e_convert) / volume; |
223 |
> |
|
224 |
|
} |
225 |
|
} |
226 |
|
} |
228 |
|
void Thermo::velocitize() { |
229 |
|
|
230 |
|
double x,y; |
231 |
< |
double vx, vy, vz; |
232 |
< |
double jx, jy, jz; |
237 |
< |
int i, vr, vd; // velocity randomizer loop counters |
231 |
> |
double aVel[3], aJ[3], I[3][3]; |
232 |
> |
int i, j, vr, vd; // velocity randomizer loop counters |
233 |
|
double vdrift[3]; |
234 |
|
double vbar; |
235 |
|
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
242 |
|
int n_oriented; |
243 |
|
int n_constraints; |
244 |
|
|
245 |
< |
atoms = entry_plug->atoms; |
246 |
< |
n_atoms = entry_plug->n_atoms; |
247 |
< |
temperature = entry_plug->target_temp; |
248 |
< |
n_oriented = entry_plug->n_oriented; |
249 |
< |
n_constraints = entry_plug->n_constraints; |
245 |
> |
atoms = info->atoms; |
246 |
> |
n_atoms = info->n_atoms; |
247 |
> |
temperature = info->target_temp; |
248 |
> |
n_oriented = info->n_oriented; |
249 |
> |
n_constraints = info->n_constraints; |
250 |
|
|
251 |
< |
kebar = kb * temperature * (double)entry_plug->ndf / |
252 |
< |
( 2.0 * (double)entry_plug->ndfRaw ); |
251 |
> |
kebar = kb * temperature * (double)info->ndf / |
252 |
> |
( 2.0 * (double)info->ndfRaw ); |
253 |
|
|
254 |
|
for(vr = 0; vr < n_atoms; vr++){ |
255 |
|
|
263 |
|
// picks random velocities from a gaussian distribution |
264 |
|
// centered on vbar |
265 |
|
|
266 |
< |
vx = vbar * gaussStream->getGaussian(); |
267 |
< |
vy = vbar * gaussStream->getGaussian(); |
268 |
< |
vz = vbar * gaussStream->getGaussian(); |
266 |
> |
for (j=0; j<3; j++) |
267 |
> |
aVel[j] = vbar * gaussStream->getGaussian(); |
268 |
> |
|
269 |
> |
atoms[vr]->setVel( aVel ); |
270 |
|
|
275 |
– |
atoms[vr]->set_vx( vx ); |
276 |
– |
atoms[vr]->set_vy( vy ); |
277 |
– |
atoms[vr]->set_vz( vz ); |
271 |
|
} |
272 |
|
|
273 |
|
// Get the Center of Mass drift velocity. |
279 |
|
|
280 |
|
for(vd = 0; vd < n_atoms; vd++){ |
281 |
|
|
282 |
< |
vx = atoms[vd]->get_vx(); |
290 |
< |
vy = atoms[vd]->get_vy(); |
291 |
< |
vz = atoms[vd]->get_vz(); |
292 |
< |
|
293 |
< |
vx -= vdrift[0]; |
294 |
< |
vy -= vdrift[1]; |
295 |
< |
vz -= vdrift[2]; |
282 |
> |
atoms[vd]->getVel(aVel); |
283 |
|
|
284 |
< |
atoms[vd]->set_vx(vx); |
285 |
< |
atoms[vd]->set_vy(vy); |
286 |
< |
atoms[vd]->set_vz(vz); |
284 |
> |
for (j=0; j < 3; j++) |
285 |
> |
aVel[j] -= vdrift[j]; |
286 |
> |
|
287 |
> |
atoms[vd]->setVel( aVel ); |
288 |
|
} |
289 |
|
if( n_oriented ){ |
290 |
|
|
293 |
|
if( atoms[i]->isDirectional() ){ |
294 |
|
|
295 |
|
dAtom = (DirectionalAtom *)atoms[i]; |
296 |
+ |
dAtom->getI( I ); |
297 |
+ |
|
298 |
+ |
for (j = 0 ; j < 3; j++) { |
299 |
|
|
300 |
< |
vbar = sqrt( 2.0 * kebar * dAtom->getIxx() ); |
301 |
< |
jx = vbar * gaussStream->getGaussian(); |
300 |
> |
vbar = sqrt( 2.0 * kebar * I[j][j] ); |
301 |
> |
aJ[j] = vbar * gaussStream->getGaussian(); |
302 |
|
|
303 |
< |
vbar = sqrt( 2.0 * kebar * dAtom->getIyy() ); |
304 |
< |
jy = vbar * gaussStream->getGaussian(); |
305 |
< |
|
306 |
< |
vbar = sqrt( 2.0 * kebar * dAtom->getIzz() ); |
316 |
< |
jz = vbar * gaussStream->getGaussian(); |
317 |
< |
|
318 |
< |
dAtom->setJx( jx ); |
319 |
< |
dAtom->setJy( jy ); |
320 |
< |
dAtom->setJz( jz ); |
303 |
> |
} |
304 |
> |
|
305 |
> |
dAtom->setJ( aJ ); |
306 |
> |
|
307 |
|
} |
308 |
|
} |
309 |
|
} |
312 |
|
void Thermo::getCOMVel(double vdrift[3]){ |
313 |
|
|
314 |
|
double mtot, mtot_local; |
315 |
+ |
double aVel[3], amass; |
316 |
|
double vdrift_local[3]; |
317 |
< |
int vd, n_atoms; |
317 |
> |
int vd, n_atoms, j; |
318 |
|
Atom** atoms; |
319 |
|
|
320 |
|
// We are very careless here with the distinction between n_atoms and n_local |
321 |
|
// We should really fix this before someone pokes an eye out. |
322 |
|
|
323 |
< |
n_atoms = entry_plug->n_atoms; |
324 |
< |
atoms = entry_plug->atoms; |
323 |
> |
n_atoms = info->n_atoms; |
324 |
> |
atoms = info->atoms; |
325 |
|
|
326 |
|
mtot_local = 0.0; |
327 |
|
vdrift_local[0] = 0.0; |
330 |
|
|
331 |
|
for(vd = 0; vd < n_atoms; vd++){ |
332 |
|
|
333 |
< |
vdrift_local[0] += atoms[vd]->get_vx() * atoms[vd]->getMass(); |
334 |
< |
vdrift_local[1] += atoms[vd]->get_vy() * atoms[vd]->getMass(); |
335 |
< |
vdrift_local[2] += atoms[vd]->get_vz() * atoms[vd]->getMass(); |
333 |
> |
amass = atoms[vd]->getMass(); |
334 |
> |
atoms[vd]->getVel( aVel ); |
335 |
> |
|
336 |
> |
for(j = 0; j < 3; j++) |
337 |
> |
vdrift_local[j] += aVel[j] * amass; |
338 |
|
|
339 |
< |
mtot_local += atoms[vd]->getMass(); |
339 |
> |
mtot_local += amass; |
340 |
|
} |
341 |
|
|
342 |
|
#ifdef IS_MPI |