# | Line 7 | Line 7 | |
---|---|---|
7 | #include <unistd.h> | |
8 | #endif //is_mpi | |
9 | ||
10 | + | #ifdef PROFILE |
11 | + | #include "mdProfile.hpp" |
12 | + | #endif // profile |
13 | + | |
14 | #include "Integrator.hpp" | |
15 | #include "simError.h" | |
16 | ||
# | Line 27 | Line 31 | template<typename T> Integrator<T>::Integrator(SimInfo | |
31 | } | |
32 | ||
33 | nAtoms = info->n_atoms; | |
34 | < | |
34 | > | integrableObjects = info->integrableObjects; |
35 | > | |
36 | // check for constraints | |
37 | ||
38 | constrainedA = NULL; | |
# | Line 40 | Line 45 | template<typename T> Integrator<T>::Integrator(SimInfo | |
45 | nConstrained = 0; | |
46 | ||
47 | checkConstraints(); | |
48 | + | |
49 | } | |
50 | ||
51 | template<typename T> Integrator<T>::~Integrator(){ | |
# | Line 64 | Line 70 | template<typename T> void Integrator<T>::checkConstrai | |
70 | ||
71 | SRI** theArray; | |
72 | for (int i = 0; i < nMols; i++){ | |
73 | < | theArray = (SRI * *) molecules[i].getMyBonds(); |
73 | > | |
74 | > | theArray = (SRI * *) molecules[i].getMyBonds(); |
75 | for (int j = 0; j < molecules[i].getNBonds(); j++){ | |
76 | constrained = theArray[j]->is_constrained(); | |
77 | ||
# | Line 110 | Line 117 | template<typename T> void Integrator<T>::checkConstrai | |
117 | } | |
118 | } | |
119 | ||
120 | + | |
121 | if (nConstrained > 0){ | |
122 | isConstrained = 1; | |
123 | ||
# | Line 131 | Line 139 | template<typename T> void Integrator<T>::checkConstrai | |
139 | } | |
140 | ||
141 | ||
142 | < | // save oldAtoms to check for lode balanceing later on. |
142 | > | // save oldAtoms to check for lode balancing later on. |
143 | ||
144 | oldAtoms = nAtoms; | |
145 | ||
# | Line 153 | Line 161 | template<typename T> void Integrator<T>::integrate(voi | |
161 | double thermalTime = info->thermalTime; | |
162 | double resetTime = info->resetTime; | |
163 | ||
164 | < | |
164 | > | double difference; |
165 | double currSample; | |
166 | double currThermal; | |
167 | double currStatus; | |
# | Line 172 | Line 180 | template<typename T> void Integrator<T>::integrate(voi | |
180 | ||
181 | readyCheck(); | |
182 | ||
183 | + | // remove center of mass drift velocity (in case we passed in a configuration |
184 | + | // that was drifting |
185 | + | tStats->removeCOMdrift(); |
186 | + | |
187 | + | // initialize the retraints if necessary |
188 | + | if (info->useSolidThermInt && !info->useLiquidThermInt) { |
189 | + | myFF->initRestraints(); |
190 | + | } |
191 | + | |
192 | // initialize the forces before the first step | |
193 | ||
194 | calcForce(1, 1); | |
195 | < | |
195 | > | |
196 | if (nConstrained){ | |
197 | preMove(); | |
198 | constrainA(); | |
199 | calcForce(1, 1); | |
200 | constrainB(); | |
201 | } | |
202 | < | |
202 | > | |
203 | if (info->setTemp){ | |
204 | thermalize(); | |
205 | } | |
# | Line 198 | Line 215 | template<typename T> void Integrator<T>::integrate(voi | |
215 | statOut->writeStat(info->getTime()); | |
216 | ||
217 | ||
201 | – | |
218 | #ifdef IS_MPI | |
219 | strcpy(checkPointMsg, "The integrator is ready to go."); | |
220 | MPIcheckPoint(); | |
221 | #endif // is_mpi | |
222 | ||
223 | < | while (info->getTime() < runTime){ |
224 | < | if ((info->getTime() + dt) >= currStatus){ |
223 | > | while (info->getTime() < runTime && !stopIntegrator()){ |
224 | > | difference = info->getTime() + dt - currStatus; |
225 | > | if (difference > 0 || fabs(difference) < 1e-4 ){ |
226 | calcPot = 1; | |
227 | calcStress = 1; | |
228 | } | |
229 | ||
230 | + | #ifdef PROFILE |
231 | + | startProfile( pro1 ); |
232 | + | #endif |
233 | + | |
234 | integrateStep(calcPot, calcStress); | |
235 | ||
236 | + | #ifdef PROFILE |
237 | + | endProfile( pro1 ); |
238 | + | |
239 | + | startProfile( pro2 ); |
240 | + | #endif // profile |
241 | + | |
242 | info->incrTime(dt); | |
243 | ||
244 | if (info->setTemp){ | |
# | Line 228 | Line 255 | template<typename T> void Integrator<T>::integrate(voi | |
255 | ||
256 | if (info->getTime() >= currStatus){ | |
257 | statOut->writeStat(info->getTime()); | |
258 | + | if (info->useSolidThermInt || info->useLiquidThermInt) |
259 | + | statOut->writeRaw(info->getTime()); |
260 | calcPot = 0; | |
261 | calcStress = 0; | |
262 | currStatus += statusTime; | |
# | Line 239 | Line 268 | template<typename T> void Integrator<T>::integrate(voi | |
268 | currReset += resetTime; | |
269 | } | |
270 | } | |
271 | + | |
272 | + | #ifdef PROFILE |
273 | + | endProfile( pro2 ); |
274 | + | #endif //profile |
275 | ||
276 | #ifdef IS_MPI | |
277 | strcpy(checkPointMsg, "successfully took a time step."); | |
# | Line 246 | Line 279 | template<typename T> void Integrator<T>::integrate(voi | |
279 | #endif // is_mpi | |
280 | } | |
281 | ||
282 | < | |
283 | < | // write the last frame |
284 | < | dumpOut->writeDump(info->getTime()); |
282 | > | // dump out a file containing the omega values for the final configuration |
283 | > | if (info->useSolidThermInt && !info->useLiquidThermInt) |
284 | > | myFF->dumpzAngle(); |
285 | > | |
286 | ||
287 | delete dumpOut; | |
288 | delete statOut; | |
# | Line 257 | Line 291 | template<typename T> void Integrator<T>::integrateStep | |
291 | template<typename T> void Integrator<T>::integrateStep(int calcPot, | |
292 | int calcStress){ | |
293 | // Position full step, and velocity half step | |
294 | + | |
295 | + | #ifdef PROFILE |
296 | + | startProfile(pro3); |
297 | + | #endif //profile |
298 | + | |
299 | preMove(); | |
300 | ||
301 | < | moveA(); |
301 | > | #ifdef PROFILE |
302 | > | endProfile(pro3); |
303 | ||
304 | + | startProfile(pro4); |
305 | + | #endif // profile |
306 | ||
307 | + | moveA(); |
308 | ||
309 | + | #ifdef PROFILE |
310 | + | endProfile(pro4); |
311 | + | |
312 | + | startProfile(pro5); |
313 | + | #endif//profile |
314 | ||
315 | + | |
316 | #ifdef IS_MPI | |
317 | strcpy(checkPointMsg, "Succesful moveA\n"); | |
318 | MPIcheckPoint(); | |
319 | #endif // is_mpi | |
320 | ||
272 | – | |
321 | // calc forces | |
274 | – | |
322 | calcForce(calcPot, calcStress); | |
323 | ||
324 | #ifdef IS_MPI | |
# | Line 279 | Line 326 | template<typename T> void Integrator<T>::integrateStep | |
326 | MPIcheckPoint(); | |
327 | #endif // is_mpi | |
328 | ||
329 | + | #ifdef PROFILE |
330 | + | endProfile( pro5 ); |
331 | ||
332 | + | startProfile( pro6 ); |
333 | + | #endif //profile |
334 | + | |
335 | // finish the velocity half step | |
336 | ||
337 | moveB(); | |
338 | ||
339 | + | #ifdef PROFILE |
340 | + | endProfile(pro6); |
341 | + | #endif // profile |
342 | ||
288 | – | |
343 | #ifdef IS_MPI | |
344 | strcpy(checkPointMsg, "Succesful moveB\n"); | |
345 | MPIcheckPoint(); | |
# | Line 294 | Line 348 | template<typename T> void Integrator<T>::moveA(void){ | |
348 | ||
349 | ||
350 | template<typename T> void Integrator<T>::moveA(void){ | |
351 | < | int i, j; |
351 | > | size_t i, j; |
352 | DirectionalAtom* dAtom; | |
353 | double Tb[3], ji[3]; | |
354 | double vel[3], pos[3], frc[3]; | |
355 | double mass; | |
356 | + | double omega; |
357 | + | |
358 | + | for (i = 0; i < integrableObjects.size() ; i++){ |
359 | + | integrableObjects[i]->getVel(vel); |
360 | + | integrableObjects[i]->getPos(pos); |
361 | + | integrableObjects[i]->getFrc(frc); |
362 | + | |
363 | + | mass = integrableObjects[i]->getMass(); |
364 | ||
303 | – | for (i = 0; i < nAtoms; i++){ |
304 | – | atoms[i]->getVel(vel); |
305 | – | atoms[i]->getPos(pos); |
306 | – | atoms[i]->getFrc(frc); |
307 | – | |
308 | – | mass = atoms[i]->getMass(); |
309 | – | |
365 | for (j = 0; j < 3; j++){ | |
366 | // velocity half step | |
367 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
# | Line 314 | Line 369 | template<typename T> void Integrator<T>::moveA(void){ | |
369 | pos[j] += dt * vel[j]; | |
370 | } | |
371 | ||
372 | < | atoms[i]->setVel(vel); |
373 | < | atoms[i]->setPos(pos); |
372 | > | integrableObjects[i]->setVel(vel); |
373 | > | integrableObjects[i]->setPos(pos); |
374 | ||
375 | < | if (atoms[i]->isDirectional()){ |
321 | < | dAtom = (DirectionalAtom *) atoms[i]; |
375 | > | if (integrableObjects[i]->isDirectional()){ |
376 | ||
377 | // get and convert the torque to body frame | |
378 | ||
379 | < | dAtom->getTrq(Tb); |
380 | < | dAtom->lab2Body(Tb); |
379 | > | integrableObjects[i]->getTrq(Tb); |
380 | > | integrableObjects[i]->lab2Body(Tb); |
381 | ||
382 | // get the angular momentum, and propagate a half step | |
383 | ||
384 | < | dAtom->getJ(ji); |
384 | > | integrableObjects[i]->getJ(ji); |
385 | ||
386 | for (j = 0; j < 3; j++) | |
387 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
388 | ||
389 | < | this->rotationPropagation( dAtom, ji ); |
389 | > | this->rotationPropagation( integrableObjects[i], ji ); |
390 | ||
391 | < | dAtom->setJ(ji); |
391 | > | integrableObjects[i]->setJ(ji); |
392 | } | |
393 | } | |
394 | ||
# | Line 346 | Line 400 | template<typename T> void Integrator<T>::moveB(void){ | |
400 | ||
401 | template<typename T> void Integrator<T>::moveB(void){ | |
402 | int i, j; | |
349 | – | DirectionalAtom* dAtom; |
403 | double Tb[3], ji[3]; | |
404 | double vel[3], frc[3]; | |
405 | double mass; | |
406 | ||
407 | < | for (i = 0; i < nAtoms; i++){ |
408 | < | atoms[i]->getVel(vel); |
409 | < | atoms[i]->getFrc(frc); |
407 | > | for (i = 0; i < integrableObjects.size(); i++){ |
408 | > | integrableObjects[i]->getVel(vel); |
409 | > | integrableObjects[i]->getFrc(frc); |
410 | ||
411 | < | mass = atoms[i]->getMass(); |
411 | > | mass = integrableObjects[i]->getMass(); |
412 | ||
413 | // velocity half step | |
414 | for (j = 0; j < 3; j++) | |
415 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
416 | ||
417 | < | atoms[i]->setVel(vel); |
417 | > | integrableObjects[i]->setVel(vel); |
418 | ||
419 | < | if (atoms[i]->isDirectional()){ |
367 | < | dAtom = (DirectionalAtom *) atoms[i]; |
419 | > | if (integrableObjects[i]->isDirectional()){ |
420 | ||
421 | // get and convert the torque to body frame | |
422 | ||
423 | < | dAtom->getTrq(Tb); |
424 | < | dAtom->lab2Body(Tb); |
423 | > | integrableObjects[i]->getTrq(Tb); |
424 | > | integrableObjects[i]->lab2Body(Tb); |
425 | ||
426 | // get the angular momentum, and propagate a half step | |
427 | ||
428 | < | dAtom->getJ(ji); |
428 | > | integrableObjects[i]->getJ(ji); |
429 | ||
430 | for (j = 0; j < 3; j++) | |
431 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
432 | ||
433 | ||
434 | < | dAtom->setJ(ji); |
434 | > | integrableObjects[i]->setJ(ji); |
435 | } | |
436 | } | |
437 | ||
# | Line 648 | Line 700 | template<typename T> void Integrator<T>::rotationPropa | |
700 | } | |
701 | ||
702 | template<typename T> void Integrator<T>::rotationPropagation | |
703 | < | ( DirectionalAtom* dAtom, double ji[3] ){ |
703 | > | ( StuntDouble* sd, double ji[3] ){ |
704 | ||
705 | double angle; | |
706 | double A[3][3], I[3][3]; | |
707 | + | int i, j, k; |
708 | ||
709 | // use the angular velocities to propagate the rotation matrix a | |
710 | // full time step | |
711 | ||
712 | < | dAtom->getA(A); |
713 | < | dAtom->getI(I); |
712 | > | sd->getA(A); |
713 | > | sd->getI(I); |
714 | ||
715 | < | // rotate about the x-axis |
716 | < | angle = dt2 * ji[0] / I[0][0]; |
717 | < | this->rotate( 1, 2, angle, ji, A ); |
718 | < | |
719 | < | // rotate about the y-axis |
720 | < | angle = dt2 * ji[1] / I[1][1]; |
721 | < | this->rotate( 2, 0, angle, ji, A ); |
715 | > | if (sd->isLinear()) { |
716 | > | i = sd->linearAxis(); |
717 | > | j = (i+1)%3; |
718 | > | k = (i+2)%3; |
719 | > | |
720 | > | angle = dt2 * ji[j] / I[j][j]; |
721 | > | this->rotate( k, i, angle, ji, A ); |
722 | ||
723 | < | // rotate about the z-axis |
724 | < | angle = dt * ji[2] / I[2][2]; |
672 | < | this->rotate( 0, 1, angle, ji, A); |
723 | > | angle = dt * ji[k] / I[k][k]; |
724 | > | this->rotate( i, j, angle, ji, A); |
725 | ||
726 | < | // rotate about the y-axis |
727 | < | angle = dt2 * ji[1] / I[1][1]; |
676 | < | this->rotate( 2, 0, angle, ji, A ); |
726 | > | angle = dt2 * ji[j] / I[j][j]; |
727 | > | this->rotate( k, i, angle, ji, A ); |
728 | ||
729 | < | // rotate about the x-axis |
730 | < | angle = dt2 * ji[0] / I[0][0]; |
731 | < | this->rotate( 1, 2, angle, ji, A ); |
732 | < | |
733 | < | dAtom->setA( A ); |
729 | > | } else { |
730 | > | // rotate about the x-axis |
731 | > | angle = dt2 * ji[0] / I[0][0]; |
732 | > | this->rotate( 1, 2, angle, ji, A ); |
733 | > | |
734 | > | // rotate about the y-axis |
735 | > | angle = dt2 * ji[1] / I[1][1]; |
736 | > | this->rotate( 2, 0, angle, ji, A ); |
737 | > | |
738 | > | // rotate about the z-axis |
739 | > | angle = dt * ji[2] / I[2][2]; |
740 | > | sd->addZangle(angle); |
741 | > | this->rotate( 0, 1, angle, ji, A); |
742 | > | |
743 | > | // rotate about the y-axis |
744 | > | angle = dt2 * ji[1] / I[1][1]; |
745 | > | this->rotate( 2, 0, angle, ji, A ); |
746 | > | |
747 | > | // rotate about the x-axis |
748 | > | angle = dt2 * ji[0] / I[0][0]; |
749 | > | this->rotate( 1, 2, angle, ji, A ); |
750 | > | |
751 | > | } |
752 | > | sd->setA( A ); |
753 | } | |
754 | ||
755 | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |