1 |
tim |
1725 |
#include <math.h> |
2 |
|
|
#include <iostream> |
3 |
|
|
|
4 |
|
|
|
5 |
tim |
1827 |
|
6 |
tim |
1725 |
#ifdef IS_MPI |
7 |
|
|
#include <mpi.h> |
8 |
|
|
#endif //is_mpi |
9 |
|
|
|
10 |
|
|
#include "brains/Thermo.hpp" |
11 |
tim |
1804 |
#include "primitives/Molecule.hpp" |
12 |
tim |
1725 |
#include "utils/simError.h" |
13 |
tim |
1804 |
#include "utils/OOPSEConstant.hpp" |
14 |
tim |
1725 |
|
15 |
|
|
namespace oopse { |
16 |
|
|
|
17 |
|
|
double Thermo::getKinetic() { |
18 |
tim |
1804 |
SimInfo::MoleculeIterator miter; |
19 |
|
|
std::vector<StuntDouble*>::iterator iiter; |
20 |
|
|
Molecule* mol; |
21 |
|
|
StuntDouble* integrableObject; |
22 |
|
|
Vector3d vel; |
23 |
|
|
Vector3d angMom; |
24 |
|
|
Mat3x3d I; |
25 |
|
|
int i; |
26 |
|
|
int j; |
27 |
|
|
int k; |
28 |
|
|
double kinetic = 0.0; |
29 |
|
|
double kinetic_global = 0.0; |
30 |
|
|
|
31 |
|
|
for (mol = info_->beginMolecule(miter); mol != NULL; mol = info_->nextMolecule(miter)) { |
32 |
|
|
for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; |
33 |
|
|
integrableObject = mol->nextIntegrableObject(iiter)) { |
34 |
tim |
1725 |
|
35 |
tim |
1804 |
double mass = integrableObject->getMass(); |
36 |
|
|
Vector3d vel = integrableObject->getVel(); |
37 |
tim |
1725 |
|
38 |
tim |
1847 |
kinetic += mass * (vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]); |
39 |
tim |
1725 |
|
40 |
tim |
1804 |
if (integrableObject->isDirectional()) { |
41 |
|
|
angMom = integrableObject->getJ(); |
42 |
|
|
I = integrableObject->getI(); |
43 |
tim |
1725 |
|
44 |
tim |
1804 |
if (integrableObject->isLinear()) { |
45 |
|
|
i = integrableObject->linearAxis(); |
46 |
|
|
j = (i + 1) % 3; |
47 |
|
|
k = (i + 2) % 3; |
48 |
|
|
kinetic += angMom[j] * angMom[j] / I(j, j) + angMom[k] * angMom[k] / I(k, k); |
49 |
|
|
} else { |
50 |
|
|
kinetic += angMom[0]*angMom[0]/I(0, 0) + angMom[1]*angMom[1]/I(1, 1) |
51 |
|
|
+ angMom[2]*angMom[2]/I(2, 2); |
52 |
|
|
} |
53 |
tim |
1725 |
} |
54 |
tim |
1804 |
|
55 |
tim |
1725 |
} |
56 |
|
|
} |
57 |
tim |
1804 |
|
58 |
tim |
1725 |
#ifdef IS_MPI |
59 |
|
|
|
60 |
|
|
MPI_Allreduce(&kinetic, &kinetic_global, 1, MPI_DOUBLE, MPI_SUM, |
61 |
|
|
MPI_COMM_WORLD); |
62 |
|
|
kinetic = kinetic_global; |
63 |
|
|
|
64 |
|
|
#endif //is_mpi |
65 |
|
|
|
66 |
tim |
1804 |
kinetic = kinetic * 0.5 / OOPSEConstant::energyConvert; |
67 |
tim |
1725 |
|
68 |
|
|
return kinetic; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
double Thermo::getPotential() { |
72 |
tim |
1804 |
double potential = 0.0; |
73 |
|
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
74 |
|
|
double potential_local = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; |
75 |
tim |
1725 |
|
76 |
tim |
1804 |
SimInfo::MoleculeIterator i; |
77 |
|
|
Molecule* mol; |
78 |
|
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
79 |
|
|
potential_local += mol->getPotential(); |
80 |
tim |
1725 |
} |
81 |
|
|
|
82 |
|
|
// Get total potential for entire system from MPI. |
83 |
|
|
|
84 |
|
|
#ifdef IS_MPI |
85 |
|
|
|
86 |
|
|
MPI_Allreduce(&potential_local, &potential, 1, MPI_DOUBLE, MPI_SUM, |
87 |
|
|
MPI_COMM_WORLD); |
88 |
|
|
|
89 |
|
|
#else |
90 |
|
|
|
91 |
|
|
potential = potential_local; |
92 |
|
|
|
93 |
|
|
#endif // is_mpi |
94 |
|
|
|
95 |
|
|
return potential; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
double Thermo::getTotalE() { |
99 |
|
|
double total; |
100 |
|
|
|
101 |
|
|
total = this->getKinetic() + this->getPotential(); |
102 |
|
|
return total; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
double Thermo::getTemperature() { |
106 |
tim |
1804 |
|
107 |
|
|
double temperature = ( 2.0 * this->getKinetic() ) / (info_->getNdf()* OOPSEConstant::kb ); |
108 |
tim |
1725 |
return temperature; |
109 |
|
|
} |
110 |
|
|
|
111 |
tim |
1804 |
double Thermo::getVolume() { |
112 |
|
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
113 |
|
|
return curSnapshot->getVolume(); |
114 |
|
|
} |
115 |
tim |
1725 |
|
116 |
|
|
double Thermo::getPressure() { |
117 |
|
|
|
118 |
|
|
// Relies on the calculation of the full molecular pressure tensor |
119 |
|
|
|
120 |
|
|
|
121 |
tim |
1804 |
Mat3x3d tensor; |
122 |
|
|
double pressure; |
123 |
tim |
1725 |
|
124 |
tim |
1822 |
tensor = getPressureTensor(); |
125 |
tim |
1725 |
|
126 |
tim |
1804 |
pressure = OOPSEConstant::pressureConvert * (tensor(0, 0) + tensor(1, 1) + tensor(2, 2)) / 3.0; |
127 |
|
|
|
128 |
tim |
1725 |
return pressure; |
129 |
|
|
} |
130 |
|
|
|
131 |
tim |
1822 |
Mat3x3d Thermo::getPressureTensor() { |
132 |
tim |
1725 |
// returns pressure tensor in units amu*fs^-2*Ang^-1 |
133 |
|
|
// routine derived via viral theorem description in: |
134 |
|
|
// Paci, E. and Marchi, M. J.Phys.Chem. 1996, 100, 4314-4322 |
135 |
tim |
1822 |
Mat3x3d pressureTensor; |
136 |
tim |
1804 |
Mat3x3d p_local(0.0); |
137 |
|
|
Mat3x3d p_global(0.0); |
138 |
tim |
1725 |
|
139 |
tim |
1804 |
SimInfo::MoleculeIterator i; |
140 |
|
|
std::vector<StuntDouble*>::iterator j; |
141 |
|
|
Molecule* mol; |
142 |
|
|
StuntDouble* integrableObject; |
143 |
|
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
144 |
|
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
145 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
146 |
tim |
1725 |
|
147 |
tim |
1804 |
double mass = integrableObject->getMass(); |
148 |
|
|
Vector3d vcom = integrableObject->getVel(); |
149 |
|
|
p_local += mass * outProduct(vcom, vcom); |
150 |
|
|
} |
151 |
tim |
1725 |
} |
152 |
tim |
1804 |
|
153 |
tim |
1725 |
#ifdef IS_MPI |
154 |
tim |
1804 |
MPI_Allreduce(p_local.getArrayPointer(), p_global.getArrayPointer(), 9, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); |
155 |
tim |
1725 |
#else |
156 |
tim |
1804 |
p_global = p_local; |
157 |
tim |
1725 |
#endif // is_mpi |
158 |
|
|
|
159 |
tim |
1804 |
double volume = this->getVolume(); |
160 |
|
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
161 |
|
|
Mat3x3d tau = curSnapshot->statData.getTau(); |
162 |
tim |
1725 |
|
163 |
tim |
1854 |
pressureTensor = (p_global + OOPSEConstant::energyConvert* tau)/volume; |
164 |
tim |
1822 |
|
165 |
|
|
return pressureTensor; |
166 |
tim |
1804 |
} |
167 |
tim |
1725 |
|
168 |
tim |
1820 |
void Thermo::saveStat(){ |
169 |
|
|
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
170 |
|
|
Stats& stat = currSnapshot->statData; |
171 |
|
|
|
172 |
|
|
stat[Stats::KINETIC_ENERGY] = getKinetic(); |
173 |
|
|
stat[Stats::POTENTIAL_ENERGY] = getPotential(); |
174 |
|
|
stat[Stats::TOTAL_ENERGY] = stat[Stats::KINETIC_ENERGY] + stat[Stats::POTENTIAL_ENERGY] ; |
175 |
|
|
stat[Stats::TEMPERATURE] = getTemperature(); |
176 |
|
|
stat[Stats::PRESSURE] = getPressure(); |
177 |
tim |
1822 |
stat[Stats::VOLUME] = getVolume(); |
178 |
tim |
1820 |
|
179 |
|
|
/**@todo need refactorying*/ |
180 |
|
|
//Conserved Quantity is set by integrator and time is set by setTime |
181 |
|
|
|
182 |
|
|
} |
183 |
|
|
|
184 |
tim |
1725 |
} //end namespace oopse |