1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* |
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. |
16 |
* |
17 |
* This software is provided "AS IS," without a warranty of any |
18 |
* kind. All express or implied conditions, representations and |
19 |
* warranties, including any implied warranty of merchantability, |
20 |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
* be liable for any damages suffered by licensee as a result of |
23 |
* using, modifying or distributing the software or its |
24 |
* derivatives. In no event will the University of Notre Dame or its |
25 |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
* direct, indirect, special, consequential, incidental or punitive |
27 |
* damages, however caused and regardless of the theory of liability, |
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, 24107 (2008). |
39 |
* [4] Vardeman & Gezelter, in progress (2009). |
40 |
*/ |
41 |
|
42 |
/** |
43 |
* @file VelocityVerletIntegrator.cpp |
44 |
* @author tlin |
45 |
* @date 11/09/2004 |
46 |
* @time 16:16am |
47 |
* @version 1.0 |
48 |
*/ |
49 |
|
50 |
#include "integrators/VelocityVerletIntegrator.hpp" |
51 |
#include "integrators/DLM.hpp" |
52 |
#include "utils/StringUtils.hpp" |
53 |
#include "utils/ProgressBar.hpp" |
54 |
|
55 |
namespace OpenMD { |
56 |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
57 |
dt2 = 0.5 * dt; |
58 |
rotAlgo = new DLM(); |
59 |
rattle = new Rattle(info); |
60 |
} |
61 |
|
62 |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
63 |
delete rotAlgo; |
64 |
delete rattle; |
65 |
} |
66 |
|
67 |
void VelocityVerletIntegrator::initialize(){ |
68 |
|
69 |
forceMan_->initialize(); |
70 |
|
71 |
// remove center of mass drift velocity (in case we passed in a |
72 |
// configuration that was drifting) |
73 |
velocitizer_->removeComDrift(); |
74 |
|
75 |
// initialize the forces before the first step |
76 |
calcForce(); |
77 |
|
78 |
// execute the constraint algorithm to make sure that the system is |
79 |
// constrained at the very beginning |
80 |
if (info_->getNGlobalConstraints() > 0) { |
81 |
rattle->constraintA(); |
82 |
calcForce(); |
83 |
rattle->constraintB(); |
84 |
//copy the current snapshot to previous snapshot |
85 |
info_->getSnapshotManager()->advance(); |
86 |
} |
87 |
|
88 |
if (needVelocityScaling) { |
89 |
velocitizer_->velocitize(targetScalingTemp); |
90 |
} |
91 |
|
92 |
dumpWriter = createDumpWriter(); |
93 |
|
94 |
statWriter = createStatWriter(); |
95 |
|
96 |
dumpWriter->writeDumpAndEor(); |
97 |
|
98 |
progressBar = new ProgressBar(); |
99 |
|
100 |
//save statistics, before writeStat, we must save statistics |
101 |
thermo.saveStat(); |
102 |
saveConservedQuantity(); |
103 |
if (simParams->getUseRNEMD()) |
104 |
rnemd_->getStarted(); |
105 |
|
106 |
statWriter->writeStat(currentSnapshot_->statData); |
107 |
|
108 |
currSample = sampleTime + currentSnapshot_->getTime(); |
109 |
currStatus = statusTime + currentSnapshot_->getTime(); |
110 |
currThermal = thermalTime + currentSnapshot_->getTime(); |
111 |
if (needReset) { |
112 |
currReset = resetTime + currentSnapshot_->getTime(); |
113 |
} |
114 |
if (simParams->getUseRNEMD()){ |
115 |
currRNEMD = RNEMD_exchangeTime + currentSnapshot_->getTime(); |
116 |
} |
117 |
needPotential = false; |
118 |
needStress = false; |
119 |
|
120 |
} |
121 |
|
122 |
void VelocityVerletIntegrator::doIntegrate() { |
123 |
|
124 |
|
125 |
initialize(); |
126 |
|
127 |
while (currentSnapshot_->getTime() < runTime) { |
128 |
|
129 |
preStep(); |
130 |
|
131 |
integrateStep(); |
132 |
|
133 |
postStep(); |
134 |
|
135 |
} |
136 |
|
137 |
finalize(); |
138 |
|
139 |
} |
140 |
|
141 |
|
142 |
void VelocityVerletIntegrator::preStep() { |
143 |
RealType difference = currentSnapshot_->getTime() + dt - currStatus; |
144 |
|
145 |
if (difference > 0 || fabs(difference) < OpenMD::epsilon) { |
146 |
needPotential = true; |
147 |
needStress = true; |
148 |
} |
149 |
} |
150 |
|
151 |
void VelocityVerletIntegrator::postStep() { |
152 |
|
153 |
//save snapshot |
154 |
info_->getSnapshotManager()->advance(); |
155 |
|
156 |
//increase time |
157 |
currentSnapshot_->increaseTime(dt); |
158 |
|
159 |
if (needVelocityScaling) { |
160 |
if (currentSnapshot_->getTime() >= currThermal) { |
161 |
velocitizer_->velocitize(targetScalingTemp); |
162 |
currThermal += thermalTime; |
163 |
} |
164 |
} |
165 |
if (useRNEMD) { |
166 |
if (currentSnapshot_->getTime() >= currRNEMD) { |
167 |
rnemd_->doRNEMD(); |
168 |
currRNEMD += RNEMD_exchangeTime; |
169 |
} |
170 |
rnemd_->collectData(); |
171 |
} |
172 |
|
173 |
if (currentSnapshot_->getTime() >= currSample) { |
174 |
dumpWriter->writeDumpAndEor(); |
175 |
|
176 |
currSample += sampleTime; |
177 |
} |
178 |
|
179 |
if (currentSnapshot_->getTime() >= currStatus) { |
180 |
//save statistics, before writeStat, we must save statistics |
181 |
thermo.saveStat(); |
182 |
saveConservedQuantity(); |
183 |
|
184 |
if (simParams->getUseRNEMD()) { |
185 |
rnemd_->getStatus(); |
186 |
} |
187 |
|
188 |
statWriter->writeStat(currentSnapshot_->statData); |
189 |
|
190 |
progressBar->setStatus(currentSnapshot_->getTime(), runTime); |
191 |
progressBar->update(); |
192 |
|
193 |
needPotential = false; |
194 |
needStress = false; |
195 |
currStatus += statusTime; |
196 |
} |
197 |
|
198 |
if (needReset && currentSnapshot_->getTime() >= currReset) { |
199 |
resetIntegrator(); |
200 |
currReset += resetTime; |
201 |
} |
202 |
} |
203 |
|
204 |
|
205 |
void VelocityVerletIntegrator::finalize() { |
206 |
dumpWriter->writeEor(); |
207 |
|
208 |
delete dumpWriter; |
209 |
delete statWriter; |
210 |
|
211 |
dumpWriter = NULL; |
212 |
statWriter = NULL; |
213 |
|
214 |
} |
215 |
|
216 |
void VelocityVerletIntegrator::integrateStep() { |
217 |
|
218 |
moveA(); |
219 |
calcForce(); |
220 |
moveB(); |
221 |
} |
222 |
|
223 |
|
224 |
void VelocityVerletIntegrator::calcForce() { |
225 |
forceMan_->calcForces(); |
226 |
} |
227 |
|
228 |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
229 |
return new DumpWriter(info_); |
230 |
} |
231 |
|
232 |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
233 |
|
234 |
std::string statFileFormatString = simParams->getStatFileFormat(); |
235 |
StatsBitSet mask = parseStatFileFormat(statFileFormatString); |
236 |
|
237 |
// if we're doing a thermodynamic integration, we'll want the raw |
238 |
// potential as well as the full potential: |
239 |
|
240 |
|
241 |
if (simParams->getUseThermodynamicIntegration()) |
242 |
mask.set(Stats::VRAW); |
243 |
|
244 |
// if we've got restraints turned on, we'll also want a report of the |
245 |
// total harmonic restraints |
246 |
if (simParams->getUseRestraints()){ |
247 |
mask.set(Stats::VHARM); |
248 |
} |
249 |
|
250 |
if (simParams->havePrintPressureTensor() && |
251 |
simParams->getPrintPressureTensor()){ |
252 |
mask.set(Stats::PRESSURE_TENSOR_XX); |
253 |
mask.set(Stats::PRESSURE_TENSOR_XY); |
254 |
mask.set(Stats::PRESSURE_TENSOR_XZ); |
255 |
mask.set(Stats::PRESSURE_TENSOR_YX); |
256 |
mask.set(Stats::PRESSURE_TENSOR_YY); |
257 |
mask.set(Stats::PRESSURE_TENSOR_YZ); |
258 |
mask.set(Stats::PRESSURE_TENSOR_ZX); |
259 |
mask.set(Stats::PRESSURE_TENSOR_ZY); |
260 |
mask.set(Stats::PRESSURE_TENSOR_ZZ); |
261 |
} |
262 |
|
263 |
if (simParams->getAccumulateBoxDipole()) { |
264 |
mask.set(Stats::BOX_DIPOLE_X); |
265 |
mask.set(Stats::BOX_DIPOLE_Y); |
266 |
mask.set(Stats::BOX_DIPOLE_Z); |
267 |
} |
268 |
|
269 |
if (simParams->haveTaggedAtomPair() && simParams->havePrintTaggedPairDistance()) { |
270 |
if (simParams->getPrintTaggedPairDistance()) { |
271 |
mask.set(Stats::TAGGED_PAIR_DISTANCE); |
272 |
} |
273 |
} |
274 |
|
275 |
if (simParams->getUseRNEMD()) { |
276 |
mask.set(Stats::RNEMD_EXCHANGE_TOTAL); |
277 |
} |
278 |
|
279 |
|
280 |
return new StatWriter(info_->getStatFileName(), mask); |
281 |
} |
282 |
|
283 |
|
284 |
} //end namespace OpenMD |