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 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 1237 by gezelter, Fri Apr 18 16:55:15 2008 UTC

# Line 39 | Line 39
39   * such damages.
40   */
41   #include <fstream>
42 + #include <iostream>
43   #include "integrators/LDForceManager.hpp"
44   #include "math/CholeskyDecomposition.hpp"
45   #include "utils/OOPSEConstant.hpp"
46   #include "hydrodynamics/Sphere.hpp"
47   #include "hydrodynamics/Ellipsoid.hpp"
48 < #include "openbabel/mol.hpp"
48 > #include "utils/ElementsTable.hpp"
49  
49 using namespace OpenBabel;
50   namespace oopse {
51  
52 <  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
53 <    Globals* simParams = info->getSimParams();
54 <        
52 >  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info), forceTolerance_(1e-6), maxIterNum_(4) {
53 >    simParams = info->getSimParams();
54 >    veloMunge = new Velocitizer(info);
55 >
56      sphericalBoundaryConditions_ = false;
57      if (simParams->getUseSphericalBoundaryConditions()) {
58        sphericalBoundaryConditions_ = true;
# Line 88 | Line 89 | namespace oopse {
89      }
90  
91      // Build the hydroProp map:
92 <    std::map<std::string, HydroProp> hydroPropMap;
92 >    std::map<std::string, HydroProp*> hydroPropMap;
93  
94      Molecule* mol;
95      StuntDouble* integrableObject;
# Line 116 | 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();  
126        }      
127 <      std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
128 <      if (iter != hydroPropMap.end()) {
129 <        hydroProps_.push_back(iter->second);
130 <      } else {
131 <        sprintf( painCave.errMsg,
132 <                 "Can not find resistance tensor for atom [%s]\n", integrableObject->getType().c_str());
133 <        painCave.severity = OOPSE_ERROR;
134 <        painCave.isFatal = 1;
135 <        simError();  
127 >
128 >      for (mol = info->beginMolecule(i); mol != NULL;
129 >           mol = info->nextMolecule(i)) {
130 >        for (integrableObject = mol->beginIntegrableObject(j);
131 >             integrableObject != NULL;
132 >             integrableObject = mol->nextIntegrableObject(j)) {
133 >
134 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
135 >          if (iter != hydroPropMap.end()) {
136 >            hydroProps_.push_back(iter->second);
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;
141 >            painCave.isFatal = 1;
142 >            simError();  
143 >          }        
144 >        }
145        }
146      } else {
147 <
148 <      std::map<std::string, HydroProp> hydroPropMap;
147 >      
148 >      std::map<std::string, HydroProp*> hydroPropMap;
149        for (mol = info->beginMolecule(i); mol != NULL;
150             mol = info->nextMolecule(i)) {
151          for (integrableObject = mol->beginIntegrableObject(j);
152               integrableObject != NULL;
153               integrableObject = mol->nextIntegrableObject(j)) {
154            Shape* currShape = NULL;
155 <          if (integrableObject->isDirectionalAtom()) {
156 <            DirectionalAtom* dAtom = static_cast<DirectionalAtom*>(integrableObject);
157 <            AtomType* atomType = dAtom->getAtomType();
155 >
156 >          if (integrableObject->isAtom()){
157 >            Atom* atom = static_cast<Atom*>(integrableObject);
158 >            AtomType* atomType = atom->getAtomType();
159              if (atomType->isGayBerne()) {
160 <              DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
150 <              
160 >              DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);              
161                GenericData* data = dAtomType->getPropertyByName("GayBerne");
162                if (data != NULL) {
163                  GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
# Line 155 | Line 165 | namespace oopse {
165                  if (gayBerneData != NULL) {  
166                    GayBerneParam gayBerneParam = gayBerneData->getData();
167                    currShape = new Ellipsoid(V3Zero,
168 <                                            gayBerneParam.GB_sigma/2.0,
169 <                                            gayBerneParam.GB_l2b_ratio*gayBerneParam.GB_sigma/2.0,
168 >                                            gayBerneParam.GB_l / 2.0,
169 >                                            gayBerneParam.GB_d / 2.0,
170                                              Mat3x3d::identity());
171                  } else {
172                    sprintf( painCave.errMsg,
# Line 171 | Line 181 | namespace oopse {
181                  painCave.isFatal = 1;
182                  simError();    
183                }
184 <            }
185 <          } else {
186 <            Atom* atom = static_cast<Atom*>(integrableObject);
187 <            AtomType* atomType = atom->getAtomType();
188 <            if (atomType->isLennardJones()){
189 <              GenericData* data = atomType->getPropertyByName("LennardJones");
190 <              if (data != NULL) {
191 <                LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
192 <                
193 <                if (ljData != NULL) {
194 <                  LJParam ljParam = ljData->getData();
195 <                  currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0);
184 >            } else {
185 >              if (atomType->isLennardJones()){
186 >                GenericData* data = atomType->getPropertyByName("LennardJones");
187 >                if (data != NULL) {
188 >                  LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
189 >                  if (ljData != NULL) {
190 >                    LJParam ljParam = ljData->getData();
191 >                    currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0);
192 >                  } else {
193 >                    sprintf( painCave.errMsg,
194 >                             "Can not cast GenericData to LJParam\n");
195 >                    painCave.severity = OOPSE_ERROR;
196 >                    painCave.isFatal = 1;
197 >                    simError();          
198 >                  }      
199 >                }
200 >              } else {
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 <                           "Can not cast GenericData to LJParam\n");
206 >                           "Could not find atom type in default element.txt\n");
207                    painCave.severity = OOPSE_ERROR;
208                    painCave.isFatal = 1;
209                    simError();          
210 <                }      
193 <              }
194 <            } else {
195 <              int obanum = etab.GetAtomicNum((atom->getType()).c_str());
196 <              if (obanum != 0) {
197 <                currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum));
198 <              } else {
199 <                sprintf( painCave.errMsg,
200 <                         "Could not find atom type in default element.txt\n");
201 <                painCave.severity = OOPSE_ERROR;
202 <                painCave.isFatal = 1;
203 <                simError();          
210 >                }
211                }
212              }
213            }
214 <          HydroProps currHydroProp = currShape->getHydroProps(simParams->getViscosity(),simParams->getTargetTemp());
215 <          std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
214 >          HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp());
215 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
216            if (iter != hydroPropMap.end())
217              hydroProps_.push_back(iter->second);
218            else {
219 <            HydroProp myProp;
220 <            myProp.cor = V3Zero;
221 <            for (int i1 = 0; i1 < 3; i1++) {
215 <              for (int j1 = 0; j1 < 3; j1++) {
216 <                myProp.Xirtt(i1,j1) = currHydroProp.Xi(i1,j1);
217 <                myProp.Xirrt(i1,j1) = currHydroProp.Xi(i1,j1+3);
218 <                myProp.Xirtr(i1,j1) = currHydroProp.Xi(i1+3,j1);
219 <                myProp.Xirrr(i1,j1) = currHydroProp.Xi(i1+3,j1+3);
220 <              }
221 <            }
222 <            CholeskyDecomposition(currHydroProp.Xi, myProp.S);
223 <            hydroPropMap.insert(std::map<std::string, HydroProp>::value_type(integrableObject->getType(), myProp));
224 <            hydroProps_.push_back(myProp);
219 >            currHydroProp->complete();
220 >            hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp));
221 >            hydroProps_.push_back(currHydroProp);
222            }
223          }
224        }
225      }
226      variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
227 <  }
231 <  
232 <  
227 >  }  
228  
229 <
230 <
236 <  std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) {
237 <    std::map<std::string, HydroProp> props;
229 >  std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) {
230 >    std::map<std::string, HydroProp*> props;
231      std::ifstream ifs(filename.c_str());
232      if (ifs.is_open()) {
233        
# Line 243 | Line 236 | namespace oopse {
236      const unsigned int BufferSize = 65535;
237      char buffer[BufferSize];  
238      while (ifs.getline(buffer, BufferSize)) {
239 <      StringTokenizer tokenizer(buffer);
240 <      HydroProp currProp;
248 <      if (tokenizer.countTokens() >= 40) {
249 <        std::string atomName = tokenizer.nextToken();
250 <        currProp.cor[0] = tokenizer.nextTokenAsDouble();
251 <        currProp.cor[1] = tokenizer.nextTokenAsDouble();
252 <        currProp.cor[2] = tokenizer.nextTokenAsDouble();
253 <        
254 <        currProp.Xirtt(0,0) = tokenizer.nextTokenAsDouble();
255 <        currProp.Xirtt(0,1) = tokenizer.nextTokenAsDouble();
256 <        currProp.Xirtt(0,2) = tokenizer.nextTokenAsDouble();
257 <        currProp.Xirtt(1,0) = tokenizer.nextTokenAsDouble();
258 <        currProp.Xirtt(1,1) = tokenizer.nextTokenAsDouble();
259 <        currProp.Xirtt(1,2) = tokenizer.nextTokenAsDouble();
260 <        currProp.Xirtt(2,0) = tokenizer.nextTokenAsDouble();
261 <        currProp.Xirtt(2,1) = tokenizer.nextTokenAsDouble();
262 <        currProp.Xirtt(2,2) = tokenizer.nextTokenAsDouble();
263 <        
264 <        currProp.Xirrt(0,0) = tokenizer.nextTokenAsDouble();
265 <        currProp.Xirrt(0,1) = tokenizer.nextTokenAsDouble();
266 <        currProp.Xirrt(0,2) = tokenizer.nextTokenAsDouble();
267 <        currProp.Xirrt(1,0) = tokenizer.nextTokenAsDouble();
268 <        currProp.Xirrt(1,1) = tokenizer.nextTokenAsDouble();
269 <        currProp.Xirrt(1,2) = tokenizer.nextTokenAsDouble();
270 <        currProp.Xirrt(2,0) = tokenizer.nextTokenAsDouble();
271 <        currProp.Xirrt(2,1) = tokenizer.nextTokenAsDouble();
272 <        currProp.Xirrt(2,2) = tokenizer.nextTokenAsDouble();
273 <        
274 <        currProp.Xirtr(0,0) = tokenizer.nextTokenAsDouble();
275 <        currProp.Xirtr(0,1) = tokenizer.nextTokenAsDouble();
276 <        currProp.Xirtr(0,2) = tokenizer.nextTokenAsDouble();
277 <        currProp.Xirtr(1,0) = tokenizer.nextTokenAsDouble();
278 <        currProp.Xirtr(1,1) = tokenizer.nextTokenAsDouble();
279 <        currProp.Xirtr(1,2) = tokenizer.nextTokenAsDouble();
280 <        currProp.Xirtr(2,0) = tokenizer.nextTokenAsDouble();
281 <        currProp.Xirtr(2,1) = tokenizer.nextTokenAsDouble();
282 <        currProp.Xirtr(2,2) = tokenizer.nextTokenAsDouble();
283 <        
284 <        currProp.Xirrr(0,0) = tokenizer.nextTokenAsDouble();
285 <        currProp.Xirrr(0,1) = tokenizer.nextTokenAsDouble();
286 <        currProp.Xirrr(0,2) = tokenizer.nextTokenAsDouble();
287 <        currProp.Xirrr(1,0) = tokenizer.nextTokenAsDouble();
288 <        currProp.Xirrr(1,1) = tokenizer.nextTokenAsDouble();
289 <        currProp.Xirrr(1,2) = tokenizer.nextTokenAsDouble();
290 <        currProp.Xirrr(2,0) = tokenizer.nextTokenAsDouble();
291 <        currProp.Xirrr(2,1) = tokenizer.nextTokenAsDouble();
292 <        currProp.Xirrr(2,2) = tokenizer.nextTokenAsDouble();
293 <        
294 <        SquareMatrix<RealType, 6> Xir;
295 <        Xir.setSubMatrix(0, 0, currProp.Xirtt);
296 <        Xir.setSubMatrix(0, 3, currProp.Xirrt);
297 <        Xir.setSubMatrix(3, 0, currProp.Xirtr);
298 <        Xir.setSubMatrix(3, 3, currProp.Xirrr);
299 <        CholeskyDecomposition(Xir, currProp.S);            
300 <        
301 <        props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp));
302 <      }
239 >      HydroProp* currProp = new HydroProp(buffer);
240 >      props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp));
241      }
242 <    
242 >
243      return props;
244    }
245 <  
246 <  void LDForceManager::postCalculation() {
245 >  
246 >  void LDForceManager::postCalculation(bool needStress){
247      SimInfo::MoleculeIterator i;
248      Molecule::IntegrableObjectIterator  j;
249      Molecule* mol;
250      StuntDouble* integrableObject;
251 <    Vector3d vel;
251 >    RealType mass;
252      Vector3d pos;
253      Vector3d frc;
254      Mat3x3d A;
255      Mat3x3d Atrans;
256      Vector3d Tb;
257      Vector3d ji;
320    RealType mass;
258      unsigned int index = 0;
259      bool doLangevinForces;
260      bool freezeMolecule;
261      int fdf;
262 <    
262 >
263      fdf = 0;
264 +
265      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
266 <      
266 >
267 >      doLangevinForces = true;          
268 >      freezeMolecule = false;
269 >
270        if (sphericalBoundaryConditions_) {
271          
272          Vector3d molPos = mol->getCom();
273          RealType molRad = molPos.length();
274 <        
274 >
275          doLangevinForces = false;
335        freezeMolecule = false;
276          
277          if (molRad > langevinBufferRadius_) {
278            doLangevinForces = true;
# Line 350 | Line 290 | namespace oopse {
290          if (freezeMolecule)
291            fdf += integrableObject->freeze();
292          
293 <        if (doLangevinForces) {          
294 <          vel =integrableObject->getVel();
293 >        if (doLangevinForces) {  
294 >          mass = integrableObject->getMass();
295            if (integrableObject->isDirectional()){
296 <            //calculate angular velocity in lab frame
297 <            Mat3x3d I = integrableObject->getI();
298 <            Vector3d angMom = integrableObject->getJ();
359 <            Vector3d omega;
360 <            
361 <            if (integrableObject->isLinear()) {
362 <              int linearAxis = integrableObject->linearAxis();
363 <              int l = (linearAxis +1 )%3;
364 <              int m = (linearAxis +2 )%3;
365 <              omega[l] = angMom[l] /I(l, l);
366 <              omega[m] = angMom[m] /I(m, m);
367 <              
368 <            } else {
369 <              omega[0] = angMom[0] /I(0, 0);
370 <              omega[1] = angMom[1] /I(1, 1);
371 <              omega[2] = angMom[2] /I(2, 2);
372 <            }
373 <            
374 <            //apply friction force and torque at center of resistance
296 >
297 >            // preliminaries for directional objects:
298 >
299              A = integrableObject->getA();
300              Atrans = A.transpose();
301 <            Vector3d rcr = Atrans * hydroProps_[index].cor;  
302 <            Vector3d vcdLab = vel + cross(omega, rcr);
379 <            Vector3d vcdBody = A* vcdLab;
380 <            Vector3d frictionForceBody = -(hydroProps_[index].Xirtt * vcdBody + hydroProps_[index].Xirrt * omega);
381 <            Vector3d frictionForceLab = Atrans*frictionForceBody;
382 <            integrableObject->addFrc(frictionForceLab);
383 <            Vector3d frictionTorqueBody = - (hydroProps_[index].Xirtr * vcdBody + hydroProps_[index].Xirrr * omega);
384 <            Vector3d frictionTorqueLab = Atrans*frictionTorqueBody;
385 <            integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab));
386 <            
301 >            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
302 >
303              //apply random force and torque at center of resistance
304 +
305              Vector3d randomForceBody;
306              Vector3d randomTorqueBody;
307              genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
308 <            Vector3d randomForceLab = Atrans*randomForceBody;
309 <            Vector3d randomTorqueLab = Atrans* randomTorqueBody;
308 >            Vector3d randomForceLab = Atrans * randomForceBody;
309 >            Vector3d randomTorqueLab = Atrans * randomTorqueBody;
310              integrableObject->addFrc(randomForceLab);            
311 <            integrableObject->addTrq(randomTorqueLab + cross(rcr, 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].Xirtt *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            
# Line 408 | Line 445 | namespace oopse {
445      
446        }
447      }    
448 +
449      info_->setFdf(fdf);
450 <    
451 <    ForceManager::postCalculation();  
450 >    veloMunge->removeComDrift();
451 >    // Remove angular drift if we are not using periodic boundary conditions.
452 >    if(!simParams->getUsePeriodicBoundaryConditions())
453 >      veloMunge->removeAngularDrift();
454 >
455 >    ForceManager::postCalculation(needStress);  
456    }
457  
458   void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) {
# Line 418 | Line 460 | void LDForceManager::genRandomForceAndTorque(Vector3d&
460  
461      Vector<RealType, 6> Z;
462      Vector<RealType, 6> generalForce;
421
463          
464      Z[0] = randNumGen_.randNorm(0, variance);
465      Z[1] = randNumGen_.randNorm(0, variance);
# Line 427 | Line 468 | void LDForceManager::genRandomForceAndTorque(Vector3d&
468      Z[4] = randNumGen_.randNorm(0, variance);
469      Z[5] = randNumGen_.randNorm(0, variance);
470      
471 <
431 <    generalForce = hydroProps_[index].S*Z;
471 >    generalForce = hydroProps_[index]->getS()*Z;
472      
473      force[0] = generalForce[0];
474      force[1] = generalForce[1];
# Line 437 | Line 477 | void LDForceManager::genRandomForceAndTorque(Vector3d&
477      torque[1] = generalForce[4];
478      torque[2] = generalForce[5];
479      
480 < }
480 > }
481  
482   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines