1 |
< |
#inlcude "integrators/NVT.hpp" |
1 |
> |
#include "integrators/IntegratorCreator.hpp" |
2 |
> |
#include "integrators/NVT.hpp" |
3 |
> |
#include "primitives/Molecule.hpp" |
4 |
> |
#include "utils/simError.h" |
5 |
> |
#include "utils/OOPSEConstant.hpp" |
6 |
|
|
7 |
|
namespace oopse { |
8 |
|
|
9 |
+ |
static IntegratorBuilder<NVT>* NVTCreator = new IntegratorBuilder<NVT>("NVT"); |
10 |
+ |
|
11 |
|
NVT::NVT(SimInfo* info) : VelocityVerletIntegrator(info), chiTolerance_ (1e-6) { |
12 |
|
|
13 |
|
Globals* globals = info_->getGlobals(); |
43 |
|
update(); |
44 |
|
} |
45 |
|
|
40 |
– |
NVT::~NVT() { |
41 |
– |
} |
42 |
– |
|
46 |
|
void NVT::update() { |
47 |
|
oldVel_.resize(info_->getNIntegrableObjects()); |
48 |
|
oldJi_.resize(info_->getNIntegrableObjects()); |
49 |
|
} |
50 |
|
void NVT::moveA() { |
51 |
< |
typename SimInfo::MoleculeIterator i; |
52 |
< |
typename Molecule::IntegrableObjectIterator j; |
51 |
> |
SimInfo::MoleculeIterator i; |
52 |
> |
Molecule::IntegrableObjectIterator j; |
53 |
|
Molecule* mol; |
54 |
|
StuntDouble* integrableObject; |
55 |
|
Vector3d Tb; |
59 |
|
Vector3d pos; |
60 |
|
Vector3d frc; |
61 |
|
|
62 |
< |
double instTemp; |
63 |
< |
|
62 |
> |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
63 |
> |
double chi = currSnapshot->getChi(); |
64 |
> |
double integralOfChidt = currSnapshot->getIntegralOfChiDt(); |
65 |
> |
|
66 |
|
// We need the temperature at time = t for the chi update below: |
67 |
|
|
68 |
< |
instTemp = tStats->getTemperature(); |
68 |
> |
double instTemp = thermo.getTemperature(); |
69 |
|
|
70 |
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
71 |
|
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
78 |
|
mass = integrableObject->getMass(); |
79 |
|
|
80 |
|
// velocity half step (use chi from previous step here): |
81 |
< |
//vel[j] += dt2 * ((frc[j] / mass ) * eConvert - vel[j]*chi); |
82 |
< |
vel = dt2 *eConvert/mass*frc - dt2*chi*vel; |
81 |
> |
//vel[j] += dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - vel[j]*chi); |
82 |
> |
vel = dt2 *OOPSEConstant::energyConvert/mass*frc - dt2*chi*vel; |
83 |
|
|
84 |
|
// position whole step |
85 |
|
//pos[j] += dt * vel[j]; |
99 |
|
|
100 |
|
ji = integrableObject->getJ(); |
101 |
|
|
102 |
< |
//ji[j] += dt2 * (Tb[j] * eConvert - ji[j]*chi); |
103 |
< |
ji += dt2*eConvert*Tb - dt2*ch *ji; |
104 |
< |
this->rotationPropagation(integrableObject, ji); |
102 |
> |
//ji[j] += dt2 * (Tb[j] * OOPSEConstant::energyConvert - ji[j]*chi); |
103 |
> |
ji += dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *ji; |
104 |
> |
rotAlgo->rotate(integrableObject, ji, dt); |
105 |
|
|
106 |
|
integrableObject->setJ(ji); |
107 |
|
} |
114 |
|
// Finally, evolve chi a half step (just like a velocity) using |
115 |
|
// temperature at time t, not time t+dt/2 |
116 |
|
|
112 |
– |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
113 |
– |
double chi = currSnapshot->getChi(); |
114 |
– |
double integralOfChidt = currSnapshot->getIntegralOfChiDt(); |
117 |
|
|
118 |
|
chi += dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_); |
119 |
|
integralOfChidt += chi * dt2; |
123 |
|
} |
124 |
|
|
125 |
|
void NVT::moveB() { |
126 |
< |
typename SimInfo::MoleculeIterator i; |
127 |
< |
typename Molecule::IntegrableObjectIterator j; |
126 |
> |
SimInfo::MoleculeIterator i; |
127 |
> |
Molecule::IntegrableObjectIterator j; |
128 |
|
Molecule* mol; |
129 |
|
StuntDouble* integrableObject; |
130 |
|
|
134 |
|
Vector3d frc; |
135 |
|
double mass; |
136 |
|
double instTemp; |
135 |
– |
double oldChi, prevChi; |
137 |
|
int index; |
138 |
|
// Set things up for the iteration: |
139 |
|
|
140 |
|
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
141 |
|
double chi = currSnapshot->getChi(); |
142 |
+ |
double oldChi = chi; |
143 |
+ |
double prevChi; |
144 |
|
double integralOfChidt = currSnapshot->getIntegralOfChiDt(); |
142 |
– |
oldChi = chi; |
145 |
|
|
146 |
|
index = 0; |
147 |
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
157 |
|
|
158 |
|
for(int k = 0; k < maxIterNum_; k++) { |
159 |
|
index = 0; |
160 |
< |
instTemp = tStats->getTemperature(); |
160 |
> |
instTemp = thermo.getTemperature(); |
161 |
|
|
162 |
|
// evolve chi another half step using the temperature at t + dt/2 |
163 |
|
|
175 |
|
|
176 |
|
// velocity half step |
177 |
|
//for(j = 0; j < 3; j++) |
178 |
< |
// vel[j] = oldVel_[3*i+j] + dt2 * ((frc[j] / mass ) * eConvert - oldVel_[3*i + j]*chi); |
179 |
< |
vel = oldVel_ + dt2/mass*eConvert * frc - dt2*chi*oldVel_[index]; |
178 |
> |
// vel[j] = oldVel_[3*i+j] + dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - oldVel_[3*i + j]*chi); |
179 |
> |
vel = oldVel_[index] + dt2/mass*OOPSEConstant::energyConvert * frc - dt2*chi*oldVel_[index]; |
180 |
|
|
181 |
|
integrableObject->setVel(vel); |
182 |
|
|
188 |
|
integrableObject->lab2Body(Tb); |
189 |
|
|
190 |
|
//for(j = 0; j < 3; j++) |
191 |
< |
// ji[j] = oldJi_[3*i + j] + dt2 * (Tb[j] * eConvert - oldJi_[3*i+j]*chi); |
192 |
< |
ji += dt2*eConvert*Tb - dt2*ch *oldJi_[index]; |
191 |
> |
// ji[j] = oldJi_[3*i + j] + dt2 * (Tb[j] * OOPSEConstant::energyConvert - oldJi_[3*i+j]*chi); |
192 |
> |
ji += dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *oldJi_[index]; |
193 |
|
|
194 |
|
integrableObject->setJ(ji); |
195 |
|
} |
199 |
|
|
200 |
|
//constraintAlgorithm->doConstrainB(); |
201 |
|
|
202 |
< |
if (fabs(prevChi - chi) <= chiTolerance) |
202 |
> |
if (fabs(prevChi - chi) <= chiTolerance_) |
203 |
|
break; |
204 |
|
|
205 |
|
++index; |
213 |
|
|
214 |
|
|
215 |
|
double NVT::calcConservedQuantity() { |
216 |
+ |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
217 |
+ |
double chi = currSnapshot->getChi(); |
218 |
+ |
double integralOfChidt = currSnapshot->getIntegralOfChiDt(); |
219 |
|
double conservedQuantity; |
220 |
|
double fkBT; |
221 |
|
double Energy; |
222 |
|
double thermostat_kinetic; |
223 |
|
double thermostat_potential; |
224 |
+ |
|
225 |
+ |
fkBT = info_->getNdf() *OOPSEConstant::kB *targetTemp_; |
226 |
|
|
227 |
< |
fkBT = info_->getNdf() *kB *targetTemp_; |
227 |
> |
Energy = thermo.getTotalE(); |
228 |
|
|
229 |
< |
Energy = tStats->getTotalE(); |
229 |
> |
thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * chi * chi / (2.0 * OOPSEConstant::energyConvert); |
230 |
|
|
231 |
< |
thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * chi * chi / (2.0 * eConvert); |
231 |
> |
thermostat_potential = fkBT * integralOfChidt / OOPSEConstant::energyConvert; |
232 |
|
|
226 |
– |
thermostat_potential = fkBT * integralOfChidt / eConvert; |
227 |
– |
|
233 |
|
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential; |
234 |
|
|
235 |
|
return conservedQuantity; |