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

Comparing:
trunk/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 895 by tim, Mon Mar 13 22:42:40 2006 UTC vs.
branches/development/src/integrators/LDForceManager.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines