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 |
|
36 |
namespace oopse { |
37 |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { |
38 |
dt2 = 0.5 * dt; |
39 |
} |
40 |
|
41 |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { } |
42 |
|
43 |
void VelocityVerletIntegrator::initialize(){ |
44 |
|
45 |
currSample = 0.0; |
46 |
currStatus = 0.0; |
47 |
currThermal = 0.0; |
48 |
needPotential = false; |
49 |
needStress = false; |
50 |
|
51 |
// remove center of mass drift velocity (in case we passed in a configuration |
52 |
// that was drifting |
53 |
velocitizer_->removeComDrift(); |
54 |
|
55 |
// initialize the forces before the first step |
56 |
calcForce(true, true); |
57 |
|
58 |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
59 |
//if (nConstrained) { |
60 |
// constrainA(); |
61 |
// calcForce(true, true); |
62 |
// constrainB(); |
63 |
//} |
64 |
|
65 |
if (needVelocityScaling) { |
66 |
velocitizer_->velocitize(targetScalingTemp); |
67 |
} |
68 |
|
69 |
dumpWriter = createDumpWriter(); |
70 |
statWriter = createStatWriter(); |
71 |
|
72 |
dumpWriter->writeFrame(); |
73 |
statWriter->writeStat(currentSnapshot_.statData); |
74 |
|
75 |
|
76 |
} |
77 |
|
78 |
void VelocityVerletIntegrator::doIntegrate() { |
79 |
|
80 |
|
81 |
initialize(); |
82 |
|
83 |
while (currentSnapshot_->getTime() < runTime) { |
84 |
|
85 |
preStep(); |
86 |
|
87 |
integrateStep(); |
88 |
|
89 |
info_->incrTime(dt); |
90 |
|
91 |
postStep(); |
92 |
|
93 |
} |
94 |
|
95 |
finalize(); |
96 |
|
97 |
} |
98 |
|
99 |
|
100 |
void VelocityVerletIntegrator::preStep() { |
101 |
double difference = currentSnapshot_->getTime() + dt - currStatus; |
102 |
|
103 |
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
104 |
needPotential = true; |
105 |
needStress = true; |
106 |
} |
107 |
|
108 |
} |
109 |
|
110 |
void VelocityVerletIntegrator::postStep() { |
111 |
|
112 |
|
113 |
if (needVelocityScaling) { |
114 |
if (currentSnapshot_->getTime() >= currThermal) { |
115 |
velocitizer_->velocitize(targetScalingTemp); |
116 |
currThermal += thermalTime; |
117 |
} |
118 |
} |
119 |
|
120 |
if (currentSnapshot_->getTime() >= currSample) { |
121 |
dumpWriter->writeFrame(currentSnapshot_->getTime()); |
122 |
currSample += sampleTime; |
123 |
} |
124 |
|
125 |
if (currentSnapshot_->getTime() >= currStatus) { |
126 |
statWriter->writeStat(currentSnapshot_.statData); |
127 |
needPotential = false; |
128 |
needStress = false; |
129 |
currStatus += statusTime; |
130 |
} |
131 |
} |
132 |
|
133 |
|
134 |
void VelocityVerletIntegrator::finalize() { |
135 |
|
136 |
dumpWriter->writeFrame(); |
137 |
|
138 |
delete dumpWriter; |
139 |
delete statWriter; |
140 |
|
141 |
dumpWriter = NULL; |
142 |
statWriter = NULL; |
143 |
|
144 |
} |
145 |
|
146 |
void VelocityVerletIntegrator::integrateStep() { |
147 |
|
148 |
moveA(); |
149 |
calcForce(needPotential, needStress); |
150 |
moveB(); |
151 |
} |
152 |
|
153 |
|
154 |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
155 |
bool needStress) { |
156 |
forceMan_->calcForces(needPotential, needStress) |
157 |
} |
158 |
|
159 |
|
160 |
} //end namespace oopse |