ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/Thermo.cpp
Revision: 1901
Committed: Tue Jan 4 22:18:36 2005 UTC (19 years, 6 months ago) by tim
File size: 5234 byte(s)
Log Message:
constraints in progress

File Contents

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