ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/VelocityVerletIntegrator.cpp
Revision: 1723
Committed: Thu May 24 20:59:54 2012 UTC (12 years, 11 months ago) by gezelter
File size: 8407 byte(s)
Log Message:
Bug fixes for heat flux import

File Contents

# User Rev Content
1 gezelter 507 /*
2 gezelter 246 * 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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 gezelter 246 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 gezelter 246 * 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 gezelter 1390 *
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 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 246 */
42    
43     /**
44     * @file VelocityVerletIntegrator.cpp
45     * @author tlin
46     * @date 11/09/2004
47     * @time 16:16am
48     * @version 1.0
49     */
50    
51     #include "integrators/VelocityVerletIntegrator.hpp"
52     #include "integrators/DLM.hpp"
53 tim 276 #include "utils/StringUtils.hpp"
54 gezelter 1413 #include "utils/ProgressBar.hpp"
55 gezelter 246
56 gezelter 1390 namespace OpenMD {
57 gezelter 1715 VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) {
58 gezelter 246 dt2 = 0.5 * dt;
59 chrisfen 417 }
60    
61     VelocityVerletIntegrator::~VelocityVerletIntegrator() {
62     }
63    
64     void VelocityVerletIntegrator::initialize(){
65    
66 gezelter 1576 forceMan_->initialize();
67 chrisfen 417
68 chrisfen 993 // remove center of mass drift velocity (in case we passed in a
69     // configuration that was drifting)
70 gezelter 246 velocitizer_->removeComDrift();
71 gezelter 1715
72     // find the initial fluctuating charges.
73     flucQ_->initialize();
74 chrisfen 417
75 gezelter 246 // initialize the forces before the first step
76 gezelter 1464 calcForce();
77 chrisfen 417
78 chrisfen 993 // execute the constraint algorithm to make sure that the system is
79     // constrained at the very beginning
80 gezelter 246 if (info_->getNGlobalConstraints() > 0) {
81 gezelter 1715 rattle_->constraintA();
82 gezelter 1464 calcForce();
83 gezelter 1715 rattle_->constraintB();
84 chrisfen 993 //copy the current snapshot to previous snapshot
85     info_->getSnapshotManager()->advance();
86 gezelter 246 }
87 chrisfen 417
88 gezelter 246 if (needVelocityScaling) {
89 chrisfen 417 velocitizer_->velocitize(targetScalingTemp);
90 gezelter 246 }
91    
92     dumpWriter = createDumpWriter();
93 chrisfen 417
94 gezelter 246 statWriter = createStatWriter();
95 chrisfen 993
96     dumpWriter->writeDumpAndEor();
97    
98 gezelter 1413 progressBar = new ProgressBar();
99    
100 gezelter 246 //save statistics, before writeStat, we must save statistics
101     thermo.saveStat();
102     saveConservedQuantity();
103 skuang 1341 if (simParams->getUseRNEMD())
104 skuang 1368 rnemd_->getStarted();
105 skuang 1341
106 gezelter 246 statWriter->writeStat(currentSnapshot_->statData);
107 chrisfen 417
108 gezelter 246 currSample = sampleTime + currentSnapshot_->getTime();
109 gezelter 1329 currStatus = statusTime + currentSnapshot_->getTime();
110 tim 546 currThermal = thermalTime + currentSnapshot_->getTime();
111     if (needReset) {
112     currReset = resetTime + currentSnapshot_->getTime();
113     }
114 gezelter 1329 if (simParams->getUseRNEMD()){
115 skuang 1368 currRNEMD = RNEMD_exchangeTime + currentSnapshot_->getTime();
116 gezelter 1329 }
117 gezelter 246 needPotential = false;
118     needStress = false;
119 chrisfen 417
120 gezelter 507 }
121 gezelter 1413
122 gezelter 507 void VelocityVerletIntegrator::doIntegrate() {
123 chrisfen 417
124 gezelter 507 initialize();
125 chrisfen 417
126 gezelter 1715 while (currentSnapshot_->getTime() < runTime) {
127     preStep();
128     integrateStep();
129     postStep();
130     }
131 gezelter 507 finalize();
132     }
133 gezelter 246
134    
135 gezelter 507 void VelocityVerletIntegrator::preStep() {
136 tim 963 RealType difference = currentSnapshot_->getTime() + dt - currStatus;
137 chrisfen 417
138 gezelter 1390 if (difference > 0 || fabs(difference) < OpenMD::epsilon) {
139 gezelter 507 needPotential = true;
140     needStress = true;
141     }
142 chrisfen 417 }
143 gezelter 246
144 gezelter 507 void VelocityVerletIntegrator::postStep() {
145 tim 749
146 gezelter 507 //save snapshot
147     info_->getSnapshotManager()->advance();
148 chrisfen 417
149 gezelter 507 //increase time
150     currentSnapshot_->increaseTime(dt);
151 chrisfen 993
152 gezelter 507 if (needVelocityScaling) {
153     if (currentSnapshot_->getTime() >= currThermal) {
154     velocitizer_->velocitize(targetScalingTemp);
155     currThermal += thermalTime;
156     }
157 chrisfen 417 }
158 gezelter 1329 if (useRNEMD) {
159     if (currentSnapshot_->getTime() >= currRNEMD) {
160 skuang 1368 rnemd_->doRNEMD();
161     currRNEMD += RNEMD_exchangeTime;
162 gezelter 1329 }
163 gezelter 1396 rnemd_->collectData();
164 gezelter 1329 }
165    
166 gezelter 507 if (currentSnapshot_->getTime() >= currSample) {
167     dumpWriter->writeDumpAndEor();
168 gezelter 1329
169 gezelter 507 currSample += sampleTime;
170     }
171 gezelter 1329
172 gezelter 507 if (currentSnapshot_->getTime() >= currStatus) {
173     //save statistics, before writeStat, we must save statistics
174     thermo.saveStat();
175     saveConservedQuantity();
176 skuang 1341
177 skuang 1368 if (simParams->getUseRNEMD()) {
178 skuang 1338 rnemd_->getStatus();
179 skuang 1368 }
180 skuang 1341
181     statWriter->writeStat(currentSnapshot_->statData);
182 gezelter 1413
183     progressBar->setStatus(currentSnapshot_->getTime(), runTime);
184     progressBar->update();
185    
186 gezelter 507 needPotential = false;
187     needStress = false;
188     currStatus += statusTime;
189     }
190 gezelter 1329
191     if (needReset && currentSnapshot_->getTime() >= currReset) {
192     resetIntegrator();
193     currReset += resetTime;
194     }
195 gezelter 507 }
196 gezelter 246
197    
198 gezelter 507 void VelocityVerletIntegrator::finalize() {
199     dumpWriter->writeEor();
200 chrisfen 417
201 gezelter 507 delete dumpWriter;
202     delete statWriter;
203 chrisfen 417
204 gezelter 507 dumpWriter = NULL;
205     statWriter = NULL;
206     }
207 gezelter 246
208 gezelter 507 void VelocityVerletIntegrator::integrateStep() {
209 chrisfen 417
210 gezelter 507 moveA();
211 gezelter 1464 calcForce();
212 gezelter 507 moveB();
213     }
214 gezelter 246
215    
216 gezelter 1464 void VelocityVerletIntegrator::calcForce() {
217     forceMan_->calcForces();
218 gezelter 1718 flucQ_->applyConstraints();
219 gezelter 507 }
220 gezelter 246
221 gezelter 507 DumpWriter* VelocityVerletIntegrator::createDumpWriter() {
222     return new DumpWriter(info_);
223     }
224 gezelter 246
225 gezelter 507 StatWriter* VelocityVerletIntegrator::createStatWriter() {
226 tim 681
227     std::string statFileFormatString = simParams->getStatFileFormat();
228     StatsBitSet mask = parseStatFileFormat(statFileFormatString);
229 cli2 1360
230     // if we're doing a thermodynamic integration, we'll want the raw
231     // potential as well as the full potential:
232    
233    
234     if (simParams->getUseThermodynamicIntegration())
235 gezelter 507 mask.set(Stats::VRAW);
236 cli2 1360
237     // if we've got restraints turned on, we'll also want a report of the
238     // total harmonic restraints
239     if (simParams->getUseRestraints()){
240 gezelter 507 mask.set(Stats::VHARM);
241     }
242 tim 541
243 chrisfen 993 if (simParams->havePrintPressureTensor() &&
244     simParams->getPrintPressureTensor()){
245 gezelter 1291 mask.set(Stats::PRESSURE_TENSOR_XX);
246     mask.set(Stats::PRESSURE_TENSOR_XY);
247     mask.set(Stats::PRESSURE_TENSOR_XZ);
248     mask.set(Stats::PRESSURE_TENSOR_YX);
249     mask.set(Stats::PRESSURE_TENSOR_YY);
250     mask.set(Stats::PRESSURE_TENSOR_YZ);
251     mask.set(Stats::PRESSURE_TENSOR_ZX);
252     mask.set(Stats::PRESSURE_TENSOR_ZY);
253     mask.set(Stats::PRESSURE_TENSOR_ZZ);
254 tim 541 }
255    
256 chrisfen 998 if (simParams->getAccumulateBoxDipole()) {
257     mask.set(Stats::BOX_DIPOLE_X);
258     mask.set(Stats::BOX_DIPOLE_Y);
259     mask.set(Stats::BOX_DIPOLE_Z);
260     }
261 gezelter 1723
262     if (simParams->getPrintHeatFlux()) {
263     mask.set(Stats::HEATFLUX_X);
264     mask.set(Stats::HEATFLUX_Y);
265     mask.set(Stats::HEATFLUX_Z);
266     }
267 gezelter 1329
268 gezelter 1291 if (simParams->haveTaggedAtomPair() && simParams->havePrintTaggedPairDistance()) {
269     if (simParams->getPrintTaggedPairDistance()) {
270     mask.set(Stats::TAGGED_PAIR_DISTANCE);
271     }
272     }
273 gezelter 1329
274     if (simParams->getUseRNEMD()) {
275 skuang 1368 mask.set(Stats::RNEMD_EXCHANGE_TOTAL);
276 gezelter 1329 }
277 skuang 1368
278 chrisfen 998
279 skuang 1368 return new StatWriter(info_->getStatFileName(), mask);
280 chrisfen 417 }
281 gezelter 246
282    
283 gezelter 1390 } //end namespace OpenMD

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date