ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/integrators/LDForceManager.cpp
(Generate patch)

Comparing trunk/src/integrators/LDForceManager.cpp (file contents):
Revision 1216 by xsun, Wed Jan 23 21:22:50 2008 UTC vs.
Revision 1237 by gezelter, Fri Apr 18 16:55:15 2008 UTC

# Line 49 | Line 49 | namespace oopse {
49  
50   namespace oopse {
51  
52 <  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
52 >  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info), forceTolerance_(1e-6), maxIterNum_(4) {
53      simParams = info->getSimParams();
54      veloMunge = new Velocitizer(info);
55  
# Line 117 | Line 117 | namespace oopse {
117          hydroPropMap = parseFrictionFile(simParams->getHydroPropFile());
118        } else {              
119          sprintf( painCave.errMsg,
120 <                 "HydroPropFile must be set to a file name if Langevin\n"
121 <                 "\tDynamics is specified for rigidBodies which contain more\n"
122 <                 "\tthan one atom.  To create a HydroPropFile, run \"Hydro\".\n");
120 >                 "HydroPropFile must be set to a file name if Langevin Dynamics\n"
121 >                 "\tis specified for rigidBodies which contain more than one atom\n"
122 >                 "\tTo create a HydroPropFile, run the \"Hydro\" program.\n");
123          painCave.severity = OOPSE_ERROR;
124          painCave.isFatal = 1;
125          simError();  
# Line 198 | Line 198 | namespace oopse {
198                    }      
199                  }
200                } else {
201 <                int obanum = etab.GetAtomicNum((atom->getType()).c_str());
202 <                if (obanum != 0) {
203 <                  currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum));
201 >                int aNum = etab.GetAtomicNum((atom->getType()).c_str());
202 >                if (aNum != 0) {
203 >                  currShape = new Sphere(atom->getPos(), etab.GetVdwRad(aNum));
204                  } else {
205                    sprintf( painCave.errMsg,
206                             "Could not find atom type in default element.txt\n");
# Line 249 | Line 249 | namespace oopse {
249      Molecule* mol;
250      StuntDouble* integrableObject;
251      RealType mass;
252    Vector3d vel;
252      Vector3d pos;
253      Vector3d frc;
254      Mat3x3d A;
# Line 261 | Line 260 | namespace oopse {
260      bool freezeMolecule;
261      int fdf;
262  
264
265
263      fdf = 0;
264  
265      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
# Line 294 | Line 291 | namespace oopse {
291            fdf += integrableObject->freeze();
292          
293          if (doLangevinForces) {  
297          vel =integrableObject->getVel();
294            mass = integrableObject->getMass();
295            if (integrableObject->isDirectional()){
300            Mat3x3d I = integrableObject->getI();
301            Vector3d angMom = integrableObject->getJ();
302            A = integrableObject->getA();
303            Atrans = A.transpose();
296  
297 <            Vector3d omegaBody;
306 <            
307 <            if (integrableObject->isLinear()) {
308 <              int linearAxis = integrableObject->linearAxis();
309 <              int l = (linearAxis +1 )%3;
310 <              int m = (linearAxis +2 )%3;
311 <              omegaBody[l] = angMom[l] /I(l, l);
312 <              omegaBody[m] = angMom[m] /I(m, m);
313 <              
314 <            } else {
315 <              omegaBody[0] = angMom[0] /I(0, 0);
316 <              omegaBody[1] = angMom[1] /I(1, 1);
317 <              omegaBody[2] = angMom[2] /I(2, 2);
318 <            }
297 >            // preliminaries for directional objects:
298  
299 <            Vector3d omegaLab = Atrans * omegaBody;
300 <
301 <            // apply friction force and torque at center of resistance
323 <
324 <            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
325 <            Vector3d vcdLab = vel + cross(omegaLab, rcrLab);
326 <        
327 <            Vector3d vcdBody = A * vcdLab;
328 <            Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody);
299 >            A = integrableObject->getA();
300 >            Atrans = A.transpose();
301 >            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
302  
330            Vector3d frictionForceLab = Atrans * frictionForceBody;
331            integrableObject->addFrc(frictionForceLab);
332            Vector3d frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody);
333            Vector3d frictionTorqueLab = Atrans * frictionTorqueBody;
334            integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab));
335
303              //apply random force and torque at center of resistance
304 +
305              Vector3d randomForceBody;
306              Vector3d randomTorqueBody;
307              genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
# Line 341 | Line 309 | namespace oopse {
309              Vector3d randomTorqueLab = Atrans * randomTorqueBody;
310              integrableObject->addFrc(randomForceLab);            
311              integrableObject->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab ));            
312 +
313 +            Mat3x3d I = integrableObject->getI();
314 +            Vector3d omegaBody;
315 +
316 +            // What remains contains velocity explicitly, but the velocity required
317 +            // is at the full step: v(t + h), while we have initially the velocity
318 +            // at the half step: v(t + h/2).  We need to iterate to converge the
319 +            // friction force and friction torque vectors.
320 +
321 +            // this is the velocity at the half-step:
322 +            
323 +            Vector3d vel =integrableObject->getVel();
324 +            Vector3d angMom = integrableObject->getJ();
325 +
326 +            //estimate velocity at full-step using everything but friction forces:          
327 +
328 +            frc = integrableObject->getFrc();
329 +            Vector3d velStep = vel + (dt2_ /mass * OOPSEConstant::energyConvert) * frc;
330 +
331 +            Tb = integrableObject->lab2Body(integrableObject->getTrq());
332 +            Vector3d angMomStep = angMom + (dt2_ * OOPSEConstant::energyConvert) * Tb;                            
333 +
334 +            Vector3d omegaLab;
335 +            Vector3d vcdLab;
336 +            Vector3d vcdBody;
337 +            Vector3d frictionForceBody;
338 +            Vector3d frictionForceLab(0.0);
339 +            Vector3d oldFFL;  // used to test for convergence
340 +            Vector3d frictionTorqueBody(0.0);
341 +            Vector3d oldFTB;  // used to test for convergence
342 +            Vector3d frictionTorqueLab;
343 +            RealType fdot;
344 +            RealType tdot;
345 +
346 +            //iteration starts here:
347 +
348 +            for (int k = 0; k < maxIterNum_; k++) {
349 +                            
350 +              if (integrableObject->isLinear()) {
351 +                int linearAxis = integrableObject->linearAxis();
352 +                int l = (linearAxis +1 )%3;
353 +                int m = (linearAxis +2 )%3;
354 +                omegaBody[l] = angMomStep[l] /I(l, l);
355 +                omegaBody[m] = angMomStep[m] /I(m, m);
356 +                
357 +              } else {
358 +                omegaBody[0] = angMomStep[0] /I(0, 0);
359 +                omegaBody[1] = angMomStep[1] /I(1, 1);
360 +                omegaBody[2] = angMomStep[2] /I(2, 2);
361 +              }
362 +              
363 +              omegaLab = Atrans * omegaBody;
364 +              
365 +              // apply friction force and torque at center of resistance
366 +              
367 +              vcdLab = velStep + cross(omegaLab, rcrLab);      
368 +              vcdBody = A * vcdLab;
369 +              frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody);
370 +              oldFFL = frictionForceLab;
371 +              frictionForceLab = Atrans * frictionForceBody;
372 +              oldFTB = frictionTorqueBody;
373 +              frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody);
374 +              frictionTorqueLab = Atrans * frictionTorqueBody;
375 +              
376 +              // re-estimate velocities at full-step using friction forces:
377 +              
378 +              velStep = vel + (dt2_ / mass * OOPSEConstant::energyConvert) * (frc + frictionForceLab);
379 +              angMomStep = angMom + (dt2_ * OOPSEConstant::energyConvert) * (Tb + frictionTorqueBody);
380 +
381 +              // check for convergence (if the vectors have converged, fdot and tdot will both be 1.0):
382 +              
383 +              fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare();
384 +              tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare();
385 +              
386 +              if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_)
387 +                break; // iteration ends here
388 +            }
389 +
390 +            integrableObject->addFrc(frictionForceLab);
391 +            integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab));
392 +
393              
394            } else {
395              //spherical atom
396 <            Vector3d frictionForce = -(hydroProps_[index]->getXitt() * vel);
396 >
397              Vector3d randomForce;
398              Vector3d randomTorque;
399              genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
400 +            integrableObject->addFrc(randomForce);            
401 +
402 +            // What remains contains velocity explicitly, but the velocity required
403 +            // is at the full step: v(t + h), while we have initially the velocity
404 +            // at the half step: v(t + h/2).  We need to iterate to converge the
405 +            // friction force vector.
406 +
407 +            // this is the velocity at the half-step:
408              
409 <            integrableObject->addFrc(frictionForce+randomForce);            
409 >            Vector3d vel =integrableObject->getVel();
410 >
411 >            //estimate velocity at full-step using everything but friction forces:          
412 >
413 >            frc = integrableObject->getFrc();
414 >            Vector3d velStep = vel + (dt2_ / mass * OOPSEConstant::energyConvert) * frc;
415 >
416 >            Vector3d frictionForce(0.0);
417 >            Vector3d oldFF;  // used to test for convergence
418 >            RealType fdot;
419 >
420 >            //iteration starts here:
421 >
422 >            for (int k = 0; k < maxIterNum_; k++) {
423 >
424 >              oldFF = frictionForce;                            
425 >              frictionForce = -hydroProps_[index]->getXitt() * velStep;
426 >
427 >              // re-estimate velocities at full-step using friction forces:
428 >              
429 >              velStep = vel + (dt2_ / mass * OOPSEConstant::energyConvert) * (frc + frictionForce);
430 >
431 >              // check for convergence (if the vector has converged, fdot will be 1.0):
432 >              
433 >              fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare();
434 >              
435 >              if (fabs(1.0 - fdot) <= forceTolerance_)
436 >                break; // iteration ends here
437 >            }
438 >
439 >            integrableObject->addFrc(frictionForce);
440 >
441            }
442          }
443            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines