10 |
|
#include "Thermo.hpp" |
11 |
|
#include "SRI.hpp" |
12 |
|
#include "Integrator.hpp" |
13 |
+ |
#include "simError.h" |
14 |
|
|
15 |
+ |
#ifdef IS_MPI |
16 |
+ |
#define __C |
17 |
+ |
#include "mpiSimulation.hpp" |
18 |
+ |
#endif // is_mpi |
19 |
+ |
|
20 |
+ |
|
21 |
|
#define BASE_SEED 123456789 |
22 |
|
|
23 |
|
Thermo::Thermo( SimInfo* the_entry_plug ) { |
84 |
|
|
85 |
|
double Thermo::getPotential(){ |
86 |
|
|
87 |
+ |
double potential_local; |
88 |
|
double potential; |
81 |
– |
double potential_global; |
89 |
|
int el, nSRI; |
90 |
< |
SRI** sris; |
90 |
> |
Molecule* molecules; |
91 |
|
|
92 |
< |
sris = entry_plug->sr_interactions; |
92 |
> |
molecules = entry_plug->molecules; |
93 |
|
nSRI = entry_plug->n_SRI; |
94 |
|
|
95 |
+ |
potential_local = 0.0; |
96 |
|
potential = 0.0; |
97 |
< |
potential_global = 0.0; |
90 |
< |
potential += entry_plug->lrPot; |
97 |
> |
potential_local += entry_plug->lrPot; |
98 |
|
|
99 |
< |
for( el=0; el<nSRI; el++ ){ |
100 |
< |
|
94 |
< |
potential += sris[el]->get_potential(); |
99 |
> |
for( el=0; el<entry_plug->n_mol; el++ ){ |
100 |
> |
potential_local += molecules[el].getPotential(); |
101 |
|
} |
102 |
|
|
103 |
+ |
#ifdef IS_MPI |
104 |
+ |
/* |
105 |
+ |
std::cerr << "node " << worldRank << ": before LONG RANGE pot = " << entry_plug->lrPot |
106 |
+ |
<< "; pot_local = " << potential_local |
107 |
+ |
<< "; pot = " << potential << "\n"; |
108 |
+ |
*/ |
109 |
+ |
#endif |
110 |
+ |
|
111 |
|
// Get total potential for entire system from MPI. |
112 |
|
#ifdef IS_MPI |
113 |
< |
MPI::COMM_WORLD.Allreduce(&potential,&potential_global,1,MPI_DOUBLE,MPI_SUM); |
114 |
< |
potential = potential_global; |
115 |
< |
|
113 |
> |
MPI::COMM_WORLD.Allreduce(&potential_local,&potential,1,MPI_DOUBLE,MPI_SUM); |
114 |
> |
#else |
115 |
> |
potential = potential_local; |
116 |
|
#endif // is_mpi |
117 |
|
|
118 |
+ |
#ifdef IS_MPI |
119 |
+ |
/* |
120 |
+ |
std::cerr << "node " << worldRank << ": after pot = " << potential << "\n"; |
121 |
+ |
*/ |
122 |
+ |
#endif |
123 |
+ |
|
124 |
|
return potential; |
125 |
|
} |
126 |
|
|
136 |
|
|
137 |
|
const double kb = 1.9872179E-3; // boltzman's constant in kcal/(mol K) |
138 |
|
double temperature; |
139 |
+ |
int ndf_local, ndf; |
140 |
|
|
141 |
< |
int ndf = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented |
142 |
< |
- entry_plug->n_constraints - 3; |
141 |
> |
ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented |
142 |
> |
- entry_plug->n_constraints; |
143 |
|
|
144 |
+ |
#ifdef IS_MPI |
145 |
+ |
MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM); |
146 |
+ |
#else |
147 |
+ |
ndf = ndf_local; |
148 |
+ |
#endif |
149 |
+ |
|
150 |
+ |
ndf = ndf - 3; |
151 |
+ |
|
152 |
|
temperature = ( 2.0 * this->getKinetic() ) / ( ndf * kb ); |
153 |
|
return temperature; |
154 |
|
} |
169 |
|
double jx, jy, jz; |
170 |
|
int i, vr, vd; // velocity randomizer loop counters |
171 |
|
double vdrift[3]; |
143 |
– |
double mtot = 0.0; |
172 |
|
double vbar; |
173 |
|
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
174 |
|
double av2; |
175 |
|
double kebar; |
176 |
< |
int ndf; // number of degrees of freedom |
177 |
< |
int ndfRaw; // the raw number of degrees of freedom |
176 |
> |
int ndf, ndf_local; // number of degrees of freedom |
177 |
> |
int ndfRaw, ndfRaw_local; // the raw number of degrees of freedom |
178 |
|
int n_atoms; |
179 |
|
Atom** atoms; |
180 |
|
DirectionalAtom* dAtom; |
188 |
|
n_oriented = entry_plug->n_oriented; |
189 |
|
n_constraints = entry_plug->n_constraints; |
190 |
|
|
191 |
+ |
// Raw degrees of freedom that we have to set |
192 |
+ |
ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented; |
193 |
|
|
194 |
< |
ndfRaw = 3 * n_atoms + 3 * n_oriented; |
195 |
< |
ndf = ndfRaw - n_constraints - 3; |
194 |
> |
// Degrees of freedom that can contain kinetic energy |
195 |
> |
ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented |
196 |
> |
- entry_plug->n_constraints; |
197 |
> |
|
198 |
> |
#ifdef IS_MPI |
199 |
> |
MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM); |
200 |
> |
MPI::COMM_WORLD.Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM); |
201 |
> |
#else |
202 |
> |
ndfRaw = ndfRaw_local; |
203 |
> |
ndf = ndf_local; |
204 |
> |
#endif |
205 |
> |
ndf = ndf - 3; |
206 |
> |
|
207 |
|
kebar = kb * temperature * (double)ndf / ( 2.0 * (double)ndfRaw ); |
208 |
|
|
209 |
|
for(vr = 0; vr < n_atoms; vr++){ |
226 |
|
atoms[vr]->set_vy( vy ); |
227 |
|
atoms[vr]->set_vz( vz ); |
228 |
|
} |
229 |
+ |
|
230 |
+ |
// Get the Center of Mass drift velocity. |
231 |
+ |
|
232 |
+ |
getCOMVel(vdrift); |
233 |
|
|
234 |
|
// Corrects for the center of mass drift. |
235 |
|
// sums all the momentum and divides by total mass. |
191 |
– |
|
192 |
– |
mtot = 0.0; |
193 |
– |
vdrift[0] = 0.0; |
194 |
– |
vdrift[1] = 0.0; |
195 |
– |
vdrift[2] = 0.0; |
196 |
– |
for(vd = 0; vd < n_atoms; vd++){ |
197 |
– |
|
198 |
– |
vdrift[0] += atoms[vd]->get_vx() * atoms[vd]->getMass(); |
199 |
– |
vdrift[1] += atoms[vd]->get_vy() * atoms[vd]->getMass(); |
200 |
– |
vdrift[2] += atoms[vd]->get_vz() * atoms[vd]->getMass(); |
201 |
– |
|
202 |
– |
mtot += atoms[vd]->getMass(); |
203 |
– |
} |
204 |
– |
|
205 |
– |
for (vd = 0; vd < 3; vd++) { |
206 |
– |
vdrift[vd] = vdrift[vd] / mtot; |
207 |
– |
} |
208 |
– |
|
236 |
|
|
237 |
|
for(vd = 0; vd < n_atoms; vd++){ |
238 |
|
|
239 |
|
vx = atoms[vd]->get_vx(); |
240 |
|
vy = atoms[vd]->get_vy(); |
241 |
|
vz = atoms[vd]->get_vz(); |
242 |
< |
|
216 |
< |
|
242 |
> |
|
243 |
|
vx -= vdrift[0]; |
244 |
|
vy -= vdrift[1]; |
245 |
|
vz -= vdrift[2]; |
272 |
|
} |
273 |
|
} |
274 |
|
} |
275 |
+ |
|
276 |
+ |
void Thermo::getCOMVel(double vdrift[3]){ |
277 |
+ |
|
278 |
+ |
double mtot, mtot_local; |
279 |
+ |
double vdrift_local[3]; |
280 |
+ |
int vd, n_atoms; |
281 |
+ |
Atom** atoms; |
282 |
+ |
|
283 |
+ |
// We are very careless here with the distinction between n_atoms and n_local |
284 |
+ |
// We should really fix this before someone pokes an eye out. |
285 |
+ |
|
286 |
+ |
n_atoms = entry_plug->n_atoms; |
287 |
+ |
atoms = entry_plug->atoms; |
288 |
+ |
|
289 |
+ |
mtot_local = 0.0; |
290 |
+ |
vdrift_local[0] = 0.0; |
291 |
+ |
vdrift_local[1] = 0.0; |
292 |
+ |
vdrift_local[2] = 0.0; |
293 |
+ |
|
294 |
+ |
for(vd = 0; vd < n_atoms; vd++){ |
295 |
+ |
|
296 |
+ |
vdrift_local[0] += atoms[vd]->get_vx() * atoms[vd]->getMass(); |
297 |
+ |
vdrift_local[1] += atoms[vd]->get_vy() * atoms[vd]->getMass(); |
298 |
+ |
vdrift_local[2] += atoms[vd]->get_vz() * atoms[vd]->getMass(); |
299 |
+ |
|
300 |
+ |
mtot_local += atoms[vd]->getMass(); |
301 |
+ |
} |
302 |
+ |
|
303 |
+ |
#ifdef IS_MPI |
304 |
+ |
MPI::COMM_WORLD.Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM); |
305 |
+ |
MPI::COMM_WORLD.Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM); |
306 |
+ |
#else |
307 |
+ |
mtot = mtot_local; |
308 |
+ |
for(vd = 0; vd < 3; vd++) { |
309 |
+ |
vdrift[vd] = vdrift_local[vd]; |
310 |
+ |
} |
311 |
+ |
#endif |
312 |
+ |
|
313 |
+ |
for (vd = 0; vd < 3; vd++) { |
314 |
+ |
vdrift[vd] = vdrift[vd] / mtot; |
315 |
+ |
} |
316 |
+ |
|
317 |
+ |
} |
318 |
+ |
|