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 |
|
} |
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; |
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 |
|
|
123 |
|
|
124 |
|
double Thermo::getTemperature(){ |
125 |
|
|
126 |
< |
const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) |
126 |
> |
const double kb = 1.9872156E-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 |
|
|
133 |
< |
double Thermo::getEnthalpy() { |
133 |
> |
double Thermo::getVolume() { |
134 |
|
|
135 |
< |
const double e_convert = 4.184E-4; // convert kcal/mol -> (amu A^2)/fs^2 |
136 |
< |
double u, p, v; |
135 |
> |
return info->boxVol; |
136 |
> |
} |
137 |
> |
|
138 |
> |
double Thermo::getPressure() { |
139 |
> |
|
140 |
> |
// Relies on the calculation of the full molecular pressure tensor |
141 |
> |
|
142 |
> |
const double p_convert = 1.63882576e8; |
143 |
|
double press[3][3]; |
144 |
+ |
double pressure; |
145 |
|
|
146 |
< |
u = this->getTotalE(); |
146 |
> |
this->getPressureTensor(press); |
147 |
|
|
148 |
+ |
pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
149 |
+ |
|
150 |
+ |
return pressure; |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
double Thermo::getPressureX() { |
154 |
+ |
|
155 |
+ |
// Relies on the calculation of the full molecular pressure tensor |
156 |
+ |
|
157 |
+ |
const double p_convert = 1.63882576e8; |
158 |
+ |
double press[3][3]; |
159 |
+ |
double pressureX; |
160 |
+ |
|
161 |
|
this->getPressureTensor(press); |
145 |
– |
p = (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
162 |
|
|
163 |
< |
v = this->getVolume(); |
163 |
> |
pressureX = p_convert * press[0][0]; |
164 |
|
|
165 |
< |
return (u + (p*v)/e_convert); |
165 |
> |
return pressureX; |
166 |
|
} |
167 |
|
|
168 |
< |
double Thermo::getVolume() { |
168 |
> |
double Thermo::getPressureY() { |
169 |
|
|
170 |
< |
return entry_plug->boxVol; |
170 |
> |
// Relies on the calculation of the full molecular pressure tensor |
171 |
> |
|
172 |
> |
const double p_convert = 1.63882576e8; |
173 |
> |
double press[3][3]; |
174 |
> |
double pressureY; |
175 |
> |
|
176 |
> |
this->getPressureTensor(press); |
177 |
> |
|
178 |
> |
pressureY = p_convert * press[1][1]; |
179 |
> |
|
180 |
> |
return pressureY; |
181 |
|
} |
182 |
|
|
183 |
< |
double Thermo::getPressure() { |
183 |
> |
double Thermo::getPressureZ() { |
184 |
|
|
185 |
|
// Relies on the calculation of the full molecular pressure tensor |
186 |
|
|
187 |
|
const double p_convert = 1.63882576e8; |
188 |
|
double press[3][3]; |
189 |
< |
double pressure; |
189 |
> |
double pressureZ; |
190 |
|
|
191 |
|
this->getPressureTensor(press); |
192 |
|
|
193 |
< |
pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
193 |
> |
pressureZ = p_convert * press[2][2]; |
194 |
|
|
195 |
< |
return pressure; |
195 |
> |
return pressureZ; |
196 |
|
} |
197 |
|
|
198 |
|
|
206 |
|
double molmass, volume; |
207 |
|
double vcom[3]; |
208 |
|
double p_local[9], p_global[9]; |
209 |
< |
int i, j, k, l, nMols; |
209 |
> |
int i, j, k, nMols; |
210 |
|
Molecule* molecules; |
211 |
|
|
212 |
< |
nMols = entry_plug->n_mol; |
213 |
< |
molecules = entry_plug->molecules; |
214 |
< |
//tau = entry_plug->tau; |
212 |
> |
nMols = info->n_mol; |
213 |
> |
molecules = info->molecules; |
214 |
> |
//tau = info->tau; |
215 |
|
|
216 |
|
// use velocities of molecular centers of mass and molecular masses: |
217 |
|
for (i=0; i < 9; i++) { |
248 |
|
for(i = 0; i < 3; i++) { |
249 |
|
for (j = 0; j < 3; j++) { |
250 |
|
k = 3*i + j; |
251 |
< |
press[i][j] = (p_global[k] + entry_plug->tau[k]*e_convert) / volume; |
251 |
> |
press[i][j] = (p_global[k] + info->tau[k]*e_convert) / volume; |
252 |
> |
|
253 |
|
} |
254 |
|
} |
255 |
|
} |
256 |
|
|
257 |
|
void Thermo::velocitize() { |
258 |
|
|
232 |
– |
double x,y; |
259 |
|
double aVel[3], aJ[3], I[3][3]; |
260 |
|
int i, j, vr, vd; // velocity randomizer loop counters |
261 |
|
double vdrift[3]; |
270 |
|
int n_oriented; |
271 |
|
int n_constraints; |
272 |
|
|
273 |
< |
atoms = entry_plug->atoms; |
274 |
< |
n_atoms = entry_plug->n_atoms; |
275 |
< |
temperature = entry_plug->target_temp; |
276 |
< |
n_oriented = entry_plug->n_oriented; |
277 |
< |
n_constraints = entry_plug->n_constraints; |
273 |
> |
atoms = info->atoms; |
274 |
> |
n_atoms = info->n_atoms; |
275 |
> |
temperature = info->target_temp; |
276 |
> |
n_oriented = info->n_oriented; |
277 |
> |
n_constraints = info->n_constraints; |
278 |
|
|
279 |
< |
kebar = kb * temperature * (double)entry_plug->ndf / |
280 |
< |
( 2.0 * (double)entry_plug->ndfRaw ); |
279 |
> |
kebar = kb * temperature * (double)info->ndfRaw / |
280 |
> |
( 2.0 * (double)info->ndf ); |
281 |
|
|
282 |
|
for(vr = 0; vr < n_atoms; vr++){ |
283 |
|
|
348 |
|
// We are very careless here with the distinction between n_atoms and n_local |
349 |
|
// We should really fix this before someone pokes an eye out. |
350 |
|
|
351 |
< |
n_atoms = entry_plug->n_atoms; |
352 |
< |
atoms = entry_plug->atoms; |
351 |
> |
n_atoms = info->n_atoms; |
352 |
> |
atoms = info->atoms; |
353 |
|
|
354 |
|
mtot_local = 0.0; |
355 |
|
vdrift_local[0] = 0.0; |
383 |
|
|
384 |
|
} |
385 |
|
|
386 |
+ |
void Thermo::getCOM(double COM[3]){ |
387 |
+ |
|
388 |
+ |
double mtot, mtot_local; |
389 |
+ |
double aPos[3], amass; |
390 |
+ |
double COM_local[3]; |
391 |
+ |
int i, n_atoms, j; |
392 |
+ |
Atom** atoms; |
393 |
+ |
|
394 |
+ |
// We are very careless here with the distinction between n_atoms and n_local |
395 |
+ |
// We should really fix this before someone pokes an eye out. |
396 |
+ |
|
397 |
+ |
n_atoms = info->n_atoms; |
398 |
+ |
atoms = info->atoms; |
399 |
+ |
|
400 |
+ |
mtot_local = 0.0; |
401 |
+ |
COM_local[0] = 0.0; |
402 |
+ |
COM_local[1] = 0.0; |
403 |
+ |
COM_local[2] = 0.0; |
404 |
+ |
|
405 |
+ |
for(i = 0; i < n_atoms; i++){ |
406 |
+ |
|
407 |
+ |
amass = atoms[i]->getMass(); |
408 |
+ |
atoms[i]->getPos( aPos ); |
409 |
+ |
|
410 |
+ |
for(j = 0; j < 3; j++) |
411 |
+ |
COM_local[j] += aPos[j] * amass; |
412 |
+ |
|
413 |
+ |
mtot_local += amass; |
414 |
+ |
} |
415 |
+ |
|
416 |
+ |
#ifdef IS_MPI |
417 |
+ |
MPI_Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
418 |
+ |
MPI_Allreduce(COM_local,COM,3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
419 |
+ |
#else |
420 |
+ |
mtot = mtot_local; |
421 |
+ |
for(i = 0; i < 3; i++) { |
422 |
+ |
COM[i] = COM_local[i]; |
423 |
+ |
} |
424 |
+ |
#endif |
425 |
+ |
|
426 |
+ |
for (i = 0; i < 3; i++) { |
427 |
+ |
COM[i] = COM[i] / mtot; |
428 |
+ |
} |
429 |
+ |
} |