# | 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 | } | |
28 | – | |
29 | – | nAtoms = info->n_atoms; |
32 | ||
33 | + | nAtoms = info->n_atoms; |
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; | |
168 | double currReset; | |
169 | < | |
169 | > | |
170 | int calcPot, calcStress; | |
171 | ||
172 | tStats = new Thermo(info); | |
# | 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->useThermInt) { |
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); |
199 | > | calcForce(1, 1); |
200 | constrainB(); | |
201 | } | |
202 | ||
# | 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 227 | Line 254 | template<typename T> void Integrator<T>::integrate(voi | |
254 | } | |
255 | ||
256 | if (info->getTime() >= currStatus){ | |
257 | < | statOut->writeStat(info->getTime()); |
258 | < | calcPot = 0; |
257 | > | statOut->writeStat(info->getTime()); |
258 | > | statOut->writeRaw(info->getTime()); |
259 | > | calcPot = 0; |
260 | calcStress = 0; | |
261 | currStatus += statusTime; | |
262 | < | } |
262 | > | } |
263 | ||
264 | if (info->resetIntegrator){ | |
265 | if (info->getTime() >= currReset){ | |
# | Line 239 | Line 267 | template<typename T> void Integrator<T>::integrate(voi | |
267 | currReset += resetTime; | |
268 | } | |
269 | } | |
270 | + | |
271 | + | #ifdef PROFILE |
272 | + | endProfile( pro2 ); |
273 | + | #endif //profile |
274 | ||
275 | #ifdef IS_MPI | |
276 | strcpy(checkPointMsg, "successfully took a time step."); | |
# | Line 246 | Line 278 | template<typename T> void Integrator<T>::integrate(voi | |
278 | #endif // is_mpi | |
279 | } | |
280 | ||
281 | < | dumpOut->writeFinal(info->getTime()); |
281 | > | // dump out a file containing the omega values for the final configuration |
282 | > | if (info->useThermInt) |
283 | > | myFF->dumpzAngle(); |
284 | > | |
285 | ||
286 | delete dumpOut; | |
287 | delete statOut; | |
# | Line 255 | Line 290 | template<typename T> void Integrator<T>::integrateStep | |
290 | template<typename T> void Integrator<T>::integrateStep(int calcPot, | |
291 | int calcStress){ | |
292 | // Position full step, and velocity half step | |
293 | + | |
294 | + | #ifdef PROFILE |
295 | + | startProfile(pro3); |
296 | + | #endif //profile |
297 | + | |
298 | preMove(); | |
299 | ||
300 | < | moveA(); |
300 | > | #ifdef PROFILE |
301 | > | endProfile(pro3); |
302 | ||
303 | + | startProfile(pro4); |
304 | + | #endif // profile |
305 | ||
306 | + | moveA(); |
307 | ||
308 | + | #ifdef PROFILE |
309 | + | endProfile(pro4); |
310 | + | |
311 | + | startProfile(pro5); |
312 | + | #endif//profile |
313 | ||
314 | + | |
315 | #ifdef IS_MPI | |
316 | strcpy(checkPointMsg, "Succesful moveA\n"); | |
317 | MPIcheckPoint(); | |
318 | #endif // is_mpi | |
319 | ||
270 | – | |
320 | // calc forces | |
272 | – | |
321 | calcForce(calcPot, calcStress); | |
322 | ||
323 | #ifdef IS_MPI | |
# | Line 277 | Line 325 | template<typename T> void Integrator<T>::integrateStep | |
325 | MPIcheckPoint(); | |
326 | #endif // is_mpi | |
327 | ||
328 | + | #ifdef PROFILE |
329 | + | endProfile( pro5 ); |
330 | ||
331 | + | startProfile( pro6 ); |
332 | + | #endif //profile |
333 | + | |
334 | // finish the velocity half step | |
335 | ||
336 | moveB(); | |
337 | ||
338 | + | #ifdef PROFILE |
339 | + | endProfile(pro6); |
340 | + | #endif // profile |
341 | ||
286 | – | |
342 | #ifdef IS_MPI | |
343 | strcpy(checkPointMsg, "Succesful moveB\n"); | |
344 | MPIcheckPoint(); | |
# | Line 292 | Line 347 | template<typename T> void Integrator<T>::moveA(void){ | |
347 | ||
348 | ||
349 | template<typename T> void Integrator<T>::moveA(void){ | |
350 | < | int i, j; |
350 | > | size_t i, j; |
351 | DirectionalAtom* dAtom; | |
352 | double Tb[3], ji[3]; | |
353 | double vel[3], pos[3], frc[3]; | |
354 | double mass; | |
355 | + | double omega; |
356 | + | |
357 | + | for (i = 0; i < integrableObjects.size() ; i++){ |
358 | + | integrableObjects[i]->getVel(vel); |
359 | + | integrableObjects[i]->getPos(pos); |
360 | + | integrableObjects[i]->getFrc(frc); |
361 | + | |
362 | + | mass = integrableObjects[i]->getMass(); |
363 | ||
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 | – | |
364 | for (j = 0; j < 3; j++){ | |
365 | // velocity half step | |
366 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
# | Line 312 | Line 368 | template<typename T> void Integrator<T>::moveA(void){ | |
368 | pos[j] += dt * vel[j]; | |
369 | } | |
370 | ||
371 | < | atoms[i]->setVel(vel); |
372 | < | atoms[i]->setPos(pos); |
371 | > | integrableObjects[i]->setVel(vel); |
372 | > | integrableObjects[i]->setPos(pos); |
373 | ||
374 | < | if (atoms[i]->isDirectional()){ |
319 | < | dAtom = (DirectionalAtom *) atoms[i]; |
374 | > | if (integrableObjects[i]->isDirectional()){ |
375 | ||
376 | // get and convert the torque to body frame | |
377 | ||
378 | < | dAtom->getTrq(Tb); |
379 | < | dAtom->lab2Body(Tb); |
378 | > | integrableObjects[i]->getTrq(Tb); |
379 | > | integrableObjects[i]->lab2Body(Tb); |
380 | ||
381 | // get the angular momentum, and propagate a half step | |
382 | ||
383 | < | dAtom->getJ(ji); |
383 | > | integrableObjects[i]->getJ(ji); |
384 | ||
385 | for (j = 0; j < 3; j++) | |
386 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
387 | ||
388 | < | this->rotationPropagation( dAtom, ji ); |
388 | > | this->rotationPropagation( integrableObjects[i], ji ); |
389 | ||
390 | < | dAtom->setJ(ji); |
390 | > | integrableObjects[i]->setJ(ji); |
391 | } | |
392 | } | |
393 | ||
# | Line 344 | Line 399 | template<typename T> void Integrator<T>::moveB(void){ | |
399 | ||
400 | template<typename T> void Integrator<T>::moveB(void){ | |
401 | int i, j; | |
347 | – | DirectionalAtom* dAtom; |
402 | double Tb[3], ji[3]; | |
403 | double vel[3], frc[3]; | |
404 | double mass; | |
405 | ||
406 | < | for (i = 0; i < nAtoms; i++){ |
407 | < | atoms[i]->getVel(vel); |
408 | < | atoms[i]->getFrc(frc); |
406 | > | for (i = 0; i < integrableObjects.size(); i++){ |
407 | > | integrableObjects[i]->getVel(vel); |
408 | > | integrableObjects[i]->getFrc(frc); |
409 | ||
410 | < | mass = atoms[i]->getMass(); |
410 | > | mass = integrableObjects[i]->getMass(); |
411 | ||
412 | // velocity half step | |
413 | for (j = 0; j < 3; j++) | |
414 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
415 | ||
416 | < | atoms[i]->setVel(vel); |
416 | > | integrableObjects[i]->setVel(vel); |
417 | ||
418 | < | if (atoms[i]->isDirectional()){ |
365 | < | dAtom = (DirectionalAtom *) atoms[i]; |
418 | > | if (integrableObjects[i]->isDirectional()){ |
419 | ||
420 | < | // get and convert the torque to body frame |
420 | > | // get and convert the torque to body frame |
421 | ||
422 | < | dAtom->getTrq(Tb); |
423 | < | dAtom->lab2Body(Tb); |
422 | > | integrableObjects[i]->getTrq(Tb); |
423 | > | integrableObjects[i]->lab2Body(Tb); |
424 | ||
425 | // get the angular momentum, and propagate a half step | |
426 | ||
427 | < | dAtom->getJ(ji); |
427 | > | integrableObjects[i]->getJ(ji); |
428 | ||
429 | for (j = 0; j < 3; j++) | |
430 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
431 | ||
432 | ||
433 | < | dAtom->setJ(ji); |
433 | > | integrableObjects[i]->setJ(ji); |
434 | } | |
435 | } | |
436 | ||
# | Line 646 | Line 699 | template<typename T> void Integrator<T>::rotationPropa | |
699 | } | |
700 | ||
701 | template<typename T> void Integrator<T>::rotationPropagation | |
702 | < | ( DirectionalAtom* dAtom, double ji[3] ){ |
702 | > | ( StuntDouble* sd, double ji[3] ){ |
703 | ||
704 | double angle; | |
705 | double A[3][3], I[3][3]; | |
706 | + | int i, j, k; |
707 | ||
708 | // use the angular velocities to propagate the rotation matrix a | |
709 | // full time step | |
710 | ||
711 | < | dAtom->getA(A); |
712 | < | dAtom->getI(I); |
713 | < | |
714 | < | // rotate about the x-axis |
715 | < | angle = dt2 * ji[0] / I[0][0]; |
716 | < | this->rotate( 1, 2, angle, ji, A ); |
717 | < | |
718 | < | // rotate about the y-axis |
719 | < | angle = dt2 * ji[1] / I[1][1]; |
720 | < | this->rotate( 2, 0, angle, ji, A ); |
721 | < | |
722 | < | // rotate about the z-axis |
723 | < | angle = dt * ji[2] / I[2][2]; |
724 | < | this->rotate( 0, 1, angle, ji, A); |
725 | < | |
726 | < | // rotate about the y-axis |
727 | < | angle = dt2 * ji[1] / I[1][1]; |
728 | < | this->rotate( 2, 0, angle, ji, A ); |
729 | < | |
730 | < | // rotate about the x-axis |
731 | < | angle = dt2 * ji[0] / I[0][0]; |
732 | < | this->rotate( 1, 2, angle, ji, A ); |
733 | < | |
734 | < | dAtom->setA( A ); |
711 | > | sd->getA(A); |
712 | > | sd->getI(I); |
713 | > | |
714 | > | if (sd->isLinear()) { |
715 | > | i = sd->linearAxis(); |
716 | > | j = (i+1)%3; |
717 | > | k = (i+2)%3; |
718 | > | |
719 | > | angle = dt2 * ji[j] / I[j][j]; |
720 | > | this->rotate( k, i, angle, ji, A ); |
721 | > | |
722 | > | angle = dt * ji[k] / I[k][k]; |
723 | > | this->rotate( i, j, angle, ji, A); |
724 | > | |
725 | > | angle = dt2 * ji[j] / I[j][j]; |
726 | > | this->rotate( k, i, angle, ji, A ); |
727 | > | |
728 | > | } else { |
729 | > | // rotate about the x-axis |
730 | > | angle = dt2 * ji[0] / I[0][0]; |
731 | > | this->rotate( 1, 2, angle, ji, A ); |
732 | > | |
733 | > | // rotate about the y-axis |
734 | > | angle = dt2 * ji[1] / I[1][1]; |
735 | > | this->rotate( 2, 0, angle, ji, A ); |
736 | > | |
737 | > | // rotate about the z-axis |
738 | > | angle = dt * ji[2] / I[2][2]; |
739 | > | sd->addZangle(angle); |
740 | > | this->rotate( 0, 1, angle, ji, A); |
741 | > | |
742 | > | // rotate about the y-axis |
743 | > | angle = dt2 * ji[1] / I[1][1]; |
744 | > | this->rotate( 2, 0, angle, ji, A ); |
745 | > | |
746 | > | // rotate about the x-axis |
747 | > | angle = dt2 * ji[0] / I[0][0]; |
748 | > | this->rotate( 1, 2, angle, ji, A ); |
749 | > | |
750 | > | } |
751 | > | sd->setA( A ); |
752 | } | |
753 | ||
754 | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, | |
# | Line 745 | Line 816 | template<typename T> void Integrator<T>::rotate(int ax | |
816 | } | |
817 | } | |
818 | ||
819 | < | // rotate the Rotation matrix acording to: |
819 | > | // rotate the Rotation matrix acording to: |
820 | // A[][] = A[][] * transpose(rot[][]) | |
821 | ||
822 | ||
# | Line 774 | Line 845 | template<typename T> double Integrator<T>::getConserve | |
845 | template<typename T> double Integrator<T>::getConservedQuantity(void){ | |
846 | return tStats->getTotalE(); | |
847 | } | |
848 | + | template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
849 | + | //By default, return a null string |
850 | + | //The reason we use string instead of char* is that if we use char*, we will |
851 | + | //return a pointer point to local variable which might cause problem |
852 | + | return string(); |
853 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |