1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
/** |
27 |
* @file VelocityVerletIntegrator.cpp |
28 |
* @author tlin |
29 |
* @date 11/09/2004 |
30 |
* @time 16:16am |
31 |
* @version 1.0 |
32 |
*/ |
33 |
|
34 |
#include "integrators/VelocityVerletIntegrator.hpp" |
35 |
#include "integrators/DLM.hpp" |
36 |
|
37 |
namespace oopse { |
38 |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
39 |
rotAlgo = new DLM(); |
40 |
dt2 = 0.5 * dt; |
41 |
} |
42 |
|
43 |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
44 |
delete rotAlgo; |
45 |
} |
46 |
|
47 |
void VelocityVerletIntegrator::initialize(){ |
48 |
|
49 |
currSample = 0.0; |
50 |
currStatus = 0.0; |
51 |
currThermal = 0.0; |
52 |
needPotential = false; |
53 |
needStress = false; |
54 |
|
55 |
// remove center of mass drift velocity (in case we passed in a configuration |
56 |
// that was drifting |
57 |
velocitizer_->removeComDrift(); |
58 |
|
59 |
// initialize the forces before the first step |
60 |
calcForce(true, true); |
61 |
|
62 |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
63 |
//if (nConstrained) { |
64 |
// constrainA(); |
65 |
// calcForce(true, true); |
66 |
// constrainB(); |
67 |
//} |
68 |
|
69 |
if (needVelocityScaling) { |
70 |
velocitizer_->velocitize(targetScalingTemp); |
71 |
} |
72 |
|
73 |
dumpWriter = createDumpWriter(); |
74 |
statWriter = createStatWriter(); |
75 |
|
76 |
dumpWriter->writeDump(); |
77 |
|
78 |
//save statistics |
79 |
thermo.saveStat(); |
80 |
saveConservedQuantity(); |
81 |
|
82 |
//before writeStat, we must save statistics |
83 |
statWriter->writeStat(currentSnapshot_->statData); |
84 |
|
85 |
} |
86 |
|
87 |
void VelocityVerletIntegrator::doIntegrate() { |
88 |
|
89 |
|
90 |
initialize(); |
91 |
|
92 |
while (currentSnapshot_->getTime() < runTime) { |
93 |
|
94 |
preStep(); |
95 |
|
96 |
integrateStep(); |
97 |
|
98 |
postStep(); |
99 |
|
100 |
} |
101 |
|
102 |
finalize(); |
103 |
|
104 |
} |
105 |
|
106 |
|
107 |
void VelocityVerletIntegrator::preStep() { |
108 |
double difference = currentSnapshot_->getTime() + dt - currStatus; |
109 |
|
110 |
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
111 |
needPotential = true; |
112 |
needStress = true; |
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
void VelocityVerletIntegrator::postStep() { |
118 |
|
119 |
//save snapshot |
120 |
info_->getSnapshotManager()->advance(); |
121 |
|
122 |
//increase time |
123 |
currentSnapshot_->increaseTime(dt); |
124 |
|
125 |
//save statistics |
126 |
thermo.saveStat(); |
127 |
saveConservedQuantity(); |
128 |
|
129 |
if (needVelocityScaling) { |
130 |
if (currentSnapshot_->getTime() >= currThermal) { |
131 |
velocitizer_->velocitize(targetScalingTemp); |
132 |
currThermal += thermalTime; |
133 |
} |
134 |
} |
135 |
|
136 |
if (currentSnapshot_->getTime() >= currSample) { |
137 |
dumpWriter->writeDump(); |
138 |
currSample += sampleTime; |
139 |
} |
140 |
|
141 |
if (currentSnapshot_->getTime() >= currStatus) { |
142 |
statWriter->writeStat(currentSnapshot_->statData); |
143 |
needPotential = false; |
144 |
needStress = false; |
145 |
currStatus += statusTime; |
146 |
} |
147 |
|
148 |
|
149 |
} |
150 |
|
151 |
|
152 |
void VelocityVerletIntegrator::finalize() { |
153 |
|
154 |
dumpWriter->writeDump(); |
155 |
|
156 |
delete dumpWriter; |
157 |
delete statWriter; |
158 |
|
159 |
dumpWriter = NULL; |
160 |
statWriter = NULL; |
161 |
|
162 |
} |
163 |
|
164 |
void VelocityVerletIntegrator::integrateStep() { |
165 |
|
166 |
moveA(); |
167 |
calcForce(needPotential, needStress); |
168 |
moveB(); |
169 |
} |
170 |
|
171 |
|
172 |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
173 |
bool needStress) { |
174 |
forceMan_->calcForces(needPotential, needStress); |
175 |
} |
176 |
|
177 |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
178 |
return new DumpWriter(info_, info_->getDumpFileName()); |
179 |
} |
180 |
|
181 |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
182 |
return new StatWriter(info_->getStatFileName()); |
183 |
} |
184 |
|
185 |
|
186 |
} //end namespace oopse |