34 |
|
#include "integrators/VelocityVerletIntegrator.hpp" |
35 |
|
|
36 |
|
namespace oopse { |
37 |
< |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) { } |
37 |
> |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { } |
38 |
|
|
39 |
|
VelocityVerletIntegrator::~VelocityVerletIntegrator() { } |
40 |
|
|
41 |
|
void VelocityVerletIntegrator::integrate() { |
42 |
< |
double runTime = info->run_time; |
42 |
> |
double runTime = info_->run_time; |
43 |
|
|
44 |
< |
double sampleTime = info->sampleTime; |
45 |
< |
double statusTime = info->statusTime; |
46 |
< |
double thermalTime = info->thermalTime; |
47 |
< |
double resetTime = info->resetTime; |
44 |
> |
int calcPot; |
45 |
> |
int calcStress; |
46 |
|
|
49 |
– |
double difference; |
50 |
– |
double currSample; |
51 |
– |
double currThermal; |
52 |
– |
double currStatus; |
53 |
– |
double currReset; |
47 |
|
|
48 |
< |
int calcPot, |
56 |
< |
calcStress; |
57 |
< |
|
58 |
< |
tStats = new Thermo(info); |
59 |
< |
statOut = new StatWriter(info); |
60 |
< |
dumpOut = new DumpWriter(info); |
61 |
< |
|
62 |
< |
atoms = info->atoms; |
63 |
< |
|
64 |
< |
fullStep_ = info->dt; |
48 |
> |
fullStep_ = info_->dt; |
49 |
|
halfStep_ = 0.5 * fullStep_; |
50 |
|
|
51 |
|
readyCheck(); |
65 |
|
constrainB(); |
66 |
|
} |
67 |
|
|
68 |
< |
if (info->setTemp) { |
68 |
> |
if (info_->setTemp) { |
69 |
|
thermalize(); |
70 |
|
} |
71 |
|
|
72 |
|
calcPot = 0; |
73 |
|
calcStress = 0; |
90 |
– |
currSample = sampleTime + info->getTime(); |
91 |
– |
currThermal = thermalTime + info->getTime(); |
92 |
– |
currStatus = statusTime + info->getTime(); |
93 |
– |
currReset = resetTime + info->getTime(); |
74 |
|
|
75 |
< |
dumpOut->writeDump(info->getTime()); |
76 |
< |
statOut->writeStat(info->getTime()); |
75 |
> |
tStats = new Thermo(info_); |
76 |
> |
statOut = new StatWriter(info_); |
77 |
> |
dumpOut = new DumpWriter(info_); |
78 |
> |
|
79 |
> |
dumpOut->writeDump(info_->getTime()); |
80 |
> |
statOut->writeStat(info_->getTime()); |
81 |
|
|
82 |
|
#ifdef IS_MPI |
83 |
|
|
86 |
|
|
87 |
|
#endif // is_mpi |
88 |
|
|
89 |
< |
while (info->getTime() < runTime && !stopIntegrator()) { |
90 |
< |
difference = info->getTime() + fullStep_ - currStatus; |
89 |
> |
while (info_->getTime() < runTime) { |
90 |
> |
difference = info_->getTime() + fullStep_ - currStatus; |
91 |
|
|
92 |
|
if (difference > 0 || fabs(difference) < 1e - 4) { |
93 |
|
calcPot = 1; |
94 |
|
calcStress = 1; |
95 |
|
} |
96 |
|
|
97 |
< |
#ifdef PROFILE |
98 |
< |
|
115 |
< |
startProfile(pro1); |
116 |
< |
|
117 |
< |
#endif |
118 |
< |
|
97 |
> |
//notify before integrateStep |
98 |
> |
notify() |
99 |
|
integrateStep(calcPot, calcStress); |
100 |
< |
|
101 |
< |
#ifdef PROFILE |
102 |
< |
|
103 |
< |
endProfile(pro1); |
104 |
< |
|
105 |
< |
startProfile(pro2); |
106 |
< |
|
107 |
< |
#endif // profile |
128 |
< |
|
129 |
< |
info->incrTime(fullStep_); |
130 |
< |
|
131 |
< |
if (info->setTemp) { |
132 |
< |
if (info->getTime() >= currThermal) { |
100 |
> |
|
101 |
> |
info_->incrTime(fullStep_); |
102 |
> |
|
103 |
> |
//notify after integratreStep |
104 |
> |
notify(); |
105 |
> |
|
106 |
> |
if (info_->setTemp) { |
107 |
> |
if (info_->getTime() >= currThermal) { |
108 |
|
thermalize(); |
109 |
|
currThermal += thermalTime; |
110 |
|
} |
111 |
|
} |
112 |
|
|
113 |
< |
if (info->getTime() >= currSample) { |
114 |
< |
dumpOut->writeDump(info->getTime()); |
113 |
> |
if (info_->getTime() >= currSample) { |
114 |
> |
dumpOut->writeDump(info_->getTime()); |
115 |
|
currSample += sampleTime; |
116 |
|
} |
117 |
|
|
118 |
< |
if (info->getTime() >= currStatus) { |
119 |
< |
statOut->writeStat(info->getTime()); |
118 |
> |
if (info_->getTime() >= currStatus) { |
119 |
> |
statOut->writeStat(info_->getTime()); |
120 |
|
calcPot = 0; |
121 |
|
calcStress = 0; |
122 |
|
currStatus += statusTime; |
123 |
|
} |
124 |
|
|
125 |
< |
if (info->resetIntegrator) { |
126 |
< |
if (info->getTime() >= currReset) { |
125 |
> |
if (info_->resetIntegrator) { |
126 |
> |
if (info_->getTime() >= currReset) { |
127 |
|
this->resetIntegrator(); |
128 |
|
currReset += resetTime; |
129 |
|
} |
130 |
|
} |
131 |
|
|
157 |
– |
#ifdef PROFILE |
158 |
– |
|
159 |
– |
endProfile(pro2); |
160 |
– |
|
161 |
– |
#endif //profile |
162 |
– |
|
132 |
|
#ifdef IS_MPI |
133 |
|
|
134 |
|
strcpy(checkPointMsg, "successfully took a time step."); |
138 |
|
|
139 |
|
} |
140 |
|
|
141 |
< |
dumpOut->writeFinal(info->getTime()); |
141 |
> |
dumpOut->writeFinal(info_->getTime()); |
142 |
|
|
143 |
|
delete dumpOut; |
144 |
|
delete statOut; |
149 |
|
|
150 |
|
void VelocityVerletIntegrator::thermalize() { |
151 |
|
|
152 |
< |
if (!info_->have_target_temp) { |
152 |
> |
if (!info__->have_target_temp) { |
153 |
|
sprintf(painCave.errMsg, |
154 |
|
"You can't resample the velocities without a targetTemp!\n"); |
155 |
|
painCave.isFatal = 1; |
160 |
|
|
161 |
|
} |
162 |
|
|
194 |
– |
void VelocityVerletIntegrator::velocitize(double temperature) { |
195 |
– |
Vector3d aVel; |
196 |
– |
Vector3d aJ; |
197 |
– |
Mat3x3d I; |
198 |
– |
int l; |
199 |
– |
int m; |
200 |
– |
int n; // velocity randomizer loop counts |
201 |
– |
Vector3d vdrift; |
202 |
– |
double vbar; |
203 |
– |
const double kb = 8.31451e - 7; // kb in amu, angstroms, fs, etc. |
204 |
– |
double av2; |
205 |
– |
double kebar; |
206 |
– |
|
207 |
– |
std::vector<Molecule *>::iterator i; |
208 |
– |
std::vector<StuntDouble *>::iterator j; |
209 |
– |
Molecule * mol; |
210 |
– |
StuntDouble * integrableObject; |
211 |
– |
gaussianSPRNG gaussStream(info_->getSeed()); |
212 |
– |
|
213 |
– |
kebar = kb * temperature * info_->getNdfRaw() / (2.0 * info_->getNdf()); |
214 |
– |
|
215 |
– |
for( mol = info_->beginMolecule(i); mol != NULL; |
216 |
– |
mol = info_->nextMolecule(i) ) { |
217 |
– |
for( integrableObject = mol->beginIntegrableObject(j); |
218 |
– |
integrableObject != NULL; |
219 |
– |
integrableObject = mol->nextIntegrableObject(j) ) { |
220 |
– |
|
221 |
– |
// uses equipartition theory to solve for vbar in angstrom/fs |
222 |
– |
|
223 |
– |
av2 = 2.0 * kebar / integrableObject->getMass(); |
224 |
– |
vbar = sqrt(av2); |
225 |
– |
|
226 |
– |
// picks random velocities from a gaussian distribution |
227 |
– |
// centered on vbar |
228 |
– |
|
229 |
– |
for( int k = 0; k < 3; k++ ) { |
230 |
– |
aVel[k] = vbar * gaussStream.getGaussian(); |
231 |
– |
} |
232 |
– |
|
233 |
– |
integrableObject->setVel(aVel); |
234 |
– |
|
235 |
– |
if (integrableObject->isDirectional()) { |
236 |
– |
I = integrableObject->getI(); |
237 |
– |
|
238 |
– |
if (integrableObject->isLinear()) { |
239 |
– |
l = integrableObject->linearAxis(); |
240 |
– |
m = (l + 1) % 3; |
241 |
– |
n = (l + 2) % 3; |
242 |
– |
|
243 |
– |
aJ[l] = 0.0; |
244 |
– |
vbar = sqrt(2.0 * kebar * I(m, m)); |
245 |
– |
aJ[m] = vbar * gaussStream.getGaussian(); |
246 |
– |
vbar = sqrt(2.0 * kebar * I(n, n)); |
247 |
– |
aJ[n] = vbar * gaussStream.getGaussian(); |
248 |
– |
} else { |
249 |
– |
for( int k = 0; k < 3; k++ ) { |
250 |
– |
vbar = sqrt(2.0 * kebar * I(k, k)); |
251 |
– |
aJ[k] = vbar * gaussStream.getGaussian(); |
252 |
– |
} |
253 |
– |
} // else isLinear |
254 |
– |
|
255 |
– |
integrableObject->setJ(aJ); |
256 |
– |
} //isDirectional |
257 |
– |
} |
258 |
– |
} //end for (mol = beginMolecule(i); ...) |
259 |
– |
|
260 |
– |
// Get the Center of Mass drift velocity. |
261 |
– |
vdrift = info_->getComVel(); |
262 |
– |
|
263 |
– |
removeComDrift(vdrift); |
264 |
– |
|
265 |
– |
} |
266 |
– |
|
163 |
|
void VelocityVerletIntegrator::calcForce(bool needPotential, |
164 |
|
bool needStress) { } |
165 |
|
|
270 |
– |
void VelocityVerletIntegrator::removeComDrift(const Vector3d& vdrift) { |
166 |
|
|
272 |
– |
std::vector<Molecule *>::iterator i; |
273 |
– |
std::vector<StuntDouble *>::iterator j; |
274 |
– |
Molecule * mol; |
275 |
– |
StuntDouble * integrableObject; |
276 |
– |
|
277 |
– |
// Corrects for the center of mass drift. |
278 |
– |
// sums all the momentum and divides by total mass. |
279 |
– |
for( mol = info_->beginMolecule(i); mol != NULL; |
280 |
– |
mol = info_->nextMolecule(i) ) { |
281 |
– |
for( integrableObject = mol->beginIntegrableObject(j); |
282 |
– |
integrableObject != NULL; |
283 |
– |
integrableObject = mol->nextIntegrableObject(j) ) { |
284 |
– |
integrableObject->setVel(integrableObject->getVel() - vdrift); |
285 |
– |
} |
286 |
– |
} |
287 |
– |
|
288 |
– |
} |
289 |
– |
|
167 |
|
} //end namespace oopse |