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

Comparing:
trunk/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
branches/development/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 1769 by gezelter, Mon Jul 9 14:15:52 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines