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 597 by mmeineke, Mon Jul 14 21:28:54 2003 UTC vs.
Revision 641 by mmeineke, Mon Jul 21 16:23:10 2003 UTC

# Line 27 | Line 27 | Integrator::Integrator( SimInfo *theInfo, ForceFields*
27  
28    nAtoms = info->n_atoms;
29  
30  std::cerr << "integ nAtoms = "  << nAtoms << "\n";
31
30    // check for constraints
31    
32    constrainedA    = NULL;
# Line 75 | Line 73 | void Integrator::checkConstraints( void ){
73        
74        constrained = theArray[j]->is_constrained();
75  
78      std::cerr << "Is the folowing bond constrained \n";
79      theArray[j]->printMe();
80      
76        if(constrained){
82        
83        std::cerr << "Yes\n";
77  
78          dummy_plug = theArray[j]->get_constraint();
79          temp_con[nConstrained].set_a( dummy_plug->get_a() );
# Line 90 | Line 83 | void Integrator::checkConstraints( void ){
83          nConstrained++;
84          constrained = 0;
85        }
93      else std::cerr << "No.\n";
86      }
87  
88      theArray = (SRI**) molecules[i].getMyBends();
# Line 175 | Line 167 | void Integrator::integrate( void ){
167    double currSample;
168    double currThermal;
169    double currStatus;
178  double currTime;
170  
171    int calcPot, calcStress;
172    int isError;
173  
183
184
174    tStats   = new Thermo( info );
175    statOut  = new StatWriter( info );
176    dumpOut  = new DumpWriter( info );
# Line 201 | Line 190 | void Integrator::integrate( void ){
190      tStats->velocitize();
191    }
192    
204  dumpOut->writeDump( 0.0 );
205  statOut->writeStat( 0.0 );
206  
193    calcPot     = 0;
194    calcStress  = 0;
195    currSample  = sampleTime;
196    currThermal = thermalTime;
197    currStatus  = statusTime;
212  currTime    = 0.0;;
198  
199 +  dumpOut->writeDump( info->currTime );
200 +  statOut->writeStat( info->currTime );
201  
202    readyCheck();
203  
# Line 220 | Line 207 | void Integrator::integrate( void ){
207    MPIcheckPoint();
208   #endif // is_mpi
209  
210 +  while( info->currTime < runTime ){
211  
212 <  pos  = Atom::getPosArray();
225 <  vel  = Atom::getVelArray();
226 <  frc  = Atom::getFrcArray();
227 <
228 <  while( currTime < runTime ){
229 <
230 <    if( (currTime+dt) >= currStatus ){
212 >    if( (info->currTime+dt) >= currStatus ){
213        calcPot = 1;
214        calcStress = 1;
215      }
216  
235    std::cerr << currTime << "\n";
236
217      integrateStep( calcPot, calcStress );
218        
219 <    currTime += dt;
219 >    info->currTime += dt;
220 >    info->setTime(info->currTime);
221  
222      if( info->setTemp ){
223 <      if( currTime >= currThermal ){
223 >      if( info->currTime >= currThermal ){
224          tStats->velocitize();
225          currThermal += thermalTime;
226        }
227      }
228  
229 <    if( currTime >= currSample ){
230 <      dumpOut->writeDump( currTime );
229 >    if( info->currTime >= currSample ){
230 >      dumpOut->writeDump( info->currTime );
231        currSample += sampleTime;
232      }
233  
234 <    if( currTime >= currStatus ){
235 <      statOut->writeStat( currTime );
234 >    if( info->currTime >= currStatus ){
235 >      statOut->writeStat( info->currTime );
236        calcPot = 0;
237        calcStress = 0;
238        currStatus += statusTime;
# Line 265 | Line 246 | void Integrator::integrate( void ){
246  
247    }
248  
249 <  dumpOut->writeFinal(currTime);
249 >  dumpOut->writeFinal(info->currTime);
250  
251    delete dumpOut;
252    delete statOut;
# Line 279 | Line 260 | void Integrator::integrateStep( int calcPot, int calcS
260  
261    preMove();
262    moveA();
263 <  //if( nConstrained ) constrainA();
263 >  if( nConstrained ) constrainA();
264  
265 +  
266 + #ifdef IS_MPI
267 +  strcpy( checkPointMsg, "Succesful moveA\n" );
268 +  MPIcheckPoint();
269 + #endif // is_mpi
270 +  
271 +
272    // calc forces
273  
274    myFF->doForces(calcPot,calcStress);
275  
276 + #ifdef IS_MPI
277 +  strcpy( checkPointMsg, "Succesful doForces\n" );
278 +  MPIcheckPoint();
279 + #endif // is_mpi
280 +  
281 +
282    // finish the velocity  half step
283    
284    moveB();
285    if( nConstrained ) constrainB();
286 <  
286 >  
287 > #ifdef IS_MPI
288 >  strcpy( checkPointMsg, "Succesful moveB\n" );
289 >  MPIcheckPoint();
290 > #endif // is_mpi
291 >  
292 >
293   }
294  
295  
296   void Integrator::moveA( void ){
297    
298 <  int i,j,k;
299 <  int atomIndex, aMatIndex;
298 >  int i, j;
299    DirectionalAtom* dAtom;
300 <  double Tb[3];
301 <  double ji[3];
300 >  double Tb[3], ji[3];
301 >  double A[3][3], I[3][3];
302    double angle;
303 <  double A[3][3], At[3][3];
303 >  double vel[3], pos[3], frc[3];
304 >  double mass;
305  
306
306    for( i=0; i<nAtoms; i++ ){
308    atomIndex = i * 3;
309    aMatIndex = i * 9;
307  
308 <    // velocity half step
309 <    for( j=atomIndex; j<(atomIndex+3); j++ )
310 <      vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert;
308 >    atoms[i]->getVel( vel );
309 >    atoms[i]->getPos( pos );
310 >    atoms[i]->getFrc( frc );
311  
312 +    mass = atoms[i]->getMass();
313  
314 <    // position whole step    
315 <    for( j=atomIndex; j<(atomIndex+3); j++ ) pos[j] += dt * vel[j];
316 <    
314 >    for (j=0; j < 3; j++) {
315 >      // velocity half step
316 >      vel[j] += ( dt2 * frc[j] / mass ) * eConvert;
317 >      // position whole step
318 >      pos[j] += dt * vel[j];
319 >    }
320  
321 +    atoms[i]->setVel( vel );
322 +    atoms[i]->setPos( pos );
323 +
324      if( atoms[i]->isDirectional() ){
325  
326        dAtom = (DirectionalAtom *)atoms[i];
327            
328        // get and convert the torque to body frame
329        
330 <      Tb[0] = dAtom->getTx();
327 <      Tb[1] = dAtom->getTy();
328 <      Tb[2] = dAtom->getTz();
329 <
330 >      dAtom->getTrq( Tb );
331        dAtom->lab2Body( Tb );
332  
333        // get the angular momentum, and propagate a half step
334 <      
335 <      ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert;
336 <      ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert;
337 <      ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert;
334 >
335 >      dAtom->getJ( ji );
336 >
337 >      for (j=0; j < 3; j++)
338 >        ji[j] += (dt2 * Tb[j]) * eConvert;
339        
340        // use the angular velocities to propagate the rotation matrix a
341        // full time step
342 <      
342 >
343 >      dAtom->getA(A);
344 >      dAtom->getI(I);
345 >    
346        // rotate about the x-axis      
347 <      angle = dt2 * ji[0] / dAtom->getIxx();
348 <      this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] );
347 >      angle = dt2 * ji[0] / I[0][0];
348 >      this->rotate( 1, 2, angle, ji, A );
349  
350        // rotate about the y-axis
351 <      angle = dt2 * ji[1] / dAtom->getIyy();
352 <      this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] );
351 >      angle = dt2 * ji[1] / I[1][1];
352 >      this->rotate( 2, 0, angle, ji, A );
353        
354        // rotate about the z-axis
355 <      angle = dt * ji[2] / dAtom->getIzz();
356 <      this->rotate( 0, 1, angle, ji, &Amat[aMatIndex] );
355 >      angle = dt * ji[2] / I[2][2];
356 >      this->rotate( 0, 1, angle, ji, A);
357        
358        // rotate about the y-axis
359 <      angle = dt2 * ji[1] / dAtom->getIyy();
360 <      this->rotate( 2, 0, angle, ji, &Amat[aMatIndex] );
359 >      angle = dt2 * ji[1] / I[1][1];
360 >      this->rotate( 2, 0, angle, ji, A );
361        
362         // rotate about the x-axis
363 <      angle = dt2 * ji[0] / dAtom->getIxx();
364 <      this->rotate( 1, 2, angle, ji, &Amat[aMatIndex] );
363 >      angle = dt2 * ji[0] / I[0][0];
364 >      this->rotate( 1, 2, angle, ji, A );
365        
361      dAtom->setJx( ji[0] );
362      dAtom->setJy( ji[1] );
363      dAtom->setJz( ji[2] );
366  
367 <      std::cerr << "Amat[" << i << "]\n";
368 <      info->printMat9( &Amat[aMatIndex] );
367 >      dAtom->setJ( ji );
368 >      dAtom->setA( A  );
369            
370 <      std::cerr << "ji[" << i << "]\t"
369 <                << ji[0] << "\t"
370 <                << ji[1] << "\t"
371 <                << ji[2] << "\n";
372 <          
373 <    }
374 <    
370 >    }    
371    }
372   }
373  
374  
375   void Integrator::moveB( void ){
376 <  int i,j,k;
381 <  int atomIndex, aMatIndex;
376 >  int i, j;
377    DirectionalAtom* dAtom;
378 <  double Tb[3];
379 <  double ji[3];
378 >  double Tb[3], ji[3];
379 >  double vel[3], frc[3];
380 >  double mass;
381  
382    for( i=0; i<nAtoms; i++ ){
383 <    atomIndex = i * 3;
384 <    aMatIndex = i * 9;
383 >
384 >    atoms[i]->getVel( vel );
385 >    atoms[i]->getFrc( frc );
386  
387 <    // velocity half step
391 <    for( j=atomIndex; j<(atomIndex+3); j++ )
392 <      vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert;
387 >    mass = atoms[i]->getMass();
388  
389 +    // velocity half step
390 +    for (j=0; j < 3; j++)
391 +      vel[j] += ( dt2 * frc[j] / mass ) * eConvert;
392 +    
393 +    atoms[i]->setVel( vel );
394  
395      if( atoms[i]->isDirectional() ){
396 <      
396 >
397        dAtom = (DirectionalAtom *)atoms[i];
398 <      
399 <      // get and convert the torque to body frame
400 <      
401 <      Tb[0] = dAtom->getTx();
402 <      Tb[1] = dAtom->getTy();
403 <      Tb[2] = dAtom->getTz();
404 <      
405 <      std::cerr << "TrqB[" << i << "]\t"
406 <                << Tb[0] << "\t"
407 <                << Tb[1] << "\t"
408 <                << Tb[2] << "\n";
409 <
398 >
399 >      // get and convert the torque to body frame      
400 >
401 >      dAtom->getTrq( Tb );
402        dAtom->lab2Body( Tb );
411      
412      // get the angular momentum, and complete the angular momentum
413      // half step
414      
415      ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert;
416      ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert;
417      ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert;
418      
419      dAtom->setJx( ji[0] );
420      dAtom->setJy( ji[1] );
421      dAtom->setJz( ji[2] );
403  
404 +      // get the angular momentum, and propagate a half step
405  
406 <      std::cerr << "Amat[" << i << "]\n";
407 <      info->printMat9( &Amat[aMatIndex] );
408 <          
409 <      std::cerr << "ji[" << i << "]\t"
410 <                << ji[0] << "\t"
411 <                << ji[1] << "\t"
412 <                << ji[2] << "\n";
406 >      dAtom->getJ( ji );
407 >
408 >      for (j=0; j < 3; j++)
409 >        ji[j] += (dt2 * Tb[j]) * eConvert;
410 >      
411 >
412 >      dAtom->setJ( ji );
413      }
414    }
433
415   }
416  
417   void Integrator::preMove( void ){
418 <  int i;
418 >  int i, j;
419 >  double pos[3];
420  
421    if( nConstrained ){
422  
423 <    for(i=0; i<(nAtoms*3); i++) oldPos[i] = pos[i];
424 <  }
425 < }  
423 >    for(i=0; i < nAtoms; i++) {
424 >
425 >      atoms[i]->getPos( pos );
426  
427 +      for (j = 0; j < 3; j++) {        
428 +        oldPos[3*i + j] = pos[j];
429 +      }
430 +
431 +    }
432 +  }  
433 + }
434 +
435   void Integrator::constrainA(){
436  
437    int i,j,k;
438    int done;
439 +  double posA[3], posB[3];
440 +  double velA[3], velB[3];
441    double pab[3];
442    double rab[3];
443    int a, b, ax, ay, az, bx, by, bz;
# Line 457 | Line 449 | void Integrator::constrainA(){
449    double gab;
450    int iteration;
451  
452 <  for( i=0; i<nAtoms; i++){
461 <    
452 >  for( i=0; i<nAtoms; i++){    
453      moving[i] = 0;
454      moved[i]  = 1;
455    }
# Line 482 | Line 473 | void Integrator::constrainA(){
473        bz = (b*3) + 2;
474  
475        if( moved[a] || moved[b] ){
476 <        
477 <        pab[0] = pos[ax] - pos[bx];
478 <        pab[1] = pos[ay] - pos[by];
479 <        pab[2] = pos[az] - pos[bz];
480 <
476 >        
477 >        atoms[a]->getPos( posA );
478 >        atoms[b]->getPos( posB );
479 >        
480 >        for (j = 0; j < 3; j++ )
481 >          pab[j] = posA[j] - posB[j];
482 >        
483          //periodic boundary condition
484  
485          info->wrapVector( pab );
# Line 531 | Line 524 | void Integrator::constrainA(){
524            dy = rab[1] * gab;
525            dz = rab[2] * gab;
526  
527 <          pos[ax] += rma * dx;
528 <          pos[ay] += rma * dy;
529 <          pos[az] += rma * dz;
527 >          posA[0] += rma * dx;
528 >          posA[1] += rma * dy;
529 >          posA[2] += rma * dz;
530  
531 <          pos[bx] -= rmb * dx;
532 <          pos[by] -= rmb * dy;
533 <          pos[bz] -= rmb * dz;
531 >          atoms[a]->setPos( posA );
532 >
533 >          posB[0] -= rmb * dx;
534 >          posB[1] -= rmb * dy;
535 >          posB[2] -= rmb * dz;
536 >
537 >          atoms[b]->setPos( posB );
538  
539            dx = dx / dt;
540            dy = dy / dt;
541            dz = dz / dt;
542  
543 <          vel[ax] += rma * dx;
547 <          vel[ay] += rma * dy;
548 <          vel[az] += rma * dz;
543 >          atoms[a]->getVel( velA );
544  
545 <          vel[bx] -= rmb * dx;
546 <          vel[by] -= rmb * dy;
547 <          vel[bz] -= rmb * dz;
545 >          velA[0] += rma * dx;
546 >          velA[1] += rma * dy;
547 >          velA[2] += rma * dz;
548  
549 +          atoms[a]->setVel( velA );
550 +
551 +          atoms[b]->getVel( velB );
552 +
553 +          velB[0] -= rmb * dx;
554 +          velB[1] -= rmb * dy;
555 +          velB[2] -= rmb * dz;
556 +
557 +          atoms[b]->setVel( velB );
558 +
559            moving[a] = 1;
560            moving[b] = 1;
561            done = 0;
# Line 582 | Line 587 | void Integrator::constrainB( void ){
587    
588    int i,j,k;
589    int done;
590 +  double posA[3], posB[3];
591 +  double velA[3], velB[3];
592    double vxab, vyab, vzab;
593    double rab[3];
594    int a, b, ax, ay, az, bx, by, bz;
# Line 617 | Line 624 | void Integrator::constrainB( void ){
624        bz = (b*3) + 2;
625  
626        if( moved[a] || moved[b] ){
620        
621        vxab = vel[ax] - vel[bx];
622        vyab = vel[ay] - vel[by];
623        vzab = vel[az] - vel[bz];
627  
628 <        rab[0] = pos[ax] - pos[bx];
629 <        rab[1] = pos[ay] - pos[by];
630 <        rab[2] = pos[az] - pos[bz];
631 <        
628 >        atoms[a]->getVel( velA );
629 >        atoms[b]->getVel( velB );
630 >          
631 >        vxab = velA[0] - velB[0];
632 >        vyab = velA[1] - velB[1];
633 >        vzab = velA[2] - velB[2];
634 >
635 >        atoms[a]->getPos( posA );
636 >        atoms[b]->getPos( posB );
637 >
638 >        for (j = 0; j < 3; j++)
639 >          rab[j] = posA[j] - posB[j];
640 >          
641          info->wrapVector( rab );
642          
643          rma = 1.0 / atoms[a]->getMass();
# Line 640 | Line 652 | void Integrator::constrainB( void ){
652            dx = rab[0] * gab;
653            dy = rab[1] * gab;
654            dz = rab[2] * gab;
655 <          
656 <          vel[ax] += rma * dx;
657 <          vel[ay] += rma * dy;
658 <          vel[az] += rma * dz;
655 >        
656 >          velA[0] += rma * dx;
657 >          velA[1] += rma * dy;
658 >          velA[2] += rma * dz;
659  
660 <          vel[bx] -= rmb * dx;
661 <          vel[by] -= rmb * dy;
662 <          vel[bz] -= rmb * dz;
660 >          atoms[a]->setVel( velA );
661 >
662 >          velB[0] -= rmb * dx;
663 >          velB[1] -= rmb * dy;
664 >          velB[2] -= rmb * dz;
665 >
666 >          atoms[b]->setVel( velB );
667            
668            moving[a] = 1;
669            moving[b] = 1;
# Line 663 | Line 679 | void Integrator::constrainB( void ){
679      
680      iteration++;
681    }
682 <
682 >  
683    if( !done ){
684  
685    
# Line 676 | Line 692 | void Integrator::constrainB( void ){
692  
693   }
694  
679
680
681
682
683
684
695   void Integrator::rotate( int axes1, int axes2, double angle, double ji[3],
696 <                         double A[9] ){
696 >                         double A[3][3] ){
697  
698    int i,j,k;
699    double sinAngle;
# Line 695 | Line 705 | void Integrator::rotate( int axes1, int axes2, double
705    double tempA[3][3];
706    double tempJ[3];
707  
698
708    // initialize the tempA
709  
710    for(i=0; i<3; i++){
711      for(j=0; j<3; j++){
712 <      tempA[j][i] = A[3*i+j];
712 >      tempA[j][i] = A[i][j];
713      }
714    }
715  
# Line 757 | Line 766 | void Integrator::rotate( int axes1, int axes2, double
766  
767    for(i=0; i<3; i++){
768      for(j=0; j<3; j++){
769 <      A[3*j+i] = 0.0;
769 >      A[j][i] = 0.0;
770        for(k=0; k<3; k++){
771 <        A[3*j+i] += tempA[i][k] * rot[j][k];
771 >        A[j][i] += tempA[i][k] * rot[j][k];
772        }
773      }
774    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines