34 |
|
#include "integrators/VelocityVerletIntegrator.hpp" |
35 |
|
|
36 |
|
namespace oopse { |
37 |
< |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { } |
37 |
> |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info) { |
38 |
> |
dt2 = 0.5 * dt; |
39 |
> |
} |
40 |
|
|
41 |
|
VelocityVerletIntegrator::~VelocityVerletIntegrator() { } |
42 |
|
|
43 |
< |
void VelocityVerletIntegrator::integrate() { |
42 |
< |
double runTime = info_->run_time; |
43 |
> |
void VelocityVerletIntegrator::initialize(){ |
44 |
|
|
45 |
< |
int calcPot; |
46 |
< |
int calcStress; |
45 |
> |
currSample = 0.0; |
46 |
> |
currStatus = 0.0; |
47 |
> |
currThermal = 0.0; |
48 |
> |
needPotential = false; |
49 |
> |
needStress = false; |
50 |
|
|
47 |
– |
|
48 |
– |
dt_ = info_->dt; |
49 |
– |
dt2_ = 0.5 * dt_; |
50 |
– |
|
51 |
– |
readyCheck(); |
52 |
– |
|
51 |
|
// remove center of mass drift velocity (in case we passed in a configuration |
52 |
|
// that was drifting |
53 |
< |
tStats->removeCOMdrift(); |
53 |
> |
velocitizer_->removeComDrift(); |
54 |
|
|
55 |
|
// initialize the forces before the first step |
56 |
+ |
calcForce(true, true); |
57 |
|
|
59 |
– |
calcForce(1, 1); |
60 |
– |
|
58 |
|
//execute constraint algorithm to make sure at the very beginning the system is constrained |
59 |
< |
if (nConstrained) { |
60 |
< |
constrainA(); |
61 |
< |
calcForce(1, 1); |
62 |
< |
constrainB(); |
63 |
< |
} |
59 |
> |
//if (nConstrained) { |
60 |
> |
// constrainA(); |
61 |
> |
// calcForce(true, true); |
62 |
> |
// constrainB(); |
63 |
> |
//} |
64 |
|
|
65 |
< |
if (info_->setTemp) { |
66 |
< |
thermalize(); |
65 |
> |
if (needVelocityScaling) { |
66 |
> |
velocitizer_->velocitize(targetScalingTemp); |
67 |
|
} |
68 |
+ |
|
69 |
+ |
dumpWriter = createDumpWriter(); |
70 |
+ |
statWriter = createStatWriter(); |
71 |
|
|
72 |
< |
calcPot = 0; |
73 |
< |
calcStress = 0; |
72 |
> |
dumpWriter->writeFrame(); |
73 |
> |
statWriter->writeStat(currentSnapshot_.statData); |
74 |
|
|
75 |
– |
tStats = new Thermo(info_); |
76 |
– |
statOut = new StatWriter(info_); |
77 |
– |
dumpOut = new DumpWriter(info_); |
75 |
|
|
76 |
< |
dumpOut->writeDump(info_->getTime()); |
77 |
< |
statOut->writeStat(info_->getTime()); |
76 |
> |
} |
77 |
> |
|
78 |
> |
void VelocityVerletIntegrator::doIntegrate() { |
79 |
|
|
82 |
– |
#ifdef IS_MPI |
80 |
|
|
81 |
< |
strcpy(checkPointMsg, "The integrator is ready to go."); |
85 |
< |
MPIcheckPoint(); |
81 |
> |
initialize(); |
82 |
|
|
83 |
< |
#endif // is_mpi |
83 |
> |
while (currentSnapshot_->getTime() < runTime) { |
84 |
> |
|
85 |
> |
preStep(); |
86 |
|
|
87 |
< |
while (info_->getTime() < runTime) { |
90 |
< |
difference = info_->getTime() + dt_ - currStatus; |
87 |
> |
integrateStep(); |
88 |
|
|
89 |
< |
if (difference > 0 || fabs(difference) < 1e - 4) { |
90 |
< |
calcPot = 1; |
91 |
< |
calcStress = 1; |
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 |
< |
//notify before integrateStep |
109 |
< |
notify() |
110 |
< |
integrateStep(calcPot, calcStress); |
108 |
> |
} |
109 |
> |
|
110 |
> |
void VelocityVerletIntegrator::postStep() { |
111 |
|
|
101 |
– |
info_->incrTime(dt_); |
112 |
|
|
113 |
< |
//notify after integratreStep |
114 |
< |
notify(); |
115 |
< |
|
106 |
< |
if (info_->setTemp) { |
107 |
< |
if (info_->getTime() >= currThermal) { |
108 |
< |
thermalize(); |
113 |
> |
if (needVelocityScaling) { |
114 |
> |
if (currentSnapshot_->getTime() >= currThermal) { |
115 |
> |
velocitizer_->velocitize(targetScalingTemp); |
116 |
|
currThermal += thermalTime; |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
< |
if (info_->getTime() >= currSample) { |
121 |
< |
dumpOut->writeDump(info_->getTime()); |
120 |
> |
if (currentSnapshot_->getTime() >= currSample) { |
121 |
> |
dumpWriter->writeFrame(currentSnapshot_->getTime()); |
122 |
|
currSample += sampleTime; |
123 |
|
} |
124 |
|
|
125 |
< |
if (info_->getTime() >= currStatus) { |
126 |
< |
statOut->writeStat(info_->getTime()); |
127 |
< |
calcPot = 0; |
128 |
< |
calcStress = 0; |
125 |
> |
if (currentSnapshot_->getTime() >= currStatus) { |
126 |
> |
statWriter->writeStat(currentSnapshot_.statData); |
127 |
> |
needPotential = false; |
128 |
> |
needStress = false; |
129 |
|
currStatus += statusTime; |
130 |
|
} |
131 |
+ |
} |
132 |
|
|
125 |
– |
if (info_->resetIntegrator) { |
126 |
– |
if (info_->getTime() >= currReset) { |
127 |
– |
this->resetIntegrator(); |
128 |
– |
currReset += resetTime; |
129 |
– |
} |
130 |
– |
} |
133 |
|
|
134 |
< |
#ifdef IS_MPI |
134 |
> |
void VelocityVerletIntegrator::finalize() { |
135 |
|
|
136 |
< |
strcpy(checkPointMsg, "successfully took a time step."); |
135 |
< |
MPIcheckPoint(); |
136 |
> |
dumpWriter->writeFrame(); |
137 |
|
|
138 |
< |
#endif // is_mpi |
138 |
> |
delete dumpWriter; |
139 |
> |
delete statWriter; |
140 |
|
|
141 |
< |
} |
142 |
< |
|
143 |
< |
dumpOut->writeFinal(info_->getTime()); |
142 |
< |
|
143 |
< |
delete dumpOut; |
144 |
< |
delete statOut; |
141 |
> |
dumpWriter = NULL; |
142 |
> |
statWriter = NULL; |
143 |
> |
|
144 |
|
} |
145 |
|
|
146 |
|
void VelocityVerletIntegrator::integrateStep() { |
147 |
|
|
148 |
|
moveA(); |
149 |
< |
calcForce(bool needPotential, bool needStress); |
149 |
> |
calcForce(needPotential, needStress); |
150 |
|
moveB(); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
< |
void VelocityVerletIntegrator::thermalize() { |
155 |
< |
|
156 |
< |
if (!info__->have_target_temp) { |
158 |
< |
sprintf(painCave.errMsg, |
159 |
< |
"You can't resample the velocities without a targetTemp!\n"); |
160 |
< |
painCave.isFatal = 1; |
161 |
< |
painCave.severity = OOPSE_ERROR; |
162 |
< |
simError(); |
163 |
< |
return; |
164 |
< |
} |
165 |
< |
|
154 |
> |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
155 |
> |
bool needStress) { |
156 |
> |
forceMan_->calcForces(needPotential, needStress) |
157 |
|
} |
158 |
|
|
168 |
– |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
169 |
– |
bool needStress) { } |
159 |
|
|
171 |
– |
|
160 |
|
} //end namespace oopse |