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 558 by mmeineke, Thu Jun 19 19:21:23 2003 UTC vs.
Revision 693 by tim, Wed Aug 13 19:21:53 2003 UTC

# Line 1 | Line 1
1   #include <iostream>
2   #include <cstdlib>
3 + #include <cmath>
4  
5   #ifdef IS_MPI
6   #include "mpiSimulation.hpp"
# Line 10 | Line 11 | Integrator::Integrator( SimInfo* theInfo, ForceFields*
11   #include "simError.h"
12  
13  
14 < Integrator::Integrator( SimInfo* theInfo, ForceFields* the_ff ){
14 > template<typename T> Integrator<T>::Integrator( SimInfo *theInfo, ForceFields* the_ff ) {
15    
16    info = theInfo;
17    myFF = the_ff;
# Line 33 | Line 34 | Integrator::Integrator( SimInfo* theInfo, ForceFields*
34    constrainedDsqr = NULL;
35    moving          = NULL;
36    moved           = NULL;
37 <  prePos          = NULL;
37 >  oldPos          = NULL;
38    
39    nConstrained = 0;
40  
41    checkConstraints();
42   }
43  
44 < Integrator::~Integrator() {
44 > template<typename T> Integrator<T>::~Integrator() {
45    
46    if( nConstrained ){
47      delete[] constrainedA;
# Line 48 | Line 49 | Integrator::~Integrator() {
49      delete[] constrainedDsqr;
50      delete[] moving;
51      delete[] moved;
52 <    delete[] prePos;
52 < k
52 >    delete[] oldPos;
53    }
54    
55   }
56  
57 < void Integrator::checkConstraints( void ){
57 > template<typename T> void Integrator<T>::checkConstraints( void ){
58  
59  
60    isConstrained = 0;
# Line 72 | Line 72 | void Integrator::checkConstraints( void ){
72      for(int j=0; j<molecules[i].getNBonds(); j++){
73        
74        constrained = theArray[j]->is_constrained();
75 <      
75 >
76        if(constrained){
77 <        
77 >
78          dummy_plug = theArray[j]->get_constraint();
79          temp_con[nConstrained].set_a( dummy_plug->get_a() );
80          temp_con[nConstrained].set_b( dummy_plug->get_b() );
# Line 82 | Line 82 | void Integrator::checkConstraints( void ){
82          
83          nConstrained++;
84          constrained = 0;
85 <      }
85 >      }
86      }
87  
88      theArray = (SRI**) molecules[i].getMyBends();
# Line 137 | Line 137 | void Integrator::checkConstraints( void ){
137        constrainedA[i] = temp_con[i].get_a();
138        constrainedB[i] = temp_con[i].get_b();
139        constrainedDsqr[i] = temp_con[i].get_dsqr();
140 +
141      }
142  
143      
# Line 147 | Line 148 | void Integrator::checkConstraints( void ){
148      moving = new int[nAtoms];
149      moved  = new int[nAtoms];
150  
151 <    prePos = new double[nAtoms*3];
151 >    oldPos = new double[nAtoms*3];
152    }
153    
154    delete[] temp_con;
155   }
156  
157  
158 < void Integrator::integrate( void ){
158 > template<typename T> void Integrator<T>::integrate( void ){
159  
160    int i, j;                         // loop counters
160  double kE = 0.0;                  // the kinetic energy  
161  double rot_kE;
162  double trans_kE;
163  int tl;                        // the time loop conter
164  double dt2;                       // half the dt
161  
166  double vx, vy, vz;    // the velocities
167  double vx2, vy2, vz2; // the square of the velocities
168  double rx, ry, rz;    // the postitions
169  
170  double ji[3];   // the body frame angular momentum
171  double jx2, jy2, jz2; // the square of the angular momentums
172  double Tb[3];   // torque in the body frame
173  double angle;   // the angle through which to rotate the rotation matrix
174  double A[3][3]; // the rotation matrix
175  double press[9];
176
177  double dt          = info->dt;
162    double runTime     = info->run_time;
163    double sampleTime  = info->sampleTime;
164    double statusTime  = info->statusTime;
# Line 183 | Line 167 | void Integrator::integrate( void ){
167    double currSample;
168    double currThermal;
169    double currStatus;
186  double currTime;
170  
171    int calcPot, calcStress;
172    int isError;
173  
174    tStats   = new Thermo( info );
175 <  e_out    = new StatWriter( info );
176 <  dump_out = new DumpWriter( info );
175 >  statOut  = new StatWriter( info );
176 >  dumpOut  = new DumpWriter( info );
177  
178 <  Atom** atoms = info->atoms;
178 >  atoms = info->atoms;
179    DirectionalAtom* dAtom;
180 +
181 +  dt = info->dt;
182    dt2 = 0.5 * dt;
183  
184    // initialize the forces before the first step
185  
186 <  myFF->doForces(1,1);
187 <  
186 >  calcForce(1, 1);
187 >  // myFF->doForces(1,1);
188 >        
189    if( info->setTemp ){
190      
191 <    tStats->velocitize();
191 >    thermalize();
192    }
193    
208  dump_out->writeDump( 0.0 );
209  e_out->writeStat( 0.0 );
210  
194    calcPot     = 0;
195    calcStress  = 0;
196    currSample  = sampleTime;
197    currThermal = thermalTime;
198    currStatus  = statusTime;
216  currTime    = 0.0;;
199  
200 <  while( currTime < runTime ){
200 >  dumpOut->writeDump( info->getTime() );
201 >  statOut->writeStat( info->getTime() );
202  
203 <    if( (currTime+dt) >= currStatus ){
203 >  readyCheck();
204 >
205 > #ifdef IS_MPI
206 >  strcpy( checkPointMsg,
207 >          "The integrator is ready to go." );
208 >  MPIcheckPoint();
209 > #endif // is_mpi
210 >
211 >  while( info->getTime() < runTime ){
212 >
213 >    if( (info->getTime()+dt) >= currStatus ){
214        calcPot = 1;
215        calcStress = 1;
216      }
217 <    
217 >
218      integrateStep( calcPot, calcStress );
219        
220 <    currTime += dt;
220 >    info->incrTime(dt);
221  
222      if( info->setTemp ){
223 <      if( currTime >= currThermal ){
224 <        tStats->velocitize();
223 >      if( info->getTime() >= currThermal ){
224 >        thermalize();
225          currThermal += thermalTime;
226        }
227      }
228  
229 <    if( currTime >= currSample ){
230 <      dump_out->writeDump( currTime );
229 >    if( info->getTime() >= currSample ){
230 >      dumpOut->writeDump( info->getTime() );
231        currSample += sampleTime;
232      }
233  
234 <    if( currTime >= currStatus ){
235 <      e_out->writeStat( time * dt );
234 >    if( info->getTime() >= currStatus ){
235 >      statOut->writeStat( info->getTime() );
236        calcPot = 0;
237        calcStress = 0;
238        currStatus += statusTime;
239      }
240 +
241 + #ifdef IS_MPI
242 +    strcpy( checkPointMsg,
243 +            "successfully took a time step." );
244 +    MPIcheckPoint();
245 + #endif // is_mpi
246 +
247    }
248  
249 <  dump_out->writeFinal();
249 >  dumpOut->writeFinal(info->getTime());
250  
251 <  delete dump_out;
252 <  delete e_out;
251 >  delete dumpOut;
252 >  delete statOut;
253   }
254  
255 < void Integrator::integrateStep( int calcPot, int calcStress ){
255 > template<typename T> void Integrator<T>::integrateStep( int calcPot, int calcStress ){
256  
257 +
258 +      
259    // Position full step, and velocity half step
260  
261 <  //preMove();
261 >  preMove();
262    moveA();
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);
274 >  calcForce(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 ){
296 > template<typename T> void Integrator<T>::moveA( void ){
297    
298 <  int i,j,k;
278 <  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 vel[3], pos[3], frc[3];
304 >  double mass;
305  
306    for( i=0; i<nAtoms; i++ ){
284    atomIndex = i * 3;
285    aMatIndex = i * 9;
286    
287    // velocity half step
288    for( j=atomIndex; j<(atomIndex+3); j++ )
289      vel[j] += ( dt2 * frc[j] / atoms[i]->getMass() ) * eConvert;
307  
308 <    // position whole step    
309 <    for( j=atomIndex; j<(atomIndex+3); j++ )
308 >    atoms[i]->getVel( vel );
309 >    atoms[i]->getPos( pos );
310 >    atoms[i]->getFrc( frc );
311 >
312 >    mass = atoms[i]->getMass();
313 >
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 <  
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();
303 <      Tb[1] = dAtom->getTy();
304 <      Tb[2] = dAtom->getTz();
305 <      
330 >      dAtom->getTrq( Tb );
331        dAtom->lab2Body( Tb );
332 <      
332 >
333        // get the angular momentum, and propagate a half step
334 +
335 +      dAtom->getJ( ji );
336 +
337 +      for (j=0; j < 3; j++)
338 +        ji[j] += (dt2 * Tb[j]) * eConvert;
339        
310      ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert;
311      ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert;
312      ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert;
313      
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] );
349 <      
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        
366 <      dAtom->setJx( ji[0] );
367 <      dAtom->setJy( ji[1] );
368 <      dAtom->setJz( ji[2] );
369 <    }
370 <    
366 >
367 >      dAtom->setJ( ji );
368 >      dAtom->setA( A  );
369 >          
370 >    }    
371    }
372   }
373  
374  
375 < void Integrator::moveB( void ){
376 <  int i,j,k;
348 <  int atomIndex;
375 > template<typename T> void Integrator<T>::moveB( void ){
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;
383 >
384 >    atoms[i]->getVel( vel );
385 >    atoms[i]->getFrc( frc );
386  
387 <    // velocity half step
357 <    for( j=atomIndex; j<(atomIndex+3); j++ )
358 <      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();
367 <      Tb[1] = dAtom->getTy();
368 <      Tb[2] = dAtom->getTz();
369 <      
398 >
399 >      // get and convert the torque to body frame      
400 >
401 >      dAtom->getTrq( Tb );
402        dAtom->lab2Body( Tb );
403 +
404 +      // get the angular momentum, and propagate a half step
405 +
406 +      dAtom->getJ( ji );
407 +
408 +      for (j=0; j < 3; j++)
409 +        ji[j] += (dt2 * Tb[j]) * eConvert;
410        
411 <      // get the angular momentum, and complete the angular momentum
412 <      // half step
374 <      
375 <      ji[0] = dAtom->getJx() + ( dt2 * Tb[0] ) * eConvert;
376 <      ji[1] = dAtom->getJy() + ( dt2 * Tb[1] ) * eConvert;
377 <      ji[2] = dAtom->getJz() + ( dt2 * Tb[2] ) * eConvert;
378 <      
379 <      jx2 = ji[0] * ji[0];
380 <      jy2 = ji[1] * ji[1];
381 <      jz2 = ji[2] * ji[2];
382 <      
383 <      dAtom->setJx( ji[0] );
384 <      dAtom->setJy( ji[1] );
385 <      dAtom->setJz( ji[2] );
411 >
412 >      dAtom->setJ( ji );
413      }
414    }
388
415   }
416  
417 < void Integrator::preMove( void ){
418 <  int i;
417 > template<typename T> void Integrator<T>::preMove( void ){
418 >  int i, j;
419 >  double pos[3];
420  
421    if( nConstrained ){
422 <    if( oldAtoms != nAtoms ){
423 <      
424 <      // save oldAtoms to check for lode balanceing later on.
425 <      
426 <      oldAtoms = nAtoms;
427 <      
428 <      delete[] moving;
429 <      delete[] moved;
430 <      delete[] oldPos;
404 <      
405 <      moving = new int[nAtoms];
406 <      moved  = new int[nAtoms];
407 <      
408 <      oldPos = new double[nAtoms*3];
422 >
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 <    for(i=0; i<(nAtoms*3); i++) oldPos[i] = pos[i];
412 <  }
413 < }  
432 >  }  
433 > }
434  
435 < void Integrator::constrainA(){
435 > template<typename T> void Integrator<T>::constrainA(){
436  
437    int i,j,k;
438    int done;
439 <  double pxab, pyab, pzab;
440 <  double rxab, ryab, rzab;
441 <  int a, b;
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;
444    double rma, rmb;
445    double dx, dy, dz;
446 +  double rpab;
447    double rabsq, pabsq, rpabsq;
448    double diffsq;
449    double gab;
450    int iteration;
451  
452 <
430 <  
431 <  for( i=0; i<nAtoms; i++){
432 <    
452 >  for( i=0; i<nAtoms; i++){    
453      moving[i] = 0;
454      moved[i]  = 1;
455    }
456 <  
437 <  
456 >
457    iteration = 0;
458    done = 0;
459    while( !done && (iteration < maxIteration )){
# Line 444 | Line 463 | void Integrator::constrainA(){
463  
464        a = constrainedA[i];
465        b = constrainedB[i];
466 <    
466 >      
467 >      ax = (a*3) + 0;
468 >      ay = (a*3) + 1;
469 >      az = (a*3) + 2;
470 >
471 >      bx = (b*3) + 0;
472 >      by = (b*3) + 1;
473 >      bz = (b*3) + 2;
474 >
475        if( moved[a] || moved[b] ){
476 <        
477 <        pxab = pos[3*a+0] - pos[3*b+0];
478 <        pyab = pos[3*a+1] - pos[3*b+1];
479 <        pzab = pos[3*a+2] - pos[3*b+2];
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 <        //periodic boundary condition
455 <        pxab = pxab - info->box_x * copysign(1, pxab)
456 <          * int(pxab / info->box_x + 0.5);
457 <        pyab = pyab - info->box_y * copysign(1, pyab)
458 <          * int(pyab / info->box_y + 0.5);
459 <        pzab = pzab - info->box_z * copysign(1, pzab)
460 <          * int(pzab / info->box_z + 0.5);
461 <      
462 <        pabsq = pxab * pxab + pyab * pyab + pzab * pzab;
463 <        rabsq = constraintedDsqr[i];
464 <        diffsq = pabsq - rabsq;
485 >        info->wrapVector( pab );
486  
487 +        pabsq = pab[0] * pab[0] + pab[1] * pab[1] + pab[2] * pab[2];
488 +
489 +        rabsq = constrainedDsqr[i];
490 +        diffsq = rabsq - pabsq;
491 +
492          // the original rattle code from alan tidesley
493 <        if (fabs(diffsq) > tol*rabsq*2) {
494 <          rxab = oldPos[3*a+0] - oldPos[3*b+0];
495 <          ryab = oldPos[3*a+1] - oldPos[3*b+1];
496 <          rzab = oldPos[3*a+2] - oldPos[3*b+2];
471 <
472 <          rxab = rxab - info->box_x * copysign(1, rxab)
473 <            * int(rxab / info->box_x + 0.5);
474 <          ryab = ryab - info->box_y * copysign(1, ryab)
475 <            * int(ryab / info->box_y + 0.5);
476 <          rzab = rzab - info->box_z * copysign(1, rzab)
477 <            * int(rzab / info->box_z + 0.5);
493 >        if (fabs(diffsq) > (tol*rabsq*2)) {
494 >          rab[0] = oldPos[ax] - oldPos[bx];
495 >          rab[1] = oldPos[ay] - oldPos[by];
496 >          rab[2] = oldPos[az] - oldPos[bz];
497  
498 <          rpab = rxab * pxab + ryab * pyab + rzab * pzab;
498 >          info->wrapVector( rab );
499 >
500 >          rpab = rab[0] * pab[0] + rab[1] * pab[1] + rab[2] * pab[2];
501 >
502            rpabsq = rpab * rpab;
503  
504  
505            if (rpabsq < (rabsq * -diffsq)){
506 +
507   #ifdef IS_MPI
508              a = atoms[a]->getGlobalIndex();
509              b = atoms[b]->getGlobalIndex();
510   #endif //is_mpi
511              sprintf( painCave.errMsg,
512 <                     "Constraint failure in constrainA at atom %d and %d\n.",
512 >                     "Constraint failure in constrainA at atom %d and %d.\n",
513                       a, b );
514              painCave.isFatal = 1;
515              simError();
# Line 494 | Line 517 | void Integrator::constrainA(){
517  
518            rma = 1.0 / atoms[a]->getMass();
519            rmb = 1.0 / atoms[b]->getMass();
520 <          
520 >
521            gab = diffsq / ( 2.0 * ( rma + rmb ) * rpab );
499          dx = rxab * gab;
500          dy = ryab * gab;
501          dz = rzab * gab;
522  
523 <          pos[3*a+0] += rma * dx;
524 <          pos[3*a+1] += rma * dy;
525 <          pos[3*a+2] += rma * dz;
523 >          dx = rab[0] * gab;
524 >          dy = rab[1] * gab;
525 >          dz = rab[2] * gab;
526  
527 <          pos[3*b+0] -= rmb * dx;
528 <          pos[3*b+1] -= rmb * dy;
529 <          pos[3*b+2] -= rmb * dz;
527 >          posA[0] += rma * dx;
528 >          posA[1] += rma * dy;
529 >          posA[2] += rma * dz;
530  
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[3*a+0] += rma * dx;
516 <          vel[3*a+1] += rma * dy;
517 <          vel[3*a+2] += rma * dz;
543 >          atoms[a]->getVel( velA );
544  
545 <          vel[3*b+0] -= rmb * dx;
546 <          vel[3*b+1] -= rmb * dy;
547 <          vel[3*b+2] -= 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 538 | Line 574 | void Integrator::constrainA(){
574  
575    if( !done ){
576  
577 <    sprintf( painCae.errMsg,
577 >    sprintf( painCave.errMsg,
578               "Constraint failure in constrainA, too many iterations: %d\n",
579 <             iterations );
579 >             iteration );
580      painCave.isFatal = 1;
581      simError();
582    }
583  
584   }
585  
586 < void Integrator::constrainB( void ){
586 > template<typename T> void Integrator<T>::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 rxab, ryab, rzab;
594 <  int a, b;
593 >  double rab[3];
594 >  int a, b, ax, ay, az, bx, by, bz;
595    double rma, rmb;
596    double dx, dy, dz;
597    double rabsq, pabsq, rvab;
# Line 561 | Line 599 | void Integrator::constrainB( void ){
599    double gab;
600    int iteration;
601  
602 <  for(i=0; i<nAtom; i++){
602 >  for(i=0; i<nAtoms; i++){
603      moving[i] = 0;
604      moved[i] = 1;
605    }
606  
607    done = 0;
608 +  iteration = 0;
609    while( !done && (iteration < maxIteration ) ){
610  
611 +    done = 1;
612 +
613      for(i=0; i<nConstrained; i++){
614        
615        a = constrainedA[i];
616        b = constrainedB[i];
617  
618 +      ax = (a*3) + 0;
619 +      ay = (a*3) + 1;
620 +      az = (a*3) + 2;
621 +
622 +      bx = (b*3) + 0;
623 +      by = (b*3) + 1;
624 +      bz = (b*3) + 2;
625 +
626        if( moved[a] || moved[b] ){
578        
579        vxab = vel[3*a+0] - vel[3*b+0];
580        vyab = vel[3*a+1] - vel[3*b+1];
581        vzab = vel[3*a+2] - vel[3*b+2];
627  
628 <        rxab = pos[3*a+0] - pos[3*b+0];q
629 <        ryab = pos[3*a+1] - pos[3*b+1];
630 <        rzab = pos[3*a+2] - pos[3*b+2];
631 <        
632 <        rxab = rxab - info->box_x * copysign(1, rxab)
633 <          * int(rxab / info->box_x + 0.5);
589 <        ryab = ryab - info->box_y * copysign(1, ryab)
590 <          * int(ryab / info->box_y + 0.5);
591 <        rzab = rzab - info->box_z * copysign(1, rzab)
592 <          * int(rzab / info->box_z + 0.5);
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();
644          rmb = 1.0 / atoms[b]->getMass();
645  
646 <        rvab = rxab * vxab + ryab * vyab + rzab * vzab;
646 >        rvab = rab[0] * vxab + rab[1] * vyab + rab[2] * vzab;
647            
648 <        gab = -rvab / ( ( rma + rmb ) * constraintsDsqr[i] );
648 >        gab = -rvab / ( ( rma + rmb ) * constrainedDsqr[i] );
649  
650          if (fabs(gab) > tol) {
651            
652 <          dx = rxab * gab;
653 <          dy = ryab * gab;
654 <          dz = rzab * gab;
655 <          
656 <          vel[3*a+0] += rma * dx;
657 <          vel[3*a+1] += rma * dy;
658 <          vel[3*a+2] += rma * dz;
652 >          dx = rab[0] * gab;
653 >          dy = rab[1] * gab;
654 >          dz = rab[2] * gab;
655 >        
656 >          velA[0] += rma * dx;
657 >          velA[1] += rma * dy;
658 >          velA[2] += rma * dz;
659  
660 <          vel[3*b+0] -= rmb * dx;
661 <          vel[3*b+1] -= rmb * dy;
662 <          vel[3*b+2] -= 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 626 | Line 679 | void Integrator::constrainB( void ){
679      
680      iteration++;
681    }
682 <
682 >  
683    if( !done ){
684  
685    
686 <    sprintf( painCae.errMsg,
686 >    sprintf( painCave.errMsg,
687               "Constraint failure in constrainB, too many iterations: %d\n",
688 <             iterations );
688 >             iteration );
689      painCave.isFatal = 1;
690      simError();
691    }
692  
693   }
694  
695 <
643 <
644 <
645 <
646 <
647 <
648 < void Integrator::rotate( int axes1, int axes2, double angle, double ji[3],
695 > template<typename T> void Integrator<T>::rotate( int axes1, int axes2, double angle, double ji[3],
696                           double A[3][3] ){
697  
698    int i,j,k;
# Line 713 | Line 760 | void Integrator::rotate( int axes1, int axes2, double
760    //            A[][] = A[][] * transpose(rot[][])
761  
762  
763 <  // NOte for as yet unknown reason, we are setting the performing the
763 >  // NOte for as yet unknown reason, we are performing the
764    // calculation as:
765    //                transpose(A[][]) = transpose(A[][]) * transpose(rot[][])
766  
# Line 726 | Line 773 | void Integrator::rotate( int axes1, int axes2, double
773      }
774    }
775   }
776 +
777 + template<typename T> void Integrator<T>::calcForce( int calcPot, int calcStress ){
778 +   myFF->doForces(calcPot,calcStress);
779 +  
780 + }
781 +
782 + template<typename T> void Integrator<T>::thermalize(){
783 +  tStats->velocitize();  
784 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines