# | Line 1 | Line 1 | |
---|---|---|
1 | #include <iostream> | |
2 | < | #include <cstdlib> |
3 | < | #include <cmath> |
2 | > | #include <stdlib.h> |
3 | > | #include <math.h> |
4 | ||
5 | #ifdef IS_MPI | |
6 | #include "mpiSimulation.hpp" | |
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 25 | Line 29 | template<typename T> Integrator<T>::Integrator(SimInfo | |
29 | if (info->the_integrator != NULL){ | |
30 | delete info->the_integrator; | |
31 | } | |
32 | < | |
32 | > | |
33 | nAtoms = info->n_atoms; | |
34 | + | integrableObjects = info->integrableObjects; |
35 | ||
36 | // check for constraints | |
37 | ||
# | Line 64 | Line 69 | template<typename T> void Integrator<T>::checkConstrai | |
69 | ||
70 | SRI** theArray; | |
71 | for (int i = 0; i < nMols; i++){ | |
72 | < | theArray = (SRI * *) molecules[i].getMyBonds(); |
72 | > | |
73 | > | theArray = (SRI * *) molecules[i].getMyBonds(); |
74 | for (int j = 0; j < molecules[i].getNBonds(); j++){ | |
75 | constrained = theArray[j]->is_constrained(); | |
76 | ||
# | Line 110 | Line 116 | template<typename T> void Integrator<T>::checkConstrai | |
116 | } | |
117 | } | |
118 | ||
119 | + | |
120 | if (nConstrained > 0){ | |
121 | isConstrained = 1; | |
122 | ||
# | Line 131 | Line 138 | template<typename T> void Integrator<T>::checkConstrai | |
138 | } | |
139 | ||
140 | ||
141 | < | // save oldAtoms to check for lode balanceing later on. |
141 | > | // save oldAtoms to check for lode balancing later on. |
142 | ||
143 | oldAtoms = nAtoms; | |
144 | ||
# | Line 158 | Line 165 | template<typename T> void Integrator<T>::integrate(voi | |
165 | double currThermal; | |
166 | double currStatus; | |
167 | double currReset; | |
168 | < | |
168 | > | |
169 | int calcPot, calcStress; | |
170 | ||
171 | tStats = new Thermo(info); | |
# | Line 172 | Line 179 | template<typename T> void Integrator<T>::integrate(voi | |
179 | ||
180 | readyCheck(); | |
181 | ||
182 | + | // remove center of mass drift velocity (in case we passed in a configuration |
183 | + | // that was drifting |
184 | + | tStats->removeCOMdrift(); |
185 | + | |
186 | // initialize the forces before the first step | |
187 | ||
188 | calcForce(1, 1); | |
189 | < | |
189 | > | |
190 | if (nConstrained){ | |
191 | preMove(); | |
192 | constrainA(); | |
193 | < | calcForce(1, 1); |
193 | > | calcForce(1, 1); |
194 | constrainB(); | |
195 | } | |
196 | ||
# | Line 198 | Line 209 | template<typename T> void Integrator<T>::integrate(voi | |
209 | statOut->writeStat(info->getTime()); | |
210 | ||
211 | ||
201 | – | |
212 | #ifdef IS_MPI | |
213 | strcpy(checkPointMsg, "The integrator is ready to go."); | |
214 | MPIcheckPoint(); | |
215 | #endif // is_mpi | |
216 | ||
217 | < | while (info->getTime() < runTime){ |
217 | > | while (info->getTime() < runTime && !stopIntegrator()){ |
218 | if ((info->getTime() + dt) >= currStatus){ | |
219 | calcPot = 1; | |
220 | calcStress = 1; | |
221 | } | |
222 | ||
223 | + | #ifdef PROFILE |
224 | + | startProfile( pro1 ); |
225 | + | #endif |
226 | + | |
227 | integrateStep(calcPot, calcStress); | |
228 | ||
229 | + | #ifdef PROFILE |
230 | + | endProfile( pro1 ); |
231 | + | |
232 | + | startProfile( pro2 ); |
233 | + | #endif // profile |
234 | + | |
235 | info->incrTime(dt); | |
236 | ||
237 | if (info->setTemp){ | |
# | Line 227 | Line 247 | template<typename T> void Integrator<T>::integrate(voi | |
247 | } | |
248 | ||
249 | if (info->getTime() >= currStatus){ | |
250 | < | statOut->writeStat(info->getTime()); |
251 | < | calcPot = 0; |
250 | > | statOut->writeStat(info->getTime()); |
251 | > | calcPot = 0; |
252 | calcStress = 0; | |
253 | currStatus += statusTime; | |
254 | < | } |
254 | > | } |
255 | ||
256 | if (info->resetIntegrator){ | |
257 | if (info->getTime() >= currReset){ | |
# | Line 239 | Line 259 | template<typename T> void Integrator<T>::integrate(voi | |
259 | currReset += resetTime; | |
260 | } | |
261 | } | |
262 | + | |
263 | + | #ifdef PROFILE |
264 | + | endProfile( pro2 ); |
265 | + | #endif //profile |
266 | ||
267 | #ifdef IS_MPI | |
268 | strcpy(checkPointMsg, "successfully took a time step."); | |
# | Line 246 | Line 270 | template<typename T> void Integrator<T>::integrate(voi | |
270 | #endif // is_mpi | |
271 | } | |
272 | ||
249 | – | dumpOut->writeFinal(info->getTime()); |
250 | – | |
273 | delete dumpOut; | |
274 | delete statOut; | |
275 | } | |
# | Line 255 | Line 277 | template<typename T> void Integrator<T>::integrateStep | |
277 | template<typename T> void Integrator<T>::integrateStep(int calcPot, | |
278 | int calcStress){ | |
279 | // Position full step, and velocity half step | |
280 | + | |
281 | + | #ifdef PROFILE |
282 | + | startProfile(pro3); |
283 | + | #endif //profile |
284 | + | |
285 | preMove(); | |
286 | ||
287 | < | moveA(); |
287 | > | #ifdef PROFILE |
288 | > | endProfile(pro3); |
289 | ||
290 | + | startProfile(pro4); |
291 | + | #endif // profile |
292 | ||
293 | + | moveA(); |
294 | ||
295 | + | #ifdef PROFILE |
296 | + | endProfile(pro4); |
297 | + | |
298 | + | startProfile(pro5); |
299 | + | #endif//profile |
300 | ||
301 | + | |
302 | #ifdef IS_MPI | |
303 | strcpy(checkPointMsg, "Succesful moveA\n"); | |
304 | MPIcheckPoint(); | |
# | Line 277 | Line 314 | template<typename T> void Integrator<T>::integrateStep | |
314 | MPIcheckPoint(); | |
315 | #endif // is_mpi | |
316 | ||
317 | + | #ifdef PROFILE |
318 | + | endProfile( pro5 ); |
319 | ||
320 | + | startProfile( pro6 ); |
321 | + | #endif //profile |
322 | + | |
323 | // finish the velocity half step | |
324 | ||
325 | moveB(); | |
326 | ||
327 | + | #ifdef PROFILE |
328 | + | endProfile(pro6); |
329 | + | #endif // profile |
330 | ||
286 | – | |
331 | #ifdef IS_MPI | |
332 | strcpy(checkPointMsg, "Succesful moveB\n"); | |
333 | MPIcheckPoint(); | |
# | Line 292 | Line 336 | template<typename T> void Integrator<T>::moveA(void){ | |
336 | ||
337 | ||
338 | template<typename T> void Integrator<T>::moveA(void){ | |
339 | < | int i, j; |
339 | > | size_t i, j; |
340 | DirectionalAtom* dAtom; | |
341 | double Tb[3], ji[3]; | |
342 | double vel[3], pos[3], frc[3]; | |
343 | double mass; | |
344 | + | |
345 | + | for (i = 0; i < integrableObjects.size() ; i++){ |
346 | + | integrableObjects[i]->getVel(vel); |
347 | + | integrableObjects[i]->getPos(pos); |
348 | + | integrableObjects[i]->getFrc(frc); |
349 | + | |
350 | + | mass = integrableObjects[i]->getMass(); |
351 | ||
301 | – | for (i = 0; i < nAtoms; i++){ |
302 | – | atoms[i]->getVel(vel); |
303 | – | atoms[i]->getPos(pos); |
304 | – | atoms[i]->getFrc(frc); |
305 | – | |
306 | – | mass = atoms[i]->getMass(); |
307 | – | |
352 | for (j = 0; j < 3; j++){ | |
353 | // velocity half step | |
354 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
# | Line 312 | Line 356 | template<typename T> void Integrator<T>::moveA(void){ | |
356 | pos[j] += dt * vel[j]; | |
357 | } | |
358 | ||
359 | < | atoms[i]->setVel(vel); |
360 | < | atoms[i]->setPos(pos); |
359 | > | integrableObjects[i]->setVel(vel); |
360 | > | integrableObjects[i]->setPos(pos); |
361 | ||
362 | < | if (atoms[i]->isDirectional()){ |
319 | < | dAtom = (DirectionalAtom *) atoms[i]; |
362 | > | if (integrableObjects[i]->isDirectional()){ |
363 | ||
364 | // get and convert the torque to body frame | |
365 | ||
366 | < | dAtom->getTrq(Tb); |
367 | < | dAtom->lab2Body(Tb); |
366 | > | integrableObjects[i]->getTrq(Tb); |
367 | > | integrableObjects[i]->lab2Body(Tb); |
368 | ||
369 | // get the angular momentum, and propagate a half step | |
370 | ||
371 | < | dAtom->getJ(ji); |
371 | > | integrableObjects[i]->getJ(ji); |
372 | ||
373 | for (j = 0; j < 3; j++) | |
374 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
375 | ||
376 | < | this->rotationPropagation( dAtom, ji ); |
376 | > | this->rotationPropagation( integrableObjects[i], ji ); |
377 | ||
378 | < | dAtom->setJ(ji); |
378 | > | integrableObjects[i]->setJ(ji); |
379 | } | |
380 | } | |
381 | ||
# | Line 344 | Line 387 | template<typename T> void Integrator<T>::moveB(void){ | |
387 | ||
388 | template<typename T> void Integrator<T>::moveB(void){ | |
389 | int i, j; | |
347 | – | DirectionalAtom* dAtom; |
390 | double Tb[3], ji[3]; | |
391 | double vel[3], frc[3]; | |
392 | double mass; | |
393 | ||
394 | < | for (i = 0; i < nAtoms; i++){ |
395 | < | atoms[i]->getVel(vel); |
396 | < | atoms[i]->getFrc(frc); |
394 | > | for (i = 0; i < integrableObjects.size(); i++){ |
395 | > | integrableObjects[i]->getVel(vel); |
396 | > | integrableObjects[i]->getFrc(frc); |
397 | ||
398 | < | mass = atoms[i]->getMass(); |
398 | > | mass = integrableObjects[i]->getMass(); |
399 | ||
400 | // velocity half step | |
401 | for (j = 0; j < 3; j++) | |
402 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
403 | ||
404 | < | atoms[i]->setVel(vel); |
404 | > | integrableObjects[i]->setVel(vel); |
405 | ||
406 | < | if (atoms[i]->isDirectional()){ |
365 | < | dAtom = (DirectionalAtom *) atoms[i]; |
406 | > | if (integrableObjects[i]->isDirectional()){ |
407 | ||
408 | < | // get and convert the torque to body frame |
408 | > | // get and convert the torque to body frame |
409 | ||
410 | < | dAtom->getTrq(Tb); |
411 | < | dAtom->lab2Body(Tb); |
410 | > | integrableObjects[i]->getTrq(Tb); |
411 | > | integrableObjects[i]->lab2Body(Tb); |
412 | ||
413 | // get the angular momentum, and propagate a half step | |
414 | ||
415 | < | dAtom->getJ(ji); |
415 | > | integrableObjects[i]->getJ(ji); |
416 | ||
417 | for (j = 0; j < 3; j++) | |
418 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
419 | ||
420 | ||
421 | < | dAtom->setJ(ji); |
421 | > | integrableObjects[i]->setJ(ji); |
422 | } | |
423 | } | |
424 | ||
# | Line 646 | Line 687 | template<typename T> void Integrator<T>::rotationPropa | |
687 | } | |
688 | ||
689 | template<typename T> void Integrator<T>::rotationPropagation | |
690 | < | ( DirectionalAtom* dAtom, double ji[3] ){ |
690 | > | ( StuntDouble* sd, double ji[3] ){ |
691 | ||
692 | double angle; | |
693 | double A[3][3], I[3][3]; | |
694 | + | int i, j, k; |
695 | ||
696 | // use the angular velocities to propagate the rotation matrix a | |
697 | // full time step | |
698 | ||
699 | < | dAtom->getA(A); |
700 | < | dAtom->getI(I); |
701 | < | |
702 | < | // rotate about the x-axis |
703 | < | angle = dt2 * ji[0] / I[0][0]; |
704 | < | this->rotate( 1, 2, angle, ji, A ); |
705 | < | |
706 | < | // rotate about the y-axis |
707 | < | angle = dt2 * ji[1] / I[1][1]; |
708 | < | this->rotate( 2, 0, angle, ji, A ); |
709 | < | |
710 | < | // rotate about the z-axis |
711 | < | angle = dt * ji[2] / I[2][2]; |
712 | < | this->rotate( 0, 1, angle, ji, A); |
713 | < | |
714 | < | // rotate about the y-axis |
715 | < | angle = dt2 * ji[1] / I[1][1]; |
716 | < | this->rotate( 2, 0, angle, ji, A ); |
717 | < | |
718 | < | // rotate about the x-axis |
719 | < | angle = dt2 * ji[0] / I[0][0]; |
720 | < | this->rotate( 1, 2, angle, ji, A ); |
721 | < | |
722 | < | dAtom->setA( A ); |
699 | > | sd->getA(A); |
700 | > | sd->getI(I); |
701 | > | |
702 | > | if (sd->isLinear()) { |
703 | > | i = sd->linearAxis(); |
704 | > | j = (i+1)%3; |
705 | > | k = (i+2)%3; |
706 | > | |
707 | > | angle = dt2 * ji[j] / I[j][j]; |
708 | > | this->rotate( k, i, angle, ji, A ); |
709 | > | |
710 | > | angle = dt * ji[k] / I[k][k]; |
711 | > | this->rotate( i, j, angle, ji, A); |
712 | > | |
713 | > | angle = dt2 * ji[j] / I[j][j]; |
714 | > | this->rotate( k, i, angle, ji, A ); |
715 | > | |
716 | > | } else { |
717 | > | // rotate about the x-axis |
718 | > | angle = dt2 * ji[0] / I[0][0]; |
719 | > | this->rotate( 1, 2, angle, ji, A ); |
720 | > | |
721 | > | // rotate about the y-axis |
722 | > | angle = dt2 * ji[1] / I[1][1]; |
723 | > | this->rotate( 2, 0, angle, ji, A ); |
724 | > | |
725 | > | // rotate about the z-axis |
726 | > | angle = dt * ji[2] / I[2][2]; |
727 | > | this->rotate( 0, 1, angle, ji, A); |
728 | > | |
729 | > | // rotate about the y-axis |
730 | > | angle = dt2 * ji[1] / I[1][1]; |
731 | > | this->rotate( 2, 0, angle, ji, A ); |
732 | > | |
733 | > | // rotate about the x-axis |
734 | > | angle = dt2 * ji[0] / I[0][0]; |
735 | > | this->rotate( 1, 2, angle, ji, A ); |
736 | > | |
737 | > | } |
738 | > | sd->setA( A ); |
739 | } | |
740 | ||
741 | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, | |
# | Line 745 | Line 803 | template<typename T> void Integrator<T>::rotate(int ax | |
803 | } | |
804 | } | |
805 | ||
806 | < | // rotate the Rotation matrix acording to: |
806 | > | // rotate the Rotation matrix acording to: |
807 | // A[][] = A[][] * transpose(rot[][]) | |
808 | ||
809 | ||
# | Line 774 | Line 832 | template<typename T> double Integrator<T>::getConserve | |
832 | template<typename T> double Integrator<T>::getConservedQuantity(void){ | |
833 | return tStats->getTotalE(); | |
834 | } | |
835 | + | template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
836 | + | //By default, return a null string |
837 | + | //The reason we use string instead of char* is that if we use char*, we will |
838 | + | //return a pointer point to local variable which might cause problem |
839 | + | return string(); |
840 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |