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 904 by tim, Thu Mar 16 22:50:48 2006 UTC vs.
branches/development/src/integrators/LDForceManager.cpp (file contents), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41   #include <fstream>
42 + #include <iostream>
43   #include "integrators/LDForceManager.hpp"
44   #include "math/CholeskyDecomposition.hpp"
45 < #include "utils/OOPSEConstant.hpp"
46 < namespace oopse {
45 > #include "utils/PhysicalConstants.hpp"
46 > #include "hydrodynamics/Sphere.hpp"
47 > #include "hydrodynamics/Ellipsoid.hpp"
48 > #include "utils/ElementsTable.hpp"
49  
50 <  LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){
51 <    Globals* simParams = info->getSimParams();
52 <    std::map<std::string, HydroProp> hydroPropMap;
53 <    if (simParams->haveHydroPropFile()) {
54 <        hydroPropMap = parseFrictionFile(simParams->getHydroPropFile());
55 <    } else {
56 <        //error
50 > namespace OpenMD {
51 >
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;
59 >      if (simParams->haveLangevinBufferRadius()) {
60 >        langevinBufferRadius_ = simParams->getLangevinBufferRadius();
61 >      } else {
62 >        sprintf( painCave.errMsg,
63 >                 "langevinBufferRadius must be specified "
64 >                 "when useSphericalBoundaryConditions is turned on.\n");
65 >        painCave.severity = OPENMD_ERROR;
66 >        painCave.isFatal = 1;
67 >        simError();  
68 >      }
69 >    
70 >      if (simParams->haveFrozenBufferRadius()) {
71 >        frozenBufferRadius_ = simParams->getFrozenBufferRadius();
72 >      } else {
73 >        sprintf( painCave.errMsg,
74 >                 "frozenBufferRadius must be specified "
75 >                 "when useSphericalBoundaryConditions is turned on.\n");
76 >        painCave.severity = OPENMD_ERROR;
77 >        painCave.isFatal = 1;
78 >        simError();  
79 >      }
80 >
81 >      if (frozenBufferRadius_ < langevinBufferRadius_) {
82 >        sprintf( painCave.errMsg,
83 >                 "frozenBufferRadius has been set smaller than the "
84 >                 "langevinBufferRadius.  This is probably an error.\n");
85 >        painCave.severity = OPENMD_WARNING;
86 >        painCave.isFatal = 0;
87 >        simError();  
88 >      }
89      }
90  
91 <    SimInfo::MoleculeIterator i;
92 <    Molecule::IntegrableObjectIterator  j;
91 >    // Build the hydroProp map:
92 >    std::map<std::string, HydroProp*> hydroPropMap;
93 >
94      Molecule* mol;
95      StuntDouble* integrableObject;
96 <    for (mol = info->beginMolecule(i); mol != NULL; mol = info->nextMolecule(i)) {
97 <      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
98 <              integrableObject = mol->nextIntegrableObject(j)) {
99 <            std::map<std::string, HydroProp>::iterator iter = hydroPropMap.find(integrableObject->getType());
100 <            if (iter != hydroPropMap.end()) {
101 <                hydroProps_.push_back(iter->second);
102 <            } else {
103 <                //error
104 <            }
105 <            
106 <           }
96 >    SimInfo::MoleculeIterator i;
97 >    Molecule::IntegrableObjectIterator  j;              
98 >    bool needHydroPropFile = false;
99 >    
100 >    for (mol = info->beginMolecule(i); mol != NULL;
101 >         mol = info->nextMolecule(i)) {
102 >      for (integrableObject = mol->beginIntegrableObject(j);
103 >           integrableObject != NULL;
104 >           integrableObject = mol->nextIntegrableObject(j)) {
105 >        
106 >        if (integrableObject->isRigidBody()) {
107 >          RigidBody* rb = static_cast<RigidBody*>(integrableObject);
108 >          if (rb->getNumAtoms() > 1) needHydroPropFile = true;
109 >        }
110 >        
111 >      }
112      }
113 <    variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt();
73 <  }
74 <  std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) {
75 <    std::map<std::string, HydroProp> props;
76 <    std::ifstream ifs(filename.c_str());
77 <    if (ifs.is_open()) {
113 >        
114  
115 <    }
115 >    if (needHydroPropFile) {              
116 >      if (simParams->haveHydroPropFile()) {
117 >        hydroPropMap = parseFrictionFile(simParams->getHydroPropFile());
118 >      } else {              
119 >        sprintf( painCave.errMsg,
120 >                 "HydroPropFile must be set to a file name if Langevin Dynamics\n"
121 >                 "\tis specified for rigidBodies which contain more than one atom\n"
122 >                 "\tTo create a HydroPropFile, run the \"Hydro\" program.\n");
123 >        painCave.severity = OPENMD_ERROR;
124 >        painCave.isFatal = 1;
125 >        simError();  
126 >      }      
127  
128 <    const unsigned int BufferSize = 65535;
129 <    char buffer[BufferSize];  
130 <    while (ifs.getline(buffer, BufferSize)) {
131 <        StringTokenizer tokenizer(buffer);
132 <        HydroProp currProp;
86 <        if (tokenizer.countTokens() >= 67) {
87 <            std::string atomName = tokenizer.nextToken();
88 <            currProp.cod[0] = tokenizer.nextTokenAsDouble();
89 <            currProp.cod[1] = tokenizer.nextTokenAsDouble();
90 <            currProp.cod[2] = tokenizer.nextTokenAsDouble();
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 <            currProp.Ddtt(0,0) = tokenizer.nextTokenAsDouble();
135 <            currProp.Ddtt(0,1) = tokenizer.nextTokenAsDouble();
136 <            currProp.Ddtt(0,2) = tokenizer.nextTokenAsDouble();
137 <            currProp.Ddtt(1,0) = tokenizer.nextTokenAsDouble();
138 <            currProp.Ddtt(1,1) = tokenizer.nextTokenAsDouble();
139 <            currProp.Ddtt(1,2) = tokenizer.nextTokenAsDouble();
140 <            currProp.Ddtt(2,0) = tokenizer.nextTokenAsDouble();
141 <            currProp.Ddtt(2,1) = tokenizer.nextTokenAsDouble();
142 <            currProp.Ddtt(2,2) = tokenizer.nextTokenAsDouble();
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 = OPENMD_ERROR;
141 >            painCave.isFatal = 1;
142 >            simError();  
143 >          }        
144 >        }
145 >      }
146 >    } else {
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  
156 <            currProp.Ddtr(0,0) = tokenizer.nextTokenAsDouble();
157 <            currProp.Ddtr(0,1) = tokenizer.nextTokenAsDouble();
158 <            currProp.Ddtr(0,2) = tokenizer.nextTokenAsDouble();
159 <            currProp.Ddtr(1,0) = tokenizer.nextTokenAsDouble();
160 <            currProp.Ddtr(1,1) = tokenizer.nextTokenAsDouble();
161 <            currProp.Ddtr(1,2) = tokenizer.nextTokenAsDouble();
162 <            currProp.Ddtr(2,0) = tokenizer.nextTokenAsDouble();
163 <            currProp.Ddtr(2,1) = tokenizer.nextTokenAsDouble();
164 <            currProp.Ddtr(2,2) = tokenizer.nextTokenAsDouble();
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);              
161 >              GenericData* data = dAtomType->getPropertyByName("GayBerne");
162 >              if (data != NULL) {
163 >                GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data);
164 >                
165 >                if (gayBerneData != NULL) {  
166 >                  GayBerneParam gayBerneParam = gayBerneData->getData();
167 >                  currShape = new Ellipsoid(V3Zero,
168 >                                            gayBerneParam.GB_l / 2.0,
169 >                                            gayBerneParam.GB_d / 2.0,
170 >                                            Mat3x3d::identity());
171 >                } else {
172 >                  sprintf( painCave.errMsg,
173 >                           "Can not cast GenericData to GayBerneParam\n");
174 >                  painCave.severity = OPENMD_ERROR;
175 >                  painCave.isFatal = 1;
176 >                  simError();  
177 >                }
178 >              } else {
179 >                sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n");
180 >                painCave.severity = OPENMD_ERROR;
181 >                painCave.isFatal = 1;
182 >                simError();    
183 >              }
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 = OPENMD_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 >                           "Could not find atom type in default element.txt\n");
207 >                  painCave.severity = OPENMD_ERROR;
208 >                  painCave.isFatal = 1;
209 >                  simError();          
210 >                }
211 >              }
212 >            }
213 >          }
214  
215 <            currProp.Ddrr(0,0) = tokenizer.nextTokenAsDouble();
216 <            currProp.Ddrr(0,1) = tokenizer.nextTokenAsDouble();
217 <            currProp.Ddrr(0,2) = tokenizer.nextTokenAsDouble();
218 <            currProp.Ddrr(1,0) = tokenizer.nextTokenAsDouble();
219 <            currProp.Ddrr(1,1) = tokenizer.nextTokenAsDouble();
220 <            currProp.Ddrr(1,2) = tokenizer.nextTokenAsDouble();
118 <            currProp.Ddrr(2,0) = tokenizer.nextTokenAsDouble();
119 <            currProp.Ddrr(2,1) = tokenizer.nextTokenAsDouble();
120 <            currProp.Ddrr(2,2) = tokenizer.nextTokenAsDouble();                
215 >          if (!simParams->haveTargetTemp()) {
216 >            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a targetTemp!\n");
217 >            painCave.isFatal = 1;
218 >            painCave.severity = OPENMD_ERROR;
219 >            simError();
220 >          }
221  
222 <            currProp.Xidtt(0,0) = tokenizer.nextTokenAsDouble();
223 <            currProp.Xidtt(0,1) = tokenizer.nextTokenAsDouble();
224 <            currProp.Xidtt(0,2) = tokenizer.nextTokenAsDouble();
225 <            currProp.Xidtt(1,0) = tokenizer.nextTokenAsDouble();
226 <            currProp.Xidtt(1,1) = tokenizer.nextTokenAsDouble();
227 <            currProp.Xidtt(1,2) = tokenizer.nextTokenAsDouble();
128 <            currProp.Xidtt(2,0) = tokenizer.nextTokenAsDouble();
129 <            currProp.Xidtt(2,1) = tokenizer.nextTokenAsDouble();
130 <            currProp.Xidtt(2,2) = tokenizer.nextTokenAsDouble();
222 >          if (!simParams->haveViscosity()) {
223 >            sprintf(painCave.errMsg, "You can't use LangevinDynamics without a viscosity!\n");
224 >            painCave.isFatal = 1;
225 >            painCave.severity = OPENMD_ERROR;
226 >            simError();
227 >          }
228  
132            currProp.Xidrt(0,0) = tokenizer.nextTokenAsDouble();
133            currProp.Xidrt(0,1) = tokenizer.nextTokenAsDouble();
134            currProp.Xidrt(0,2) = tokenizer.nextTokenAsDouble();
135            currProp.Xidrt(1,0) = tokenizer.nextTokenAsDouble();
136            currProp.Xidrt(1,1) = tokenizer.nextTokenAsDouble();
137            currProp.Xidrt(1,2) = tokenizer.nextTokenAsDouble();
138            currProp.Xidrt(2,0) = tokenizer.nextTokenAsDouble();
139            currProp.Xidrt(2,1) = tokenizer.nextTokenAsDouble();
140            currProp.Xidrt(2,2) = tokenizer.nextTokenAsDouble();
141            
142            currProp.Xidtr(0,0) = tokenizer.nextTokenAsDouble();
143            currProp.Xidtr(0,1) = tokenizer.nextTokenAsDouble();
144            currProp.Xidtr(0,2) = tokenizer.nextTokenAsDouble();
145            currProp.Xidtr(1,0) = tokenizer.nextTokenAsDouble();
146            currProp.Xidtr(1,1) = tokenizer.nextTokenAsDouble();
147            currProp.Xidtr(1,2) = tokenizer.nextTokenAsDouble();
148            currProp.Xidtr(2,0) = tokenizer.nextTokenAsDouble();
149            currProp.Xidtr(2,1) = tokenizer.nextTokenAsDouble();
150            currProp.Xidtr(2,2) = tokenizer.nextTokenAsDouble();
229  
230 <            currProp.Xidrr(0,0) = tokenizer.nextTokenAsDouble();
231 <            currProp.Xidrr(0,1) = tokenizer.nextTokenAsDouble();
232 <            currProp.Xidrr(0,2) = tokenizer.nextTokenAsDouble();
233 <            currProp.Xidrr(1,0) = tokenizer.nextTokenAsDouble();
234 <            currProp.Xidrr(1,1) = tokenizer.nextTokenAsDouble();
235 <            currProp.Xidrr(1,2) = tokenizer.nextTokenAsDouble();
236 <            currProp.Xidrr(2,0) = tokenizer.nextTokenAsDouble();
237 <            currProp.Xidrr(2,1) = tokenizer.nextTokenAsDouble();
238 <            currProp.Xidrr(2,2) = tokenizer.nextTokenAsDouble();
161 <            props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp));
230 >          HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp());
231 >          std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType());
232 >          if (iter != hydroPropMap.end())
233 >            hydroProps_.push_back(iter->second);
234 >          else {
235 >            currHydroProp->complete();
236 >            hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp));
237 >            hydroProps_.push_back(currHydroProp);
238 >          }
239          }
240 +      }
241      }
242 +    variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt();
243 +  }  
244  
245 +  std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) {
246 +    std::map<std::string, HydroProp*> props;
247 +    std::ifstream ifs(filename.c_str());
248 +    if (ifs.is_open()) {
249 +      
250 +    }
251 +    
252 +    const unsigned int BufferSize = 65535;
253 +    char buffer[BufferSize];  
254 +    while (ifs.getline(buffer, BufferSize)) {
255 +      HydroProp* currProp = new HydroProp(buffer);
256 +      props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp));
257 +    }
258 +
259      return props;
260    }
261 <  
262 <  void LDForceManager::postCalculation() {
261 >  
262 >  void LDForceManager::postCalculation(){
263      SimInfo::MoleculeIterator i;
264      Molecule::IntegrableObjectIterator  j;
265      Molecule* mol;
266      StuntDouble* integrableObject;
267 <    Vector3d vel;
267 >    RealType mass;
268      Vector3d pos;
269      Vector3d frc;
270      Mat3x3d A;
271      Mat3x3d Atrans;
272      Vector3d Tb;
273      Vector3d ji;
180    double mass;
274      unsigned int index = 0;
275 +    bool doLangevinForces;
276 +    bool freezeMolecule;
277 +    int fdf;
278 +
279 +    fdf = 0;
280 +
281      for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) {
183      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
184           integrableObject = mol->nextIntegrableObject(j)) {
282  
283 <          vel =integrableObject->getVel();
283 >      doLangevinForces = true;          
284 >      freezeMolecule = false;
285 >
286 >      if (sphericalBoundaryConditions_) {
287 >        
288 >        Vector3d molPos = mol->getCom();
289 >        RealType molRad = molPos.length();
290 >
291 >        doLangevinForces = false;
292 >        
293 >        if (molRad > langevinBufferRadius_) {
294 >          doLangevinForces = true;
295 >          freezeMolecule = false;
296 >        }
297 >        if (molRad > frozenBufferRadius_) {
298 >          doLangevinForces = false;
299 >          freezeMolecule = true;
300 >        }
301 >      }
302 >      
303 >      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
304 >           integrableObject = mol->nextIntegrableObject(j)) {
305 >          
306 >        if (freezeMolecule)
307 >          fdf += integrableObject->freeze();
308 >        
309 >        if (doLangevinForces) {  
310 >          mass = integrableObject->getMass();
311            if (integrableObject->isDirectional()){
188             //calculate angular velocity in lab frame
189             Mat3x3d I = integrableObject->getI();
190             Vector3d angMom = integrableObject->getJ();
191             Vector3d omega;
312  
313 <             if (integrableObject->isLinear()) {
313 >            // preliminaries for directional objects:
314 >
315 >            A = integrableObject->getA();
316 >            Atrans = A.transpose();
317 >            Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR();  
318 >
319 >            //apply random force and torque at center of resistance
320 >
321 >            Vector3d randomForceBody;
322 >            Vector3d randomTorqueBody;
323 >            genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_);
324 >            Vector3d randomForceLab = Atrans * randomForceBody;
325 >            Vector3d randomTorqueLab = Atrans * randomTorqueBody;
326 >            integrableObject->addFrc(randomForceLab);            
327 >            integrableObject->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab ));            
328 >
329 >            Mat3x3d I = integrableObject->getI();
330 >            Vector3d omegaBody;
331 >
332 >            // What remains contains velocity explicitly, but the velocity required
333 >            // is at the full step: v(t + h), while we have initially the velocity
334 >            // at the half step: v(t + h/2).  We need to iterate to converge the
335 >            // friction force and friction torque vectors.
336 >
337 >            // this is the velocity at the half-step:
338 >            
339 >            Vector3d vel =integrableObject->getVel();
340 >            Vector3d angMom = integrableObject->getJ();
341 >
342 >            //estimate velocity at full-step using everything but friction forces:          
343 >
344 >            frc = integrableObject->getFrc();
345 >            Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc;
346 >
347 >            Tb = integrableObject->lab2Body(integrableObject->getTrq());
348 >            Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb;                            
349 >
350 >            Vector3d omegaLab;
351 >            Vector3d vcdLab;
352 >            Vector3d vcdBody;
353 >            Vector3d frictionForceBody;
354 >            Vector3d frictionForceLab(0.0);
355 >            Vector3d oldFFL;  // used to test for convergence
356 >            Vector3d frictionTorqueBody(0.0);
357 >            Vector3d oldFTB;  // used to test for convergence
358 >            Vector3d frictionTorqueLab;
359 >            RealType fdot;
360 >            RealType tdot;
361 >
362 >            //iteration starts here:
363 >
364 >            for (int k = 0; k < maxIterNum_; k++) {
365 >                            
366 >              if (integrableObject->isLinear()) {
367                  int linearAxis = integrableObject->linearAxis();
368                  int l = (linearAxis +1 )%3;
369                  int m = (linearAxis +2 )%3;
370 <                omega[l] = angMom[l] /I(l, l);
371 <                omega[m] = angMom[m] /I(m, m);
370 >                omegaBody[l] = angMomStep[l] /I(l, l);
371 >                omegaBody[m] = angMomStep[m] /I(m, m);
372                  
373 <             } else {
374 <                 omega[0] = angMom[0] /I(0, 0);
375 <                 omega[1] = angMom[1] /I(1, 1);
376 <                 omega[2] = angMom[2] /I(2, 2);
377 <             }
373 >              } else {
374 >                omegaBody[0] = angMomStep[0] /I(0, 0);
375 >                omegaBody[1] = angMomStep[1] /I(1, 1);
376 >                omegaBody[2] = angMomStep[2] /I(2, 2);
377 >              }
378 >              
379 >              omegaLab = Atrans * omegaBody;
380 >              
381 >              // apply friction force and torque at center of resistance
382 >              
383 >              vcdLab = velStep + cross(omegaLab, rcrLab);      
384 >              vcdBody = A * vcdLab;
385 >              frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody);
386 >              oldFFL = frictionForceLab;
387 >              frictionForceLab = Atrans * frictionForceBody;
388 >              oldFTB = frictionTorqueBody;
389 >              frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody);
390 >              frictionTorqueLab = Atrans * frictionTorqueBody;
391 >              
392 >              // re-estimate velocities at full-step using friction forces:
393 >              
394 >              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab);
395 >              angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody);
396  
397 <             //apply friction force and torque at center of diffusion
398 <             A = integrableObject->getA();
399 <             Atrans = A.transpose();
400 <             Vector3d rcd = Atrans * hydroProps_[index].cod;  
401 <             Vector3d vcd = vel + cross(omega, rcd);
402 <             vcd = A* vcd;
403 <             Vector3d frictionForce = -(hydroProps_[index].Xidtt * vcd + hydroProps_[index].Xidrt * omega);
404 <             frictionForce = Atrans*frictionForce;
405 <             integrableObject->addFrc(frictionForce);
406 <             Vector3d frictionTorque = - (hydroProps_[index].Xidtr * vcd + hydroProps_[index].Xidrr * omega);
407 <             frictionTorque = Atrans*frictionTorque;
408 <             integrableObject->addTrq(frictionTorque+ cross(rcd, frictionForce));
409 <            
219 <             //apply random force and torque at center of diffustion
220 <             Vector3d randomForce;
221 <             Vector3d randomTorque;
222 <             genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
223 <             randomForce = Atrans*randomForce;
224 <             randomTorque = Atrans* randomTorque;
225 <             integrableObject->addFrc(randomForce);            
226 <             integrableObject->addTrq(randomTorque + cross(rcd, randomForce ));
227 <            
397 >              // check for convergence (if the vectors have converged, fdot and tdot will both be 1.0):
398 >              
399 >              fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare();
400 >              tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare();
401 >              
402 >              if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_)
403 >                break; // iteration ends here
404 >            }
405 >
406 >            integrableObject->addFrc(frictionForceLab);
407 >            integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab));
408 >
409 >            
410            } else {
411 <             //spheric atom
230 <             Vector3d frictionForce = -(hydroProps_[index].Xidtt *vel);    
231 <             Vector3d randomForce;
232 <             Vector3d randomTorque;
233 <             genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
411 >            //spherical atom
412  
413 <             //randomForce /= OOPSEConstant::energyConvert;
414 <             //randomTorque /= OOPSEConstant::energyConvert;
415 <             integrableObject->addFrc(frictionForce+randomForce);            
416 <          }
413 >            Vector3d randomForce;
414 >            Vector3d randomTorque;
415 >            genRandomForceAndTorque(randomForce, randomTorque, index, variance_);
416 >            integrableObject->addFrc(randomForce);            
417  
418 +            // What remains contains velocity explicitly, but the velocity required
419 +            // is at the full step: v(t + h), while we have initially the velocity
420 +            // at the half step: v(t + h/2).  We need to iterate to converge the
421 +            // friction force vector.
422 +
423 +            // this is the velocity at the half-step:
424 +            
425 +            Vector3d vel =integrableObject->getVel();
426 +
427 +            //estimate velocity at full-step using everything but friction forces:          
428 +
429 +            frc = integrableObject->getFrc();
430 +            Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc;
431 +
432 +            Vector3d frictionForce(0.0);
433 +            Vector3d oldFF;  // used to test for convergence
434 +            RealType fdot;
435 +
436 +            //iteration starts here:
437 +
438 +            for (int k = 0; k < maxIterNum_; k++) {
439 +
440 +              oldFF = frictionForce;                            
441 +              frictionForce = -hydroProps_[index]->getXitt() * velStep;
442 +
443 +              // re-estimate velocities at full-step using friction forces:
444 +              
445 +              velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce);
446 +
447 +              // check for convergence (if the vector has converged, fdot will be 1.0):
448 +              
449 +              fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare();
450 +              
451 +              if (fabs(1.0 - fdot) <= forceTolerance_)
452 +                break; // iteration ends here
453 +            }
454 +
455 +            integrableObject->addFrc(frictionForce);
456 +
457 +          }
458 +        }
459 +          
460          ++index;
461      
462        }
463      }    
464  
465 <    ForceManager::postCalculation();
465 >    info_->setFdf(fdf);
466 >    veloMunge->removeComDrift();
467 >    // Remove angular drift if we are not using periodic boundary conditions.
468 >    if(!simParams->getUsePeriodicBoundaryConditions())
469 >      veloMunge->removeAngularDrift();
470  
471 <
248 <
471 >    ForceManager::postCalculation();  
472    }
473  
474 < void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, double variance) {
252 <    /*
253 <    SquareMatrix<double, 6> Dd;
254 <    SquareMatrix<double, 6> S;
255 <    Vector<double, 6> Z;
256 <    Vector<double, 6> generalForce;
257 <    Dd.setSubMatrix(0, 0, hydroProps_[index].Ddtt);
258 <    Dd.setSubMatrix(0, 3, hydroProps_[index].Ddtr.transpose());
259 <    Dd.setSubMatrix(3, 0, hydroProps_[index].Ddtr);
260 <    Dd.setSubMatrix(3, 3, hydroProps_[index].Ddrr);
261 <    CholeskyDecomposition(Dd, S);
262 <    */
474 > void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) {
475  
264    SquareMatrix<double, 6> Xid;
265    SquareMatrix<double, 6> S;
266    Vector<double, 6> Z;
267    Vector<double, 6> generalForce;
268    Xid.setSubMatrix(0, 0, hydroProps_[index].Xidtt);
269    Xid.setSubMatrix(0, 3, hydroProps_[index].Xidrt);
270    Xid.setSubMatrix(3, 0, hydroProps_[index].Xidtr);
271    Xid.setSubMatrix(3, 3, hydroProps_[index].Xidrr);
272    CholeskyDecomposition(Xid, S);
476  
477 <    /*
478 <    Xid *= variance;
276 <    Z[0] = randNumGen_.randNorm(0, 1.0);
277 <    Z[1] = randNumGen_.randNorm(0, 1.0);
278 <    Z[2] = randNumGen_.randNorm(0, 1.0);
279 <    Z[3] = randNumGen_.randNorm(0, 1.0);
280 <    Z[4] = randNumGen_.randNorm(0, 1.0);
281 <    Z[5] = randNumGen_.randNorm(0, 1.0);
282 <    */
477 >    Vector<RealType, 6> Z;
478 >    Vector<RealType, 6> generalForce;
479          
480      Z[0] = randNumGen_.randNorm(0, variance);
481      Z[1] = randNumGen_.randNorm(0, variance);
# Line 288 | Line 484 | void LDForceManager::genRandomForceAndTorque(Vector3d&
484      Z[4] = randNumGen_.randNorm(0, variance);
485      Z[5] = randNumGen_.randNorm(0, variance);
486      
487 <
292 <    generalForce = S*Z;
487 >    generalForce = hydroProps_[index]->getS()*Z;
488      
489      force[0] = generalForce[0];
490      force[1] = generalForce[1];
# Line 298 | Line 493 | void LDForceManager::genRandomForceAndTorque(Vector3d&
493      torque[1] = generalForce[4];
494      torque[2] = generalForce[5];
495      
496 < }
496 > }
497  
498   }

Comparing:
trunk/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 904 by tim, Thu Mar 16 22:50:48 2006 UTC vs.
branches/development/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines