1 |
gezelter |
246 |
/* |
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. 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 |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
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 |
tim |
276 |
#include "utils/StringUtils.hpp" |
53 |
gezelter |
246 |
|
54 |
|
|
namespace oopse { |
55 |
chrisfen |
417 |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
56 |
gezelter |
246 |
dt2 = 0.5 * dt; |
57 |
|
|
rotAlgo = new DLM(); |
58 |
|
|
rattle = new Rattle(info); |
59 |
chrisfen |
417 |
} |
60 |
|
|
|
61 |
|
|
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
62 |
gezelter |
246 |
delete rotAlgo; |
63 |
|
|
delete rattle; |
64 |
chrisfen |
417 |
} |
65 |
|
|
|
66 |
|
|
void VelocityVerletIntegrator::initialize(){ |
67 |
|
|
|
68 |
gezelter |
246 |
forceMan_->init(); |
69 |
chrisfen |
417 |
|
70 |
gezelter |
246 |
// remove center of mass drift velocity (in case we passed in a configuration |
71 |
|
|
// that was drifting |
72 |
|
|
velocitizer_->removeComDrift(); |
73 |
chrisfen |
417 |
|
74 |
gezelter |
246 |
// initialize the forces before the first step |
75 |
|
|
calcForce(true, true); |
76 |
chrisfen |
417 |
|
77 |
gezelter |
246 |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
78 |
|
|
if (info_->getNGlobalConstraints() > 0) { |
79 |
chrisfen |
417 |
rattle->constraintA(); |
80 |
|
|
calcForce(true, true); |
81 |
|
|
rattle->constraintB(); |
82 |
|
|
info_->getSnapshotManager()->advance();//copy the current snapshot to previous snapshot |
83 |
gezelter |
246 |
} |
84 |
chrisfen |
417 |
|
85 |
gezelter |
246 |
if (needVelocityScaling) { |
86 |
chrisfen |
417 |
velocitizer_->velocitize(targetScalingTemp); |
87 |
gezelter |
246 |
} |
88 |
|
|
|
89 |
|
|
dumpWriter = createDumpWriter(); |
90 |
chrisfen |
417 |
|
91 |
gezelter |
246 |
statWriter = createStatWriter(); |
92 |
chrisfen |
417 |
|
93 |
|
|
if (simParams->getUseSolidThermInt()) { |
94 |
|
|
restWriter = createRestWriter(); |
95 |
|
|
restWriter->writeZangle(); |
96 |
|
|
} |
97 |
|
|
|
98 |
tim |
376 |
dumpWriter->writeDumpAndEor(); |
99 |
tim |
276 |
|
100 |
chrisfen |
417 |
|
101 |
gezelter |
246 |
//save statistics, before writeStat, we must save statistics |
102 |
|
|
thermo.saveStat(); |
103 |
|
|
saveConservedQuantity(); |
104 |
|
|
statWriter->writeStat(currentSnapshot_->statData); |
105 |
chrisfen |
417 |
|
106 |
gezelter |
246 |
currSample = sampleTime + currentSnapshot_->getTime(); |
107 |
|
|
currStatus = statusTime + currentSnapshot_->getTime();; |
108 |
|
|
currThermal = thermalTime + + currentSnapshot_->getTime(); |
109 |
|
|
needPotential = false; |
110 |
|
|
needStress = false; |
111 |
chrisfen |
417 |
|
112 |
gezelter |
246 |
} |
113 |
chrisfen |
417 |
|
114 |
gezelter |
246 |
void VelocityVerletIntegrator::doIntegrate() { |
115 |
chrisfen |
417 |
|
116 |
|
|
|
117 |
|
|
initialize(); |
118 |
|
|
|
119 |
|
|
while (currentSnapshot_->getTime() < runTime) { |
120 |
gezelter |
246 |
|
121 |
chrisfen |
417 |
preStep(); |
122 |
|
|
|
123 |
|
|
integrateStep(); |
124 |
|
|
|
125 |
|
|
postStep(); |
126 |
|
|
|
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
finalize(); |
130 |
|
|
|
131 |
gezelter |
246 |
} |
132 |
|
|
|
133 |
|
|
|
134 |
|
|
void VelocityVerletIntegrator::preStep() { |
135 |
chrisfen |
417 |
double difference = currentSnapshot_->getTime() + dt - currStatus; |
136 |
|
|
|
137 |
|
|
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
138 |
|
|
needPotential = true; |
139 |
|
|
needStress = true; |
140 |
|
|
} |
141 |
|
|
|
142 |
gezelter |
246 |
} |
143 |
|
|
|
144 |
|
|
void VelocityVerletIntegrator::postStep() { |
145 |
chrisfen |
417 |
|
146 |
|
|
//save snapshot |
147 |
|
|
info_->getSnapshotManager()->advance(); |
148 |
|
|
|
149 |
|
|
//increase time |
150 |
|
|
currentSnapshot_->increaseTime(dt); |
151 |
|
|
|
152 |
|
|
if (needVelocityScaling) { |
153 |
|
|
if (currentSnapshot_->getTime() >= currThermal) { |
154 |
|
|
velocitizer_->velocitize(targetScalingTemp); |
155 |
|
|
currThermal += thermalTime; |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
if (currentSnapshot_->getTime() >= currSample) { |
160 |
|
|
dumpWriter->writeDumpAndEor(); |
161 |
|
|
|
162 |
|
|
if (simParams->getUseSolidThermInt()) |
163 |
|
|
restWriter->writeZangle(); |
164 |
|
|
|
165 |
|
|
currSample += sampleTime; |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
if (currentSnapshot_->getTime() >= currStatus) { |
169 |
|
|
//save statistics, before writeStat, we must save statistics |
170 |
|
|
thermo.saveStat(); |
171 |
|
|
saveConservedQuantity(); |
172 |
|
|
statWriter->writeStat(currentSnapshot_->statData); |
173 |
|
|
|
174 |
|
|
needPotential = false; |
175 |
|
|
needStress = false; |
176 |
|
|
currStatus += statusTime; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
|
180 |
gezelter |
246 |
} |
181 |
|
|
|
182 |
|
|
|
183 |
|
|
void VelocityVerletIntegrator::finalize() { |
184 |
chrisfen |
417 |
dumpWriter->writeEor(); |
185 |
|
|
|
186 |
|
|
if (simParams->getUseSolidThermInt()) { |
187 |
|
|
restWriter->writeZangle(); |
188 |
|
|
delete restWriter; |
189 |
|
|
restWriter = NULL; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
delete dumpWriter; |
193 |
|
|
delete statWriter; |
194 |
|
|
|
195 |
|
|
dumpWriter = NULL; |
196 |
|
|
statWriter = NULL; |
197 |
|
|
|
198 |
gezelter |
246 |
} |
199 |
|
|
|
200 |
|
|
void VelocityVerletIntegrator::integrateStep() { |
201 |
chrisfen |
417 |
|
202 |
|
|
moveA(); |
203 |
|
|
calcForce(needPotential, needStress); |
204 |
|
|
moveB(); |
205 |
gezelter |
246 |
} |
206 |
|
|
|
207 |
|
|
|
208 |
|
|
void VelocityVerletIntegrator::calcForce(bool needPotential, |
209 |
|
|
bool needStress) { |
210 |
chrisfen |
417 |
forceMan_->calcForces(needPotential, needStress); |
211 |
gezelter |
246 |
} |
212 |
|
|
|
213 |
|
|
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
214 |
chrisfen |
417 |
return new DumpWriter(info_); |
215 |
gezelter |
246 |
} |
216 |
|
|
|
217 |
|
|
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
218 |
chrisfen |
417 |
// if solidThermInt is true, add extra information to the statfile |
219 |
|
|
if (simParams->getUseSolidThermInt()){ |
220 |
|
|
StatsBitSet mask; |
221 |
|
|
mask.set(Stats::TIME); |
222 |
|
|
mask.set(Stats::TOTAL_ENERGY); |
223 |
|
|
mask.set(Stats::POTENTIAL_ENERGY); |
224 |
|
|
mask.set(Stats::KINETIC_ENERGY); |
225 |
|
|
mask.set(Stats::TEMPERATURE); |
226 |
|
|
mask.set(Stats::PRESSURE); |
227 |
chrisfen |
471 |
mask.set(Stats::VOLUME); |
228 |
chrisfen |
417 |
mask.set(Stats::CONSERVED_QUANTITY); |
229 |
|
|
mask.set(Stats::VRAW); |
230 |
|
|
mask.set(Stats::VHARM); |
231 |
|
|
return new StatWriter(info_->getStatFileName(), mask); |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
return new StatWriter(info_->getStatFileName()); |
235 |
gezelter |
246 |
} |
236 |
|
|
|
237 |
chrisfen |
417 |
RestWriter* VelocityVerletIntegrator::createRestWriter(){ |
238 |
|
|
return new RestWriter(info_); |
239 |
|
|
} |
240 |
gezelter |
246 |
|
241 |
chrisfen |
417 |
|
242 |
gezelter |
246 |
} //end namespace oopse |