6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
#include "integrators/NVT.hpp" |
44 |
|
#include "primitives/Molecule.hpp" |
45 |
|
#include "utils/simError.h" |
46 |
< |
#include "utils/OOPSEConstant.hpp" |
46 |
> |
#include "utils/PhysicalConstants.hpp" |
47 |
|
|
48 |
< |
namespace oopse { |
48 |
> |
namespace OpenMD { |
49 |
|
|
50 |
|
NVT::NVT(SimInfo* info) : VelocityVerletIntegrator(info), chiTolerance_ (1e-6), maxIterNum_(4) { |
51 |
|
|
52 |
|
Globals* simParams = info_->getSimParams(); |
53 |
|
|
54 |
< |
if (!simParams->getUseInitXSstate()) { |
55 |
< |
Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
56 |
< |
currSnapshot->setChi(0.0); |
56 |
< |
currSnapshot->setIntegralOfChiDt(0.0); |
54 |
> |
if (!simParams->getUseIntialExtendedSystemState()) { |
55 |
> |
Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); |
56 |
> |
snap->setThermostat(make_pair(0.0, 0.0)); |
57 |
|
} |
58 |
|
|
59 |
|
if (!simParams->haveTargetTemp()) { |
60 |
|
sprintf(painCave.errMsg, "You can't use the NVT integrator without a targetTemp_!\n"); |
61 |
|
painCave.isFatal = 1; |
62 |
< |
painCave.severity = OOPSE_ERROR; |
62 |
> |
painCave.severity = OPENMD_ERROR; |
63 |
|
simError(); |
64 |
|
} else { |
65 |
|
targetTemp_ = simParams->getTargetTemp(); |
66 |
|
} |
67 |
|
|
68 |
< |
// We must set tauThermostat_. |
68 |
> |
// We must set tauThermostat. |
69 |
|
|
70 |
|
if (!simParams->haveTauThermostat()) { |
71 |
|
sprintf(painCave.errMsg, "If you use the constant temperature\n" |
72 |
< |
"\tintegrator, you must set tauThermostat_.\n"); |
72 |
> |
"\tintegrator, you must set tauThermostat.\n"); |
73 |
|
|
74 |
< |
painCave.severity = OOPSE_ERROR; |
74 |
> |
painCave.severity = OPENMD_ERROR; |
75 |
|
painCave.isFatal = 1; |
76 |
|
simError(); |
77 |
|
} else { |
78 |
|
tauThermostat_ = simParams->getTauThermostat(); |
79 |
|
} |
80 |
|
|
81 |
< |
update(); |
81 |
> |
updateSizes(); |
82 |
|
} |
83 |
|
|
84 |
< |
void NVT::doUpdate() { |
84 |
> |
void NVT::doUpdateSizes() { |
85 |
|
oldVel_.resize(info_->getNIntegrableObjects()); |
86 |
< |
oldJi_.resize(info_->getNIntegrableObjects()); |
86 |
> |
oldJi_.resize(info_->getNIntegrableObjects()); |
87 |
|
} |
88 |
+ |
|
89 |
|
void NVT::moveA() { |
90 |
|
SimInfo::MoleculeIterator i; |
91 |
|
Molecule::IntegrableObjectIterator j; |
92 |
|
Molecule* mol; |
93 |
< |
StuntDouble* integrableObject; |
93 |
> |
StuntDouble* sd; |
94 |
|
Vector3d Tb; |
95 |
|
Vector3d ji; |
96 |
< |
double mass; |
96 |
> |
RealType mass; |
97 |
|
Vector3d vel; |
98 |
|
Vector3d pos; |
99 |
|
Vector3d frc; |
100 |
|
|
101 |
< |
double chi = currentSnapshot_->getChi(); |
102 |
< |
double integralOfChidt = currentSnapshot_->getIntegralOfChiDt(); |
102 |
< |
|
101 |
> |
pair<RealType, RealType> thermostat = snap->getThermostat(); |
102 |
> |
|
103 |
|
// We need the temperature at time = t for the chi update below: |
104 |
|
|
105 |
< |
double instTemp = thermo.getTemperature(); |
105 |
> |
RealType instTemp = thermo.getTemperature(); |
106 |
|
|
107 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
108 |
< |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
109 |
< |
integrableObject = mol->nextIntegrableObject(j)) { |
107 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
108 |
> |
mol = info_->nextMolecule(i)) { |
109 |
|
|
110 |
< |
vel = integrableObject->getVel(); |
111 |
< |
pos = integrableObject->getPos(); |
113 |
< |
frc = integrableObject->getFrc(); |
110 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
111 |
> |
sd = mol->nextIntegrableObject(j)) { |
112 |
|
|
113 |
< |
mass = integrableObject->getMass(); |
113 |
> |
vel = sd->getVel(); |
114 |
> |
pos = sd->getPos(); |
115 |
> |
frc = sd->getFrc(); |
116 |
|
|
117 |
< |
// velocity half step (use chi from previous step here): |
118 |
< |
//vel[j] += dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - vel[j]*chi); |
119 |
< |
vel += dt2 *OOPSEConstant::energyConvert/mass*frc - dt2*chi*vel; |
117 |
> |
mass = sd->getMass(); |
118 |
> |
|
119 |
> |
// velocity half step (use chi from previous step here): |
120 |
> |
vel += dt2 *PhysicalConstants::energyConvert/mass*frc |
121 |
> |
- dt2*thermostat.first*vel; |
122 |
|
|
123 |
|
// position whole step |
122 |
– |
//pos[j] += dt * vel[j]; |
124 |
|
pos += dt * vel; |
125 |
|
|
126 |
< |
integrableObject->setVel(vel); |
127 |
< |
integrableObject->setPos(pos); |
126 |
> |
sd->setVel(vel); |
127 |
> |
sd->setPos(pos); |
128 |
|
|
129 |
< |
if (integrableObject->isDirectional()) { |
129 |
> |
if (sd->isDirectional()) { |
130 |
|
|
131 |
|
//convert the torque to body frame |
132 |
< |
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
132 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
133 |
|
|
134 |
|
// get the angular momentum, and propagate a half step |
135 |
|
|
136 |
< |
ji = integrableObject->getJ(); |
136 |
> |
ji = sd->getJ(); |
137 |
|
|
138 |
< |
//ji[j] += dt2 * (Tb[j] * OOPSEConstant::energyConvert - ji[j]*chi); |
139 |
< |
ji += dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *ji; |
139 |
< |
rotAlgo->rotate(integrableObject, ji, dt); |
138 |
> |
ji += dt2*PhysicalConstants::energyConvert*Tb |
139 |
> |
- dt2*thermostat.first *ji; |
140 |
|
|
141 |
< |
integrableObject->setJ(ji); |
141 |
> |
rotAlgo_->rotate(sd, ji, dt); |
142 |
> |
|
143 |
> |
sd->setJ(ji); |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
} |
148 |
|
|
149 |
< |
rattle->constraintA(); |
149 |
> |
flucQ_->moveA(); |
150 |
> |
rattle_->constraintA(); |
151 |
|
|
152 |
|
// Finally, evolve chi a half step (just like a velocity) using |
153 |
|
// temperature at time t, not time t+dt/2 |
154 |
|
|
155 |
< |
|
156 |
< |
chi += dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_); |
157 |
< |
integralOfChidt += chi * dt2; |
155 |
> |
thermostat.first += dt2 * (instTemp / targetTemp_ - 1.0) |
156 |
> |
/ (tauThermostat_ * tauThermostat_); |
157 |
> |
thermostat.second += thermostat.first * dt2; |
158 |
|
|
159 |
< |
currentSnapshot_->setChi(chi); |
157 |
< |
currentSnapshot_->setIntegralOfChiDt(integralOfChidt); |
159 |
> |
snap->setThermostat(thermostat); |
160 |
|
} |
161 |
|
|
162 |
|
void NVT::moveB() { |
163 |
|
SimInfo::MoleculeIterator i; |
164 |
|
Molecule::IntegrableObjectIterator j; |
165 |
|
Molecule* mol; |
166 |
< |
StuntDouble* integrableObject; |
166 |
> |
StuntDouble* sd; |
167 |
|
|
168 |
|
Vector3d Tb; |
169 |
|
Vector3d ji; |
170 |
|
Vector3d vel; |
171 |
|
Vector3d frc; |
172 |
< |
double mass; |
173 |
< |
double instTemp; |
172 |
> |
RealType mass; |
173 |
> |
RealType instTemp; |
174 |
|
int index; |
175 |
|
// Set things up for the iteration: |
176 |
|
|
177 |
< |
double chi = currentSnapshot_->getChi(); |
178 |
< |
double oldChi = chi; |
179 |
< |
double prevChi; |
178 |
< |
double integralOfChidt = currentSnapshot_->getIntegralOfChiDt(); |
177 |
> |
pair<RealType, RealType> thermostat = snap->getThermostat(); |
178 |
> |
RealType oldChi = thermostat.first; |
179 |
> |
RealType prevChi; |
180 |
|
|
181 |
|
index = 0; |
182 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
183 |
< |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
183 |
< |
integrableObject = mol->nextIntegrableObject(j)) { |
184 |
< |
oldVel_[index] = integrableObject->getVel(); |
185 |
< |
oldJi_[index] = integrableObject->getJ(); |
182 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
183 |
> |
mol = info_->nextMolecule(i)) { |
184 |
|
|
185 |
+ |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
186 |
+ |
sd = mol->nextIntegrableObject(j)) { |
187 |
+ |
|
188 |
+ |
oldVel_[index] = sd->getVel(); |
189 |
+ |
|
190 |
+ |
if (sd->isDirectional()) |
191 |
+ |
oldJi_[index] = sd->getJ(); |
192 |
+ |
|
193 |
|
++index; |
194 |
< |
} |
189 |
< |
|
194 |
> |
} |
195 |
|
} |
196 |
|
|
197 |
|
// do the iteration: |
202 |
|
|
203 |
|
// evolve chi another half step using the temperature at t + dt/2 |
204 |
|
|
205 |
< |
prevChi = chi; |
206 |
< |
chi = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) / (tauThermostat_ * tauThermostat_); |
205 |
> |
prevChi = thermostat.first; |
206 |
> |
thermostat.first = oldChi + dt2 * (instTemp / targetTemp_ - 1.0) |
207 |
> |
/ (tauThermostat_ * tauThermostat_); |
208 |
|
|
209 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
210 |
< |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
211 |
< |
integrableObject = mol->nextIntegrableObject(j)) { |
209 |
> |
for (mol = info_->beginMolecule(i); mol != NULL; |
210 |
> |
mol = info_->nextMolecule(i)) { |
211 |
> |
|
212 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
213 |
> |
sd = mol->nextIntegrableObject(j)) { |
214 |
|
|
215 |
< |
frc = integrableObject->getFrc(); |
216 |
< |
vel = integrableObject->getVel(); |
215 |
> |
frc = sd->getFrc(); |
216 |
> |
mass = sd->getMass(); |
217 |
|
|
210 |
– |
mass = integrableObject->getMass(); |
211 |
– |
|
218 |
|
// velocity half step |
219 |
< |
//for(j = 0; j < 3; j++) |
220 |
< |
// vel[j] = oldVel_[3*i+j] + dt2 * ((frc[j] / mass ) * OOPSEConstant::energyConvert - oldVel_[3*i + j]*chi); |
221 |
< |
vel = oldVel_[index] + dt2/mass*OOPSEConstant::energyConvert * frc - dt2*chi*oldVel_[index]; |
219 |
> |
|
220 |
> |
vel = oldVel_[index] |
221 |
> |
+ dt2/mass*PhysicalConstants::energyConvert * frc |
222 |
> |
- dt2*thermostat.first*oldVel_[index]; |
223 |
|
|
224 |
< |
integrableObject->setVel(vel); |
224 |
> |
sd->setVel(vel); |
225 |
|
|
226 |
< |
if (integrableObject->isDirectional()) { |
226 |
> |
if (sd->isDirectional()) { |
227 |
|
|
228 |
|
// get and convert the torque to body frame |
229 |
|
|
230 |
< |
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
230 |
> |
Tb = sd->lab2Body(sd->getTrq()); |
231 |
|
|
232 |
< |
//for(j = 0; j < 3; j++) |
233 |
< |
// ji[j] = oldJi_[3*i + j] + dt2 * (Tb[j] * OOPSEConstant::energyConvert - oldJi_[3*i+j]*chi); |
227 |
< |
ji = oldJi_[index] + dt2*OOPSEConstant::energyConvert*Tb - dt2*chi *oldJi_[index]; |
232 |
> |
ji = oldJi_[index] + dt2*PhysicalConstants::energyConvert*Tb |
233 |
> |
- dt2*thermostat.first *oldJi_[index]; |
234 |
|
|
235 |
< |
integrableObject->setJ(ji); |
235 |
> |
sd->setJ(ji); |
236 |
|
} |
237 |
|
|
238 |
|
|
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
+ |
rattle_->constraintB(); |
244 |
|
|
245 |
< |
rattle->constraintB(); |
239 |
< |
|
240 |
< |
if (fabs(prevChi - chi) <= chiTolerance_) |
245 |
> |
if (fabs(prevChi - thermostat.first) <= chiTolerance_) |
246 |
|
break; |
247 |
|
|
248 |
|
} |
249 |
|
|
250 |
< |
integralOfChidt += dt2 * chi; |
250 |
> |
flucQ_->moveB(); |
251 |
|
|
252 |
< |
currentSnapshot_->setChi(chi); |
253 |
< |
currentSnapshot_->setIntegralOfChiDt(integralOfChidt); |
252 |
> |
thermostat.second += dt2 * thermostat.first; |
253 |
> |
snap->setThermostat(thermostat); |
254 |
|
} |
255 |
|
|
256 |
|
void NVT::resetIntegrator() { |
257 |
< |
currentSnapshot_->setChi(0.0); |
253 |
< |
currentSnapshot_->setIntegralOfChiDt(0.0); |
257 |
> |
snap->setThermostat(make_pair(0.0, 0.0)); |
258 |
|
} |
259 |
|
|
260 |
< |
double NVT::calcConservedQuantity() { |
260 |
> |
RealType NVT::calcConservedQuantity() { |
261 |
|
|
262 |
< |
double chi = currentSnapshot_->getChi(); |
263 |
< |
double integralOfChidt = currentSnapshot_->getIntegralOfChiDt(); |
264 |
< |
double conservedQuantity; |
265 |
< |
double fkBT; |
266 |
< |
double Energy; |
267 |
< |
double thermostat_kinetic; |
264 |
< |
double thermostat_potential; |
262 |
> |
pair<RealType, RealType> thermostat = snap->getThermostat(); |
263 |
> |
RealType conservedQuantity; |
264 |
> |
RealType fkBT; |
265 |
> |
RealType Energy; |
266 |
> |
RealType thermostat_kinetic; |
267 |
> |
RealType thermostat_potential; |
268 |
|
|
269 |
< |
fkBT = info_->getNdf() *OOPSEConstant::kB *targetTemp_; |
269 |
> |
fkBT = info_->getNdf() *PhysicalConstants::kB *targetTemp_; |
270 |
|
|
271 |
< |
Energy = thermo.getTotalE(); |
271 |
> |
Energy = thermo.getTotalEnergy(); |
272 |
|
|
273 |
< |
thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * chi * chi / (2.0 * OOPSEConstant::energyConvert); |
273 |
> |
thermostat_kinetic = fkBT * tauThermostat_ * tauThermostat_ * thermostat.first * thermostat.first / (2.0 * PhysicalConstants::energyConvert); |
274 |
|
|
275 |
< |
thermostat_potential = fkBT * integralOfChidt / OOPSEConstant::energyConvert; |
275 |
> |
thermostat_potential = fkBT * thermostat.second / PhysicalConstants::energyConvert; |
276 |
|
|
277 |
|
conservedQuantity = Energy + thermostat_kinetic + thermostat_potential; |
278 |
|
|
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
}//end namespace oopse |
283 |
> |
}//end namespace OpenMD |