| 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 |
|
|
| 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 |
+ |
if (nConstrained){ |
| 184 |
+ |
preMove(); |
| 185 |
+ |
constrainA(); |
| 186 |
+ |
calcForce(1, 1); |
| 187 |
+ |
constrainB(); |
| 188 |
+ |
} |
| 189 |
|
|
| 190 |
|
if (info->setTemp){ |
| 191 |
|
thermalize(); |
| 201 |
|
dumpOut->writeDump(info->getTime()); |
| 202 |
|
statOut->writeStat(info->getTime()); |
| 203 |
|
|
| 195 |
– |
readyCheck(); |
| 204 |
|
|
| 205 |
|
#ifdef IS_MPI |
| 206 |
|
strcpy(checkPointMsg, "The integrator is ready to go."); |
| 213 |
|
calcStress = 1; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
+ |
#ifdef PROFILE |
| 217 |
+ |
startProfile( pro1 ); |
| 218 |
+ |
#endif |
| 219 |
+ |
|
| 220 |
|
integrateStep(calcPot, calcStress); |
| 221 |
|
|
| 222 |
+ |
#ifdef PROFILE |
| 223 |
+ |
endProfile( pro1 ); |
| 224 |
+ |
|
| 225 |
+ |
startProfile( pro2 ); |
| 226 |
+ |
#endif // profile |
| 227 |
+ |
|
| 228 |
|
info->incrTime(dt); |
| 229 |
|
|
| 230 |
|
if (info->setTemp){ |
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
if (info->getTime() >= currStatus){ |
| 243 |
< |
statOut->writeStat(info->getTime()); |
| 244 |
< |
calcPot = 0; |
| 243 |
> |
statOut->writeStat(info->getTime()); |
| 244 |
> |
calcPot = 0; |
| 245 |
|
calcStress = 0; |
| 246 |
|
currStatus += statusTime; |
| 247 |
< |
} |
| 247 |
> |
} |
| 248 |
|
|
| 249 |
|
if (info->resetIntegrator){ |
| 250 |
|
if (info->getTime() >= currReset){ |
| 252 |
|
currReset += resetTime; |
| 253 |
|
} |
| 254 |
|
} |
| 255 |
+ |
|
| 256 |
+ |
#ifdef PROFILE |
| 257 |
+ |
endProfile( pro2 ); |
| 258 |
+ |
#endif //profile |
| 259 |
|
|
| 260 |
|
#ifdef IS_MPI |
| 261 |
|
strcpy(checkPointMsg, "successfully took a time step."); |
| 263 |
|
#endif // is_mpi |
| 264 |
|
} |
| 265 |
|
|
| 244 |
– |
dumpOut->writeFinal(info->getTime()); |
| 266 |
|
|
| 267 |
+ |
// write the last frame |
| 268 |
+ |
dumpOut->writeDump(info->getTime()); |
| 269 |
+ |
|
| 270 |
|
delete dumpOut; |
| 271 |
|
delete statOut; |
| 272 |
|
} |
| 274 |
|
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
| 275 |
|
int calcStress){ |
| 276 |
|
// Position full step, and velocity half step |
| 277 |
+ |
|
| 278 |
+ |
#ifdef PROFILE |
| 279 |
+ |
startProfile(pro3); |
| 280 |
+ |
#endif //profile |
| 281 |
+ |
|
| 282 |
|
preMove(); |
| 283 |
|
|
| 284 |
< |
moveA(); |
| 284 |
> |
#ifdef PROFILE |
| 285 |
> |
endProfile(pro3); |
| 286 |
|
|
| 287 |
+ |
startProfile(pro4); |
| 288 |
+ |
#endif // profile |
| 289 |
|
|
| 290 |
+ |
moveA(); |
| 291 |
|
|
| 292 |
+ |
#ifdef PROFILE |
| 293 |
+ |
endProfile(pro4); |
| 294 |
+ |
|
| 295 |
+ |
startProfile(pro5); |
| 296 |
+ |
#endif//profile |
| 297 |
|
|
| 298 |
+ |
|
| 299 |
|
#ifdef IS_MPI |
| 300 |
|
strcpy(checkPointMsg, "Succesful moveA\n"); |
| 301 |
|
MPIcheckPoint(); |
| 311 |
|
MPIcheckPoint(); |
| 312 |
|
#endif // is_mpi |
| 313 |
|
|
| 314 |
+ |
#ifdef PROFILE |
| 315 |
+ |
endProfile( pro5 ); |
| 316 |
|
|
| 317 |
+ |
startProfile( pro6 ); |
| 318 |
+ |
#endif //profile |
| 319 |
+ |
|
| 320 |
|
// finish the velocity half step |
| 321 |
|
|
| 322 |
|
moveB(); |
| 323 |
|
|
| 324 |
+ |
#ifdef PROFILE |
| 325 |
+ |
endProfile(pro6); |
| 326 |
+ |
#endif // profile |
| 327 |
|
|
| 281 |
– |
|
| 328 |
|
#ifdef IS_MPI |
| 329 |
|
strcpy(checkPointMsg, "Succesful moveB\n"); |
| 330 |
|
MPIcheckPoint(); |
| 405 |
|
if (atoms[i]->isDirectional()){ |
| 406 |
|
dAtom = (DirectionalAtom *) atoms[i]; |
| 407 |
|
|
| 408 |
< |
// get and convert the torque to body frame |
| 408 |
> |
// get and convert the torque to body frame |
| 409 |
|
|
| 410 |
|
dAtom->getTrq(Tb); |
| 411 |
|
dAtom->lab2Body(Tb); |
| 443 |
|
} |
| 444 |
|
|
| 445 |
|
template<typename T> void Integrator<T>::constrainA(){ |
| 446 |
< |
int i, j, k; |
| 446 |
> |
int i, j; |
| 447 |
|
int done; |
| 448 |
|
double posA[3], posB[3]; |
| 449 |
|
double velA[3], velB[3]; |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
template<typename T> void Integrator<T>::constrainB(void){ |
| 590 |
< |
int i, j, k; |
| 590 |
> |
int i, j; |
| 591 |
|
int done; |
| 592 |
|
double posA[3], posB[3]; |
| 593 |
|
double velA[3], velB[3]; |
| 596 |
|
int a, b, ax, ay, az, bx, by, bz; |
| 597 |
|
double rma, rmb; |
| 598 |
|
double dx, dy, dz; |
| 599 |
< |
double rabsq, pabsq, rvab; |
| 554 |
< |
double diffsq; |
| 599 |
> |
double rvab; |
| 600 |
|
double gab; |
| 601 |
|
int iteration; |
| 602 |
|
|
| 697 |
|
|
| 698 |
|
dAtom->getA(A); |
| 699 |
|
dAtom->getI(I); |
| 700 |
< |
|
| 701 |
< |
// rotate about the x-axis |
| 700 |
> |
|
| 701 |
> |
// rotate about the x-axis |
| 702 |
|
angle = dt2 * ji[0] / I[0][0]; |
| 703 |
< |
this->rotate( 1, 2, angle, ji, A ); |
| 704 |
< |
|
| 703 |
> |
this->rotate( 1, 2, angle, ji, A ); |
| 704 |
> |
|
| 705 |
|
// rotate about the y-axis |
| 706 |
|
angle = dt2 * ji[1] / I[1][1]; |
| 707 |
|
this->rotate( 2, 0, angle, ji, A ); |
| 708 |
< |
|
| 708 |
> |
|
| 709 |
|
// rotate about the z-axis |
| 710 |
|
angle = dt * ji[2] / I[2][2]; |
| 711 |
|
this->rotate( 0, 1, angle, ji, A); |
| 712 |
< |
|
| 712 |
> |
|
| 713 |
|
// rotate about the y-axis |
| 714 |
|
angle = dt2 * ji[1] / I[1][1]; |
| 715 |
|
this->rotate( 2, 0, angle, ji, A ); |
| 716 |
< |
|
| 716 |
> |
|
| 717 |
|
// rotate about the x-axis |
| 718 |
|
angle = dt2 * ji[0] / I[0][0]; |
| 719 |
|
this->rotate( 1, 2, angle, ji, A ); |
| 720 |
< |
|
| 721 |
< |
dAtom->setA( A ); |
| 720 |
> |
|
| 721 |
> |
dAtom->setA( A ); |
| 722 |
|
} |
| 723 |
|
|
| 724 |
|
template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
| 786 |
|
} |
| 787 |
|
} |
| 788 |
|
|
| 789 |
< |
// rotate the Rotation matrix acording to: |
| 789 |
> |
// rotate the Rotation matrix acording to: |
| 790 |
|
// A[][] = A[][] * transpose(rot[][]) |
| 791 |
|
|
| 792 |
|
|
| 815 |
|
template<typename T> double Integrator<T>::getConservedQuantity(void){ |
| 816 |
|
return tStats->getTotalE(); |
| 817 |
|
} |
| 818 |
+ |
template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
| 819 |
+ |
//By default, return a null string |
| 820 |
+ |
//The reason we use string instead of char* is that if we use char*, we will |
| 821 |
+ |
//return a pointer point to local variable which might cause problem |
| 822 |
+ |
return string(); |
| 823 |
+ |
} |