1 |
|
#include <iostream> |
2 |
|
#include <stdlib.h> |
3 |
|
#include <math.h> |
4 |
< |
|
4 |
> |
#include "Rattle.hpp" |
5 |
> |
#include "Roll.hpp" |
6 |
|
#ifdef IS_MPI |
7 |
|
#include "mpiSimulation.hpp" |
8 |
|
#include <unistd.h> |
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; |
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; |
71 |
|
delete[] moved; |
72 |
|
delete[] oldPos; |
73 |
|
} |
74 |
+ |
*/ |
75 |
|
} |
76 |
|
|
77 |
+ |
/* |
78 |
|
template<typename T> void Integrator<T>::checkConstraints(void){ |
79 |
|
isConstrained = 0; |
80 |
|
|
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++; |
167 |
|
|
168 |
|
delete[] temp_con; |
169 |
|
} |
170 |
+ |
*/ |
171 |
|
|
154 |
– |
|
172 |
|
template<typename T> void Integrator<T>::integrate(void){ |
173 |
|
|
174 |
|
double runTime = info->run_time; |
177 |
|
double thermalTime = info->thermalTime; |
178 |
|
double resetTime = info->resetTime; |
179 |
|
|
180 |
< |
|
180 |
> |
double difference; |
181 |
|
double currSample; |
182 |
|
double currThermal; |
183 |
|
double currStatus; |
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 |
< |
//temp test |
213 |
< |
tStats->getPotential(); |
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 |
|
|
189 |
– |
if (nConstrained){ |
190 |
– |
preMove(); |
191 |
– |
constrainA(); |
192 |
– |
calcForce(1, 1); |
193 |
– |
constrainB(); |
194 |
– |
} |
195 |
– |
|
218 |
|
if (info->setTemp){ |
219 |
|
thermalize(); |
220 |
|
} |
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 |
|
} |
292 |
|
#endif // is_mpi |
293 |
|
} |
294 |
|
|
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; |
302 |
|
} |
309 |
|
startProfile(pro3); |
310 |
|
#endif //profile |
311 |
|
|
312 |
< |
preMove(); |
312 |
> |
//save old state (position, velocity etc) |
313 |
> |
consFramework->doPreConstraint(); |
314 |
|
|
315 |
|
#ifdef PROFILE |
316 |
|
endProfile(pro3); |
332 |
|
MPIcheckPoint(); |
333 |
|
#endif // is_mpi |
334 |
|
|
306 |
– |
|
335 |
|
// calc forces |
308 |
– |
|
336 |
|
calcForce(calcPot, calcStress); |
337 |
|
|
338 |
|
#ifdef IS_MPI |
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); |
406 |
|
} |
407 |
|
} |
408 |
|
|
409 |
< |
if (nConstrained){ |
382 |
< |
constrainA(); |
383 |
< |
} |
409 |
> |
consFramework->doConstrainA(); |
410 |
|
} |
411 |
|
|
412 |
|
|
447 |
|
} |
448 |
|
} |
449 |
|
|
450 |
< |
if (nConstrained){ |
425 |
< |
constrainB(); |
426 |
< |
} |
450 |
> |
consFramework->doConstrainB(); |
451 |
|
} |
452 |
|
|
453 |
+ |
/* |
454 |
|
template<typename T> void Integrator<T>::preMove(void){ |
455 |
|
int i, j; |
456 |
|
double pos[3]; |
709 |
|
simError(); |
710 |
|
} |
711 |
|
} |
712 |
< |
|
712 |
> |
*/ |
713 |
|
template<typename T> void Integrator<T>::rotationPropagation |
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 |
723 |
|
sd->getA(A); |
724 |
|
sd->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 ); |
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 |
< |
// rotate about the z-axis |
735 |
< |
angle = dt * ji[2] / I[2][2]; |
710 |
< |
this->rotate( 0, 1, angle, ji, A); |
734 |
> |
angle = dt * ji[k] / I[k][k]; |
735 |
> |
this->rotate( i, j, angle, ji, A); |
736 |
|
|
737 |
< |
// rotate about the y-axis |
738 |
< |
angle = dt2 * ji[1] / I[1][1]; |
739 |
< |
this->rotate( 2, 0, angle, ji, A ); |
740 |
< |
|
741 |
< |
// rotate about the x-axis |
742 |
< |
angle = dt2 * ji[0] / I[0][0]; |
743 |
< |
this->rotate( 1, 2, angle, ji, A ); |
744 |
< |
|
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 |
|
|