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 841 by mmeineke, Wed Oct 29 17:55:28 2003 UTC vs.
Revision 1221 by chrisfen, Wed Jun 2 14:56:18 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 <
34 >  integrableObjects = info->integrableObjects;
35 >
36    // check for constraints
37  
38    constrainedA = NULL;
# Line 40 | Line 45 | template<typename T> Integrator<T>::Integrator(SimInfo
45    nConstrained = 0;
46  
47    checkConstraints();
48 +
49   }
50  
51   template<typename T> Integrator<T>::~Integrator(){
# Line 64 | Line 70 | template<typename T> void Integrator<T>::checkConstrai
70  
71    SRI** theArray;
72    for (int i = 0; i < nMols; i++){
73 <    theArray = (SRI * *) molecules[i].getMyBonds();
73 >
74 >          theArray = (SRI * *) molecules[i].getMyBonds();
75      for (int j = 0; j < molecules[i].getNBonds(); j++){
76        constrained = theArray[j]->is_constrained();
77  
# Line 110 | Line 117 | template<typename T> void Integrator<T>::checkConstrai
117      }
118    }
119  
120 +
121    if (nConstrained > 0){
122      isConstrained = 1;
123  
# Line 131 | Line 139 | template<typename T> void Integrator<T>::checkConstrai
139      }
140  
141  
142 <    // save oldAtoms to check for lode balanceing later on.
142 >    // save oldAtoms to check for lode balancing later on.
143  
144      oldAtoms = nAtoms;
145  
# Line 153 | Line 161 | template<typename T> void Integrator<T>::integrate(voi
161    double thermalTime = info->thermalTime;
162    double resetTime = info->resetTime;
163  
164 <
164 >  double difference;
165    double currSample;
166    double currThermal;
167    double currStatus;
# Line 172 | Line 180 | template<typename T> void Integrator<T>::integrate(voi
180  
181    readyCheck();
182  
183 <  // initialize the forces before the first step
183 >  // remove center of mass drift velocity (in case we passed in a configuration
184 >  // that was drifting
185 >  tStats->removeCOMdrift();
186  
187 <  std::cerr << "Before initial Force calc\n";
187 >  // initialize the retraints if necessary
188 >  if (info->useSolidThermInt && !info->useLiquidThermInt) {
189 >    myFF->initRestraints();
190 >  }
191  
192 <  calcForce(1, 1);
192 >  // initialize the forces before the first step
193  
194 +  calcForce(1, 1);
195 +  
196    if (nConstrained){
197      preMove();
198      constrainA();
199      calcForce(1, 1);
200      constrainB();
186    std::cerr << "premove done\n";
201    }
202 <
189 <
190 <
202 >  
203    if (info->setTemp){
204      thermalize();
205    }
# Line 203 | Line 215 | template<typename T> void Integrator<T>::integrate(voi
215    statOut->writeStat(info->getTime());
216  
217  
206
218   #ifdef IS_MPI
219    strcpy(checkPointMsg, "The integrator is ready to go.");
220    MPIcheckPoint();
221   #endif // is_mpi
222  
223 <  while (info->getTime() < runTime){
224 <    if ((info->getTime() + dt) >= currStatus){
223 >  while (info->getTime() < runTime && !stopIntegrator()){
224 >    difference = info->getTime() + dt - currStatus;
225 >    if (difference > 0 || fabs(difference) < 1e-4 ){
226        calcPot = 1;
227        calcStress = 1;
228      }
229  
230 + #ifdef PROFILE
231 +    startProfile( pro1 );
232 + #endif
233 +    
234      integrateStep(calcPot, calcStress);
235  
236 + #ifdef PROFILE
237 +    endProfile( pro1 );
238 +
239 +    startProfile( pro2 );
240 + #endif // profile
241 +
242      info->incrTime(dt);
243  
244      if (info->setTemp){
# Line 244 | Line 266 | template<typename T> void Integrator<T>::integrate(voi
266          currReset += resetTime;
267        }
268      }
269 <
270 <    std::cerr << "done with time = " << info->getTime() << "\n";
269 >    
270 > #ifdef PROFILE
271 >    endProfile( pro2 );
272 > #endif //profile
273  
274   #ifdef IS_MPI
275      strcpy(checkPointMsg, "successfully took a time step.");
# Line 253 | Line 277 | template<typename T> void Integrator<T>::integrate(voi
277   #endif // is_mpi
278    }
279  
280 +  // dump out a file containing the omega values for the final configuration
281 +  if (info->useSolidThermInt && !info->useLiquidThermInt)
282 +    myFF->dumpzAngle();
283 +  
284  
257  // write the last frame
258  dumpOut->writeDump(info->getTime());
259
285    delete dumpOut;
286    delete statOut;
287   }
# Line 264 | Line 289 | template<typename T> void Integrator<T>::integrateStep
289   template<typename T> void Integrator<T>::integrateStep(int calcPot,
290                                                         int calcStress){
291    // Position full step, and velocity half step
292 +
293 + #ifdef PROFILE
294 +  startProfile(pro3);
295 + #endif //profile
296 +
297    preMove();
298  
299 <  moveA();
299 > #ifdef PROFILE
300 >  endProfile(pro3);
301  
302 +  startProfile(pro4);
303 + #endif // profile
304  
305 +  moveA();
306  
307 + #ifdef PROFILE
308 +  endProfile(pro4);
309 +  
310 +  startProfile(pro5);
311 + #endif//profile
312  
313 +
314   #ifdef IS_MPI
315    strcpy(checkPointMsg, "Succesful moveA\n");
316    MPIcheckPoint();
317   #endif // is_mpi
318  
279
319    // calc forces
281
320    calcForce(calcPot, calcStress);
321  
322   #ifdef IS_MPI
# Line 286 | Line 324 | template<typename T> void Integrator<T>::integrateStep
324    MPIcheckPoint();
325   #endif // is_mpi
326  
327 + #ifdef PROFILE
328 +  endProfile( pro5 );
329  
330 +  startProfile( pro6 );
331 + #endif //profile
332 +
333    // finish the velocity  half step
334  
335    moveB();
336  
337 + #ifdef PROFILE
338 +  endProfile(pro6);
339 + #endif // profile
340  
295
341   #ifdef IS_MPI
342    strcpy(checkPointMsg, "Succesful moveB\n");
343    MPIcheckPoint();
# Line 301 | Line 346 | template<typename T> void Integrator<T>::moveA(void){
346  
347  
348   template<typename T> void Integrator<T>::moveA(void){
349 <  int i, j;
349 >  size_t i, j;
350    DirectionalAtom* dAtom;
351    double Tb[3], ji[3];
352    double vel[3], pos[3], frc[3];
353    double mass;
354 +  double omega;
355 +
356 +  for (i = 0; i < integrableObjects.size() ; i++){
357 +    integrableObjects[i]->getVel(vel);
358 +    integrableObjects[i]->getPos(pos);
359 +    integrableObjects[i]->getFrc(frc);
360 +    
361 +    mass = integrableObjects[i]->getMass();
362  
310  for (i = 0; i < nAtoms; i++){
311    atoms[i]->getVel(vel);
312    atoms[i]->getPos(pos);
313    atoms[i]->getFrc(frc);
314
315    mass = atoms[i]->getMass();
316
363      for (j = 0; j < 3; j++){
364        // velocity half step
365        vel[j] += (dt2 * frc[j] / mass) * eConvert;
# Line 321 | Line 367 | template<typename T> void Integrator<T>::moveA(void){
367        pos[j] += dt * vel[j];
368      }
369  
370 <    atoms[i]->setVel(vel);
371 <    atoms[i]->setPos(pos);
370 >    integrableObjects[i]->setVel(vel);
371 >    integrableObjects[i]->setPos(pos);
372  
373 <    if (atoms[i]->isDirectional()){
328 <      dAtom = (DirectionalAtom *) atoms[i];
373 >    if (integrableObjects[i]->isDirectional()){
374  
375        // get and convert the torque to body frame
376  
377 <      dAtom->getTrq(Tb);
378 <      dAtom->lab2Body(Tb);
377 >      integrableObjects[i]->getTrq(Tb);
378 >      integrableObjects[i]->lab2Body(Tb);
379  
380        // get the angular momentum, and propagate a half step
381  
382 <      dAtom->getJ(ji);
382 >      integrableObjects[i]->getJ(ji);
383  
384        for (j = 0; j < 3; j++)
385          ji[j] += (dt2 * Tb[j]) * eConvert;
386  
387 <      this->rotationPropagation( dAtom, ji );
387 >      this->rotationPropagation( integrableObjects[i], ji );
388  
389 <      dAtom->setJ(ji);
389 >      integrableObjects[i]->setJ(ji);
390      }
391    }
392  
# Line 353 | Line 398 | template<typename T> void Integrator<T>::moveB(void){
398  
399   template<typename T> void Integrator<T>::moveB(void){
400    int i, j;
356  DirectionalAtom* dAtom;
401    double Tb[3], ji[3];
402    double vel[3], frc[3];
403    double mass;
404  
405 <  for (i = 0; i < nAtoms; i++){
406 <    atoms[i]->getVel(vel);
407 <    atoms[i]->getFrc(frc);
405 >  for (i = 0; i < integrableObjects.size(); i++){
406 >    integrableObjects[i]->getVel(vel);
407 >    integrableObjects[i]->getFrc(frc);
408  
409 <    mass = atoms[i]->getMass();
409 >    mass = integrableObjects[i]->getMass();
410  
411      // velocity half step
412      for (j = 0; j < 3; j++)
413        vel[j] += (dt2 * frc[j] / mass) * eConvert;
414  
415 <    atoms[i]->setVel(vel);
415 >    integrableObjects[i]->setVel(vel);
416  
417 <    if (atoms[i]->isDirectional()){
374 <      dAtom = (DirectionalAtom *) atoms[i];
417 >    if (integrableObjects[i]->isDirectional()){
418  
419        // get and convert the torque to body frame
420  
421 <      dAtom->getTrq(Tb);
422 <      dAtom->lab2Body(Tb);
421 >      integrableObjects[i]->getTrq(Tb);
422 >      integrableObjects[i]->lab2Body(Tb);
423  
424        // get the angular momentum, and propagate a half step
425  
426 <      dAtom->getJ(ji);
426 >      integrableObjects[i]->getJ(ji);
427  
428        for (j = 0; j < 3; j++)
429          ji[j] += (dt2 * Tb[j]) * eConvert;
430  
431  
432 <      dAtom->setJ(ji);
432 >      integrableObjects[i]->setJ(ji);
433      }
434    }
435  
# Line 655 | Line 698 | template<typename T> void Integrator<T>::rotationPropa
698   }
699  
700   template<typename T> void Integrator<T>::rotationPropagation
701 < ( DirectionalAtom* dAtom, double ji[3] ){
701 > ( StuntDouble* sd, double ji[3] ){
702  
703    double angle;
704    double A[3][3], I[3][3];
705 +  int i, j, k;
706  
707    // use the angular velocities to propagate the rotation matrix a
708    // full time step
709  
710 <  dAtom->getA(A);
711 <  dAtom->getI(I);
710 >  sd->getA(A);
711 >  sd->getI(I);
712  
713 <  // rotate about the x-axis
714 <  angle = dt2 * ji[0] / I[0][0];
715 <  this->rotate( 1, 2, angle, ji, A );
716 <
717 <  // rotate about the y-axis
718 <  angle = dt2 * ji[1] / I[1][1];
719 <  this->rotate( 2, 0, angle, ji, A );
713 >  if (sd->isLinear()) {
714 >    i = sd->linearAxis();
715 >    j = (i+1)%3;
716 >    k = (i+2)%3;
717 >    
718 >    angle = dt2 * ji[j] / I[j][j];
719 >    this->rotate( k, i, angle, ji, A );
720  
721 <  // rotate about the z-axis
722 <  angle = dt * ji[2] / I[2][2];
679 <  this->rotate( 0, 1, angle, ji, A);
721 >    angle = dt * ji[k] / I[k][k];
722 >    this->rotate( i, j, angle, ji, A);
723  
724 <  // rotate about the y-axis
725 <  angle = dt2 * ji[1] / I[1][1];
683 <  this->rotate( 2, 0, angle, ji, A );
724 >    angle = dt2 * ji[j] / I[j][j];
725 >    this->rotate( k, i, angle, ji, A );
726  
727 <  // rotate about the x-axis
728 <  angle = dt2 * ji[0] / I[0][0];
729 <  this->rotate( 1, 2, angle, ji, A );
730 <
731 <  dAtom->setA( A  );
727 >  } else {
728 >    // rotate about the x-axis
729 >    angle = dt2 * ji[0] / I[0][0];
730 >    this->rotate( 1, 2, angle, ji, A );
731 >    
732 >    // rotate about the y-axis
733 >    angle = dt2 * ji[1] / I[1][1];
734 >    this->rotate( 2, 0, angle, ji, A );
735 >    
736 >    // rotate about the z-axis
737 >    angle = dt * ji[2] / I[2][2];
738 >    sd->addZangle(angle);
739 >    this->rotate( 0, 1, angle, ji, A);
740 >    
741 >    // rotate about the y-axis
742 >    angle = dt2 * ji[1] / I[1][1];
743 >    this->rotate( 2, 0, angle, ji, A );
744 >    
745 >    // rotate about the x-axis
746 >    angle = dt2 * ji[0] / I[0][0];
747 >    this->rotate( 1, 2, angle, ji, A );
748 >    
749 >  }
750 >  sd->setA( A  );
751   }
752  
753   template<typename T> void Integrator<T>::rotate(int axes1, int axes2,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines