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 |
|
|
68 |
|
|
69 |
|
SRI** theArray; |
70 |
|
for (int i = 0; i < nMols; i++){ |
71 |
< |
theArray = (SRI * *) molecules[i].getMyBonds(); |
71 |
> |
|
72 |
> |
theArray = (SRI * *) molecules[i].getMyBonds(); |
73 |
|
for (int j = 0; j < molecules[i].getNBonds(); j++){ |
74 |
|
constrained = theArray[j]->is_constrained(); |
75 |
|
|
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
+ |
|
119 |
|
if (nConstrained > 0){ |
120 |
|
isConstrained = 1; |
121 |
|
|
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
< |
// save oldAtoms to check for lode balanceing later on. |
140 |
> |
// save oldAtoms to check for lode balancing later on. |
141 |
|
|
142 |
|
oldAtoms = nAtoms; |
143 |
|
|
152 |
|
|
153 |
|
|
154 |
|
template<typename T> void Integrator<T>::integrate(void){ |
150 |
– |
int i, j; // loop counters |
155 |
|
|
156 |
|
double runTime = info->run_time; |
157 |
|
double sampleTime = info->sampleTime; |
164 |
|
double currThermal; |
165 |
|
double currStatus; |
166 |
|
double currReset; |
167 |
< |
|
167 |
> |
|
168 |
|
int calcPot, calcStress; |
165 |
– |
int isError; |
169 |
|
|
170 |
|
tStats = new Thermo(info); |
171 |
|
statOut = new StatWriter(info); |
172 |
|
dumpOut = new DumpWriter(info); |
173 |
|
|
174 |
|
atoms = info->atoms; |
172 |
– |
DirectionalAtom* dAtom; |
175 |
|
|
176 |
|
dt = info->dt; |
177 |
|
dt2 = 0.5 * dt; |
178 |
|
|
179 |
+ |
readyCheck(); |
180 |
+ |
|
181 |
|
// initialize the forces before the first step |
182 |
|
|
183 |
|
calcForce(1, 1); |
184 |
+ |
|
185 |
+ |
//temp test |
186 |
+ |
tStats->getPotential(); |
187 |
|
|
188 |
+ |
if (nConstrained){ |
189 |
+ |
preMove(); |
190 |
+ |
constrainA(); |
191 |
+ |
calcForce(1, 1); |
192 |
+ |
constrainB(); |
193 |
+ |
} |
194 |
+ |
|
195 |
|
if (info->setTemp){ |
196 |
|
thermalize(); |
197 |
|
} |
206 |
|
dumpOut->writeDump(info->getTime()); |
207 |
|
statOut->writeStat(info->getTime()); |
208 |
|
|
195 |
– |
readyCheck(); |
209 |
|
|
210 |
|
#ifdef IS_MPI |
211 |
|
strcpy(checkPointMsg, "The integrator is ready to go."); |
218 |
|
calcStress = 1; |
219 |
|
} |
220 |
|
|
221 |
+ |
#ifdef PROFILE |
222 |
+ |
startProfile( pro1 ); |
223 |
+ |
#endif |
224 |
+ |
|
225 |
|
integrateStep(calcPot, calcStress); |
226 |
|
|
227 |
+ |
#ifdef PROFILE |
228 |
+ |
endProfile( pro1 ); |
229 |
+ |
|
230 |
+ |
startProfile( pro2 ); |
231 |
+ |
#endif // profile |
232 |
+ |
|
233 |
|
info->incrTime(dt); |
234 |
|
|
235 |
|
if (info->setTemp){ |
245 |
|
} |
246 |
|
|
247 |
|
if (info->getTime() >= currStatus){ |
248 |
< |
statOut->writeStat(info->getTime()); |
249 |
< |
calcPot = 0; |
248 |
> |
statOut->writeStat(info->getTime()); |
249 |
> |
calcPot = 0; |
250 |
|
calcStress = 0; |
251 |
|
currStatus += statusTime; |
252 |
< |
} |
252 |
> |
} |
253 |
|
|
254 |
|
if (info->resetIntegrator){ |
255 |
|
if (info->getTime() >= currReset){ |
257 |
|
currReset += resetTime; |
258 |
|
} |
259 |
|
} |
260 |
+ |
|
261 |
+ |
#ifdef PROFILE |
262 |
+ |
endProfile( pro2 ); |
263 |
+ |
#endif //profile |
264 |
|
|
265 |
|
#ifdef IS_MPI |
266 |
|
strcpy(checkPointMsg, "successfully took a time step."); |
268 |
|
#endif // is_mpi |
269 |
|
} |
270 |
|
|
244 |
– |
dumpOut->writeFinal(info->getTime()); |
245 |
– |
|
271 |
|
delete dumpOut; |
272 |
|
delete statOut; |
273 |
|
} |
275 |
|
template<typename T> void Integrator<T>::integrateStep(int calcPot, |
276 |
|
int calcStress){ |
277 |
|
// Position full step, and velocity half step |
278 |
+ |
|
279 |
+ |
#ifdef PROFILE |
280 |
+ |
startProfile(pro3); |
281 |
+ |
#endif //profile |
282 |
+ |
|
283 |
|
preMove(); |
284 |
|
|
285 |
< |
moveA(); |
285 |
> |
#ifdef PROFILE |
286 |
> |
endProfile(pro3); |
287 |
|
|
288 |
+ |
startProfile(pro4); |
289 |
+ |
#endif // profile |
290 |
|
|
291 |
+ |
moveA(); |
292 |
|
|
293 |
+ |
#ifdef PROFILE |
294 |
+ |
endProfile(pro4); |
295 |
+ |
|
296 |
+ |
startProfile(pro5); |
297 |
+ |
#endif//profile |
298 |
|
|
299 |
+ |
|
300 |
|
#ifdef IS_MPI |
301 |
|
strcpy(checkPointMsg, "Succesful moveA\n"); |
302 |
|
MPIcheckPoint(); |
312 |
|
MPIcheckPoint(); |
313 |
|
#endif // is_mpi |
314 |
|
|
315 |
+ |
#ifdef PROFILE |
316 |
+ |
endProfile( pro5 ); |
317 |
|
|
318 |
+ |
startProfile( pro6 ); |
319 |
+ |
#endif //profile |
320 |
+ |
|
321 |
|
// finish the velocity half step |
322 |
|
|
323 |
|
moveB(); |
324 |
|
|
325 |
< |
|
325 |
> |
#ifdef PROFILE |
326 |
> |
endProfile(pro6); |
327 |
> |
#endif // profile |
328 |
|
|
329 |
|
#ifdef IS_MPI |
330 |
|
strcpy(checkPointMsg, "Succesful moveB\n"); |
337 |
|
int i, j; |
338 |
|
DirectionalAtom* dAtom; |
339 |
|
double Tb[3], ji[3]; |
293 |
– |
double A[3][3], I[3][3]; |
294 |
– |
double angle; |
340 |
|
double vel[3], pos[3], frc[3]; |
341 |
|
double mass; |
342 |
|
|
371 |
|
|
372 |
|
for (j = 0; j < 3; j++) |
373 |
|
ji[j] += (dt2 * Tb[j]) * eConvert; |
329 |
– |
|
330 |
– |
// use the angular velocities to propagate the rotation matrix a |
331 |
– |
// full time step |
332 |
– |
|
333 |
– |
dAtom->getA(A); |
334 |
– |
dAtom->getI(I); |
335 |
– |
|
336 |
– |
// rotate about the x-axis |
337 |
– |
angle = dt2 * ji[0] / I[0][0]; |
338 |
– |
this->rotate(1, 2, angle, ji, A); |
339 |
– |
|
340 |
– |
// rotate about the y-axis |
341 |
– |
angle = dt2 * ji[1] / I[1][1]; |
342 |
– |
this->rotate(2, 0, angle, ji, A); |
343 |
– |
|
344 |
– |
// rotate about the z-axis |
345 |
– |
angle = dt * ji[2] / I[2][2]; |
346 |
– |
this->rotate(0, 1, angle, ji, A); |
374 |
|
|
375 |
< |
// rotate about the y-axis |
349 |
< |
angle = dt2 * ji[1] / I[1][1]; |
350 |
< |
this->rotate(2, 0, angle, ji, A); |
375 |
> |
this->rotationPropagation( dAtom, ji ); |
376 |
|
|
352 |
– |
// rotate about the x-axis |
353 |
– |
angle = dt2 * ji[0] / I[0][0]; |
354 |
– |
this->rotate(1, 2, angle, ji, A); |
355 |
– |
|
377 |
|
dAtom->setJ(ji); |
357 |
– |
dAtom->setA(A); |
378 |
|
} |
379 |
|
} |
380 |
|
|
406 |
|
if (atoms[i]->isDirectional()){ |
407 |
|
dAtom = (DirectionalAtom *) atoms[i]; |
408 |
|
|
409 |
< |
// get and convert the torque to body frame |
409 |
> |
// get and convert the torque to body frame |
410 |
|
|
411 |
|
dAtom->getTrq(Tb); |
412 |
|
dAtom->lab2Body(Tb); |
444 |
|
} |
445 |
|
|
446 |
|
template<typename T> void Integrator<T>::constrainA(){ |
447 |
< |
int i, j, k; |
447 |
> |
int i, j; |
448 |
|
int done; |
449 |
|
double posA[3], posB[3]; |
450 |
|
double velA[3], velB[3]; |
588 |
|
} |
589 |
|
|
590 |
|
template<typename T> void Integrator<T>::constrainB(void){ |
591 |
< |
int i, j, k; |
591 |
> |
int i, j; |
592 |
|
int done; |
593 |
|
double posA[3], posB[3]; |
594 |
|
double velA[3], velB[3]; |
597 |
|
int a, b, ax, ay, az, bx, by, bz; |
598 |
|
double rma, rmb; |
599 |
|
double dx, dy, dz; |
600 |
< |
double rabsq, pabsq, rvab; |
581 |
< |
double diffsq; |
600 |
> |
double rvab; |
601 |
|
double gab; |
602 |
|
int iteration; |
603 |
|
|
687 |
|
} |
688 |
|
} |
689 |
|
|
690 |
+ |
template<typename T> void Integrator<T>::rotationPropagation |
691 |
+ |
( DirectionalAtom* dAtom, double ji[3] ){ |
692 |
+ |
|
693 |
+ |
double angle; |
694 |
+ |
double A[3][3], I[3][3]; |
695 |
+ |
|
696 |
+ |
// use the angular velocities to propagate the rotation matrix a |
697 |
+ |
// full time step |
698 |
+ |
|
699 |
+ |
dAtom->getA(A); |
700 |
+ |
dAtom->getI(I); |
701 |
+ |
|
702 |
+ |
// rotate about the x-axis |
703 |
+ |
angle = dt2 * ji[0] / I[0][0]; |
704 |
+ |
this->rotate( 1, 2, angle, ji, A ); |
705 |
+ |
|
706 |
+ |
// rotate about the y-axis |
707 |
+ |
angle = dt2 * ji[1] / I[1][1]; |
708 |
+ |
this->rotate( 2, 0, angle, ji, A ); |
709 |
+ |
|
710 |
+ |
// rotate about the z-axis |
711 |
+ |
angle = dt * ji[2] / I[2][2]; |
712 |
+ |
this->rotate( 0, 1, angle, ji, A); |
713 |
+ |
|
714 |
+ |
// rotate about the y-axis |
715 |
+ |
angle = dt2 * ji[1] / I[1][1]; |
716 |
+ |
this->rotate( 2, 0, angle, ji, A ); |
717 |
+ |
|
718 |
+ |
// rotate about the x-axis |
719 |
+ |
angle = dt2 * ji[0] / I[0][0]; |
720 |
+ |
this->rotate( 1, 2, angle, ji, A ); |
721 |
+ |
|
722 |
+ |
dAtom->setA( A ); |
723 |
+ |
} |
724 |
+ |
|
725 |
|
template<typename T> void Integrator<T>::rotate(int axes1, int axes2, |
726 |
|
double angle, double ji[3], |
727 |
|
double A[3][3]){ |
787 |
|
} |
788 |
|
} |
789 |
|
|
790 |
< |
// rotate the Rotation matrix acording to: |
790 |
> |
// rotate the Rotation matrix acording to: |
791 |
|
// A[][] = A[][] * transpose(rot[][]) |
792 |
|
|
793 |
|
|
816 |
|
template<typename T> double Integrator<T>::getConservedQuantity(void){ |
817 |
|
return tStats->getTotalE(); |
818 |
|
} |
819 |
+ |
template<typename T> string Integrator<T>::getAdditionalParameters(void){ |
820 |
+ |
//By default, return a null string |
821 |
+ |
//The reason we use string instead of char* is that if we use char*, we will |
822 |
+ |
//return a pointer point to local variable which might cause problem |
823 |
+ |
return string(); |
824 |
+ |
} |