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 |
|
} |
32 |
< |
|
32 |
> |
|
33 |
|
nAtoms = info->n_atoms; |
34 |
+ |
integrableObjects = info->integrableObjects; |
35 |
|
|
36 |
|
// check for constraints |
37 |
|
|
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 |
|
|
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
+ |
|
120 |
|
if (nConstrained > 0){ |
121 |
|
isConstrained = 1; |
122 |
|
|
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 |
|
|
165 |
|
double currThermal; |
166 |
|
double currStatus; |
167 |
|
double currReset; |
168 |
< |
|
168 |
> |
|
169 |
|
int calcPot, calcStress; |
170 |
|
|
171 |
|
tStats = new Thermo(info); |
183 |
|
|
184 |
|
calcForce(1, 1); |
185 |
|
|
186 |
+ |
//temp test |
187 |
+ |
tStats->getPotential(); |
188 |
+ |
|
189 |
|
if (nConstrained){ |
190 |
|
preMove(); |
191 |
|
constrainA(); |
192 |
< |
calcForce(1, 1); |
192 |
> |
calcForce(1, 1); |
193 |
|
constrainB(); |
194 |
|
} |
195 |
|
|
208 |
|
statOut->writeStat(info->getTime()); |
209 |
|
|
210 |
|
|
201 |
– |
|
211 |
|
#ifdef IS_MPI |
212 |
|
strcpy(checkPointMsg, "The integrator is ready to go."); |
213 |
|
MPIcheckPoint(); |
219 |
|
calcStress = 1; |
220 |
|
} |
221 |
|
|
222 |
+ |
#ifdef PROFILE |
223 |
+ |
startProfile( pro1 ); |
224 |
+ |
#endif |
225 |
+ |
|
226 |
|
integrateStep(calcPot, calcStress); |
227 |
|
|
228 |
+ |
#ifdef PROFILE |
229 |
+ |
endProfile( pro1 ); |
230 |
+ |
|
231 |
+ |
startProfile( pro2 ); |
232 |
+ |
#endif // profile |
233 |
+ |
|
234 |
|
info->incrTime(dt); |
235 |
|
|
236 |
|
if (info->setTemp){ |
246 |
|
} |
247 |
|
|
248 |
|
if (info->getTime() >= currStatus){ |
249 |
< |
statOut->writeStat(info->getTime()); |
250 |
< |
calcPot = 0; |
249 |
> |
statOut->writeStat(info->getTime()); |
250 |
> |
calcPot = 0; |
251 |
|
calcStress = 0; |
252 |
|
currStatus += statusTime; |
253 |
< |
} |
253 |
> |
} |
254 |
|
|
255 |
|
if (info->resetIntegrator){ |
256 |
|
if (info->getTime() >= currReset){ |
258 |
|
currReset += resetTime; |
259 |
|
} |
260 |
|
} |
261 |
+ |
|
262 |
+ |
#ifdef PROFILE |
263 |
+ |
endProfile( pro2 ); |
264 |
+ |
#endif //profile |
265 |
|
|
266 |
|
#ifdef IS_MPI |
267 |
|
strcpy(checkPointMsg, "successfully took a time step."); |
269 |
|
#endif // is_mpi |
270 |
|
} |
271 |
|
|
249 |
– |
|
250 |
– |
// write the last frame |
251 |
– |
dumpOut->writeDump(info->getTime()); |
252 |
– |
|
272 |
|
delete dumpOut; |
273 |
|
delete statOut; |
274 |
|
} |
276 |
|
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
277 |
|
int calcStress){ |
278 |
|
// Position full step, and velocity half step |
279 |
+ |
|
280 |
+ |
#ifdef PROFILE |
281 |
+ |
startProfile(pro3); |
282 |
+ |
#endif //profile |
283 |
+ |
|
284 |
|
preMove(); |
285 |
|
|
286 |
< |
moveA(); |
286 |
> |
#ifdef PROFILE |
287 |
> |
endProfile(pro3); |
288 |
|
|
289 |
+ |
startProfile(pro4); |
290 |
+ |
#endif // profile |
291 |
|
|
292 |
+ |
moveA(); |
293 |
|
|
294 |
+ |
#ifdef PROFILE |
295 |
+ |
endProfile(pro4); |
296 |
+ |
|
297 |
+ |
startProfile(pro5); |
298 |
+ |
#endif//profile |
299 |
|
|
300 |
+ |
|
301 |
|
#ifdef IS_MPI |
302 |
|
strcpy(checkPointMsg, "Succesful moveA\n"); |
303 |
|
MPIcheckPoint(); |
313 |
|
MPIcheckPoint(); |
314 |
|
#endif // is_mpi |
315 |
|
|
316 |
+ |
#ifdef PROFILE |
317 |
+ |
endProfile( pro5 ); |
318 |
|
|
319 |
+ |
startProfile( pro6 ); |
320 |
+ |
#endif //profile |
321 |
+ |
|
322 |
|
// finish the velocity half step |
323 |
|
|
324 |
|
moveB(); |
325 |
|
|
326 |
+ |
#ifdef PROFILE |
327 |
+ |
endProfile(pro6); |
328 |
+ |
#endif // profile |
329 |
|
|
288 |
– |
|
330 |
|
#ifdef IS_MPI |
331 |
|
strcpy(checkPointMsg, "Succesful moveB\n"); |
332 |
|
MPIcheckPoint(); |
335 |
|
|
336 |
|
|
337 |
|
template<typename T> void Integrator<T>::moveA(void){ |
338 |
< |
int i, j; |
338 |
> |
size_t i, j; |
339 |
|
DirectionalAtom* dAtom; |
340 |
|
double Tb[3], ji[3]; |
341 |
|
double vel[3], pos[3], frc[3]; |
342 |
|
double mass; |
343 |
< |
|
344 |
< |
for (i = 0; i < nAtoms; i++){ |
345 |
< |
atoms[i]->getVel(vel); |
346 |
< |
atoms[i]->getPos(pos); |
347 |
< |
atoms[i]->getFrc(frc); |
348 |
< |
|
349 |
< |
mass = atoms[i]->getMass(); |
343 |
> |
|
344 |
> |
for (i = 0; i < integrableObjects.size() ; i++){ |
345 |
> |
integrableObjects[i]->getVel(vel); |
346 |
> |
integrableObjects[i]->getPos(pos); |
347 |
> |
integrableObjects[i]->getFrc(frc); |
348 |
> |
|
349 |
> |
mass = integrableObjects[i]->getMass(); |
350 |
|
|
351 |
|
for (j = 0; j < 3; j++){ |
352 |
|
// velocity half step |
355 |
|
pos[j] += dt * vel[j]; |
356 |
|
} |
357 |
|
|
358 |
< |
atoms[i]->setVel(vel); |
359 |
< |
atoms[i]->setPos(pos); |
358 |
> |
integrableObjects[i]->setVel(vel); |
359 |
> |
integrableObjects[i]->setPos(pos); |
360 |
|
|
361 |
< |
if (atoms[i]->isDirectional()){ |
321 |
< |
dAtom = (DirectionalAtom *) atoms[i]; |
361 |
> |
if (integrableObjects[i]->isDirectional()){ |
362 |
|
|
363 |
|
// get and convert the torque to body frame |
364 |
|
|
365 |
< |
dAtom->getTrq(Tb); |
366 |
< |
dAtom->lab2Body(Tb); |
365 |
> |
integrableObjects[i]->getTrq(Tb); |
366 |
> |
integrableObjects[i]->lab2Body(Tb); |
367 |
|
|
368 |
|
// get the angular momentum, and propagate a half step |
369 |
|
|
370 |
< |
dAtom->getJ(ji); |
370 |
> |
integrableObjects[i]->getJ(ji); |
371 |
|
|
372 |
|
for (j = 0; j < 3; j++) |
373 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
374 |
|
|
375 |
< |
this->rotationPropagation( dAtom, ji ); |
375 |
> |
this->rotationPropagation( integrableObjects[i], ji ); |
376 |
|
|
377 |
< |
dAtom->setJ(ji); |
377 |
> |
integrableObjects[i]->setJ(ji); |
378 |
|
} |
379 |
|
} |
380 |
|
|
386 |
|
|
387 |
|
template<typename T> void Integrator<T>::moveB(void){ |
388 |
|
int i, j; |
349 |
– |
DirectionalAtom* dAtom; |
389 |
|
double Tb[3], ji[3]; |
390 |
|
double vel[3], frc[3]; |
391 |
|
double mass; |
392 |
|
|
393 |
< |
for (i = 0; i < nAtoms; i++){ |
394 |
< |
atoms[i]->getVel(vel); |
395 |
< |
atoms[i]->getFrc(frc); |
393 |
> |
for (i = 0; i < integrableObjects.size(); i++){ |
394 |
> |
integrableObjects[i]->getVel(vel); |
395 |
> |
integrableObjects[i]->getFrc(frc); |
396 |
|
|
397 |
< |
mass = atoms[i]->getMass(); |
397 |
> |
mass = integrableObjects[i]->getMass(); |
398 |
|
|
399 |
|
// velocity half step |
400 |
|
for (j = 0; j < 3; j++) |
401 |
|
vel[j] += (dt2 * frc[j] / mass) * eConvert; |
402 |
|
|
403 |
< |
atoms[i]->setVel(vel); |
403 |
> |
integrableObjects[i]->setVel(vel); |
404 |
|
|
405 |
< |
if (atoms[i]->isDirectional()){ |
367 |
< |
dAtom = (DirectionalAtom *) atoms[i]; |
405 |
> |
if (integrableObjects[i]->isDirectional()){ |
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); |
409 |
> |
integrableObjects[i]->getTrq(Tb); |
410 |
> |
integrableObjects[i]->lab2Body(Tb); |
411 |
|
|
412 |
|
// get the angular momentum, and propagate a half step |
413 |
|
|
414 |
< |
dAtom->getJ(ji); |
414 |
> |
integrableObjects[i]->getJ(ji); |
415 |
|
|
416 |
|
for (j = 0; j < 3; j++) |
417 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
418 |
|
|
419 |
|
|
420 |
< |
dAtom->setJ(ji); |
420 |
> |
integrableObjects[i]->setJ(ji); |
421 |
|
} |
422 |
|
} |
423 |
|
|
686 |
|
} |
687 |
|
|
688 |
|
template<typename T> void Integrator<T>::rotationPropagation |
689 |
< |
( DirectionalAtom* dAtom, double ji[3] ){ |
689 |
> |
( StuntDouble* sd, double ji[3] ){ |
690 |
|
|
691 |
|
double angle; |
692 |
|
double A[3][3], I[3][3]; |
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 |
697 |
> |
sd->getA(A); |
698 |
> |
sd->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 |
< |
|
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 |
< |
|
707 |
> |
|
708 |
|
// rotate about the z-axis |
709 |
|
angle = dt * ji[2] / I[2][2]; |
710 |
|
this->rotate( 0, 1, angle, ji, A); |
711 |
< |
|
711 |
> |
|
712 |
|
// rotate about the y-axis |
713 |
|
angle = dt2 * ji[1] / I[1][1]; |
714 |
|
this->rotate( 2, 0, angle, ji, A ); |
715 |
< |
|
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 ); |
719 |
> |
|
720 |
> |
sd->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 |
|
|
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 |
+ |
} |