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 |
|
|
29 |
|
if (info->the_integrator != NULL){ |
30 |
|
delete info->the_integrator; |
31 |
|
} |
28 |
– |
info->the_integrator = this; |
32 |
|
|
33 |
|
nAtoms = info->n_atoms; |
34 |
|
|
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
< |
// save oldAtoms to check for lode balanceing later on. |
138 |
> |
// save oldAtoms to check for lode balancing later on. |
139 |
|
|
140 |
|
oldAtoms = nAtoms; |
141 |
|
|
150 |
|
|
151 |
|
|
152 |
|
template<typename T> void Integrator<T>::integrate(void){ |
150 |
– |
int i, j; // loop counters |
153 |
|
|
154 |
|
double runTime = info->run_time; |
155 |
|
double sampleTime = info->sampleTime; |
162 |
|
double currThermal; |
163 |
|
double currStatus; |
164 |
|
double currReset; |
165 |
< |
|
165 |
> |
|
166 |
|
int calcPot, calcStress; |
165 |
– |
int isError; |
167 |
|
|
168 |
|
tStats = new Thermo(info); |
169 |
|
statOut = new StatWriter(info); |
170 |
|
dumpOut = new DumpWriter(info); |
171 |
|
|
172 |
|
atoms = info->atoms; |
172 |
– |
DirectionalAtom* dAtom; |
173 |
|
|
174 |
|
dt = info->dt; |
175 |
|
dt2 = 0.5 * dt; |
176 |
|
|
177 |
+ |
readyCheck(); |
178 |
+ |
|
179 |
|
// initialize the forces before the first step |
180 |
|
|
181 |
|
calcForce(1, 1); |
182 |
+ |
|
183 |
+ |
//temp test |
184 |
+ |
tStats->getPotential(); |
185 |
|
|
186 |
+ |
if (nConstrained){ |
187 |
+ |
preMove(); |
188 |
+ |
constrainA(); |
189 |
+ |
calcForce(1, 1); |
190 |
+ |
constrainB(); |
191 |
+ |
} |
192 |
+ |
|
193 |
|
if (info->setTemp){ |
194 |
|
thermalize(); |
195 |
|
} |
204 |
|
dumpOut->writeDump(info->getTime()); |
205 |
|
statOut->writeStat(info->getTime()); |
206 |
|
|
195 |
– |
readyCheck(); |
207 |
|
|
208 |
|
#ifdef IS_MPI |
209 |
|
strcpy(checkPointMsg, "The integrator is ready to go."); |
216 |
|
calcStress = 1; |
217 |
|
} |
218 |
|
|
219 |
+ |
#ifdef PROFILE |
220 |
+ |
startProfile( pro1 ); |
221 |
+ |
#endif |
222 |
+ |
|
223 |
|
integrateStep(calcPot, calcStress); |
224 |
|
|
225 |
+ |
#ifdef PROFILE |
226 |
+ |
endProfile( pro1 ); |
227 |
+ |
|
228 |
+ |
startProfile( pro2 ); |
229 |
+ |
#endif // profile |
230 |
+ |
|
231 |
|
info->incrTime(dt); |
232 |
|
|
233 |
|
if (info->setTemp){ |
243 |
|
} |
244 |
|
|
245 |
|
if (info->getTime() >= currStatus){ |
246 |
< |
statOut->writeStat(info->getTime()); |
247 |
< |
calcPot = 0; |
246 |
> |
statOut->writeStat(info->getTime()); |
247 |
> |
calcPot = 0; |
248 |
|
calcStress = 0; |
249 |
|
currStatus += statusTime; |
250 |
< |
} |
250 |
> |
} |
251 |
|
|
252 |
|
if (info->resetIntegrator){ |
253 |
|
if (info->getTime() >= currReset){ |
255 |
|
currReset += resetTime; |
256 |
|
} |
257 |
|
} |
258 |
+ |
|
259 |
+ |
#ifdef PROFILE |
260 |
+ |
endProfile( pro2 ); |
261 |
+ |
#endif //profile |
262 |
|
|
263 |
|
#ifdef IS_MPI |
264 |
|
strcpy(checkPointMsg, "successfully took a time step."); |
266 |
|
#endif // is_mpi |
267 |
|
} |
268 |
|
|
244 |
– |
dumpOut->writeFinal(info->getTime()); |
245 |
– |
|
269 |
|
delete dumpOut; |
270 |
|
delete statOut; |
271 |
|
} |
273 |
|
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
274 |
|
int calcStress){ |
275 |
|
// Position full step, and velocity half step |
276 |
+ |
|
277 |
+ |
#ifdef PROFILE |
278 |
+ |
startProfile(pro3); |
279 |
+ |
#endif //profile |
280 |
+ |
|
281 |
|
preMove(); |
282 |
|
|
283 |
+ |
#ifdef PROFILE |
284 |
+ |
endProfile(pro3); |
285 |
+ |
|
286 |
+ |
startProfile(pro4); |
287 |
+ |
#endif // profile |
288 |
+ |
|
289 |
|
moveA(); |
290 |
|
|
291 |
< |
if (nConstrained){ |
292 |
< |
constrainA(); |
293 |
< |
} |
291 |
> |
#ifdef PROFILE |
292 |
> |
endProfile(pro4); |
293 |
> |
|
294 |
> |
startProfile(pro5); |
295 |
> |
#endif//profile |
296 |
|
|
297 |
|
|
298 |
|
#ifdef IS_MPI |
310 |
|
MPIcheckPoint(); |
311 |
|
#endif // is_mpi |
312 |
|
|
313 |
+ |
#ifdef PROFILE |
314 |
+ |
endProfile( pro5 ); |
315 |
|
|
316 |
+ |
startProfile( pro6 ); |
317 |
+ |
#endif //profile |
318 |
+ |
|
319 |
|
// finish the velocity half step |
320 |
|
|
321 |
|
moveB(); |
322 |
|
|
323 |
< |
if (nConstrained){ |
324 |
< |
constrainB(); |
325 |
< |
} |
323 |
> |
#ifdef PROFILE |
324 |
> |
endProfile(pro6); |
325 |
> |
#endif // profile |
326 |
|
|
327 |
|
#ifdef IS_MPI |
328 |
|
strcpy(checkPointMsg, "Succesful moveB\n"); |
335 |
|
int i, j; |
336 |
|
DirectionalAtom* dAtom; |
337 |
|
double Tb[3], ji[3]; |
297 |
– |
double A[3][3], I[3][3]; |
298 |
– |
double angle; |
338 |
|
double vel[3], pos[3], frc[3]; |
339 |
|
double mass; |
340 |
|
|
370 |
|
for (j = 0; j < 3; j++) |
371 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
372 |
|
|
373 |
< |
// use the angular velocities to propagate the rotation matrix a |
335 |
< |
// full time step |
373 |
> |
this->rotationPropagation( dAtom, ji ); |
374 |
|
|
375 |
< |
dAtom->getA(A); |
376 |
< |
dAtom->getI(I); |
377 |
< |
|
340 |
< |
// rotate about the x-axis |
341 |
< |
angle = dt2 * ji[0] / I[0][0]; |
342 |
< |
this->rotate(1, 2, angle, ji, A); |
343 |
< |
|
344 |
< |
// rotate about the y-axis |
345 |
< |
angle = dt2 * ji[1] / I[1][1]; |
346 |
< |
this->rotate(2, 0, angle, ji, A); |
347 |
< |
|
348 |
< |
// rotate about the z-axis |
349 |
< |
angle = dt * ji[2] / I[2][2]; |
350 |
< |
this->rotate(0, 1, angle, ji, A); |
351 |
< |
|
352 |
< |
// rotate about the y-axis |
353 |
< |
angle = dt2 * ji[1] / I[1][1]; |
354 |
< |
this->rotate(2, 0, angle, ji, A); |
355 |
< |
|
356 |
< |
// rotate about the x-axis |
357 |
< |
angle = dt2 * ji[0] / I[0][0]; |
358 |
< |
this->rotate(1, 2, angle, ji, A); |
375 |
> |
dAtom->setJ(ji); |
376 |
> |
} |
377 |
> |
} |
378 |
|
|
379 |
< |
dAtom->setJ(ji); |
380 |
< |
dAtom->setA(A); |
362 |
< |
} |
379 |
> |
if (nConstrained){ |
380 |
> |
constrainA(); |
381 |
|
} |
382 |
|
} |
383 |
|
|
404 |
|
if (atoms[i]->isDirectional()){ |
405 |
|
dAtom = (DirectionalAtom *) atoms[i]; |
406 |
|
|
407 |
< |
// get and convert the torque to body frame |
407 |
> |
// get and convert the torque to body frame |
408 |
|
|
409 |
|
dAtom->getTrq(Tb); |
410 |
|
dAtom->lab2Body(Tb); |
419 |
|
|
420 |
|
dAtom->setJ(ji); |
421 |
|
} |
422 |
+ |
} |
423 |
+ |
|
424 |
+ |
if (nConstrained){ |
425 |
+ |
constrainB(); |
426 |
|
} |
427 |
|
} |
428 |
|
|
442 |
|
} |
443 |
|
|
444 |
|
template<typename T> void Integrator<T>::constrainA(){ |
445 |
< |
int i, j, k; |
445 |
> |
int i, j; |
446 |
|
int done; |
447 |
|
double posA[3], posB[3]; |
448 |
|
double velA[3], velB[3]; |
582 |
|
painCave.isFatal = 1; |
583 |
|
simError(); |
584 |
|
} |
585 |
+ |
|
586 |
|
} |
587 |
|
|
588 |
|
template<typename T> void Integrator<T>::constrainB(void){ |
589 |
< |
int i, j, k; |
589 |
> |
int i, j; |
590 |
|
int done; |
591 |
|
double posA[3], posB[3]; |
592 |
|
double velA[3], velB[3]; |
595 |
|
int a, b, ax, ay, az, bx, by, bz; |
596 |
|
double rma, rmb; |
597 |
|
double dx, dy, dz; |
598 |
< |
double rabsq, pabsq, rvab; |
576 |
< |
double diffsq; |
598 |
> |
double rvab; |
599 |
|
double gab; |
600 |
|
int iteration; |
601 |
|
|
683 |
|
painCave.isFatal = 1; |
684 |
|
simError(); |
685 |
|
} |
686 |
+ |
} |
687 |
+ |
|
688 |
+ |
template<typename T> void Integrator<T>::rotationPropagation |
689 |
+ |
( DirectionalAtom* dAtom, double ji[3] ){ |
690 |
+ |
|
691 |
+ |
double angle; |
692 |
+ |
double A[3][3], I[3][3]; |
693 |
+ |
|
694 |
+ |
// use the angular velocities to propagate the rotation matrix a |
695 |
+ |
// full time step |
696 |
+ |
|
697 |
+ |
dAtom->getA(A); |
698 |
+ |
dAtom->getI(I); |
699 |
+ |
|
700 |
+ |
// rotate about the x-axis |
701 |
+ |
angle = dt2 * ji[0] / I[0][0]; |
702 |
+ |
this->rotate( 1, 2, angle, ji, A ); |
703 |
+ |
|
704 |
+ |
// rotate about the y-axis |
705 |
+ |
angle = dt2 * ji[1] / I[1][1]; |
706 |
+ |
this->rotate( 2, 0, angle, ji, A ); |
707 |
+ |
|
708 |
+ |
// rotate about the z-axis |
709 |
+ |
angle = dt * ji[2] / I[2][2]; |
710 |
+ |
this->rotate( 0, 1, angle, ji, A); |
711 |
+ |
|
712 |
+ |
// rotate about the y-axis |
713 |
+ |
angle = dt2 * ji[1] / I[1][1]; |
714 |
+ |
this->rotate( 2, 0, angle, ji, A ); |
715 |
+ |
|
716 |
+ |
// rotate about the x-axis |
717 |
+ |
angle = dt2 * ji[0] / I[0][0]; |
718 |
+ |
this->rotate( 1, 2, angle, ji, A ); |
719 |
+ |
|
720 |
+ |
dAtom->setA( A ); |
721 |
|
} |
722 |
|
|
723 |
|
template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
785 |
|
} |
786 |
|
} |
787 |
|
|
788 |
< |
// rotate the Rotation matrix acording to: |
788 |
> |
// rotate the Rotation matrix acording to: |
789 |
|
// A[][] = A[][] * transpose(rot[][]) |
790 |
|
|
791 |
|
|
810 |
|
template<typename T> void Integrator<T>::thermalize(){ |
811 |
|
tStats->velocitize(); |
812 |
|
} |
813 |
+ |
|
814 |
+ |
template<typename T> double Integrator<T>::getConservedQuantity(void){ |
815 |
+ |
return tStats->getTotalE(); |
816 |
+ |
} |
817 |
+ |
template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
818 |
+ |
//By default, return a null string |
819 |
+ |
//The reason we use string instead of char* is that if we use char*, we will |
820 |
+ |
//return a pointer point to local variable which might cause problem |
821 |
+ |
return string(); |
822 |
+ |
} |