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. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
35 |
+ |
* |
36 |
+ |
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
+ |
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
+ |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
#include <fstream> |
43 |
|
#include <iostream> |
44 |
|
#include "integrators/LDForceManager.hpp" |
45 |
|
#include "math/CholeskyDecomposition.hpp" |
46 |
< |
#include "utils/OOPSEConstant.hpp" |
46 |
> |
#include "utils/PhysicalConstants.hpp" |
47 |
|
#include "hydrodynamics/Sphere.hpp" |
48 |
|
#include "hydrodynamics/Ellipsoid.hpp" |
49 |
< |
#include "openbabel/mol.hpp" |
49 |
> |
#include "utils/ElementsTable.hpp" |
50 |
> |
#include "types/LennardJonesAdapter.hpp" |
51 |
> |
#include "types/GayBerneAdapter.hpp" |
52 |
|
|
53 |
< |
using namespace OpenBabel; |
51 |
< |
namespace oopse { |
53 |
> |
namespace OpenMD { |
54 |
|
|
55 |
< |
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){ |
55 |
> |
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info), forceTolerance_(1e-6), maxIterNum_(4) { |
56 |
|
simParams = info->getSimParams(); |
57 |
|
veloMunge = new Velocitizer(info); |
58 |
|
|
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 |
|
} |
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 |
|
} |
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 |
|
} |
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 |
|
|
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 |
|
|
131 |
|
for (mol = info->beginMolecule(i); mol != NULL; |
132 |
|
mol = info->nextMolecule(i)) { |
131 |
– |
for (integrableObject = mol->beginIntegrableObject(j); |
132 |
– |
integrableObject != NULL; |
133 |
– |
integrableObject = mol->nextIntegrableObject(j)) { |
133 |
|
|
134 |
< |
std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType()); |
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", integrableObject->getType().c_str()); |
143 |
< |
painCave.severity = OOPSE_ERROR; |
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 |
|
} |
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(); |
159 |
< |
if (atomType->isGayBerne()) { |
160 |
< |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
161 |
< |
|
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_d / 2.0, |
170 |
< |
gayBerneParam.GB_l / 2.0, |
171 |
< |
Mat3x3d::identity()); |
172 |
< |
} else { |
173 |
< |
sprintf( painCave.errMsg, |
174 |
< |
"Can not cast GenericData to GayBerneParam\n"); |
175 |
< |
painCave.severity = OOPSE_ERROR; |
176 |
< |
painCave.isFatal = 1; |
177 |
< |
simError(); |
178 |
< |
} |
179 |
< |
} else { |
180 |
< |
sprintf( painCave.errMsg, "Can not find Parameters for GayBerne\n"); |
181 |
< |
painCave.severity = OOPSE_ERROR; |
182 |
< |
painCave.isFatal = 1; |
183 |
< |
simError(); |
184 |
< |
} |
185 |
< |
} |
186 |
< |
} else { |
187 |
< |
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 |
|
} |
205 |
– |
} else { |
206 |
– |
int obanum = etab.GetAtomicNum((atom->getType()).c_str()); |
207 |
– |
if (obanum != 0) { |
208 |
– |
currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum)); |
209 |
– |
} else { |
210 |
– |
sprintf( painCave.errMsg, |
211 |
– |
"Could not find atom type in default element.txt\n"); |
212 |
– |
painCave.severity = OOPSE_ERROR; |
213 |
– |
painCave.isFatal = 1; |
214 |
– |
simError(); |
215 |
– |
} |
184 |
|
} |
185 |
|
} |
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(integrableObject->getType()); |
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 |
|
currHydroProp->complete(); |
208 |
< |
hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp)); |
208 |
> |
hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(sd->getType(), currHydroProp)); |
209 |
|
hydroProps_.push_back(currHydroProp); |
210 |
|
} |
211 |
+ |
delete currShape; |
212 |
|
} |
213 |
|
} |
214 |
|
} |
215 |
< |
variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt(); |
215 |
> |
variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt(); |
216 |
|
} |
217 |
|
|
218 |
|
std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) { |
232 |
|
return props; |
233 |
|
} |
234 |
|
|
235 |
< |
void LDForceManager::postCalculation() { |
235 |
> |
void LDForceManager::postCalculation(){ |
236 |
|
SimInfo::MoleculeIterator i; |
237 |
|
Molecule::IntegrableObjectIterator j; |
238 |
|
Molecule* mol; |
239 |
< |
StuntDouble* integrableObject; |
240 |
< |
Vector3d vel; |
239 |
> |
StuntDouble* sd; |
240 |
> |
RealType mass; |
241 |
|
Vector3d pos; |
242 |
|
Vector3d frc; |
243 |
|
Mat3x3d A; |
244 |
|
Mat3x3d Atrans; |
245 |
|
Vector3d Tb; |
246 |
|
Vector3d ji; |
262 |
– |
RealType mass; |
247 |
|
unsigned int index = 0; |
248 |
|
bool doLangevinForces; |
249 |
|
bool freezeMolecule; |
250 |
|
int fdf; |
267 |
– |
int nIntegrated; |
268 |
– |
int nFrozen; |
251 |
|
|
252 |
|
fdf = 0; |
253 |
|
|
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
< |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
277 |
< |
integrableObject = mol->nextIntegrableObject(j)) { |
276 |
> |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
277 |
> |
sd = mol->nextIntegrableObject(j)) { |
278 |
|
|
279 |
|
if (freezeMolecule) |
280 |
< |
fdf += integrableObject->freeze(); |
280 |
> |
fdf += sd->freeze(); |
281 |
|
|
282 |
|
if (doLangevinForces) { |
283 |
< |
vel =integrableObject->getVel(); |
284 |
< |
if (integrableObject->isDirectional()){ |
285 |
< |
//calculate angular velocity in lab frame |
286 |
< |
Mat3x3d I = integrableObject->getI(); |
287 |
< |
Vector3d angMom = integrableObject->getJ(); |
288 |
< |
Vector3d omega; |
307 |
< |
|
308 |
< |
if (integrableObject->isLinear()) { |
309 |
< |
int linearAxis = integrableObject->linearAxis(); |
310 |
< |
int l = (linearAxis +1 )%3; |
311 |
< |
int m = (linearAxis +2 )%3; |
312 |
< |
omega[l] = angMom[l] /I(l, l); |
313 |
< |
omega[m] = angMom[m] /I(m, m); |
314 |
< |
|
315 |
< |
} else { |
316 |
< |
omega[0] = angMom[0] /I(0, 0); |
317 |
< |
omega[1] = angMom[1] /I(1, 1); |
318 |
< |
omega[2] = angMom[2] /I(2, 2); |
319 |
< |
} |
320 |
< |
|
321 |
< |
//apply friction force and torque at center of resistance |
322 |
< |
A = integrableObject->getA(); |
283 |
> |
mass = sd->getMass(); |
284 |
> |
if (sd->isDirectional()){ |
285 |
> |
|
286 |
> |
// preliminaries for directional objects: |
287 |
> |
|
288 |
> |
A = sd->getA(); |
289 |
|
Atrans = A.transpose(); |
290 |
< |
Vector3d rcr = Atrans * hydroProps_[index]->getCOR(); |
291 |
< |
Vector3d vcdLab = vel + cross(omega, rcr); |
326 |
< |
Vector3d vcdBody = A* vcdLab; |
327 |
< |
Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omega); |
328 |
< |
Vector3d frictionForceLab = Atrans*frictionForceBody; |
329 |
< |
integrableObject->addFrc(frictionForceLab); |
330 |
< |
Vector3d frictionTorqueBody = - (hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omega); |
331 |
< |
Vector3d frictionTorqueLab = Atrans*frictionTorqueBody; |
332 |
< |
integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab)); |
333 |
< |
|
290 |
> |
Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR(); |
291 |
> |
|
292 |
|
//apply random force and torque at center of resistance |
293 |
+ |
|
294 |
|
Vector3d randomForceBody; |
295 |
|
Vector3d randomTorqueBody; |
296 |
|
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
297 |
< |
Vector3d randomForceLab = Atrans*randomForceBody; |
298 |
< |
Vector3d randomTorqueLab = Atrans* randomTorqueBody; |
299 |
< |
integrableObject->addFrc(randomForceLab); |
300 |
< |
integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab )); |
297 |
> |
Vector3d randomForceLab = Atrans * randomForceBody; |
298 |
> |
Vector3d randomTorqueLab = Atrans * randomTorqueBody; |
299 |
> |
sd->addFrc(randomForceLab); |
300 |
> |
sd->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab )); |
301 |
> |
|
302 |
> |
Mat3x3d I = sd->getI(); |
303 |
> |
Vector3d omegaBody; |
304 |
> |
|
305 |
> |
// What remains contains velocity explicitly, but the velocity required |
306 |
> |
// is at the full step: v(t + h), while we have initially the velocity |
307 |
> |
// at the half step: v(t + h/2). We need to iterate to converge the |
308 |
> |
// friction force and friction torque vectors. |
309 |
> |
|
310 |
> |
// this is the velocity at the half-step: |
311 |
|
|
312 |
+ |
Vector3d vel =sd->getVel(); |
313 |
+ |
Vector3d angMom = sd->getJ(); |
314 |
+ |
|
315 |
+ |
//estimate velocity at full-step using everything but friction forces: |
316 |
+ |
|
317 |
+ |
frc = sd->getFrc(); |
318 |
+ |
Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc; |
319 |
+ |
|
320 |
+ |
Tb = sd->lab2Body(sd->getTrq()); |
321 |
+ |
Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb; |
322 |
+ |
|
323 |
+ |
Vector3d omegaLab; |
324 |
+ |
Vector3d vcdLab; |
325 |
+ |
Vector3d vcdBody; |
326 |
+ |
Vector3d frictionForceBody; |
327 |
+ |
Vector3d frictionForceLab(0.0); |
328 |
+ |
Vector3d oldFFL; // used to test for convergence |
329 |
+ |
Vector3d frictionTorqueBody(0.0); |
330 |
+ |
Vector3d oldFTB; // used to test for convergence |
331 |
+ |
Vector3d frictionTorqueLab; |
332 |
+ |
RealType fdot; |
333 |
+ |
RealType tdot; |
334 |
+ |
|
335 |
+ |
//iteration starts here: |
336 |
+ |
|
337 |
+ |
for (int k = 0; k < maxIterNum_; k++) { |
338 |
+ |
|
339 |
+ |
if (sd->isLinear()) { |
340 |
+ |
int linearAxis = sd->linearAxis(); |
341 |
+ |
int l = (linearAxis +1 )%3; |
342 |
+ |
int m = (linearAxis +2 )%3; |
343 |
+ |
omegaBody[l] = angMomStep[l] /I(l, l); |
344 |
+ |
omegaBody[m] = angMomStep[m] /I(m, m); |
345 |
+ |
|
346 |
+ |
} else { |
347 |
+ |
omegaBody[0] = angMomStep[0] /I(0, 0); |
348 |
+ |
omegaBody[1] = angMomStep[1] /I(1, 1); |
349 |
+ |
omegaBody[2] = angMomStep[2] /I(2, 2); |
350 |
+ |
} |
351 |
+ |
|
352 |
+ |
omegaLab = Atrans * omegaBody; |
353 |
+ |
|
354 |
+ |
// apply friction force and torque at center of resistance |
355 |
+ |
|
356 |
+ |
vcdLab = velStep + cross(omegaLab, rcrLab); |
357 |
+ |
vcdBody = A * vcdLab; |
358 |
+ |
frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody); |
359 |
+ |
oldFFL = frictionForceLab; |
360 |
+ |
frictionForceLab = Atrans * frictionForceBody; |
361 |
+ |
oldFTB = frictionTorqueBody; |
362 |
+ |
frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody); |
363 |
+ |
frictionTorqueLab = Atrans * frictionTorqueBody; |
364 |
+ |
|
365 |
+ |
// re-estimate velocities at full-step using friction forces: |
366 |
+ |
|
367 |
+ |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab); |
368 |
+ |
angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody); |
369 |
+ |
|
370 |
+ |
// check for convergence (if the vectors have converged, fdot and tdot will both be 1.0): |
371 |
+ |
|
372 |
+ |
fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare(); |
373 |
+ |
tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare(); |
374 |
+ |
|
375 |
+ |
if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_) |
376 |
+ |
break; // iteration ends here |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
sd->addFrc(frictionForceLab); |
380 |
+ |
sd->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab)); |
381 |
+ |
|
382 |
+ |
|
383 |
|
} else { |
384 |
|
//spherical atom |
385 |
< |
Vector3d frictionForce = -(hydroProps_[index]->getXitt() * vel); |
385 |
> |
|
386 |
|
Vector3d randomForce; |
387 |
|
Vector3d randomTorque; |
388 |
|
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
389 |
+ |
sd->addFrc(randomForce); |
390 |
+ |
|
391 |
+ |
// What remains contains velocity explicitly, but the velocity required |
392 |
+ |
// is at the full step: v(t + h), while we have initially the velocity |
393 |
+ |
// at the half step: v(t + h/2). We need to iterate to converge the |
394 |
+ |
// friction force vector. |
395 |
+ |
|
396 |
+ |
// this is the velocity at the half-step: |
397 |
|
|
398 |
< |
integrableObject->addFrc(frictionForce+randomForce); |
398 |
> |
Vector3d vel =sd->getVel(); |
399 |
> |
|
400 |
> |
//estimate velocity at full-step using everything but friction forces: |
401 |
> |
|
402 |
> |
frc = sd->getFrc(); |
403 |
> |
Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc; |
404 |
> |
|
405 |
> |
Vector3d frictionForce(0.0); |
406 |
> |
Vector3d oldFF; // used to test for convergence |
407 |
> |
RealType fdot; |
408 |
> |
|
409 |
> |
//iteration starts here: |
410 |
> |
|
411 |
> |
for (int k = 0; k < maxIterNum_; k++) { |
412 |
> |
|
413 |
> |
oldFF = frictionForce; |
414 |
> |
frictionForce = -hydroProps_[index]->getXitt() * velStep; |
415 |
> |
|
416 |
> |
// re-estimate velocities at full-step using friction forces: |
417 |
> |
|
418 |
> |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce); |
419 |
> |
|
420 |
> |
// check for convergence (if the vector has converged, fdot will be 1.0): |
421 |
> |
|
422 |
> |
fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare(); |
423 |
> |
|
424 |
> |
if (fabs(1.0 - fdot) <= forceTolerance_) |
425 |
> |
break; // iteration ends here |
426 |
> |
} |
427 |
> |
|
428 |
> |
sd->addFrc(frictionForce); |
429 |
> |
|
430 |
|
} |
431 |
|
} |
432 |
|
|
449 |
|
|
450 |
|
Vector<RealType, 6> Z; |
451 |
|
Vector<RealType, 6> generalForce; |
373 |
– |
|
452 |
|
|
453 |
|
Z[0] = randNumGen_.randNorm(0, variance); |
454 |
|
Z[1] = randNumGen_.randNorm(0, variance); |
457 |
|
Z[4] = randNumGen_.randNorm(0, variance); |
458 |
|
Z[5] = randNumGen_.randNorm(0, variance); |
459 |
|
|
382 |
– |
|
460 |
|
generalForce = hydroProps_[index]->getS()*Z; |
461 |
|
|
462 |
|
force[0] = generalForce[0]; |
466 |
|
torque[1] = generalForce[4]; |
467 |
|
torque[2] = generalForce[5]; |
468 |
|
|
469 |
< |
} |
469 |
> |
} |
470 |
|
|
471 |
|
} |