ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Integrator.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Integrator.cpp (file contents):
Revision 843 by mmeineke, Wed Oct 29 20:41:39 2003 UTC vs.
Revision 1178 by gezelter, Thu May 13 21:08:05 2004 UTC

# Line 7 | Line 7
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  
# Line 27 | Line 31 | template<typename T> Integrator<T>::Integrator(SimInfo
31    }
32  
33    nAtoms = info->n_atoms;
34 +  integrableObjects = info->integrableObjects;
35  
36    // check for constraints
37  
# Line 64 | Line 69 | template<typename T> void Integrator<T>::checkConstrai
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  
# Line 110 | Line 116 | template<typename T> void Integrator<T>::checkConstrai
116      }
117    }
118  
119 +
120    if (nConstrained > 0){
121      isConstrained = 1;
122  
# Line 131 | Line 138 | template<typename T> void Integrator<T>::checkConstrai
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  
# Line 153 | Line 160 | template<typename T> void Integrator<T>::integrate(voi
160    double thermalTime = info->thermalTime;
161    double resetTime = info->resetTime;
162  
163 <
163 >  double difference;
164    double currSample;
165    double currThermal;
166    double currStatus;
# Line 172 | Line 179 | template<typename T> void Integrator<T>::integrate(voi
179  
180    readyCheck();
181  
182 +  // remove center of mass drift velocity (in case we passed in a configuration
183 +  // that was drifting
184 +  tStats->removeCOMdrift();
185 +
186    // initialize the forces before the first step
187  
188    calcForce(1, 1);
189 <
189 >  
190    if (nConstrained){
191      preMove();
192      constrainA();
# Line 203 | Line 214 | template<typename T> void Integrator<T>::integrate(voi
214    MPIcheckPoint();
215   #endif // is_mpi
216  
217 <  while (info->getTime() < runTime){
218 <    if ((info->getTime() + dt) >= currStatus){
217 >  while (info->getTime() < runTime && !stopIntegrator()){
218 >    difference = info->getTime() + dt - currStatus;
219 >    if (difference > 0 || fabs(difference) < 1e-4 ){
220        calcPot = 1;
221        calcStress = 1;
222      }
223  
224 + #ifdef PROFILE
225 +    startProfile( pro1 );
226 + #endif
227 +    
228      integrateStep(calcPot, calcStress);
229  
230 + #ifdef PROFILE
231 +    endProfile( pro1 );
232 +
233 +    startProfile( pro2 );
234 + #endif // profile
235 +
236      info->incrTime(dt);
237  
238      if (info->setTemp){
# Line 238 | Line 260 | template<typename T> void Integrator<T>::integrate(voi
260          currReset += resetTime;
261        }
262      }
263 +    
264 + #ifdef PROFILE
265 +    endProfile( pro2 );
266 + #endif //profile
267  
268   #ifdef IS_MPI
269      strcpy(checkPointMsg, "successfully took a time step.");
# Line 245 | Line 271 | template<typename T> void Integrator<T>::integrate(voi
271   #endif // is_mpi
272    }
273  
248
249  // write the last frame
250  dumpOut->writeDump(info->getTime());
251
274    delete dumpOut;
275    delete statOut;
276   }
# Line 256 | Line 278 | template<typename T> void Integrator<T>::integrateStep
278   template<typename T> void Integrator<T>::integrateStep(int calcPot,
279                                                         int calcStress){
280    // Position full step, and velocity half step
281 +
282 + #ifdef PROFILE
283 +  startProfile(pro3);
284 + #endif //profile
285 +
286    preMove();
287  
288 <  moveA();
288 > #ifdef PROFILE
289 >  endProfile(pro3);
290 >
291 >  startProfile(pro4);
292 > #endif // profile
293  
294 +  moveA();
295  
296 + #ifdef PROFILE
297 +  endProfile(pro4);
298 +  
299 +  startProfile(pro5);
300 + #endif//profile
301  
302  
303   #ifdef IS_MPI
# Line 278 | Line 315 | template<typename T> void Integrator<T>::integrateStep
315    MPIcheckPoint();
316   #endif // is_mpi
317  
318 + #ifdef PROFILE
319 +  endProfile( pro5 );
320  
321 +  startProfile( pro6 );
322 + #endif //profile
323 +
324    // finish the velocity  half step
325  
326    moveB();
327  
328 + #ifdef PROFILE
329 +  endProfile(pro6);
330 + #endif // profile
331  
287
332   #ifdef IS_MPI
333    strcpy(checkPointMsg, "Succesful moveB\n");
334    MPIcheckPoint();
# Line 293 | Line 337 | template<typename T> void Integrator<T>::moveA(void){
337  
338  
339   template<typename T> void Integrator<T>::moveA(void){
340 <  int i, j;
340 >  size_t i, j;
341    DirectionalAtom* dAtom;
342    double Tb[3], ji[3];
343    double vel[3], pos[3], frc[3];
344    double mass;
345 +
346 +  for (i = 0; i < integrableObjects.size() ; i++){
347 +    integrableObjects[i]->getVel(vel);
348 +    integrableObjects[i]->getPos(pos);
349 +    integrableObjects[i]->getFrc(frc);
350 +    
351 +    mass = integrableObjects[i]->getMass();
352  
302  for (i = 0; i < nAtoms; i++){
303    atoms[i]->getVel(vel);
304    atoms[i]->getPos(pos);
305    atoms[i]->getFrc(frc);
306
307    mass = atoms[i]->getMass();
308
353      for (j = 0; j < 3; j++){
354        // velocity half step
355        vel[j] += (dt2 * frc[j] / mass) * eConvert;
# Line 313 | Line 357 | template<typename T> void Integrator<T>::moveA(void){
357        pos[j] += dt * vel[j];
358      }
359  
360 <    atoms[i]->setVel(vel);
361 <    atoms[i]->setPos(pos);
360 >    integrableObjects[i]->setVel(vel);
361 >    integrableObjects[i]->setPos(pos);
362  
363 <    if (atoms[i]->isDirectional()){
320 <      dAtom = (DirectionalAtom *) atoms[i];
363 >    if (integrableObjects[i]->isDirectional()){
364  
365        // get and convert the torque to body frame
366  
367 <      dAtom->getTrq(Tb);
368 <      dAtom->lab2Body(Tb);
367 >      integrableObjects[i]->getTrq(Tb);
368 >      integrableObjects[i]->lab2Body(Tb);
369  
370        // get the angular momentum, and propagate a half step
371  
372 <      dAtom->getJ(ji);
372 >      integrableObjects[i]->getJ(ji);
373  
374        for (j = 0; j < 3; j++)
375          ji[j] += (dt2 * Tb[j]) * eConvert;
376  
377 <      this->rotationPropagation( dAtom, ji );
377 >      this->rotationPropagation( integrableObjects[i], ji );
378  
379 <      dAtom->setJ(ji);
379 >      integrableObjects[i]->setJ(ji);
380      }
381    }
382  
# Line 345 | Line 388 | template<typename T> void Integrator<T>::moveB(void){
388  
389   template<typename T> void Integrator<T>::moveB(void){
390    int i, j;
348  DirectionalAtom* dAtom;
391    double Tb[3], ji[3];
392    double vel[3], frc[3];
393    double mass;
394  
395 <  for (i = 0; i < nAtoms; i++){
396 <    atoms[i]->getVel(vel);
397 <    atoms[i]->getFrc(frc);
395 >  for (i = 0; i < integrableObjects.size(); i++){
396 >    integrableObjects[i]->getVel(vel);
397 >    integrableObjects[i]->getFrc(frc);
398  
399 <    mass = atoms[i]->getMass();
399 >    mass = integrableObjects[i]->getMass();
400  
401      // velocity half step
402      for (j = 0; j < 3; j++)
403        vel[j] += (dt2 * frc[j] / mass) * eConvert;
404  
405 <    atoms[i]->setVel(vel);
405 >    integrableObjects[i]->setVel(vel);
406  
407 <    if (atoms[i]->isDirectional()){
366 <      dAtom = (DirectionalAtom *) atoms[i];
407 >    if (integrableObjects[i]->isDirectional()){
408  
409        // get and convert the torque to body frame
410  
411 <      dAtom->getTrq(Tb);
412 <      dAtom->lab2Body(Tb);
411 >      integrableObjects[i]->getTrq(Tb);
412 >      integrableObjects[i]->lab2Body(Tb);
413  
414        // get the angular momentum, and propagate a half step
415  
416 <      dAtom->getJ(ji);
416 >      integrableObjects[i]->getJ(ji);
417  
418        for (j = 0; j < 3; j++)
419          ji[j] += (dt2 * Tb[j]) * eConvert;
420  
421  
422 <      dAtom->setJ(ji);
422 >      integrableObjects[i]->setJ(ji);
423      }
424    }
425  
# Line 647 | Line 688 | template<typename T> void Integrator<T>::rotationPropa
688   }
689  
690   template<typename T> void Integrator<T>::rotationPropagation
691 < ( DirectionalAtom* dAtom, double ji[3] ){
691 > ( StuntDouble* sd, double ji[3] ){
692  
693    double angle;
694    double A[3][3], I[3][3];
695 +  int i, j, k;
696  
697    // use the angular velocities to propagate the rotation matrix a
698    // full time step
657
658  dAtom->getA(A);
659  dAtom->getI(I);
699  
700 <  // rotate about the x-axis
701 <  angle = dt2 * ji[0] / I[0][0];
663 <  this->rotate( 1, 2, angle, ji, A );
700 >  sd->getA(A);
701 >  sd->getI(I);
702  
703 <  // rotate about the y-axis
704 <  angle = dt2 * ji[1] / I[1][1];
705 <  this->rotate( 2, 0, angle, ji, A );
706 <
707 <  // rotate about the z-axis
708 <  angle = dt * ji[2] / I[2][2];
709 <  this->rotate( 0, 1, angle, ji, A);
703 >  if (sd->isLinear()) {
704 >    i = sd->linearAxis();
705 >    j = (i+1)%3;
706 >    k = (i+2)%3;
707 >    
708 >    angle = dt2 * ji[j] / I[j][j];
709 >    this->rotate( k, i, angle, ji, A );
710  
711 <  // rotate about the y-axis
712 <  angle = dt2 * ji[1] / I[1][1];
675 <  this->rotate( 2, 0, angle, ji, A );
711 >    angle = dt * ji[k] / I[k][k];
712 >    this->rotate( i, j, angle, ji, A);
713  
714 <  // rotate about the x-axis
715 <  angle = dt2 * ji[0] / I[0][0];
679 <  this->rotate( 1, 2, angle, ji, A );
714 >    angle = dt2 * ji[j] / I[j][j];
715 >    this->rotate( k, i, angle, ji, A );
716  
717 <  dAtom->setA( A  );
717 >  } else {
718 >    // rotate about the x-axis
719 >    angle = dt2 * ji[0] / I[0][0];
720 >    this->rotate( 1, 2, angle, ji, A );
721 >    
722 >    // rotate about the y-axis
723 >    angle = dt2 * ji[1] / I[1][1];
724 >    this->rotate( 2, 0, angle, ji, A );
725 >    
726 >    // rotate about the z-axis
727 >    angle = dt * ji[2] / I[2][2];
728 >    this->rotate( 0, 1, 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 );
733 >    
734 >    // rotate about the x-axis
735 >    angle = dt2 * ji[0] / I[0][0];
736 >    this->rotate( 1, 2, angle, ji, A );
737 >    
738 >  }
739 >  sd->setA( A  );
740   }
741  
742   template<typename T> void Integrator<T>::rotate(int axes1, int axes2,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines