4 |
|
using namespace std; |
5 |
|
|
6 |
|
#ifdef IS_MPI |
7 |
– |
|
7 |
|
#include <mpi.h> |
8 |
|
#endif //is_mpi |
9 |
|
|
10 |
|
#include "brains/Thermo.hpp" |
11 |
< |
#include "primitives/SRI.hpp" |
13 |
< |
#include "integrators/Integrator.hpp" |
11 |
> |
#include "primitives/Molecule.hpp" |
12 |
|
#include "utils/simError.h" |
13 |
< |
#include "math/MatVec3.h" |
13 |
> |
#include "utils/OOPSEConstant.hpp" |
14 |
|
|
17 |
– |
#ifdef IS_MPI |
18 |
– |
|
19 |
– |
#define __C |
20 |
– |
#include "brains/mpiSimulation.hpp" |
21 |
– |
#endif // is_mpi |
22 |
– |
|
15 |
|
namespace oopse { |
24 |
– |
Thermo::Thermo(SimInfo *the_info) { info = the_info; } |
16 |
|
|
26 |
– |
Thermo::~Thermo() { } |
27 |
– |
|
17 |
|
double Thermo::getKinetic() { |
18 |
< |
const double e_convert = |
19 |
< |
4.184E - 4; // convert kcal/mol -> (amu A^2)/fs^2 |
20 |
< |
double kinetic; |
21 |
< |
double amass; |
22 |
< |
double aVel[3], |
23 |
< |
aJ[3], |
24 |
< |
I[3][3]; |
25 |
< |
int i, |
26 |
< |
j, |
27 |
< |
k, |
28 |
< |
kl; |
18 |
> |
SimInfo::MoleculeIterator miter; |
19 |
> |
std::vector<StuntDouble*>::iterator iiter; |
20 |
> |
Molecule* mol; |
21 |
> |
StuntDouble* integrableObject; |
22 |
> |
double mass; |
23 |
> |
Vector3d vel; |
24 |
> |
Vector3d angMom; |
25 |
> |
Mat3x3d I; |
26 |
> |
int i; |
27 |
> |
int j; |
28 |
> |
int k; |
29 |
> |
double kinetic = 0.0; |
30 |
> |
double kinetic_global = 0.0; |
31 |
> |
|
32 |
> |
for (mol = info_->beginMolecule(miter); mol != NULL; mol = info_->nextMolecule(miter)) { |
33 |
> |
for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; |
34 |
> |
integrableObject = mol->nextIntegrableObject(iiter)) { |
35 |
|
|
36 |
< |
double kinetic_global; |
37 |
< |
vector<StuntDouble *>integrableObjects = info->integrableObjects; |
36 |
> |
double mass = integrableObject->getMass(); |
37 |
> |
Vector3d vel = integrableObject->getVel(); |
38 |
|
|
39 |
< |
kinetic = 0.0; |
45 |
< |
kinetic_global = 0.0; |
39 |
> |
kinetic = mass * (vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]); |
40 |
|
|
41 |
< |
for( kl = 0; kl < integrableObjects.size(); kl++ ) { |
42 |
< |
aVel = integrableObjects[kl]->getVel(); |
43 |
< |
amass = integrableObjects[kl]->getMass(); |
41 |
> |
if (integrableObject->isDirectional()) { |
42 |
> |
angMom = integrableObject->getJ(); |
43 |
> |
I = integrableObject->getI(); |
44 |
|
|
45 |
< |
for( j = 0; j < 3; j++ ) |
46 |
< |
kinetic += amass * aVel[j] * aVel[j]; |
47 |
< |
|
48 |
< |
if (integrableObjects[kl]->isDirectional()) { |
49 |
< |
aJ = integrableObjects[kl]->getJ(); |
50 |
< |
integrableObjects[kl]->getI(I); |
51 |
< |
|
52 |
< |
if (integrableObjects[kl]->isLinear()) { |
53 |
< |
i = integrableObjects[kl]->linearAxis(); |
60 |
< |
j = (i + 1) % 3; |
61 |
< |
k = (i + 2) % 3; |
62 |
< |
kinetic += aJ[j] * aJ[j] / I[j][j] + aJ[k] * aJ[k] / I[k][k]; |
63 |
< |
} else { |
64 |
< |
for( j = 0; j < 3; j++ ) |
65 |
< |
kinetic += aJ[j] * aJ[j] / I[j][j]; |
45 |
> |
if (integrableObject->isLinear()) { |
46 |
> |
i = integrableObject->linearAxis(); |
47 |
> |
j = (i + 1) % 3; |
48 |
> |
k = (i + 2) % 3; |
49 |
> |
kinetic += angMom[j] * angMom[j] / I(j, j) + angMom[k] * angMom[k] / I(k, k); |
50 |
> |
} else { |
51 |
> |
kinetic += angMom[0]*angMom[0]/I(0, 0) + angMom[1]*angMom[1]/I(1, 1) |
52 |
> |
+ angMom[2]*angMom[2]/I(2, 2); |
53 |
> |
} |
54 |
|
} |
55 |
+ |
|
56 |
|
} |
57 |
|
} |
58 |
< |
|
58 |
> |
|
59 |
|
#ifdef IS_MPI |
60 |
|
|
61 |
|
MPI_Allreduce(&kinetic, &kinetic_global, 1, MPI_DOUBLE, MPI_SUM, |
64 |
|
|
65 |
|
#endif //is_mpi |
66 |
|
|
67 |
< |
kinetic = kinetic * 0.5 / e_convert; |
67 |
> |
kinetic = kinetic * 0.5 / OOPSEConstant::energyConvert; |
68 |
|
|
69 |
|
return kinetic; |
70 |
|
} |
71 |
|
|
72 |
|
double Thermo::getPotential() { |
73 |
< |
double potential_local; |
74 |
< |
double potential; |
75 |
< |
int el, |
87 |
< |
nSRI; |
88 |
< |
Molecule *molecules; |
73 |
> |
double potential = 0.0; |
74 |
> |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
75 |
> |
double potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; |
76 |
|
|
77 |
< |
molecules = info->molecules; |
78 |
< |
nSRI = info->n_SRI; |
79 |
< |
|
80 |
< |
potential_local = 0.0; |
94 |
< |
potential = 0.0; |
95 |
< |
potential_local += info->lrPot; |
96 |
< |
|
97 |
< |
for( el = 0; el < info->n_mol; el++ ) { |
98 |
< |
potential_local += molecules[el].getPotential(); |
77 |
> |
SimInfo::MoleculeIterator i; |
78 |
> |
Molecule* mol; |
79 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
80 |
> |
potential_local += mol->getPotential(); |
81 |
|
} |
82 |
|
|
83 |
|
// Get total potential for entire system from MPI. |
104 |
|
} |
105 |
|
|
106 |
|
double Thermo::getTemperature() { |
107 |
< |
const double kb = 1.9872156E - 3; // boltzman's constant in kcal/(mol K) |
108 |
< |
double temperature; |
127 |
< |
|
128 |
< |
temperature |
129 |
< |
|
130 |
< |
= ( 2.0 * this->getKinetic() ) / ((double)info->ndf * kb ); |
131 |
< |
|
107 |
> |
|
108 |
> |
double temperature = ( 2.0 * this->getKinetic() ) / (info_->getNdf()* OOPSEConstant::kb ); |
109 |
|
return temperature; |
110 |
|
} |
111 |
|
|
112 |
< |
double Thermo::getVolume() { return info->boxVol; } |
112 |
> |
double Thermo::getVolume() { |
113 |
> |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
114 |
> |
return curSnapshot->getVolume(); |
115 |
> |
} |
116 |
|
|
117 |
|
double Thermo::getPressure() { |
118 |
|
|
119 |
|
// Relies on the calculation of the full molecular pressure tensor |
120 |
|
|
141 |
– |
const double p_convert = 1.63882576e8; |
142 |
– |
double press[3][3]; |
143 |
– |
double pressure; |
121 |
|
|
122 |
< |
this->getPressureTensor(press); |
122 |
> |
Mat3x3d tensor; |
123 |
> |
double pressure; |
124 |
|
|
125 |
< |
pressure = p_convert * (press[0][0] + press[1][1] + press[2][2]) / 3.0; |
125 |
> |
this->getPressureTensor(tensor); |
126 |
|
|
127 |
+ |
pressure = OOPSEConstant::pressureConvert * (tensor(0, 0) + tensor(1, 1) + tensor(2, 2)) / 3.0; |
128 |
+ |
|
129 |
|
return pressure; |
130 |
|
} |
131 |
|
|
132 |
< |
double Thermo::getPressureX() { |
153 |
< |
|
154 |
< |
// Relies on the calculation of the full molecular pressure tensor |
155 |
< |
|
156 |
< |
const double p_convert = 1.63882576e8; |
157 |
< |
double press[3][3]; |
158 |
< |
double pressureX; |
159 |
< |
|
160 |
< |
this->getPressureTensor(press); |
161 |
< |
|
162 |
< |
pressureX = p_convert * press[0][0]; |
163 |
< |
|
164 |
< |
return pressureX; |
165 |
< |
} |
166 |
< |
|
167 |
< |
double Thermo::getPressureY() { |
168 |
< |
|
169 |
< |
// Relies on the calculation of the full molecular pressure tensor |
170 |
< |
|
171 |
< |
const double p_convert = 1.63882576e8; |
172 |
< |
double press[3][3]; |
173 |
< |
double pressureY; |
174 |
< |
|
175 |
< |
this->getPressureTensor(press); |
176 |
< |
|
177 |
< |
pressureY = p_convert * press[1][1]; |
178 |
< |
|
179 |
< |
return pressureY; |
180 |
< |
} |
181 |
< |
|
182 |
< |
double Thermo::getPressureZ() { |
183 |
< |
|
184 |
< |
// Relies on the calculation of the full molecular pressure tensor |
185 |
< |
|
186 |
< |
const double p_convert = 1.63882576e8; |
187 |
< |
double press[3][3]; |
188 |
< |
double pressureZ; |
189 |
< |
|
190 |
< |
this->getPressureTensor(press); |
191 |
< |
|
192 |
< |
pressureZ = p_convert * press[2][2]; |
193 |
< |
|
194 |
< |
return pressureZ; |
195 |
< |
} |
196 |
< |
|
197 |
< |
void Thermo::getPressureTensor(double press[3][3]) { |
132 |
> |
void Thermo::getPressureTensor(Mat3x3d pressureTensor) { |
133 |
|
// returns pressure tensor in units amu*fs^-2*Ang^-1 |
134 |
|
// routine derived via viral theorem description in: |
135 |
|
// Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 |
136 |
|
|
137 |
< |
const double e_convert = 4.184e - 4; |
137 |
> |
Mat3x3d p_local(0.0); |
138 |
> |
Mat3x3d p_global(0.0); |
139 |
|
|
140 |
< |
double molmass, |
141 |
< |
volume; |
142 |
< |
double vcom[3]; |
143 |
< |
double p_local[9], |
144 |
< |
p_global[9]; |
145 |
< |
int i, |
146 |
< |
j, |
211 |
< |
k; |
140 |
> |
SimInfo::MoleculeIterator i; |
141 |
> |
std::vector<StuntDouble*>::iterator j; |
142 |
> |
Molecule* mol; |
143 |
> |
StuntDouble* integrableObject; |
144 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
145 |
> |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
146 |
> |
integrableObject = mol->nextIntegrableObject(j)) { |
147 |
|
|
148 |
< |
for( i = 0; i < 9; i++ ) { |
149 |
< |
p_local[i] = 0.0; |
150 |
< |
p_global[i] = 0.0; |
148 |
> |
double mass = integrableObject->getMass(); |
149 |
> |
Vector3d vcom = integrableObject->getVel(); |
150 |
> |
p_local += mass * outProduct(vcom, vcom); |
151 |
> |
} |
152 |
|
} |
153 |
< |
|
218 |
< |
// use velocities of integrableObjects and their masses: |
219 |
< |
|
220 |
< |
for( i = 0; i < info->integrableObjects.size(); i++ ) { |
221 |
< |
molmass = info->integrableObjects[i]->getMass(); |
222 |
< |
|
223 |
< |
vcom = info->integrableObjects[i]->getVel(); |
224 |
< |
|
225 |
< |
p_local[0] += molmass * (vcom[0] * vcom[0]); |
226 |
< |
p_local[1] += molmass * (vcom[0] * vcom[1]); |
227 |
< |
p_local[2] += molmass * (vcom[0] * vcom[2]); |
228 |
< |
p_local[3] += molmass * (vcom[1] * vcom[0]); |
229 |
< |
p_local[4] += molmass * (vcom[1] * vcom[1]); |
230 |
< |
p_local[5] += molmass * (vcom[1] * vcom[2]); |
231 |
< |
p_local[6] += molmass * (vcom[2] * vcom[0]); |
232 |
< |
p_local[7] += molmass * (vcom[2] * vcom[1]); |
233 |
< |
p_local[8] += molmass * (vcom[2] * vcom[2]); |
234 |
< |
} |
235 |
< |
|
236 |
< |
// Get total for entire system from MPI. |
237 |
< |
|
153 |
> |
|
154 |
|
#ifdef IS_MPI |
155 |
< |
|
240 |
< |
MPI_Allreduce(p_local, p_global, 9, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); |
241 |
< |
|
155 |
> |
MPI_Allreduce(p_local.getArrayPointer(), p_global.getArrayPointer(), 9, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); |
156 |
|
#else |
157 |
< |
|
244 |
< |
for( i = 0; i < 9; i++ ) { |
245 |
< |
p_global[i] = p_local[i]; |
246 |
< |
} |
247 |
< |
|
157 |
> |
p_global = p_local; |
158 |
|
#endif // is_mpi |
159 |
|
|
160 |
< |
volume = this->getVolume(); |
160 |
> |
double volume = this->getVolume(); |
161 |
> |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
162 |
> |
Mat3x3d tau = curSnapshot->statData.getTau(); |
163 |
|
|
164 |
< |
for( i = 0; i < 3; i++ ) { |
253 |
< |
for( j = 0; j < 3; j++ ) { |
254 |
< |
k = 3 * i + j; |
255 |
< |
|
256 |
< |
press |
257 |
< |
|
258 |
< |
[i][j] = (p_global[k] + info->tau[k]*e_convert) / volume; |
259 |
< |
} |
260 |
< |
} |
164 |
> |
pressureTensor = p_global + OOPSEConstant::energyConvert/volume * tau; |
165 |
|
} |
166 |
+ |
|
167 |
|
} //end namespace oopse |