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 784 by mmeineke, Wed Sep 24 19:34:39 2003 UTC vs.
Revision 1234 by tim, Fri Jun 4 03:15:31 2004 UTC

# Line 1 | Line 1
1   #include <iostream>
2 < #include <cstdlib>
3 < #include <cmath>
4 <
2 > #include <stdlib.h>
3 > #include <math.h>
4 > #include "Rattle.hpp"
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  
# Line 25 | Line 29 | template<typename T> Integrator<T>::Integrator(SimInfo
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 +  rattle = new RattleFramework(info);
37 +
38 +  if(rattle == NULL){
39 +    sprintf(painCave.errMsg,
40 +      "Integrator::Intergrator() Error: Memory allocation error for RattleFramework" );
41 +    painCave.isFatal = 1;
42 +    simError();
43 +  }
44 +  
45 + /*
46    // check for constraints
47  
48    constrainedA = NULL;
# Line 40 | Line 55 | template<typename T> Integrator<T>::Integrator(SimInfo
55    nConstrained = 0;
56  
57    checkConstraints();
58 + */
59   }
60  
61   template<typename T> Integrator<T>::~Integrator(){
62 +  if (rattle != NULL)
63 +    delete rattle;
64 + /*
65    if (nConstrained){
66      delete[] constrainedA;
67      delete[] constrainedB;
# Line 51 | Line 70 | template<typename T> Integrator<T>::~Integrator(){
70      delete[] moved;
71      delete[] oldPos;
72    }
73 + */
74   }
75  
76 + /*
77   template<typename T> void Integrator<T>::checkConstraints(void){
78    isConstrained = 0;
79  
# Line 64 | Line 85 | template<typename T> void Integrator<T>::checkConstrai
85  
86    SRI** theArray;
87    for (int i = 0; i < nMols; i++){
88 <    theArray = (SRI * *) molecules[i].getMyBonds();
88 >
89 >          theArray = (SRI * *) molecules[i].getMyBonds();
90      for (int j = 0; j < molecules[i].getNBonds(); j++){
91        constrained = theArray[j]->is_constrained();
92  
# Line 110 | Line 132 | template<typename T> void Integrator<T>::checkConstrai
132      }
133    }
134  
135 +
136    if (nConstrained > 0){
137      isConstrained = 1;
138  
# Line 131 | Line 154 | template<typename T> void Integrator<T>::checkConstrai
154      }
155  
156  
157 <    // save oldAtoms to check for lode balanceing later on.
157 >    // save oldAtoms to check for lode balancing later on.
158  
159      oldAtoms = nAtoms;
160  
# Line 143 | Line 166 | template<typename T> void Integrator<T>::checkConstrai
166  
167    delete[] temp_con;
168   }
169 + */
170  
147
171   template<typename T> void Integrator<T>::integrate(void){
149  int i, j;                         // loop counters
172  
173    double runTime = info->run_time;
174    double sampleTime = info->sampleTime;
# Line 154 | Line 176 | template<typename T> void Integrator<T>::integrate(voi
176    double thermalTime = info->thermalTime;
177    double resetTime = info->resetTime;
178  
179 <
179 >  double difference;
180    double currSample;
181    double currThermal;
182    double currStatus;
183    double currReset;
184 <  
184 >
185    int calcPot, calcStress;
164  int isError;
186  
187    tStats = new Thermo(info);
188    statOut = new StatWriter(info);
189    dumpOut = new DumpWriter(info);
190  
191    atoms = info->atoms;
171  DirectionalAtom* dAtom;
192  
193    dt = info->dt;
194    dt2 = 0.5 * dt;
195  
196    readyCheck();
197  
198 +  // remove center of mass drift velocity (in case we passed in a configuration
199 +  // that was drifting
200 +  tStats->removeCOMdrift();
201 +
202 +  // initialize the retraints if necessary
203 +  if (info->useSolidThermInt && !info->useLiquidThermInt) {
204 +    myFF->initRestraints();
205 +  }
206 +
207    // initialize the forces before the first step
208  
209    calcForce(1, 1);
210  
211 <  if (nConstrained){
212 <    preMove();
213 <    constrainA();
214 <    calcForce(1, 1);    
215 <    constrainB();
187 <  }
211 >  //execute constraint algorithm to make sure at the very beginning the system is constrained  
212 >  rattle->doPreConstraint();
213 >  rattle->doRattleA();
214 >  calcForce(1, 1);
215 >  rattle->doRattleB();
216    
217    if (info->setTemp){
218      thermalize();
# Line 201 | Line 229 | template<typename T> void Integrator<T>::integrate(voi
229    statOut->writeStat(info->getTime());
230  
231  
204
232   #ifdef IS_MPI
233    strcpy(checkPointMsg, "The integrator is ready to go.");
234    MPIcheckPoint();
235   #endif // is_mpi
236  
237 <  while (info->getTime() < runTime){
238 <    if ((info->getTime() + dt) >= currStatus){
237 >  while (info->getTime() < runTime && !stopIntegrator()){
238 >    difference = info->getTime() + dt - currStatus;
239 >    if (difference > 0 || fabs(difference) < 1e-4 ){
240        calcPot = 1;
241        calcStress = 1;
242      }
243  
244 + #ifdef PROFILE
245 +    startProfile( pro1 );
246 + #endif
247 +    
248      integrateStep(calcPot, calcStress);
249  
250 + #ifdef PROFILE
251 +    endProfile( pro1 );
252 +
253 +    startProfile( pro2 );
254 + #endif // profile
255 +
256      info->incrTime(dt);
257  
258      if (info->setTemp){
# Line 230 | Line 268 | template<typename T> void Integrator<T>::integrate(voi
268      }
269  
270      if (info->getTime() >= currStatus){
271 <      statOut->writeStat(info->getTime());
272 <      calcPot = 0;
271 >      statOut->writeStat(info->getTime());
272 >      calcPot = 0;
273        calcStress = 0;
274        currStatus += statusTime;
275 <    }
275 >    }
276  
277      if (info->resetIntegrator){
278        if (info->getTime() >= currReset){
# Line 242 | Line 280 | template<typename T> void Integrator<T>::integrate(voi
280          currReset += resetTime;
281        }
282      }
283 +    
284 + #ifdef PROFILE
285 +    endProfile( pro2 );
286 + #endif //profile
287  
288   #ifdef IS_MPI
289      strcpy(checkPointMsg, "successfully took a time step.");
# Line 249 | Line 291 | template<typename T> void Integrator<T>::integrate(voi
291   #endif // is_mpi
292    }
293  
294 <  dumpOut->writeFinal(info->getTime());
294 >  // dump out a file containing the omega values for the final configuration
295 >  if (info->useSolidThermInt && !info->useLiquidThermInt)
296 >    myFF->dumpzAngle();
297 >  
298  
299    delete dumpOut;
300    delete statOut;
# Line 258 | Line 303 | template<typename T> void Integrator<T>::integrateStep
303   template<typename T> void Integrator<T>::integrateStep(int calcPot,
304                                                         int calcStress){
305    // Position full step, and velocity half step
261  preMove();
306  
307 <  moveA();
307 > #ifdef PROFILE
308 >  startProfile(pro3);
309 > #endif //profile
310  
311 +  //save old state (position, velocity etc)
312 +  rattle->doPreConstraint();
313  
314 + #ifdef PROFILE
315 +  endProfile(pro3);
316  
317 +  startProfile(pro4);
318 + #endif // profile
319  
320 +  moveA();
321 +
322 + #ifdef PROFILE
323 +  endProfile(pro4);
324 +  
325 +  startProfile(pro5);
326 + #endif//profile
327 +
328 +
329   #ifdef IS_MPI
330    strcpy(checkPointMsg, "Succesful moveA\n");
331    MPIcheckPoint();
332   #endif // is_mpi
333  
273
334    // calc forces
275
335    calcForce(calcPot, calcStress);
336  
337   #ifdef IS_MPI
# Line 280 | Line 339 | template<typename T> void Integrator<T>::integrateStep
339    MPIcheckPoint();
340   #endif // is_mpi
341  
342 + #ifdef PROFILE
343 +  endProfile( pro5 );
344  
345 +  startProfile( pro6 );
346 + #endif //profile
347 +
348    // finish the velocity  half step
349  
350    moveB();
351  
352 + #ifdef PROFILE
353 +  endProfile(pro6);
354 + #endif // profile
355  
289
356   #ifdef IS_MPI
357    strcpy(checkPointMsg, "Succesful moveB\n");
358    MPIcheckPoint();
# Line 295 | Line 361 | template<typename T> void Integrator<T>::moveA(void){
361  
362  
363   template<typename T> void Integrator<T>::moveA(void){
364 <  int i, j;
364 >  size_t i, j;
365    DirectionalAtom* dAtom;
366    double Tb[3], ji[3];
367    double vel[3], pos[3], frc[3];
368    double mass;
369 +  double omega;
370 +
371 +  for (i = 0; i < integrableObjects.size() ; i++){
372 +    integrableObjects[i]->getVel(vel);
373 +    integrableObjects[i]->getPos(pos);
374 +    integrableObjects[i]->getFrc(frc);
375 +    
376 +    mass = integrableObjects[i]->getMass();
377  
304  for (i = 0; i < nAtoms; i++){
305    atoms[i]->getVel(vel);
306    atoms[i]->getPos(pos);
307    atoms[i]->getFrc(frc);
308
309    mass = atoms[i]->getMass();
310
378      for (j = 0; j < 3; j++){
379        // velocity half step
380        vel[j] += (dt2 * frc[j] / mass) * eConvert;
# Line 315 | Line 382 | template<typename T> void Integrator<T>::moveA(void){
382        pos[j] += dt * vel[j];
383      }
384  
385 <    atoms[i]->setVel(vel);
386 <    atoms[i]->setPos(pos);
385 >    integrableObjects[i]->setVel(vel);
386 >    integrableObjects[i]->setPos(pos);
387  
388 <    if (atoms[i]->isDirectional()){
322 <      dAtom = (DirectionalAtom *) atoms[i];
388 >    if (integrableObjects[i]->isDirectional()){
389  
390        // get and convert the torque to body frame
391  
392 <      dAtom->getTrq(Tb);
393 <      dAtom->lab2Body(Tb);
392 >      integrableObjects[i]->getTrq(Tb);
393 >      integrableObjects[i]->lab2Body(Tb);
394  
395        // get the angular momentum, and propagate a half step
396  
397 <      dAtom->getJ(ji);
397 >      integrableObjects[i]->getJ(ji);
398  
399        for (j = 0; j < 3; j++)
400          ji[j] += (dt2 * Tb[j]) * eConvert;
401  
402 <      this->rotationPropagation( dAtom, ji );
402 >      this->rotationPropagation( integrableObjects[i], ji );
403  
404 <      dAtom->setJ(ji);
404 >      integrableObjects[i]->setJ(ji);
405      }
406    }
407  
408 <  if (nConstrained){
343 <    constrainA();
344 <  }
408 >  rattle->doRattleA();
409   }
410  
411  
412   template<typename T> void Integrator<T>::moveB(void){
413    int i, j;
350  DirectionalAtom* dAtom;
414    double Tb[3], ji[3];
415    double vel[3], frc[3];
416    double mass;
417  
418 <  for (i = 0; i < nAtoms; i++){
419 <    atoms[i]->getVel(vel);
420 <    atoms[i]->getFrc(frc);
418 >  for (i = 0; i < integrableObjects.size(); i++){
419 >    integrableObjects[i]->getVel(vel);
420 >    integrableObjects[i]->getFrc(frc);
421  
422 <    mass = atoms[i]->getMass();
422 >    mass = integrableObjects[i]->getMass();
423  
424      // velocity half step
425      for (j = 0; j < 3; j++)
426        vel[j] += (dt2 * frc[j] / mass) * eConvert;
427  
428 <    atoms[i]->setVel(vel);
428 >    integrableObjects[i]->setVel(vel);
429  
430 <    if (atoms[i]->isDirectional()){
368 <      dAtom = (DirectionalAtom *) atoms[i];
430 >    if (integrableObjects[i]->isDirectional()){
431  
432 <      // get and convert the torque to body frame      
432 >      // get and convert the torque to body frame
433  
434 <      dAtom->getTrq(Tb);
435 <      dAtom->lab2Body(Tb);
434 >      integrableObjects[i]->getTrq(Tb);
435 >      integrableObjects[i]->lab2Body(Tb);
436  
437        // get the angular momentum, and propagate a half step
438  
439 <      dAtom->getJ(ji);
439 >      integrableObjects[i]->getJ(ji);
440  
441        for (j = 0; j < 3; j++)
442          ji[j] += (dt2 * Tb[j]) * eConvert;
443  
444  
445 <      dAtom->setJ(ji);
445 >      integrableObjects[i]->setJ(ji);
446      }
447    }
448  
449 <  if (nConstrained){
388 <    constrainB();
389 <  }
449 >  rattle->doRattleB();
450   }
451  
452 + /*
453   template<typename T> void Integrator<T>::preMove(void){
454    int i, j;
455    double pos[3];
# Line 405 | Line 466 | template<typename T> void Integrator<T>::constrainA(){
466   }
467  
468   template<typename T> void Integrator<T>::constrainA(){
469 <  int i, j, k;
469 >  int i, j;
470    int done;
471    double posA[3], posB[3];
472    double velA[3], velB[3];
# Line 549 | Line 610 | template<typename T> void Integrator<T>::constrainB(vo
610   }
611  
612   template<typename T> void Integrator<T>::constrainB(void){
613 <  int i, j, k;
613 >  int i, j;
614    int done;
615    double posA[3], posB[3];
616    double velA[3], velB[3];
# Line 558 | Line 619 | template<typename T> void Integrator<T>::constrainB(vo
619    int a, b, ax, ay, az, bx, by, bz;
620    double rma, rmb;
621    double dx, dy, dz;
622 <  double rabsq, pabsq, rvab;
562 <  double diffsq;
622 >  double rvab;
623    double gab;
624    int iteration;
625  
# Line 648 | Line 708 | template<typename T> void Integrator<T>::constrainB(vo
708      simError();
709    }
710   }
711 <
711 > */
712   template<typename T> void Integrator<T>::rotationPropagation
713 < ( DirectionalAtom* dAtom, double ji[3] ){
713 > ( StuntDouble* sd, double ji[3] ){
714  
715    double angle;
716    double A[3][3], I[3][3];
717 +  int i, j, k;
718  
719    // use the angular velocities to propagate the rotation matrix a
720    // full time step
721  
722 <  dAtom->getA(A);
723 <  dAtom->getI(I);
724 <  
725 <  // rotate about the x-axis      
726 <  angle = dt2 * ji[0] / I[0][0];
727 <  this->rotate( 1, 2, angle, ji, A );
728 <  
729 <  // rotate about the y-axis
730 <  angle = dt2 * ji[1] / I[1][1];
731 <  this->rotate( 2, 0, angle, ji, A );
732 <  
733 <  // rotate about the z-axis
734 <  angle = dt * ji[2] / I[2][2];
735 <  this->rotate( 0, 1, angle, ji, A);
736 <  
737 <  // rotate about the y-axis
738 <  angle = dt2 * ji[1] / I[1][1];
739 <  this->rotate( 2, 0, angle, ji, A );
740 <  
741 <  // rotate about the x-axis
742 <  angle = dt2 * ji[0] / I[0][0];
743 <  this->rotate( 1, 2, angle, ji, A );
744 <  
745 <  dAtom->setA( A  );    
722 >  sd->getA(A);
723 >  sd->getI(I);
724 >
725 >  if (sd->isLinear()) {
726 >    i = sd->linearAxis();
727 >    j = (i+1)%3;
728 >    k = (i+2)%3;
729 >    
730 >    angle = dt2 * ji[j] / I[j][j];
731 >    this->rotate( k, i, angle, ji, A );
732 >
733 >    angle = dt * ji[k] / I[k][k];
734 >    this->rotate( i, j, angle, ji, A);
735 >
736 >    angle = dt2 * ji[j] / I[j][j];
737 >    this->rotate( k, i, angle, ji, A );
738 >
739 >  } else {
740 >    // rotate about the x-axis
741 >    angle = dt2 * ji[0] / I[0][0];
742 >    this->rotate( 1, 2, angle, ji, A );
743 >    
744 >    // rotate about the y-axis
745 >    angle = dt2 * ji[1] / I[1][1];
746 >    this->rotate( 2, 0, angle, ji, A );
747 >    
748 >    // rotate about the z-axis
749 >    angle = dt * ji[2] / I[2][2];
750 >    sd->addZangle(angle);
751 >    this->rotate( 0, 1, angle, ji, A);
752 >    
753 >    // rotate about the y-axis
754 >    angle = dt2 * ji[1] / I[1][1];
755 >    this->rotate( 2, 0, angle, ji, A );
756 >    
757 >    // rotate about the x-axis
758 >    angle = dt2 * ji[0] / I[0][0];
759 >    this->rotate( 1, 2, angle, ji, A );
760 >    
761 >  }
762 >  sd->setA( A  );
763   }
764  
765   template<typename T> void Integrator<T>::rotate(int axes1, int axes2,
# Line 749 | Line 827 | template<typename T> void Integrator<T>::rotate(int ax
827      }
828    }
829  
830 <  // rotate the Rotation matrix acording to:
830 >  // rotate the Rotation matrix acording to:
831    //            A[][] = A[][] * transpose(rot[][])
832  
833  
# Line 778 | Line 856 | template<typename T> double Integrator<T>::getConserve
856   template<typename T> double Integrator<T>::getConservedQuantity(void){
857    return tStats->getTotalE();
858   }
859 + template<typename T> string Integrator<T>::getAdditionalParameters(void){
860 +  //By default, return a null string
861 +  //The reason we use string instead of char* is that if we use char*, we will
862 +  //return a pointer point to local variable which might cause problem
863 +  return string();
864 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines