# | Line 1 | Line 1 | |
---|---|---|
1 | #include <iostream> | |
2 | < | #include <cstdlib> |
3 | < | #include <cmath> |
4 | < | |
2 | > | #include <stdlib.h> |
3 | > | #include <math.h> |
4 | > | #include "Rattle.hpp" |
5 | > | #include "Roll.hpp" |
6 | #ifdef IS_MPI | |
7 | #include "mpiSimulation.hpp" | |
8 | #include <unistd.h> | |
9 | #endif //is_mpi | |
10 | ||
11 | + | #ifdef PROFILE |
12 | + | #include "mdProfile.hpp" |
13 | + | #endif // profile |
14 | + | |
15 | #include "Integrator.hpp" | |
16 | #include "simError.h" | |
17 | ||
# | Line 25 | Line 30 | template<typename T> Integrator<T>::Integrator(SimInfo | |
30 | if (info->the_integrator != NULL){ | |
31 | delete info->the_integrator; | |
32 | } | |
28 | – | info->the_integrator = this; |
33 | ||
34 | nAtoms = info->n_atoms; | |
35 | + | integrableObjects = info->integrableObjects; |
36 | ||
37 | + | consFramework = new RattleFramework(info); |
38 | + | |
39 | + | if(consFramework == NULL){ |
40 | + | sprintf(painCave.errMsg, |
41 | + | "Integrator::Intergrator() Error: Memory allocation error for RattleFramework" ); |
42 | + | painCave.isFatal = 1; |
43 | + | simError(); |
44 | + | } |
45 | + | |
46 | + | /* |
47 | // check for constraints | |
48 | ||
49 | constrainedA = NULL; | |
# | Line 41 | Line 56 | template<typename T> Integrator<T>::Integrator(SimInfo | |
56 | nConstrained = 0; | |
57 | ||
58 | checkConstraints(); | |
59 | + | */ |
60 | } | |
61 | ||
62 | template<typename T> Integrator<T>::~Integrator(){ | |
63 | + | if (consFramework != NULL) |
64 | + | delete consFramework; |
65 | + | /* |
66 | if (nConstrained){ | |
67 | delete[] constrainedA; | |
68 | delete[] constrainedB; | |
# | Line 52 | Line 71 | template<typename T> Integrator<T>::~Integrator(){ | |
71 | delete[] moved; | |
72 | delete[] oldPos; | |
73 | } | |
74 | + | */ |
75 | } | |
76 | ||
77 | + | /* |
78 | template<typename T> void Integrator<T>::checkConstraints(void){ | |
79 | isConstrained = 0; | |
80 | ||
# | Line 65 | Line 86 | template<typename T> void Integrator<T>::checkConstrai | |
86 | ||
87 | SRI** theArray; | |
88 | for (int i = 0; i < nMols; i++){ | |
89 | < | theArray = (SRI * *) molecules[i].getMyBonds(); |
89 | > | |
90 | > | theArray = (SRI * *) molecules[i].getMyBonds(); |
91 | for (int j = 0; j < molecules[i].getNBonds(); j++){ | |
92 | constrained = theArray[j]->is_constrained(); | |
93 | ||
# | Line 87 | Line 109 | template<typename T> void Integrator<T>::checkConstrai | |
109 | if (constrained){ | |
110 | dummy_plug = theArray[j]->get_constraint(); | |
111 | temp_con[nConstrained].set_a(dummy_plug->get_a()); | |
112 | < | temp_con[nConstrained].set_b(dummy_plug->get_b()); |
112 | > | temp_con[nConstrained].set_b(Dummy_plug->get_b()); |
113 | temp_con[nConstrained].set_dsqr(dummy_plug->get_dsqr()); | |
114 | ||
115 | nConstrained++; | |
# | Line 111 | Line 133 | template<typename T> void Integrator<T>::checkConstrai | |
133 | } | |
134 | } | |
135 | ||
136 | + | |
137 | if (nConstrained > 0){ | |
138 | isConstrained = 1; | |
139 | ||
# | Line 132 | Line 155 | template<typename T> void Integrator<T>::checkConstrai | |
155 | } | |
156 | ||
157 | ||
158 | < | // save oldAtoms to check for lode balanceing later on. |
158 | > | // save oldAtoms to check for lode balancing later on. |
159 | ||
160 | oldAtoms = nAtoms; | |
161 | ||
# | Line 144 | Line 167 | template<typename T> void Integrator<T>::checkConstrai | |
167 | ||
168 | delete[] temp_con; | |
169 | } | |
170 | + | */ |
171 | ||
148 | – | |
172 | template<typename T> void Integrator<T>::integrate(void){ | |
150 | – | int i, j; // loop counters |
173 | ||
174 | double runTime = info->run_time; | |
175 | double sampleTime = info->sampleTime; | |
# | Line 155 | Line 177 | template<typename T> void Integrator<T>::integrate(voi | |
177 | double thermalTime = info->thermalTime; | |
178 | double resetTime = info->resetTime; | |
179 | ||
180 | < | |
180 | > | double difference; |
181 | double currSample; | |
182 | double currThermal; | |
183 | double currStatus; | |
184 | double currReset; | |
185 | < | |
185 | > | |
186 | int calcPot, calcStress; | |
165 | – | int isError; |
187 | ||
188 | tStats = new Thermo(info); | |
189 | statOut = new StatWriter(info); | |
190 | dumpOut = new DumpWriter(info); | |
191 | ||
192 | atoms = info->atoms; | |
172 | – | DirectionalAtom* dAtom; |
193 | ||
194 | dt = info->dt; | |
195 | dt2 = 0.5 * dt; | |
196 | ||
197 | + | readyCheck(); |
198 | + | |
199 | + | // remove center of mass drift velocity (in case we passed in a configuration |
200 | + | // that was drifting |
201 | + | tStats->removeCOMdrift(); |
202 | + | |
203 | + | // initialize the retraints if necessary |
204 | + | if (info->useSolidThermInt && !info->useLiquidThermInt) { |
205 | + | myFF->initRestraints(); |
206 | + | } |
207 | + | |
208 | // initialize the forces before the first step | |
209 | ||
210 | calcForce(1, 1); | |
211 | ||
212 | < | if (nConstrained){ |
213 | < | preMove(); |
214 | < | constrainA(); |
215 | < | calcForce(1, 1); |
216 | < | constrainB(); |
186 | < | } |
212 | > | //execute constraint algorithm to make sure at the very beginning the system is constrained |
213 | > | consFramework->doPreConstraint(); |
214 | > | consFramework->doConstrainA(); |
215 | > | calcForce(1, 1); |
216 | > | consFramework->doConstrainB(); |
217 | ||
218 | if (info->setTemp){ | |
219 | thermalize(); | |
# | Line 199 | Line 229 | template<typename T> void Integrator<T>::integrate(voi | |
229 | dumpOut->writeDump(info->getTime()); | |
230 | statOut->writeStat(info->getTime()); | |
231 | ||
202 | – | readyCheck(); |
232 | ||
233 | #ifdef IS_MPI | |
234 | strcpy(checkPointMsg, "The integrator is ready to go."); | |
235 | MPIcheckPoint(); | |
236 | #endif // is_mpi | |
237 | ||
238 | < | while (info->getTime() < runTime){ |
239 | < | if ((info->getTime() + dt) >= currStatus){ |
238 | > | while (info->getTime() < runTime && !stopIntegrator()){ |
239 | > | difference = info->getTime() + dt - currStatus; |
240 | > | if (difference > 0 || fabs(difference) < 1e-4 ){ |
241 | calcPot = 1; | |
242 | calcStress = 1; | |
243 | } | |
244 | ||
245 | + | #ifdef PROFILE |
246 | + | startProfile( pro1 ); |
247 | + | #endif |
248 | + | |
249 | integrateStep(calcPot, calcStress); | |
250 | ||
251 | + | #ifdef PROFILE |
252 | + | endProfile( pro1 ); |
253 | + | |
254 | + | startProfile( pro2 ); |
255 | + | #endif // profile |
256 | + | |
257 | info->incrTime(dt); | |
258 | ||
259 | if (info->setTemp){ | |
# | Line 229 | Line 269 | template<typename T> void Integrator<T>::integrate(voi | |
269 | } | |
270 | ||
271 | if (info->getTime() >= currStatus){ | |
272 | < | statOut->writeStat(info->getTime()); |
273 | < | calcPot = 0; |
272 | > | statOut->writeStat(info->getTime()); |
273 | > | calcPot = 0; |
274 | calcStress = 0; | |
275 | currStatus += statusTime; | |
276 | < | } |
276 | > | } |
277 | ||
278 | if (info->resetIntegrator){ | |
279 | if (info->getTime() >= currReset){ | |
# | Line 241 | Line 281 | template<typename T> void Integrator<T>::integrate(voi | |
281 | currReset += resetTime; | |
282 | } | |
283 | } | |
284 | + | |
285 | + | #ifdef PROFILE |
286 | + | endProfile( pro2 ); |
287 | + | #endif //profile |
288 | ||
289 | #ifdef IS_MPI | |
290 | strcpy(checkPointMsg, "successfully took a time step."); | |
# | Line 248 | Line 292 | template<typename T> void Integrator<T>::integrate(voi | |
292 | #endif // is_mpi | |
293 | } | |
294 | ||
295 | < | dumpOut->writeFinal(info->getTime()); |
295 | > | // dump out a file containing the omega values for the final configuration |
296 | > | if (info->useSolidThermInt && !info->useLiquidThermInt) |
297 | > | myFF->dumpzAngle(); |
298 | > | |
299 | ||
300 | delete dumpOut; | |
301 | delete statOut; | |
# | Line 257 | Line 304 | template<typename T> void Integrator<T>::integrateStep | |
304 | template<typename T> void Integrator<T>::integrateStep(int calcPot, | |
305 | int calcStress){ | |
306 | // Position full step, and velocity half step | |
260 | – | preMove(); |
307 | ||
308 | < | moveA(); |
308 | > | #ifdef PROFILE |
309 | > | startProfile(pro3); |
310 | > | #endif //profile |
311 | ||
312 | + | //save old state (position, velocity etc) |
313 | + | consFramework->doPreConstraint(); |
314 | ||
315 | + | #ifdef PROFILE |
316 | + | endProfile(pro3); |
317 | ||
318 | + | startProfile(pro4); |
319 | + | #endif // profile |
320 | ||
321 | + | moveA(); |
322 | + | |
323 | + | #ifdef PROFILE |
324 | + | endProfile(pro4); |
325 | + | |
326 | + | startProfile(pro5); |
327 | + | #endif//profile |
328 | + | |
329 | + | |
330 | #ifdef IS_MPI | |
331 | strcpy(checkPointMsg, "Succesful moveA\n"); | |
332 | MPIcheckPoint(); | |
333 | #endif // is_mpi | |
334 | ||
272 | – | |
335 | // calc forces | |
274 | – | |
336 | calcForce(calcPot, calcStress); | |
337 | ||
338 | #ifdef IS_MPI | |
# | Line 279 | Line 340 | template<typename T> void Integrator<T>::integrateStep | |
340 | MPIcheckPoint(); | |
341 | #endif // is_mpi | |
342 | ||
343 | + | #ifdef PROFILE |
344 | + | endProfile( pro5 ); |
345 | ||
346 | + | startProfile( pro6 ); |
347 | + | #endif //profile |
348 | + | |
349 | // finish the velocity half step | |
350 | ||
351 | moveB(); | |
352 | ||
353 | + | #ifdef PROFILE |
354 | + | endProfile(pro6); |
355 | + | #endif // profile |
356 | ||
288 | – | |
357 | #ifdef IS_MPI | |
358 | strcpy(checkPointMsg, "Succesful moveB\n"); | |
359 | MPIcheckPoint(); | |
# | Line 294 | Line 362 | template<typename T> void Integrator<T>::moveA(void){ | |
362 | ||
363 | ||
364 | template<typename T> void Integrator<T>::moveA(void){ | |
365 | < | int i, j; |
365 | > | size_t i, j; |
366 | DirectionalAtom* dAtom; | |
367 | double Tb[3], ji[3]; | |
368 | double vel[3], pos[3], frc[3]; | |
369 | double mass; | |
370 | + | double omega; |
371 | + | |
372 | + | for (i = 0; i < integrableObjects.size() ; i++){ |
373 | + | integrableObjects[i]->getVel(vel); |
374 | + | integrableObjects[i]->getPos(pos); |
375 | + | integrableObjects[i]->getFrc(frc); |
376 | + | |
377 | + | mass = integrableObjects[i]->getMass(); |
378 | ||
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 | – | |
379 | for (j = 0; j < 3; j++){ | |
380 | // velocity half step | |
381 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
# | Line 314 | Line 383 | template<typename T> void Integrator<T>::moveA(void){ | |
383 | pos[j] += dt * vel[j]; | |
384 | } | |
385 | ||
386 | < | atoms[i]->setVel(vel); |
387 | < | atoms[i]->setPos(pos); |
386 | > | integrableObjects[i]->setVel(vel); |
387 | > | integrableObjects[i]->setPos(pos); |
388 | ||
389 | < | if (atoms[i]->isDirectional()){ |
321 | < | dAtom = (DirectionalAtom *) atoms[i]; |
389 | > | if (integrableObjects[i]->isDirectional()){ |
390 | ||
391 | // get and convert the torque to body frame | |
392 | ||
393 | < | dAtom->getTrq(Tb); |
394 | < | dAtom->lab2Body(Tb); |
393 | > | integrableObjects[i]->getTrq(Tb); |
394 | > | integrableObjects[i]->lab2Body(Tb); |
395 | ||
396 | // get the angular momentum, and propagate a half step | |
397 | ||
398 | < | dAtom->getJ(ji); |
398 | > | integrableObjects[i]->getJ(ji); |
399 | ||
400 | for (j = 0; j < 3; j++) | |
401 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
402 | ||
403 | < | this->rotationPropagation( dAtom, ji ); |
403 | > | this->rotationPropagation( integrableObjects[i], ji ); |
404 | ||
405 | < | dAtom->setJ(ji); |
405 | > | integrableObjects[i]->setJ(ji); |
406 | } | |
407 | } | |
408 | ||
409 | < | if (nConstrained){ |
342 | < | constrainA(); |
343 | < | } |
409 | > | consFramework->doConstrainA(); |
410 | } | |
411 | ||
412 | ||
413 | template<typename T> void Integrator<T>::moveB(void){ | |
414 | int i, j; | |
349 | – | DirectionalAtom* dAtom; |
415 | double Tb[3], ji[3]; | |
416 | double vel[3], frc[3]; | |
417 | double mass; | |
418 | ||
419 | < | for (i = 0; i < nAtoms; i++){ |
420 | < | atoms[i]->getVel(vel); |
421 | < | atoms[i]->getFrc(frc); |
419 | > | for (i = 0; i < integrableObjects.size(); i++){ |
420 | > | integrableObjects[i]->getVel(vel); |
421 | > | integrableObjects[i]->getFrc(frc); |
422 | ||
423 | < | mass = atoms[i]->getMass(); |
423 | > | mass = integrableObjects[i]->getMass(); |
424 | ||
425 | // velocity half step | |
426 | for (j = 0; j < 3; j++) | |
427 | vel[j] += (dt2 * frc[j] / mass) * eConvert; | |
428 | ||
429 | < | atoms[i]->setVel(vel); |
429 | > | integrableObjects[i]->setVel(vel); |
430 | ||
431 | < | if (atoms[i]->isDirectional()){ |
367 | < | dAtom = (DirectionalAtom *) atoms[i]; |
431 | > | if (integrableObjects[i]->isDirectional()){ |
432 | ||
433 | < | // get and convert the torque to body frame |
433 | > | // get and convert the torque to body frame |
434 | ||
435 | < | dAtom->getTrq(Tb); |
436 | < | dAtom->lab2Body(Tb); |
435 | > | integrableObjects[i]->getTrq(Tb); |
436 | > | integrableObjects[i]->lab2Body(Tb); |
437 | ||
438 | // get the angular momentum, and propagate a half step | |
439 | ||
440 | < | dAtom->getJ(ji); |
440 | > | integrableObjects[i]->getJ(ji); |
441 | ||
442 | for (j = 0; j < 3; j++) | |
443 | ji[j] += (dt2 * Tb[j]) * eConvert; | |
444 | ||
445 | ||
446 | < | dAtom->setJ(ji); |
446 | > | integrableObjects[i]->setJ(ji); |
447 | } | |
448 | } | |
449 | ||
450 | < | if (nConstrained){ |
387 | < | constrainB(); |
388 | < | } |
450 | > | consFramework->doConstrainB(); |
451 | } | |
452 | ||
453 | + | /* |
454 | template<typename T> void Integrator<T>::preMove(void){ | |
455 | int i, j; | |
456 | double pos[3]; | |
# | Line 404 | Line 467 | template<typename T> void Integrator<T>::constrainA(){ | |
467 | } | |
468 | ||
469 | template<typename T> void Integrator<T>::constrainA(){ | |
470 | < | int i, j, k; |
470 | > | int i, j; |
471 | int done; | |
472 | double posA[3], posB[3]; | |
473 | double velA[3], velB[3]; | |
# | Line 548 | Line 611 | template<typename T> void Integrator<T>::constrainB(vo | |
611 | } | |
612 | ||
613 | template<typename T> void Integrator<T>::constrainB(void){ | |
614 | < | int i, j, k; |
614 | > | int i, j; |
615 | int done; | |
616 | double posA[3], posB[3]; | |
617 | double velA[3], velB[3]; | |
# | Line 557 | Line 620 | template<typename T> void Integrator<T>::constrainB(vo | |
620 | int a, b, ax, ay, az, bx, by, bz; | |
621 | double rma, rmb; | |
622 | double dx, dy, dz; | |
623 | < | double rabsq, pabsq, rvab; |
561 | < | double diffsq; |
623 | > | double rvab; |
624 | double gab; | |
625 | int iteration; | |
626 | ||
# | Line 647 | Line 709 | template<typename T> void Integrator<T>::constrainB(vo | |
709 | simError(); | |
710 | } | |
711 | } | |
712 | < | |
712 | > | */ |
713 | template<typename T> void Integrator<T>::rotationPropagation | |
714 | < | ( DirectionalAtom* dAtom, double ji[3] ){ |
714 | > | ( StuntDouble* sd, double ji[3] ){ |
715 | ||
716 | double angle; | |
717 | double A[3][3], I[3][3]; | |
718 | + | int i, j, k; |
719 | ||
720 | // use the angular velocities to propagate the rotation matrix a | |
721 | // full time step | |
722 | ||
723 | < | dAtom->getA(A); |
724 | < | dAtom->getI(I); |
725 | < | |
726 | < | // rotate about the x-axis |
727 | < | angle = dt2 * ji[0] / I[0][0]; |
728 | < | this->rotate( 1, 2, angle, ji, A ); |
729 | < | |
730 | < | // rotate about the y-axis |
731 | < | angle = dt2 * ji[1] / I[1][1]; |
732 | < | this->rotate( 2, 0, angle, ji, A ); |
733 | < | |
734 | < | // rotate about the z-axis |
735 | < | angle = dt * ji[2] / I[2][2]; |
736 | < | this->rotate( 0, 1, angle, ji, A); |
737 | < | |
738 | < | // rotate about the y-axis |
739 | < | angle = dt2 * ji[1] / I[1][1]; |
740 | < | this->rotate( 2, 0, angle, ji, A ); |
741 | < | |
742 | < | // rotate about the x-axis |
743 | < | angle = dt2 * ji[0] / I[0][0]; |
744 | < | this->rotate( 1, 2, angle, ji, A ); |
745 | < | |
746 | < | dAtom->setA( A ); |
723 | > | sd->getA(A); |
724 | > | sd->getI(I); |
725 | > | |
726 | > | if (sd->isLinear()) { |
727 | > | i = sd->linearAxis(); |
728 | > | j = (i+1)%3; |
729 | > | k = (i+2)%3; |
730 | > | |
731 | > | angle = dt2 * ji[j] / I[j][j]; |
732 | > | this->rotate( k, i, angle, ji, A ); |
733 | > | |
734 | > | angle = dt * ji[k] / I[k][k]; |
735 | > | this->rotate( i, j, angle, ji, A); |
736 | > | |
737 | > | angle = dt2 * ji[j] / I[j][j]; |
738 | > | this->rotate( k, i, angle, ji, A ); |
739 | > | |
740 | > | } else { |
741 | > | // rotate about the x-axis |
742 | > | angle = dt2 * ji[0] / I[0][0]; |
743 | > | this->rotate( 1, 2, angle, ji, A ); |
744 | > | |
745 | > | // rotate about the y-axis |
746 | > | angle = dt2 * ji[1] / I[1][1]; |
747 | > | this->rotate( 2, 0, angle, ji, A ); |
748 | > | |
749 | > | // rotate about the z-axis |
750 | > | angle = dt * ji[2] / I[2][2]; |
751 | > | sd->addZangle(angle); |
752 | > | this->rotate( 0, 1, angle, ji, A); |
753 | > | |
754 | > | // rotate about the y-axis |
755 | > | angle = dt2 * ji[1] / I[1][1]; |
756 | > | this->rotate( 2, 0, angle, ji, A ); |
757 | > | |
758 | > | // rotate about the x-axis |
759 | > | angle = dt2 * ji[0] / I[0][0]; |
760 | > | this->rotate( 1, 2, angle, ji, A ); |
761 | > | |
762 | > | } |
763 | > | sd->setA( A ); |
764 | } | |
765 | ||
766 | template<typename T> void Integrator<T>::rotate(int axes1, int axes2, | |
# | Line 748 | Line 828 | template<typename T> void Integrator<T>::rotate(int ax | |
828 | } | |
829 | } | |
830 | ||
831 | < | // rotate the Rotation matrix acording to: |
831 | > | // rotate the Rotation matrix acording to: |
832 | // A[][] = A[][] * transpose(rot[][]) | |
833 | ||
834 | ||
# | Line 777 | Line 857 | template<typename T> double Integrator<T>::getConserve | |
857 | template<typename T> double Integrator<T>::getConservedQuantity(void){ | |
858 | return tStats->getTotalE(); | |
859 | } | |
860 | + | template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
861 | + | //By default, return a null string |
862 | + | //The reason we use string instead of char* is that if we use char*, we will |
863 | + | //return a pointer point to local variable which might cause problem |
864 | + | return string(); |
865 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |