1 |
tim |
1722 |
/* |
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 |
tim |
1725 |
/** |
27 |
|
|
* @file VelocityVerletIntegrator.cpp |
28 |
|
|
* @author tlin |
29 |
|
|
* @date 11/09/2004 |
30 |
|
|
* @time 16:16am |
31 |
|
|
* @version 1.0 |
32 |
|
|
*/ |
33 |
|
|
|
34 |
tim |
1722 |
#include "integrators/VelocityVerletIntegrator.hpp" |
35 |
tim |
1820 |
#include "integrators/DLM.hpp" |
36 |
tim |
1722 |
|
37 |
|
|
namespace oopse { |
38 |
tim |
1820 |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
39 |
|
|
rotAlgo = new DLM(); |
40 |
tim |
1819 |
dt2 = 0.5 * dt; |
41 |
|
|
} |
42 |
tim |
1722 |
|
43 |
tim |
1820 |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
44 |
|
|
delete rotAlgo; |
45 |
|
|
} |
46 |
tim |
1722 |
|
47 |
tim |
1819 |
void VelocityVerletIntegrator::initialize(){ |
48 |
tim |
1722 |
|
49 |
tim |
1819 |
currSample = 0.0; |
50 |
|
|
currStatus = 0.0; |
51 |
|
|
currThermal = 0.0; |
52 |
|
|
needPotential = false; |
53 |
|
|
needStress = false; |
54 |
tim |
1722 |
|
55 |
tim |
1725 |
// remove center of mass drift velocity (in case we passed in a configuration |
56 |
|
|
// that was drifting |
57 |
tim |
1819 |
velocitizer_->removeComDrift(); |
58 |
tim |
1722 |
|
59 |
tim |
1725 |
// initialize the forces before the first step |
60 |
tim |
1819 |
calcForce(true, true); |
61 |
tim |
1722 |
|
62 |
tim |
1725 |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
63 |
tim |
1819 |
//if (nConstrained) { |
64 |
|
|
// constrainA(); |
65 |
|
|
// calcForce(true, true); |
66 |
|
|
// constrainB(); |
67 |
|
|
//} |
68 |
tim |
1725 |
|
69 |
tim |
1819 |
if (needVelocityScaling) { |
70 |
|
|
velocitizer_->velocitize(targetScalingTemp); |
71 |
tim |
1725 |
} |
72 |
tim |
1819 |
|
73 |
|
|
dumpWriter = createDumpWriter(); |
74 |
|
|
statWriter = createStatWriter(); |
75 |
tim |
1725 |
|
76 |
tim |
1820 |
dumpWriter->writeDump(); |
77 |
|
|
statWriter->writeStat(currentSnapshot_->statData); |
78 |
|
|
|
79 |
tim |
1819 |
} |
80 |
|
|
|
81 |
|
|
void VelocityVerletIntegrator::doIntegrate() { |
82 |
tim |
1725 |
|
83 |
|
|
|
84 |
tim |
1819 |
initialize(); |
85 |
tim |
1725 |
|
86 |
tim |
1819 |
while (currentSnapshot_->getTime() < runTime) { |
87 |
|
|
|
88 |
|
|
preStep(); |
89 |
tim |
1725 |
|
90 |
tim |
1819 |
integrateStep(); |
91 |
|
|
|
92 |
|
|
postStep(); |
93 |
|
|
|
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
finalize(); |
97 |
|
|
|
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
void VelocityVerletIntegrator::preStep() { |
102 |
|
|
double difference = currentSnapshot_->getTime() + dt - currStatus; |
103 |
|
|
|
104 |
|
|
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
105 |
|
|
needPotential = true; |
106 |
|
|
needStress = true; |
107 |
tim |
1725 |
} |
108 |
|
|
|
109 |
tim |
1819 |
} |
110 |
|
|
|
111 |
|
|
void VelocityVerletIntegrator::postStep() { |
112 |
tim |
1820 |
|
113 |
|
|
//save snapshot |
114 |
|
|
info_->getSnapshotManager()->advance(); |
115 |
|
|
|
116 |
|
|
//increase time |
117 |
|
|
currentSnapshot_->increaseTime(dt); |
118 |
|
|
|
119 |
|
|
//save statistics |
120 |
|
|
thermo.saveStat(); |
121 |
tim |
1756 |
|
122 |
tim |
1819 |
if (needVelocityScaling) { |
123 |
|
|
if (currentSnapshot_->getTime() >= currThermal) { |
124 |
|
|
velocitizer_->velocitize(targetScalingTemp); |
125 |
tim |
1725 |
currThermal += thermalTime; |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
tim |
1819 |
if (currentSnapshot_->getTime() >= currSample) { |
130 |
tim |
1820 |
dumpWriter->writeDump(); |
131 |
tim |
1725 |
currSample += sampleTime; |
132 |
|
|
} |
133 |
|
|
|
134 |
tim |
1819 |
if (currentSnapshot_->getTime() >= currStatus) { |
135 |
tim |
1820 |
statWriter->writeStat(currentSnapshot_->statData); |
136 |
tim |
1819 |
needPotential = false; |
137 |
|
|
needStress = false; |
138 |
tim |
1725 |
currStatus += statusTime; |
139 |
|
|
} |
140 |
tim |
1820 |
|
141 |
|
|
|
142 |
tim |
1819 |
} |
143 |
tim |
1725 |
|
144 |
|
|
|
145 |
tim |
1819 |
void VelocityVerletIntegrator::finalize() { |
146 |
tim |
1725 |
|
147 |
tim |
1820 |
dumpWriter->writeDump(); |
148 |
tim |
1725 |
|
149 |
tim |
1819 |
delete dumpWriter; |
150 |
|
|
delete statWriter; |
151 |
tim |
1725 |
|
152 |
tim |
1819 |
dumpWriter = NULL; |
153 |
|
|
statWriter = NULL; |
154 |
|
|
|
155 |
tim |
1722 |
} |
156 |
|
|
|
157 |
tim |
1774 |
void VelocityVerletIntegrator::integrateStep() { |
158 |
tim |
1725 |
|
159 |
tim |
1774 |
moveA(); |
160 |
tim |
1819 |
calcForce(needPotential, needStress); |
161 |
tim |
1774 |
moveB(); |
162 |
|
|
} |
163 |
tim |
1725 |
|
164 |
tim |
1774 |
|
165 |
tim |
1819 |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
166 |
|
|
bool needStress) { |
167 |
tim |
1820 |
forceMan_->calcForces(needPotential, needStress); |
168 |
tim |
1722 |
} |
169 |
|
|
|
170 |
tim |
1820 |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
171 |
|
|
return new DumpWriter(info_, info_->getDumpFileName()); |
172 |
|
|
} |
173 |
tim |
1722 |
|
174 |
tim |
1820 |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
175 |
|
|
return new StatWriter(info_->getStatFileName()); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
|
179 |
tim |
1725 |
} //end namespace oopse |