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 |
|
} |
155 |
|
|
156 |
|
double Thermo::getPressure(){ |
157 |
+ |
// returns pressure in units amu*fs^-2*Ang^-1 |
158 |
+ |
// routine derived via viral theorem description in: |
159 |
+ |
// Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 |
160 |
|
|
129 |
– |
// const double conv_Pa_atm = 9.901E-6; // convert Pa -> atm |
130 |
– |
// const double conv_internal_Pa = 1.661E-7; //convert amu/(fs^2 A) -> Pa |
131 |
– |
// const double conv_A_m = 1.0E-10; //convert A -> m |
132 |
– |
|
161 |
|
return 0.0; |
162 |
|
} |
163 |
|
|
168 |
|
double jx, jy, jz; |
169 |
|
int i, vr, vd; // velocity randomizer loop counters |
170 |
|
double vdrift[3]; |
143 |
– |
double mtot = 0.0; |
171 |
|
double vbar; |
172 |
|
const double kb = 8.31451e-7; // kb in amu, angstroms, fs, etc. |
173 |
|
double av2; |
174 |
|
double kebar; |
175 |
< |
int ndf; // number of degrees of freedom |
176 |
< |
int ndfRaw; // the raw number of degrees of freedom |
175 |
> |
int ndf, ndf_local; // number of degrees of freedom |
176 |
> |
int ndfRaw, ndfRaw_local; // the raw number of degrees of freedom |
177 |
|
int n_atoms; |
178 |
|
Atom** atoms; |
179 |
|
DirectionalAtom* dAtom; |
187 |
|
n_oriented = entry_plug->n_oriented; |
188 |
|
n_constraints = entry_plug->n_constraints; |
189 |
|
|
190 |
+ |
// Raw degrees of freedom that we have to set |
191 |
+ |
ndfRaw_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented; |
192 |
|
|
193 |
< |
ndfRaw = 3 * n_atoms + 3 * n_oriented; |
194 |
< |
ndf = ndfRaw - n_constraints - 3; |
193 |
> |
// Degrees of freedom that can contain kinetic energy |
194 |
> |
ndf_local = 3 * entry_plug->n_atoms + 3 * entry_plug->n_oriented |
195 |
> |
- entry_plug->n_constraints; |
196 |
> |
|
197 |
> |
#ifdef IS_MPI |
198 |
> |
MPI::COMM_WORLD.Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM); |
199 |
> |
MPI::COMM_WORLD.Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM); |
200 |
> |
#else |
201 |
> |
ndfRaw = ndfRaw_local; |
202 |
> |
ndf = ndf_local; |
203 |
> |
#endif |
204 |
> |
ndf = ndf - 3; |
205 |
> |
|
206 |
|
kebar = kb * temperature * (double)ndf / ( 2.0 * (double)ndfRaw ); |
207 |
|
|
208 |
|
for(vr = 0; vr < n_atoms; vr++){ |
211 |
|
|
212 |
|
av2 = 2.0 * kebar / atoms[vr]->getMass(); |
213 |
|
vbar = sqrt( av2 ); |
214 |
< |
|
214 |
> |
|
215 |
|
// vbar = sqrt( 8.31451e-7 * temperature / atoms[vr]->getMass() ); |
216 |
|
|
217 |
|
// picks random velocities from a gaussian distribution |
225 |
|
atoms[vr]->set_vy( vy ); |
226 |
|
atoms[vr]->set_vz( vz ); |
227 |
|
} |
228 |
+ |
|
229 |
+ |
// Get the Center of Mass drift velocity. |
230 |
+ |
|
231 |
+ |
getCOMVel(vdrift); |
232 |
|
|
233 |
|
// Corrects for the center of mass drift. |
234 |
|
// 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 |
– |
|
235 |
|
|
236 |
|
for(vd = 0; vd < n_atoms; vd++){ |
237 |
|
|
238 |
|
vx = atoms[vd]->get_vx(); |
239 |
|
vy = atoms[vd]->get_vy(); |
240 |
|
vz = atoms[vd]->get_vz(); |
241 |
< |
|
216 |
< |
|
241 |
> |
|
242 |
|
vx -= vdrift[0]; |
243 |
|
vy -= vdrift[1]; |
244 |
|
vz -= vdrift[2]; |
271 |
|
} |
272 |
|
} |
273 |
|
} |
274 |
+ |
|
275 |
+ |
void Thermo::getCOMVel(double vdrift[3]){ |
276 |
+ |
|
277 |
+ |
double mtot, mtot_local; |
278 |
+ |
double vdrift_local[3]; |
279 |
+ |
int vd, n_atoms; |
280 |
+ |
Atom** atoms; |
281 |
+ |
|
282 |
+ |
// We are very careless here with the distinction between n_atoms and n_local |
283 |
+ |
// We should really fix this before someone pokes an eye out. |
284 |
+ |
|
285 |
+ |
n_atoms = entry_plug->n_atoms; |
286 |
+ |
atoms = entry_plug->atoms; |
287 |
+ |
|
288 |
+ |
mtot_local = 0.0; |
289 |
+ |
vdrift_local[0] = 0.0; |
290 |
+ |
vdrift_local[1] = 0.0; |
291 |
+ |
vdrift_local[2] = 0.0; |
292 |
+ |
|
293 |
+ |
for(vd = 0; vd < n_atoms; vd++){ |
294 |
+ |
|
295 |
+ |
vdrift_local[0] += atoms[vd]->get_vx() * atoms[vd]->getMass(); |
296 |
+ |
vdrift_local[1] += atoms[vd]->get_vy() * atoms[vd]->getMass(); |
297 |
+ |
vdrift_local[2] += atoms[vd]->get_vz() * atoms[vd]->getMass(); |
298 |
+ |
|
299 |
+ |
mtot_local += atoms[vd]->getMass(); |
300 |
+ |
} |
301 |
+ |
|
302 |
+ |
#ifdef IS_MPI |
303 |
+ |
MPI::COMM_WORLD.Allreduce(&mtot_local,&mtot,1,MPI_DOUBLE,MPI_SUM); |
304 |
+ |
MPI::COMM_WORLD.Allreduce(vdrift_local,vdrift,3,MPI_DOUBLE,MPI_SUM); |
305 |
+ |
#else |
306 |
+ |
mtot = mtot_local; |
307 |
+ |
for(vd = 0; vd < 3; vd++) { |
308 |
+ |
vdrift[vd] = vdrift_local[vd]; |
309 |
+ |
} |
310 |
+ |
#endif |
311 |
+ |
|
312 |
+ |
for (vd = 0; vd < 3; vd++) { |
313 |
+ |
vdrift[vd] = vdrift[vd] / mtot; |
314 |
+ |
} |
315 |
+ |
|
316 |
+ |
} |
317 |
+ |
|