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 971 by tim, Wed May 24 16:18:00 2006 UTC vs.
Revision 1185 by xsun, Fri Oct 5 19:02:09 2007 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"
# Line 50 | Line 51 | namespace oopse {
51   namespace oopse {
52  
53    LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
54 <    Globals* simParams = info->getSimParams();
55 <        
54 >    simParams = info->getSimParams();
55 >    veloMunge = new Velocitizer(info);
56 >
57      sphericalBoundaryConditions_ = false;
58      if (simParams->getUseSphericalBoundaryConditions()) {
59        sphericalBoundaryConditions_ = true;
# Line 88 | Line 90 | namespace oopse {
90      }
91  
92      // Build the hydroProp map:
93 <    std::map<std::string, HydroProp> hydroPropMap;
93 >    std::map<std::string, HydroProp*> hydroPropMap;
94  
95      Molecule* mol;
96      StuntDouble* integrableObject;
# Line 130 | Line 132 | namespace oopse {
132               integrableObject != NULL;
133               integrableObject = mol->nextIntegrableObject(j)) {
134  
135 <          std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
135 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
136            if (iter != hydroPropMap.end()) {
137              hydroProps_.push_back(iter->second);
138            } else {
# Line 143 | Line 145 | namespace oopse {
145          }
146        }
147      } else {
148 <
149 <      std::map<std::string, HydroProp> hydroPropMap;
148 >      
149 >      std::map<std::string, HydroProp*> hydroPropMap;
150        for (mol = info->beginMolecule(i); mol != NULL;
151             mol = info->nextMolecule(i)) {
152          for (integrableObject = mol->beginIntegrableObject(j);
153               integrableObject != NULL;
154               integrableObject = mol->nextIntegrableObject(j)) {
155            Shape* currShape = NULL;
156 <          if (integrableObject->isDirectionalAtom()) {
157 <            DirectionalAtom* dAtom = static_cast<DirectionalAtom*>(integrableObject);
158 <            AtomType* atomType = dAtom->getAtomType();
156 >
157 >          if (integrableObject->isAtom()){
158 >            Atom* atom = static_cast<Atom*>(integrableObject);
159 >            AtomType* atomType = atom->getAtomType();
160              if (atomType->isGayBerne()) {
161 <              DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
159 <              
161 >              DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);              
162                GenericData* data = dAtomType->getPropertyByName("GayBerne");
163                if (data != NULL) {
164                  GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
# Line 164 | Line 166 | namespace oopse {
166                  if (gayBerneData != NULL) {  
167                    GayBerneParam gayBerneParam = gayBerneData->getData();
168                    currShape = new Ellipsoid(V3Zero,
169 <                                            gayBerneParam.GB_sigma/2.0,
170 <                                            gayBerneParam.GB_l2b_ratio*gayBerneParam.GB_sigma/2.0,
169 >                                            gayBerneParam.GB_l / 2.0,
170 >                                            gayBerneParam.GB_d / 2.0,
171                                              Mat3x3d::identity());
172                  } else {
173                    sprintf( painCave.errMsg,
# Line 180 | Line 182 | namespace oopse {
182                  painCave.isFatal = 1;
183                  simError();    
184                }
185 <            }
186 <          } else {
187 <            Atom* atom = static_cast<Atom*>(integrableObject);
188 <            AtomType* atomType = atom->getAtomType();
189 <            if (atomType->isLennardJones()){
190 <              GenericData* data = atomType->getPropertyByName("LennardJones");
191 <              if (data != NULL) {
192 <                LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
193 <                
194 <                if (ljData != NULL) {
195 <                  LJParam ljParam = ljData->getData();
196 <                  currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0);
185 >            } else {
186 >              if (atomType->isLennardJones()){
187 >                GenericData* data = atomType->getPropertyByName("LennardJones");
188 >                if (data != NULL) {
189 >                  LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
190 >                  if (ljData != NULL) {
191 >                    LJParam ljParam = ljData->getData();
192 >                    currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0);
193 >                  } else {
194 >                    sprintf( painCave.errMsg,
195 >                             "Can not cast GenericData to LJParam\n");
196 >                    painCave.severity = OOPSE_ERROR;
197 >                    painCave.isFatal = 1;
198 >                    simError();          
199 >                  }      
200 >                }
201 >              } else {
202 >                int obanum = etab.GetAtomicNum((atom->getType()).c_str());
203 >                if (obanum != 0) {
204 >                  currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum));
205                  } else {
206                    sprintf( painCave.errMsg,
207 <                           "Can not cast GenericData to LJParam\n");
207 >                           "Could not find atom type in default element.txt\n");
208                    painCave.severity = OOPSE_ERROR;
209                    painCave.isFatal = 1;
210                    simError();          
211 <                }      
211 >                }
212                }
203            } else {
204              int obanum = etab.GetAtomicNum((atom->getType()).c_str());
205              if (obanum != 0) {
206                currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum));
207              } else {
208                sprintf( painCave.errMsg,
209                         "Could not find atom type in default element.txt\n");
210                painCave.severity = OOPSE_ERROR;
211                painCave.isFatal = 1;
212                simError();          
213              }
213              }
214            }
215 <          HydroProps currHydroProp = currShape->getHydroProps(simParams->getViscosity(),simParams->getTargetTemp());
216 <          std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
215 >          HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp());
216 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
217            if (iter != hydroPropMap.end())
218              hydroProps_.push_back(iter->second);
219            else {
220 <            HydroProp myProp;
221 <            myProp.cor = V3Zero;
222 <            for (int i1 = 0; i1 < 3; i1++) {
224 <              for (int j1 = 0; j1 < 3; j1++) {
225 <                myProp.Xirtt(i1,j1) = currHydroProp.Xi(i1,j1);
226 <                myProp.Xirrt(i1,j1) = currHydroProp.Xi(i1,j1+3);
227 <                myProp.Xirtr(i1,j1) = currHydroProp.Xi(i1+3,j1);
228 <                myProp.Xirrr(i1,j1) = currHydroProp.Xi(i1+3,j1+3);
229 <              }
230 <            }
231 <            CholeskyDecomposition(currHydroProp.Xi, myProp.S);
232 <            hydroPropMap.insert(std::map<std::string, HydroProp>::value_type(integrableObject->getType(), myProp));
233 <            hydroProps_.push_back(myProp);
220 >            currHydroProp->complete();
221 >            hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp));
222 >            hydroProps_.push_back(currHydroProp);
223            }
224          }
225        }
226      }
227      variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
228 <  }
240 <  
241 <  
228 >  }  
229  
230 <
231 <
245 <  std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) {
246 <    std::map<std::string, HydroProp> props;
230 >  std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) {
231 >    std::map<std::string, HydroProp*> props;
232      std::ifstream ifs(filename.c_str());
233      if (ifs.is_open()) {
234        
# Line 252 | Line 237 | namespace oopse {
237      const unsigned int BufferSize = 65535;
238      char buffer[BufferSize];  
239      while (ifs.getline(buffer, BufferSize)) {
240 <      StringTokenizer tokenizer(buffer);
241 <      HydroProp currProp;
257 <      if (tokenizer.countTokens() >= 40) {
258 <        std::string atomName = tokenizer.nextToken();
259 <        currProp.cor[0] = tokenizer.nextTokenAsDouble();
260 <        currProp.cor[1] = tokenizer.nextTokenAsDouble();
261 <        currProp.cor[2] = tokenizer.nextTokenAsDouble();
262 <        
263 <        currProp.Xirtt(0,0) = tokenizer.nextTokenAsDouble();
264 <        currProp.Xirtt(0,1) = tokenizer.nextTokenAsDouble();
265 <        currProp.Xirtt(0,2) = tokenizer.nextTokenAsDouble();
266 <        currProp.Xirtt(1,0) = tokenizer.nextTokenAsDouble();
267 <        currProp.Xirtt(1,1) = tokenizer.nextTokenAsDouble();
268 <        currProp.Xirtt(1,2) = tokenizer.nextTokenAsDouble();
269 <        currProp.Xirtt(2,0) = tokenizer.nextTokenAsDouble();
270 <        currProp.Xirtt(2,1) = tokenizer.nextTokenAsDouble();
271 <        currProp.Xirtt(2,2) = tokenizer.nextTokenAsDouble();
272 <        
273 <        currProp.Xirrt(0,0) = tokenizer.nextTokenAsDouble();
274 <        currProp.Xirrt(0,1) = tokenizer.nextTokenAsDouble();
275 <        currProp.Xirrt(0,2) = tokenizer.nextTokenAsDouble();
276 <        currProp.Xirrt(1,0) = tokenizer.nextTokenAsDouble();
277 <        currProp.Xirrt(1,1) = tokenizer.nextTokenAsDouble();
278 <        currProp.Xirrt(1,2) = tokenizer.nextTokenAsDouble();
279 <        currProp.Xirrt(2,0) = tokenizer.nextTokenAsDouble();
280 <        currProp.Xirrt(2,1) = tokenizer.nextTokenAsDouble();
281 <        currProp.Xirrt(2,2) = tokenizer.nextTokenAsDouble();
282 <        
283 <        currProp.Xirtr(0,0) = tokenizer.nextTokenAsDouble();
284 <        currProp.Xirtr(0,1) = tokenizer.nextTokenAsDouble();
285 <        currProp.Xirtr(0,2) = tokenizer.nextTokenAsDouble();
286 <        currProp.Xirtr(1,0) = tokenizer.nextTokenAsDouble();
287 <        currProp.Xirtr(1,1) = tokenizer.nextTokenAsDouble();
288 <        currProp.Xirtr(1,2) = tokenizer.nextTokenAsDouble();
289 <        currProp.Xirtr(2,0) = tokenizer.nextTokenAsDouble();
290 <        currProp.Xirtr(2,1) = tokenizer.nextTokenAsDouble();
291 <        currProp.Xirtr(2,2) = tokenizer.nextTokenAsDouble();
292 <        
293 <        currProp.Xirrr(0,0) = tokenizer.nextTokenAsDouble();
294 <        currProp.Xirrr(0,1) = tokenizer.nextTokenAsDouble();
295 <        currProp.Xirrr(0,2) = tokenizer.nextTokenAsDouble();
296 <        currProp.Xirrr(1,0) = tokenizer.nextTokenAsDouble();
297 <        currProp.Xirrr(1,1) = tokenizer.nextTokenAsDouble();
298 <        currProp.Xirrr(1,2) = tokenizer.nextTokenAsDouble();
299 <        currProp.Xirrr(2,0) = tokenizer.nextTokenAsDouble();
300 <        currProp.Xirrr(2,1) = tokenizer.nextTokenAsDouble();
301 <        currProp.Xirrr(2,2) = tokenizer.nextTokenAsDouble();
302 <        
303 <        SquareMatrix<RealType, 6> Xir;
304 <        Xir.setSubMatrix(0, 0, currProp.Xirtt);
305 <        Xir.setSubMatrix(0, 3, currProp.Xirrt);
306 <        Xir.setSubMatrix(3, 0, currProp.Xirtr);
307 <        Xir.setSubMatrix(3, 3, currProp.Xirrr);
308 <        CholeskyDecomposition(Xir, currProp.S);            
309 <        
310 <        props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp));
311 <      }
240 >      HydroProp* currProp = new HydroProp(buffer);
241 >      props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp));
242      }
243 <    
243 >
244      return props;
245    }
246 <  
247 <  void LDForceManager::postCalculation() {
246 >  
247 >  void LDForceManager::postCalculation(bool needStress){
248      SimInfo::MoleculeIterator i;
249      Molecule::IntegrableObjectIterator  j;
250      Molecule* mol;
251      StuntDouble* integrableObject;
252 +    RealType mass;
253      Vector3d vel;
254      Vector3d pos;
255      Vector3d frc;
# Line 326 | Line 257 | namespace oopse {
257      Mat3x3d Atrans;
258      Vector3d Tb;
259      Vector3d ji;
329    RealType mass;
260      unsigned int index = 0;
261      bool doLangevinForces;
262      bool freezeMolecule;
263      int fdf;
264 <    
264 >
265 >
266 >
267      fdf = 0;
268 +
269      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
270  
271        doLangevinForces = true;          
# Line 342 | Line 275 | namespace oopse {
275          
276          Vector3d molPos = mol->getCom();
277          RealType molRad = molPos.length();
278 <        
278 >
279          doLangevinForces = false;
280          
281          if (molRad > langevinBufferRadius_) {
# Line 361 | Line 294 | namespace oopse {
294          if (freezeMolecule)
295            fdf += integrableObject->freeze();
296          
297 <        if (doLangevinForces) {          
297 >        if (doLangevinForces) {  
298            vel =integrableObject->getVel();
299 +          mass = integrableObject->getMass();
300            if (integrableObject->isDirectional()){
301              //calculate angular velocity in lab frame
302              Mat3x3d I = integrableObject->getI();
# Line 381 | Line 315 | namespace oopse {
315                omega[1] = angMom[1] /I(1, 1);
316                omega[2] = angMom[2] /I(2, 2);
317              }
318 <            
318 >
319 >            //std::cerr << "I = " << I(0,0) << "\t" << I(1,1) << "\t" << I(2,2) << "\n\n";
320 >
321              //apply friction force and torque at center of resistance
322              A = integrableObject->getA();
323              Atrans = A.transpose();
324 <            Vector3d rcr = Atrans * hydroProps_[index].cor;  
324 >            //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 <            Vector3d frictionForceBody = -(hydroProps_[index].Xirtt * vcdBody + hydroProps_[index].Xirrt * omega);
334 >            //std::cerr << "vcdB = " << vcdBody << "\n\n";
335 >            Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omega);
336 >
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 <            Vector3d frictionTorqueBody = - (hydroProps_[index].Xirtr * vcdBody + hydroProps_[index].Xirrr * omega);
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 <            
352 >            //std::cerr << "trq = " << integrableObject->getTrq() << "\n\n";
353 >
354              //apply random force and torque at center of resistance
355              Vector3d randomForceBody;
356              Vector3d randomTorqueBody;
357              genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
358 +            //std::cerr << "rfB = " << randomForceBody << "\n\n";
359 +            //std::cerr << "rtB = " << randomTorqueBody << "\n\n";
360              Vector3d randomForceLab = Atrans*randomForceBody;
361              Vector3d randomTorqueLab = Atrans* randomTorqueBody;
362              integrableObject->addFrc(randomForceLab);            
363 +            //std::cerr << "rfL = " << randomForceLab << "\n\n";
364 +            //std::cerr << "rtL = " << randomTorqueLab << "\n\n";
365 +            //std::cerr << "rtL2 = " << randomTorqueLab + cross(rcr, randomForceLab) << "\n\n";
366              integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab ));            
367              
368            } else {
369              //spherical atom
370 <            Vector3d frictionForce = -(hydroProps_[index].Xirtt *vel);    
370 >            Vector3d frictionForce = -(hydroProps_[index]->getXitt() * vel);
371 >            //std::cerr << "xitt = " << hydroProps_[index]->getXitt() << "\n\n";
372              Vector3d randomForce;
373              Vector3d randomTorque;
374              genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
# Line 419 | Line 381 | namespace oopse {
381      
382        }
383      }    
384 +
385      info_->setFdf(fdf);
386 <    
387 <    ForceManager::postCalculation();  
386 >    veloMunge->removeComDrift();
387 >    // Remove angular drift if we are not using periodic boundary conditions.
388 >    if(!simParams->getUsePeriodicBoundaryConditions())
389 >      veloMunge->removeAngularDrift();
390 >
391 >    ForceManager::postCalculation(needStress);  
392    }
393  
394   void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) {
# Line 429 | Line 396 | void LDForceManager::genRandomForceAndTorque(Vector3d&
396  
397      Vector<RealType, 6> Z;
398      Vector<RealType, 6> generalForce;
432
399          
400      Z[0] = randNumGen_.randNorm(0, variance);
401      Z[1] = randNumGen_.randNorm(0, variance);
402      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);
406      Z[3] = randNumGen_.randNorm(0, variance);
407      Z[4] = randNumGen_.randNorm(0, variance);
408      Z[5] = randNumGen_.randNorm(0, variance);
409      
410  
411 <    generalForce = hydroProps_[index].S*Z;
411 >    generalForce = hydroProps_[index]->getS()*Z;
412      
413      force[0] = generalForce[0];
414      force[1] = generalForce[1];
# Line 448 | Line 417 | void LDForceManager::genRandomForceAndTorque(Vector3d&
417      torque[1] = generalForce[4];
418      torque[2] = generalForce[5];
419      
420 < }
420 > }
421  
422   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines