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 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 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, 234107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42   #include <fstream>
43 + #include <iostream>
44   #include "integrators/LDForceManager.hpp"
45   #include "math/CholeskyDecomposition.hpp"
46 < #include "utils/OOPSEConstant.hpp"
46 > #include "utils/PhysicalConstants.hpp"
47   #include "hydrodynamics/Sphere.hpp"
48   #include "hydrodynamics/Ellipsoid.hpp"
49 < #include "openbabel/mol.hpp"
49 > #include "utils/ElementsTable.hpp"
50 > #include "types/LennardJonesAdapter.hpp"
51 > #include "types/GayBerneAdapter.hpp"
52  
53 < using namespace OpenBabel;
50 < namespace oopse {
53 > namespace OpenMD {
54  
55 <  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
56 <    Globals* simParams = info->getSimParams();
57 <        
55 >  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info),
56 >                                                  maxIterNum_(4),
57 >                                                  forceTolerance_(1e-6) {
58 >    simParams = info->getSimParams();
59 >    veloMunge = new Velocitizer(info);
60 >
61      sphericalBoundaryConditions_ = false;
62      if (simParams->getUseSphericalBoundaryConditions()) {
63        sphericalBoundaryConditions_ = true;
# Line 61 | Line 67 | namespace oopse {
67          sprintf( painCave.errMsg,
68                   "langevinBufferRadius must be specified "
69                   "when useSphericalBoundaryConditions is turned on.\n");
70 <        painCave.severity = OOPSE_ERROR;
70 >        painCave.severity = OPENMD_ERROR;
71          painCave.isFatal = 1;
72          simError();  
73        }
# Line 72 | Line 78 | namespace oopse {
78          sprintf( painCave.errMsg,
79                   "frozenBufferRadius must be specified "
80                   "when useSphericalBoundaryConditions is turned on.\n");
81 <        painCave.severity = OOPSE_ERROR;
81 >        painCave.severity = OPENMD_ERROR;
82          painCave.isFatal = 1;
83          simError();  
84        }
# Line 81 | Line 87 | namespace oopse {
87          sprintf( painCave.errMsg,
88                   "frozenBufferRadius has been set smaller than the "
89                   "langevinBufferRadius.  This is probably an error.\n");
90 <        painCave.severity = OOPSE_WARNING;
90 >        painCave.severity = OPENMD_WARNING;
91          painCave.isFatal = 0;
92          simError();  
93        }
94      }
95  
96      // Build the hydroProp map:
97 <    std::map<std::string, HydroProp> hydroPropMap;
97 >    std::map<std::string, HydroProp*> hydroPropMap;
98  
99      Molecule* mol;
100 <    StuntDouble* integrableObject;
100 >    StuntDouble* sd;
101      SimInfo::MoleculeIterator i;
102      Molecule::IntegrableObjectIterator  j;              
103      bool needHydroPropFile = false;
104      
105      for (mol = info->beginMolecule(i); mol != NULL;
106           mol = info->nextMolecule(i)) {
107 <      for (integrableObject = mol->beginIntegrableObject(j);
108 <           integrableObject != NULL;
109 <           integrableObject = mol->nextIntegrableObject(j)) {
107 >
108 >      for (sd = mol->beginIntegrableObject(j); sd != NULL;
109 >           sd = mol->nextIntegrableObject(j)) {
110          
111 <        if (integrableObject->isRigidBody()) {
112 <          RigidBody* rb = static_cast<RigidBody*>(integrableObject);
111 >        if (sd->isRigidBody()) {
112 >          RigidBody* rb = static_cast<RigidBody*>(sd);
113            if (rb->getNumAtoms() > 1) needHydroPropFile = true;
114          }
115          
# Line 116 | Line 122 | namespace oopse {
122          hydroPropMap = parseFrictionFile(simParams->getHydroPropFile());
123        } else {              
124          sprintf( painCave.errMsg,
125 <                 "HydroPropFile must be set to a file name if Langevin\n"
126 <                 "\tDynamics is specified for rigidBodies which contain more\n"
127 <                 "\tthan one atom.  To create a HydroPropFile, run \"Hydro\".\n");
128 <        painCave.severity = OOPSE_ERROR;
125 >                 "HydroPropFile must be set to a file name if Langevin Dynamics\n"
126 >                 "\tis specified for rigidBodies which contain more than one atom\n"
127 >                 "\tTo create a HydroPropFile, run the \"Hydro\" program.\n");
128 >        painCave.severity = OPENMD_ERROR;
129          painCave.isFatal = 1;
130          simError();  
131        }      
132 <      std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
133 <      if (iter != hydroPropMap.end()) {
134 <        hydroProps_.push_back(iter->second);
135 <      } else {
136 <        sprintf( painCave.errMsg,
137 <                 "Can not find resistance tensor for atom [%s]\n", integrableObject->getType().c_str());
138 <        painCave.severity = OOPSE_ERROR;
139 <        painCave.isFatal = 1;
140 <        simError();  
132 >
133 >      for (mol = info->beginMolecule(i); mol != NULL;
134 >           mol = info->nextMolecule(i)) {
135 >
136 >        for (sd = mol->beginIntegrableObject(j);  sd != NULL;
137 >             sd = mol->nextIntegrableObject(j)) {
138 >
139 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(sd->getType());
140 >          if (iter != hydroPropMap.end()) {
141 >            hydroProps_.push_back(iter->second);
142 >          } else {
143 >            sprintf( painCave.errMsg,
144 >                     "Can not find resistance tensor for atom [%s]\n", sd->getType().c_str());
145 >            painCave.severity = OPENMD_ERROR;
146 >            painCave.isFatal = 1;
147 >            simError();  
148 >          }        
149 >        }
150        }
151      } else {
152 <
153 <      std::map<std::string, HydroProp> hydroPropMap;
152 >      
153 >      std::map<std::string, HydroProp*> hydroPropMap;
154        for (mol = info->beginMolecule(i); mol != NULL;
155             mol = info->nextMolecule(i)) {
156 <        for (integrableObject = mol->beginIntegrableObject(j);
157 <             integrableObject != NULL;
158 <             integrableObject = mol->nextIntegrableObject(j)) {
156 >
157 >        for (sd = mol->beginIntegrableObject(j); sd != NULL;
158 >             sd = mol->nextIntegrableObject(j)) {
159 >
160            Shape* currShape = NULL;
161 <          if (integrableObject->isDirectionalAtom()) {
162 <            DirectionalAtom* dAtom = static_cast<DirectionalAtom*>(integrableObject);
163 <            AtomType* atomType = dAtom->getAtomType();
148 <            if (atomType->isGayBerne()) {
149 <              DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
150 <              
151 <              GenericData* data = dAtomType->getPropertyByName("GayBerne");
152 <              if (data != NULL) {
153 <                GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
154 <                
155 <                if (gayBerneData != NULL) {  
156 <                  GayBerneParam gayBerneParam = gayBerneData->getData();
157 <                  currShape = new Ellipsoid(V3Zero,
158 <                                            gayBerneParam.GB_sigma/2.0,
159 <                                            gayBerneParam.GB_l2b_ratio*gayBerneParam.GB_sigma/2.0,
160 <                                            Mat3x3d::identity());
161 <                } else {
162 <                  sprintf( painCave.errMsg,
163 <                           "Can not cast GenericData to GayBerneParam\n");
164 <                  painCave.severity = OOPSE_ERROR;
165 <                  painCave.isFatal = 1;
166 <                  simError();  
167 <                }
168 <              } else {
169 <                sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n");
170 <                painCave.severity = OOPSE_ERROR;
171 <                painCave.isFatal = 1;
172 <                simError();    
173 <              }
174 <            }
175 <          } else {
176 <            Atom* atom = static_cast<Atom*>(integrableObject);
161 >
162 >          if (sd->isAtom()){
163 >            Atom* atom = static_cast<Atom*>(sd);
164              AtomType* atomType = atom->getAtomType();
165 <            if (atomType->isLennardJones()){
166 <              GenericData* data = atomType->getPropertyByName("LennardJones");
167 <              if (data != NULL) {
168 <                LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
169 <                
170 <                if (ljData != NULL) {
171 <                  LJParam ljParam = ljData->getData();
172 <                  currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0);
165 >            GayBerneAdapter gba = GayBerneAdapter(atomType);
166 >            if (gba.isGayBerne()) {
167 >              currShape = new Ellipsoid(V3Zero, gba.getL() / 2.0,
168 >                                        gba.getD() / 2.0,
169 >                                        Mat3x3d::identity());
170 >            } else {
171 >              LennardJonesAdapter lja = LennardJonesAdapter(atomType);
172 >              if (lja.isLennardJones()){
173 >                currShape = new Sphere(atom->getPos(), lja.getSigma()/2.0);
174 >              } else {
175 >                int aNum = etab.GetAtomicNum((atom->getType()).c_str());
176 >                if (aNum != 0) {
177 >                  currShape = new Sphere(atom->getPos(), etab.GetVdwRad(aNum));
178                  } else {
179                    sprintf( painCave.errMsg,
180 <                           "Can not cast GenericData to LJParam\n");
181 <                  painCave.severity = OOPSE_ERROR;
180 >                           "Could not find atom type in default element.txt\n");
181 >                  painCave.severity = OPENMD_ERROR;
182                    painCave.isFatal = 1;
183                    simError();          
184 <                }      
184 >                }
185                }
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();          
204              }
186              }
187            }
188 <          HydroProps currHydroProp = currShape->getHydroProps(simParams->getViscosity(),simParams->getTargetTemp());
189 <          std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
188 >
189 >          if (!simParams->haveTargetTemp()) {
190 >            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a targetTemp!\n");
191 >            painCave.isFatal = 1;
192 >            painCave.severity = OPENMD_ERROR;
193 >            simError();
194 >          }
195 >
196 >          if (!simParams->haveViscosity()) {
197 >            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a viscosity!\n");
198 >            painCave.isFatal = 1;
199 >            painCave.severity = OPENMD_ERROR;
200 >            simError();
201 >          }
202 >
203 >
204 >          HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp());
205 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(sd->getType());
206            if (iter != hydroPropMap.end())
207              hydroProps_.push_back(iter->second);
208            else {
209 <            HydroProp myProp;
210 <            myProp.cor = V3Zero;
211 <            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);
209 >            currHydroProp->complete();
210 >            hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(sd->getType(), currHydroProp));
211 >            hydroProps_.push_back(currHydroProp);
212            }
213 +          delete currShape;
214          }
215        }
216      }
217 <    variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
218 <  }
231 <  
232 <  
217 >    variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt();
218 >  }  
219  
220 <
221 <
236 <  std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) {
237 <    std::map<std::string, HydroProp> props;
220 >  std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) {
221 >    std::map<std::string, HydroProp*> props;
222      std::ifstream ifs(filename.c_str());
223      if (ifs.is_open()) {
224        
# Line 243 | Line 227 | namespace oopse {
227      const unsigned int BufferSize = 65535;
228      char buffer[BufferSize];  
229      while (ifs.getline(buffer, BufferSize)) {
230 <      StringTokenizer tokenizer(buffer);
231 <      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 <      }
230 >      HydroProp* currProp = new HydroProp(buffer);
231 >      props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp));
232      }
233 <    
233 >
234      return props;
235    }
236 <  
237 <  void LDForceManager::postCalculation() {
236 >  
237 >  void LDForceManager::postCalculation(){
238      SimInfo::MoleculeIterator i;
239      Molecule::IntegrableObjectIterator  j;
240      Molecule* mol;
241 <    StuntDouble* integrableObject;
242 <    Vector3d vel;
241 >    StuntDouble* sd;
242 >    RealType mass;
243      Vector3d pos;
244      Vector3d frc;
245      Mat3x3d A;
246      Mat3x3d Atrans;
247      Vector3d Tb;
248      Vector3d ji;
320    RealType mass;
249      unsigned int index = 0;
250      bool doLangevinForces;
251      bool freezeMolecule;
252      int fdf;
253 <    
253 >
254      fdf = 0;
255 +
256      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
257 <      
257 >
258 >      doLangevinForces = true;          
259 >      freezeMolecule = false;
260 >
261        if (sphericalBoundaryConditions_) {
262          
263          Vector3d molPos = mol->getCom();
264          RealType molRad = molPos.length();
265 <        
265 >
266          doLangevinForces = false;
335        freezeMolecule = false;
267          
268          if (molRad > langevinBufferRadius_) {
269            doLangevinForces = true;
# Line 344 | Line 275 | namespace oopse {
275          }
276        }
277        
278 <      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
279 <           integrableObject = mol->nextIntegrableObject(j)) {
278 >      for (sd = mol->beginIntegrableObject(j); sd != NULL;
279 >           sd = mol->nextIntegrableObject(j)) {
280            
281          if (freezeMolecule)
282 <          fdf += integrableObject->freeze();
282 >          fdf += sd->freeze();
283          
284 <        if (doLangevinForces) {          
285 <          vel =integrableObject->getVel();
286 <          if (integrableObject->isDirectional()){
287 <            //calculate angular velocity in lab frame
288 <            Mat3x3d I = integrableObject->getI();
289 <            Vector3d angMom = integrableObject->getJ();
290 <            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
375 <            A = integrableObject->getA();
284 >        if (doLangevinForces) {  
285 >          mass = sd->getMass();
286 >          if (sd->isDirectional()){
287 >
288 >            // preliminaries for directional objects:
289 >
290 >            A = sd->getA();
291              Atrans = A.transpose();
292 <            Vector3d rcr = Atrans * hydroProps_[index].cor;  
293 <            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 <            
292 >            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
293 >
294              //apply random force and torque at center of resistance
295 +
296              Vector3d randomForceBody;
297              Vector3d randomTorqueBody;
298              genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
299 <            Vector3d randomForceLab = Atrans*randomForceBody;
300 <            Vector3d randomTorqueLab = Atrans* randomTorqueBody;
301 <            integrableObject->addFrc(randomForceLab);            
302 <            integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab ));            
299 >            Vector3d randomForceLab = Atrans * randomForceBody;
300 >            Vector3d randomTorqueLab = Atrans * randomTorqueBody;
301 >            sd->addFrc(randomForceLab);            
302 >            sd->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab ));            
303 >
304 >            Mat3x3d I = sd->getI();
305 >            Vector3d omegaBody;
306 >
307 >            // What remains contains velocity explicitly, but the velocity required
308 >            // is at the full step: v(t + h), while we have initially the velocity
309 >            // at the half step: v(t + h/2).  We need to iterate to converge the
310 >            // friction force and friction torque vectors.
311 >
312 >            // this is the velocity at the half-step:
313              
314 +            Vector3d vel =sd->getVel();
315 +            Vector3d angMom = sd->getJ();
316 +
317 +            //estimate velocity at full-step using everything but friction forces:          
318 +
319 +            frc = sd->getFrc();
320 +            Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc;
321 +
322 +            Tb = sd->lab2Body(sd->getTrq());
323 +            Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb;                            
324 +
325 +            Vector3d omegaLab;
326 +            Vector3d vcdLab;
327 +            Vector3d vcdBody;
328 +            Vector3d frictionForceBody;
329 +            Vector3d frictionForceLab(0.0);
330 +            Vector3d oldFFL;  // used to test for convergence
331 +            Vector3d frictionTorqueBody(0.0);
332 +            Vector3d oldFTB;  // used to test for convergence
333 +            Vector3d frictionTorqueLab;
334 +            RealType fdot;
335 +            RealType tdot;
336 +
337 +            //iteration starts here:
338 +
339 +            for (int k = 0; k < maxIterNum_; k++) {
340 +                            
341 +              if (sd->isLinear()) {
342 +                int linearAxis = sd->linearAxis();
343 +                int l = (linearAxis +1 )%3;
344 +                int m = (linearAxis +2 )%3;
345 +                omegaBody[l] = angMomStep[l] /I(l, l);
346 +                omegaBody[m] = angMomStep[m] /I(m, m);
347 +                
348 +              } else {
349 +                omegaBody[0] = angMomStep[0] /I(0, 0);
350 +                omegaBody[1] = angMomStep[1] /I(1, 1);
351 +                omegaBody[2] = angMomStep[2] /I(2, 2);
352 +              }
353 +              
354 +              omegaLab = Atrans * omegaBody;
355 +              
356 +              // apply friction force and torque at center of resistance
357 +              
358 +              vcdLab = velStep + cross(omegaLab, rcrLab);      
359 +              vcdBody = A * vcdLab;
360 +              frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody);
361 +              oldFFL = frictionForceLab;
362 +              frictionForceLab = Atrans * frictionForceBody;
363 +              oldFTB = frictionTorqueBody;
364 +              frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody);
365 +              frictionTorqueLab = Atrans * frictionTorqueBody;
366 +              
367 +              // re-estimate velocities at full-step using friction forces:
368 +              
369 +              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab);
370 +              angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody);
371 +
372 +              // check for convergence (if the vectors have converged, fdot and tdot will both be 1.0):
373 +              
374 +              fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare();
375 +              tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare();
376 +              
377 +              if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_)
378 +                break; // iteration ends here
379 +            }
380 +
381 +            sd->addFrc(frictionForceLab);
382 +            sd->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab));
383 +
384 +            
385            } else {
386              //spherical atom
387 <            Vector3d frictionForce = -(hydroProps_[index].Xirtt *vel);    
387 >
388              Vector3d randomForce;
389              Vector3d randomTorque;
390              genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
391 +            sd->addFrc(randomForce);            
392 +
393 +            // What remains contains velocity explicitly, but the velocity required
394 +            // is at the full step: v(t + h), while we have initially the velocity
395 +            // at the half step: v(t + h/2).  We need to iterate to converge the
396 +            // friction force vector.
397 +
398 +            // this is the velocity at the half-step:
399              
400 <            integrableObject->addFrc(frictionForce+randomForce);            
400 >            Vector3d vel =sd->getVel();
401 >
402 >            //estimate velocity at full-step using everything but friction forces:          
403 >
404 >            frc = sd->getFrc();
405 >            Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc;
406 >
407 >            Vector3d frictionForce(0.0);
408 >            Vector3d oldFF;  // used to test for convergence
409 >            RealType fdot;
410 >
411 >            //iteration starts here:
412 >
413 >            for (int k = 0; k < maxIterNum_; k++) {
414 >
415 >              oldFF = frictionForce;                            
416 >              frictionForce = -hydroProps_[index]->getXitt() * velStep;
417 >
418 >              // re-estimate velocities at full-step using friction forces:
419 >              
420 >              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce);
421 >
422 >              // check for convergence (if the vector has converged, fdot will be 1.0):
423 >              
424 >              fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare();
425 >              
426 >              if (fabs(1.0 - fdot) <= forceTolerance_)
427 >                break; // iteration ends here
428 >            }
429 >
430 >            sd->addFrc(frictionForce);
431 >
432            }
433          }
434            
# Line 408 | Line 436 | namespace oopse {
436      
437        }
438      }    
439 +
440      info_->setFdf(fdf);
441 <    
441 >    veloMunge->removeComDrift();
442 >    // Remove angular drift if we are not using periodic boundary conditions.
443 >    if(!simParams->getUsePeriodicBoundaryConditions())
444 >      veloMunge->removeAngularDrift();
445 >
446      ForceManager::postCalculation();  
447    }
448  
# Line 418 | Line 451 | void LDForceManager::genRandomForceAndTorque(Vector3d&
451  
452      Vector<RealType, 6> Z;
453      Vector<RealType, 6> generalForce;
421
454          
455      Z[0] = randNumGen_.randNorm(0, variance);
456      Z[1] = randNumGen_.randNorm(0, variance);
# Line 427 | Line 459 | void LDForceManager::genRandomForceAndTorque(Vector3d&
459      Z[4] = randNumGen_.randNorm(0, variance);
460      Z[5] = randNumGen_.randNorm(0, variance);
461      
462 <
431 <    generalForce = hydroProps_[index].S*Z;
462 >    generalForce = hydroProps_[index]->getS()*Z;
463      
464      force[0] = generalForce[0];
465      force[1] = generalForce[1];
# Line 437 | Line 468 | void LDForceManager::genRandomForceAndTorque(Vector3d&
468      torque[1] = generalForce[4];
469      torque[2] = generalForce[5];
470      
471 < }
471 > }
472  
473   }

Comparing trunk/src/integrators/LDForceManager.cpp (property svn:keywords):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines