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

Comparing trunk/src/integrators/LDForceManager.cpp (file contents):
Revision 1185 by xsun, Fri Oct 5 19:02:09 2007 UTC vs.
Revision 1610 by gezelter, Fri Aug 12 14:37:25 2011 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41   #include <fstream>
42   #include <iostream>
43   #include "integrators/LDForceManager.hpp"
44   #include "math/CholeskyDecomposition.hpp"
45 < #include "utils/OOPSEConstant.hpp"
45 > #include "utils/PhysicalConstants.hpp"
46   #include "hydrodynamics/Sphere.hpp"
47   #include "hydrodynamics/Ellipsoid.hpp"
48 < #include "openbabel/mol.hpp"
48 > #include "utils/ElementsTable.hpp"
49  
50 < using namespace OpenBabel;
51 < namespace oopse {
50 > namespace OpenMD {
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 63 | Line 62 | namespace oopse {
62          sprintf( painCave.errMsg,
63                   "langevinBufferRadius must be specified "
64                   "when useSphericalBoundaryConditions is turned on.\n");
65 <        painCave.severity = OOPSE_ERROR;
65 >        painCave.severity = OPENMD_ERROR;
66          painCave.isFatal = 1;
67          simError();  
68        }
# Line 74 | Line 73 | namespace oopse {
73          sprintf( painCave.errMsg,
74                   "frozenBufferRadius must be specified "
75                   "when useSphericalBoundaryConditions is turned on.\n");
76 <        painCave.severity = OOPSE_ERROR;
76 >        painCave.severity = OPENMD_ERROR;
77          painCave.isFatal = 1;
78          simError();  
79        }
# Line 83 | Line 82 | namespace oopse {
82          sprintf( painCave.errMsg,
83                   "frozenBufferRadius has been set smaller than the "
84                   "langevinBufferRadius.  This is probably an error.\n");
85 <        painCave.severity = OOPSE_WARNING;
85 >        painCave.severity = OPENMD_WARNING;
86          painCave.isFatal = 0;
87          simError();  
88        }
# Line 118 | 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");
123 <        painCave.severity = OOPSE_ERROR;
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 = OPENMD_ERROR;
124          painCave.isFatal = 1;
125          simError();  
126        }      
# Line 138 | Line 137 | namespace oopse {
137            } else {
138              sprintf( painCave.errMsg,
139                       "Can not find resistance tensor for atom [%s]\n", integrableObject->getType().c_str());
140 <            painCave.severity = OOPSE_ERROR;
140 >            painCave.severity = OPENMD_ERROR;
141              painCave.isFatal = 1;
142              simError();  
143            }        
# Line 165 | Line 164 | namespace oopse {
164                  
165                  if (gayBerneData != NULL) {  
166                    GayBerneParam gayBerneParam = gayBerneData->getData();
167 <                  currShape = new Ellipsoid(V3Zero,
167 >                  currShape = new Ellipsoid(V3Zero,
168                                              gayBerneParam.GB_l / 2.0,
169                                              gayBerneParam.GB_d / 2.0,
170                                              Mat3x3d::identity());
171                  } else {
172                    sprintf( painCave.errMsg,
173                             "Can not cast GenericData to GayBerneParam\n");
174 <                  painCave.severity = OOPSE_ERROR;
174 >                  painCave.severity = OPENMD_ERROR;
175                    painCave.isFatal = 1;
176                    simError();  
177                  }
178                } else {
179                  sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n");
180 <                painCave.severity = OOPSE_ERROR;
180 >                painCave.severity = OPENMD_ERROR;
181                  painCave.isFatal = 1;
182                  simError();    
183                }
# Line 193 | Line 192 | namespace oopse {
192                    } else {
193                      sprintf( painCave.errMsg,
194                               "Can not cast GenericData to LJParam\n");
195 <                    painCave.severity = OOPSE_ERROR;
195 >                    painCave.severity = OPENMD_ERROR;
196                      painCave.isFatal = 1;
197                      simError();          
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");
207 <                  painCave.severity = OOPSE_ERROR;
207 >                  painCave.severity = OPENMD_ERROR;
208                    painCave.isFatal = 1;
209                    simError();          
210                  }
211                }
212              }
213            }
214 +
215 +          if (!simParams->haveTargetTemp()) {
216 +            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a targetTemp!\n");
217 +            painCave.isFatal = 1;
218 +            painCave.severity = OPENMD_ERROR;
219 +            simError();
220 +          }
221 +
222 +          if (!simParams->haveViscosity()) {
223 +            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a viscosity!\n");
224 +            painCave.isFatal = 1;
225 +            painCave.severity = OPENMD_ERROR;
226 +            simError();
227 +          }
228 +
229            HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp());
230 +
231            std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
232            if (iter != hydroPropMap.end())
233              hydroProps_.push_back(iter->second);
# Line 224 | Line 239 | namespace oopse {
239          }
240        }
241      }
242 <    variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
242 >    variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt();
243    }  
244  
245    std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) {
# Line 244 | Line 259 | namespace oopse {
259      return props;
260    }
261    
262 <  void LDForceManager::postCalculation(bool needStress){
262 >  void LDForceManager::postCalculation(){
263      SimInfo::MoleculeIterator i;
264      Molecule::IntegrableObjectIterator  j;
265      Molecule* mol;
266      StuntDouble* integrableObject;
267      RealType mass;
253    Vector3d vel;
268      Vector3d pos;
269      Vector3d frc;
270      Mat3x3d A;
# Line 262 | Line 276 | namespace oopse {
276      bool freezeMolecule;
277      int fdf;
278  
265
266
279      fdf = 0;
280  
281      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
# Line 295 | Line 307 | namespace oopse {
307            fdf += integrableObject->freeze();
308          
309          if (doLangevinForces) {  
298          vel =integrableObject->getVel();
310            mass = integrableObject->getMass();
311            if (integrableObject->isDirectional()){
301            //calculate angular velocity in lab frame
302            Mat3x3d I = integrableObject->getI();
303            Vector3d angMom = integrableObject->getJ();
304            Vector3d omega;
305            
306            if (integrableObject->isLinear()) {
307              int linearAxis = integrableObject->linearAxis();
308              int l = (linearAxis +1 )%3;
309              int m = (linearAxis +2 )%3;
310              omega[l] = angMom[l] /I(l, l);
311              omega[m] = angMom[m] /I(m, m);
312              
313            } else {
314              omega[0] = angMom[0] /I(0, 0);
315              omega[1] = angMom[1] /I(1, 1);
316              omega[2] = angMom[2] /I(2, 2);
317            }
312  
313 <            //std::cerr << "I = " << I(0,0) << "\t" << I(1,1) << "\t" << I(2,2) << "\n\n";
313 >            // preliminaries for directional objects:
314  
321            //apply friction force and torque at center of resistance
315              A = integrableObject->getA();
316              Atrans = A.transpose();
317 <            //std::cerr << "A = " << integrableObject->getA() << "\n";
325 <            //std::cerr << "Atrans = " << A.transpose() << "\n\n";
326 <            Vector3d rcr = Atrans * hydroProps_[index]->getCOR();  
327 <            //std::cerr << "cor = " << hydroProps_[index]->getCOR() << "\n\n\n\n";
328 <            //std::cerr << "rcr = " << rcr << "\n\n";
329 <            Vector3d vcdLab = vel + cross(omega, rcr);
330 <        
331 <            //std::cerr << "velL = " << vel << "\n\n";
332 <            //std::cerr << "vcdL = " << vcdLab << "\n\n";
333 <            Vector3d vcdBody = A* vcdLab;
334 <            //std::cerr << "vcdB = " << vcdBody << "\n\n";
335 <            Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omega);
317 >            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
318  
337            //std::cerr << "xitt = " << hydroProps_[index]->getXitt() << "\n\n";
338            //std::cerr << "ffB = " << frictionForceBody << "\n\n";
339            Vector3d frictionForceLab = Atrans*frictionForceBody;
340            //std::cerr << "ffL = " << frictionForceLab << "\n\n";
341            //std::cerr << "frc = " << integrableObject->getFrc() << "\n\n";
342            integrableObject->addFrc(frictionForceLab);
343            //std::cerr << "frc = " << integrableObject->getFrc() << "\n\n";
344            //std::cerr << "ome = " << omega << "\n\n";
345            Vector3d frictionTorqueBody = - (hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omega);
346            //std::cerr << "ftB = " << frictionTorqueBody << "\n\n";
347            Vector3d frictionTorqueLab = Atrans*frictionTorqueBody;
348            //std::cerr << "ftL = " << frictionTorqueLab << "\n\n";
349            //std::cerr << "ftL2 = " << frictionTorqueLab+cross(rcr,frictionForceLab) << "\n\n";
350            //std::cerr << "trq = " << integrableObject->getTrq() << "\n\n";
351            integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab));
352            //std::cerr << "trq = " << integrableObject->getTrq() << "\n\n";
353
319              //apply random force and torque at center of resistance
320 +
321              Vector3d randomForceBody;
322              Vector3d randomTorqueBody;
323              genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
324 <            //std::cerr << "rfB = " << randomForceBody << "\n\n";
325 <            //std::cerr << "rtB = " << randomTorqueBody << "\n\n";
326 <            Vector3d randomForceLab = Atrans*randomForceBody;
361 <            Vector3d randomTorqueLab = Atrans* randomTorqueBody;
324 >            Vector3d randomForceLab = Atrans * randomForceBody;
325 >            Vector3d randomTorqueLab = Atrans * randomTorqueBody;
326 >
327              integrableObject->addFrc(randomForceLab);            
328 <            //std::cerr << "rfL = " << randomForceLab << "\n\n";
329 <            //std::cerr << "rtL = " << randomTorqueLab << "\n\n";
330 <            //std::cerr << "rtL2 = " << randomTorqueLab + cross(rcr, randomForceLab) << "\n\n";
331 <            integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab ));            
328 >            integrableObject->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab ));            
329 >
330 >            Mat3x3d I = integrableObject->getI();
331 >            Vector3d omegaBody;
332 >
333 >            // What remains contains velocity explicitly, but the velocity required
334 >            // is at the full step: v(t + h), while we have initially the velocity
335 >            // at the half step: v(t + h/2).  We need to iterate to converge the
336 >            // friction force and friction torque vectors.
337 >
338 >            // this is the velocity at the half-step:
339              
340 +            Vector3d vel =integrableObject->getVel();
341 +            Vector3d angMom = integrableObject->getJ();
342 +
343 +            //estimate velocity at full-step using everything but friction forces:          
344 +
345 +            frc = integrableObject->getFrc();
346 +            Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc;
347 +
348 +            Tb = integrableObject->lab2Body(integrableObject->getTrq());
349 +            Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb;                            
350 +
351 +            Vector3d omegaLab;
352 +            Vector3d vcdLab;
353 +            Vector3d vcdBody;
354 +            Vector3d frictionForceBody;
355 +            Vector3d frictionForceLab(0.0);
356 +            Vector3d oldFFL;  // used to test for convergence
357 +            Vector3d frictionTorqueBody(0.0);
358 +            Vector3d oldFTB;  // used to test for convergence
359 +            Vector3d frictionTorqueLab;
360 +            RealType fdot;
361 +            RealType tdot;
362 +
363 +            //iteration starts here:
364 +
365 +            for (int k = 0; k < maxIterNum_; k++) {
366 +                            
367 +              if (integrableObject->isLinear()) {
368 +                int linearAxis = integrableObject->linearAxis();
369 +                int l = (linearAxis +1 )%3;
370 +                int m = (linearAxis +2 )%3;
371 +                omegaBody[l] = angMomStep[l] /I(l, l);
372 +                omegaBody[m] = angMomStep[m] /I(m, m);
373 +                
374 +              } else {
375 +                omegaBody[0] = angMomStep[0] /I(0, 0);
376 +                omegaBody[1] = angMomStep[1] /I(1, 1);
377 +                omegaBody[2] = angMomStep[2] /I(2, 2);
378 +              }
379 +              
380 +              omegaLab = Atrans * omegaBody;
381 +              
382 +              // apply friction force and torque at center of resistance
383 +              
384 +              vcdLab = velStep + cross(omegaLab, rcrLab);      
385 +              vcdBody = A * vcdLab;
386 +              frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody);
387 +              oldFFL = frictionForceLab;
388 +              frictionForceLab = Atrans * frictionForceBody;
389 +              oldFTB = frictionTorqueBody;
390 +              frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody);
391 +              frictionTorqueLab = Atrans * frictionTorqueBody;
392 +              
393 +              // re-estimate velocities at full-step using friction forces:
394 +              
395 +              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab);
396 +              angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody);
397 +
398 +              // check for convergence (if the vectors have converged, fdot and tdot will both be 1.0):
399 +              
400 +              fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare();
401 +              tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare();
402 +              
403 +              if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_)
404 +                break; // iteration ends here
405 +            }
406 +
407 +            integrableObject->addFrc(frictionForceLab);
408 +            integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab));
409 +
410 +            
411            } else {
412              //spherical atom
413 <            Vector3d frictionForce = -(hydroProps_[index]->getXitt() * vel);
371 <            //std::cerr << "xitt = " << hydroProps_[index]->getXitt() << "\n\n";
413 >
414              Vector3d randomForce;
415              Vector3d randomTorque;
416              genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
417 +            integrableObject->addFrc(randomForce);            
418 +
419 +            // What remains contains velocity explicitly, but the velocity required
420 +            // is at the full step: v(t + h), while we have initially the velocity
421 +            // at the half step: v(t + h/2).  We need to iterate to converge the
422 +            // friction force vector.
423 +
424 +            // this is the velocity at the half-step:
425              
426 <            integrableObject->addFrc(frictionForce+randomForce);            
426 >            Vector3d vel =integrableObject->getVel();
427 >
428 >            //estimate velocity at full-step using everything but friction forces:          
429 >
430 >            frc = integrableObject->getFrc();
431 >            Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc;
432 >
433 >            Vector3d frictionForce(0.0);
434 >            Vector3d oldFF;  // used to test for convergence
435 >            RealType fdot;
436 >
437 >            //iteration starts here:
438 >
439 >            for (int k = 0; k < maxIterNum_; k++) {
440 >
441 >              oldFF = frictionForce;                            
442 >              frictionForce = -hydroProps_[index]->getXitt() * velStep;
443 >
444 >              // re-estimate velocities at full-step using friction forces:
445 >              
446 >              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce);
447 >
448 >              // check for convergence (if the vector has converged, fdot will be 1.0):
449 >              
450 >              fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare();
451 >              
452 >              if (fabs(1.0 - fdot) <= forceTolerance_)
453 >                break; // iteration ends here
454 >            }
455 >
456 >            integrableObject->addFrc(frictionForce);
457 >
458            }
459          }
460            
# Line 388 | Line 469 | namespace oopse {
469      if(!simParams->getUsePeriodicBoundaryConditions())
470        veloMunge->removeAngularDrift();
471  
472 <    ForceManager::postCalculation(needStress);  
472 >    ForceManager::postCalculation();  
473    }
474  
475   void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) {
# Line 400 | Line 481 | void LDForceManager::genRandomForceAndTorque(Vector3d&
481      Z[0] = randNumGen_.randNorm(0, variance);
482      Z[1] = randNumGen_.randNorm(0, variance);
483      Z[2] = randNumGen_.randNorm(0, variance);
403    //Z[3] = randNumGen_.randNorm(0, variance)*(2.0*M_PI);
404    //Z[4] = randNumGen_.randNorm(0, variance)*(2.0*M_PI);
405    //Z[5] = randNumGen_.randNorm(0, variance)*(2.0*M_PI);
484      Z[3] = randNumGen_.randNorm(0, variance);
485      Z[4] = randNumGen_.randNorm(0, variance);
486      Z[5] = randNumGen_.randNorm(0, variance);
487      
410
488      generalForce = hydroProps_[index]->getS()*Z;
489      
490      force[0] = generalForce[0];

Comparing trunk/src/integrators/LDForceManager.cpp (property svn:keywords):
Revision 1185 by xsun, Fri Oct 5 19:02:09 2007 UTC vs.
Revision 1610 by gezelter, Fri Aug 12 14:37:25 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines