1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
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, 24107 (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 |
|
/** |
51 |
|
#include "integrators/VelocityVerletIntegrator.hpp" |
52 |
|
#include "integrators/DLM.hpp" |
53 |
|
#include "utils/StringUtils.hpp" |
54 |
+ |
#include "utils/ProgressBar.hpp" |
55 |
|
|
56 |
< |
namespace oopse { |
57 |
< |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
56 |
> |
namespace OpenMD { |
57 |
> |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { |
58 |
|
dt2 = 0.5 * dt; |
59 |
< |
rotAlgo = new DLM(); |
60 |
< |
rattle = new Rattle(info); |
61 |
< |
} |
62 |
< |
|
63 |
< |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
64 |
< |
delete rotAlgo; |
65 |
< |
delete rattle; |
66 |
< |
} |
67 |
< |
|
68 |
< |
void VelocityVerletIntegrator::initialize(){ |
69 |
< |
|
68 |
< |
forceMan_->init(); |
69 |
< |
|
70 |
< |
// remove center of mass drift velocity (in case we passed in a configuration |
71 |
< |
// that was drifting |
59 |
> |
} |
60 |
> |
|
61 |
> |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
62 |
> |
} |
63 |
> |
|
64 |
> |
void VelocityVerletIntegrator::initialize(){ |
65 |
> |
|
66 |
> |
forceMan_->initialize(); |
67 |
> |
|
68 |
> |
// remove center of mass drift velocity (in case we passed in a |
69 |
> |
// configuration that was drifting) |
70 |
|
velocitizer_->removeComDrift(); |
71 |
|
|
72 |
+ |
// find the initial fluctuating charges. |
73 |
+ |
flucQ_->initialize(); |
74 |
+ |
|
75 |
|
// initialize the forces before the first step |
76 |
< |
calcForce(true, true); |
77 |
< |
|
78 |
< |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
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(true, true); |
83 |
< |
rattle->constraintB(); |
84 |
< |
info_->getSnapshotManager()->advance();//copy the current snapshot to previous snapshot |
81 |
> |
rattle_->constraintA(); |
82 |
> |
calcForce(); |
83 |
> |
rattle_->constraintB(); |
84 |
> |
//copy the current snapshot to previous snapshot |
85 |
> |
info_->getSnapshotManager()->advance(); |
86 |
|
} |
87 |
< |
|
87 |
> |
|
88 |
|
if (needVelocityScaling) { |
89 |
< |
velocitizer_->velocitize(targetScalingTemp); |
89 |
> |
velocitizer_->velocitize(targetScalingTemp); |
90 |
|
} |
91 |
|
|
92 |
|
dumpWriter = createDumpWriter(); |
93 |
< |
|
93 |
> |
|
94 |
|
statWriter = createStatWriter(); |
95 |
< |
|
95 |
> |
|
96 |
|
dumpWriter->writeDumpAndEor(); |
97 |
< |
|
97 |
> |
|
98 |
> |
progressBar = new ProgressBar(); |
99 |
> |
|
100 |
|
//save statistics, before writeStat, we must save statistics |
96 |
– |
thermo.saveStat(); |
101 |
|
saveConservedQuantity(); |
102 |
< |
statWriter->writeStat(currentSnapshot_->statData); |
102 |
> |
stats->collectStats(); |
103 |
|
|
104 |
< |
currSample = sampleTime + currentSnapshot_->getTime(); |
105 |
< |
currStatus = statusTime + currentSnapshot_->getTime();; |
106 |
< |
currThermal = thermalTime + + currentSnapshot_->getTime(); |
104 |
> |
if (simParams->getRNEMDParameters()->getUseRNEMD()) |
105 |
> |
rnemd_->getStarted(); |
106 |
> |
|
107 |
> |
statWriter->writeStat(); |
108 |
> |
|
109 |
> |
currSample = sampleTime + snap->getTime(); |
110 |
> |
currStatus = statusTime + snap->getTime(); |
111 |
> |
currThermal = thermalTime + snap->getTime(); |
112 |
> |
if (needReset) { |
113 |
> |
currReset = resetTime + snap->getTime(); |
114 |
> |
} |
115 |
> |
if (simParams->getRNEMDParameters()->getUseRNEMD()){ |
116 |
> |
currRNEMD = RNEMD_exchangeTime + snap->getTime(); |
117 |
> |
} |
118 |
|
needPotential = false; |
119 |
|
needStress = false; |
120 |
< |
|
121 |
< |
} |
122 |
< |
|
123 |
< |
void VelocityVerletIntegrator::doIntegrate() { |
124 |
< |
|
110 |
< |
|
120 |
> |
|
121 |
> |
} |
122 |
> |
|
123 |
> |
void VelocityVerletIntegrator::doIntegrate() { |
124 |
> |
|
125 |
|
initialize(); |
126 |
+ |
|
127 |
+ |
while (snap->getTime() < runTime) { |
128 |
+ |
preStep(); |
129 |
+ |
integrateStep(); |
130 |
+ |
postStep(); |
131 |
+ |
} |
132 |
+ |
finalize(); |
133 |
+ |
} |
134 |
|
|
113 |
– |
while (currentSnapshot_->getTime() < runTime) { |
114 |
– |
|
115 |
– |
preStep(); |
135 |
|
|
136 |
< |
integrateStep(); |
137 |
< |
|
138 |
< |
postStep(); |
139 |
< |
|
136 |
> |
void VelocityVerletIntegrator::preStep() { |
137 |
> |
RealType difference = snap->getTime() + dt - currStatus; |
138 |
> |
|
139 |
> |
if (difference > 0 || fabs(difference) < OpenMD::epsilon) { |
140 |
> |
needPotential = true; |
141 |
> |
needStress = true; |
142 |
|
} |
143 |
+ |
} |
144 |
|
|
145 |
< |
finalize(); |
145 |
> |
void VelocityVerletIntegrator::postStep() { |
146 |
> |
|
147 |
> |
//save snapshot |
148 |
> |
info_->getSnapshotManager()->advance(); |
149 |
> |
|
150 |
> |
//increase time |
151 |
> |
snap->increaseTime(dt); |
152 |
> |
|
153 |
> |
if (needVelocityScaling) { |
154 |
> |
if (snap->getTime() >= currThermal) { |
155 |
> |
velocitizer_->velocitize(targetScalingTemp); |
156 |
> |
currThermal += thermalTime; |
157 |
> |
} |
158 |
> |
} |
159 |
> |
if (useRNEMD) { |
160 |
> |
if (snap->getTime() >= currRNEMD) { |
161 |
> |
rnemd_->doRNEMD(); |
162 |
> |
currRNEMD += RNEMD_exchangeTime; |
163 |
> |
} |
164 |
> |
rnemd_->collectData(); |
165 |
> |
} |
166 |
|
|
167 |
< |
} |
167 |
> |
if (snap->getTime() >= currSample) { |
168 |
> |
dumpWriter->writeDumpAndEor(); |
169 |
> |
|
170 |
> |
currSample += sampleTime; |
171 |
> |
} |
172 |
> |
|
173 |
> |
if (snap->getTime() >= currStatus) { |
174 |
> |
//save statistics, before writeStat, we must save statistics |
175 |
> |
stats->collectStats(); |
176 |
> |
saveConservedQuantity(); |
177 |
|
|
178 |
+ |
if (simParams->getRNEMDParameters()->getUseRNEMD()) { |
179 |
+ |
rnemd_->writeOutputFile(); |
180 |
+ |
} |
181 |
|
|
182 |
< |
void VelocityVerletIntegrator::preStep() { |
129 |
< |
double difference = currentSnapshot_->getTime() + dt - currStatus; |
182 |
> |
statWriter->writeStat(); |
183 |
|
|
184 |
< |
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
185 |
< |
needPotential = true; |
133 |
< |
needStress = true; |
134 |
< |
} |
184 |
> |
progressBar->setStatus(snap->getTime(), runTime); |
185 |
> |
progressBar->update(); |
186 |
|
|
187 |
< |
} |
187 |
> |
needPotential = false; |
188 |
> |
needStress = false; |
189 |
> |
currStatus += statusTime; |
190 |
> |
} |
191 |
> |
|
192 |
> |
if (needReset && snap->getTime() >= currReset) { |
193 |
> |
resetIntegrator(); |
194 |
> |
currReset += resetTime; |
195 |
> |
} |
196 |
> |
} |
197 |
|
|
138 |
– |
void VelocityVerletIntegrator::postStep() { |
198 |
|
|
199 |
< |
//save snapshot |
200 |
< |
info_->getSnapshotManager()->advance(); |
201 |
< |
|
202 |
< |
//increase time |
144 |
< |
currentSnapshot_->increaseTime(dt); |
145 |
< |
|
146 |
< |
if (needVelocityScaling) { |
147 |
< |
if (currentSnapshot_->getTime() >= currThermal) { |
148 |
< |
velocitizer_->velocitize(targetScalingTemp); |
149 |
< |
currThermal += thermalTime; |
150 |
< |
} |
151 |
< |
} |
152 |
< |
|
153 |
< |
if (currentSnapshot_->getTime() >= currSample) { |
154 |
< |
dumpWriter->writeDumpAndEor(); |
155 |
< |
currSample += sampleTime; |
156 |
< |
} |
157 |
< |
|
158 |
< |
if (currentSnapshot_->getTime() >= currStatus) { |
159 |
< |
//save statistics, before writeStat, we must save statistics |
160 |
< |
thermo.saveStat(); |
161 |
< |
saveConservedQuantity(); |
162 |
< |
statWriter->writeStat(currentSnapshot_->statData); |
163 |
< |
|
164 |
< |
needPotential = false; |
165 |
< |
needStress = false; |
166 |
< |
currStatus += statusTime; |
167 |
< |
} |
168 |
< |
|
169 |
< |
|
170 |
< |
} |
171 |
< |
|
172 |
< |
|
173 |
< |
void VelocityVerletIntegrator::finalize() { |
174 |
< |
dumpWriter->writeEor(); |
175 |
< |
|
199 |
> |
void VelocityVerletIntegrator::finalize() { |
200 |
> |
dumpWriter->writeEor(); |
201 |
> |
rnemd_->writeOutputFile(); |
202 |
> |
|
203 |
|
delete dumpWriter; |
204 |
|
delete statWriter; |
205 |
< |
|
205 |
> |
|
206 |
|
dumpWriter = NULL; |
207 |
|
statWriter = NULL; |
208 |
< |
|
182 |
< |
} |
208 |
> |
} |
209 |
|
|
210 |
< |
void VelocityVerletIntegrator::integrateStep() { |
211 |
< |
|
210 |
> |
void VelocityVerletIntegrator::integrateStep() { |
211 |
> |
|
212 |
|
moveA(); |
213 |
< |
calcForce(needPotential, needStress); |
213 |
> |
calcForce(); |
214 |
|
moveB(); |
215 |
< |
} |
215 |
> |
} |
216 |
|
|
217 |
|
|
218 |
< |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
219 |
< |
bool needStress) { |
220 |
< |
forceMan_->calcForces(needPotential, needStress); |
221 |
< |
} |
218 |
> |
void VelocityVerletIntegrator::calcForce() { |
219 |
> |
forceMan_->calcForces(); |
220 |
> |
flucQ_->applyConstraints(); |
221 |
> |
} |
222 |
|
|
223 |
< |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
223 |
> |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
224 |
|
return new DumpWriter(info_); |
225 |
< |
} |
225 |
> |
} |
226 |
|
|
227 |
< |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
228 |
< |
return new StatWriter(info_->getStatFileName()); |
229 |
< |
} |
227 |
> |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
228 |
> |
|
229 |
> |
stats = new Stats(info_); |
230 |
> |
statWriter = new StatWriter(info_->getStatFileName(), stats); |
231 |
> |
|
232 |
> |
return statWriter; |
233 |
> |
} |
234 |
|
|
235 |
< |
|
206 |
< |
} //end namespace oopse |
235 |
> |
} //end namespace OpenMD |