1 |
tim |
895 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
10 |
tim |
895 |
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
tim |
895 |
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
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 |
gezelter |
1390 |
* |
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 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
tim |
895 |
*/ |
42 |
|
|
#include <fstream> |
43 |
chuckv |
1120 |
#include <iostream> |
44 |
tim |
895 |
#include "integrators/LDForceManager.hpp" |
45 |
|
|
#include "math/CholeskyDecomposition.hpp" |
46 |
gezelter |
1390 |
#include "utils/PhysicalConstants.hpp" |
47 |
gezelter |
956 |
#include "hydrodynamics/Sphere.hpp" |
48 |
|
|
#include "hydrodynamics/Ellipsoid.hpp" |
49 |
gezelter |
1210 |
#include "utils/ElementsTable.hpp" |
50 |
gezelter |
1710 |
#include "types/LennardJonesAdapter.hpp" |
51 |
|
|
#include "types/GayBerneAdapter.hpp" |
52 |
gezelter |
956 |
|
53 |
gezelter |
1390 |
namespace OpenMD { |
54 |
tim |
895 |
|
55 |
gezelter |
1237 |
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info), forceTolerance_(1e-6), maxIterNum_(4) { |
56 |
gezelter |
983 |
simParams = info->getSimParams(); |
57 |
|
|
veloMunge = new Velocitizer(info); |
58 |
|
|
|
59 |
gezelter |
945 |
sphericalBoundaryConditions_ = false; |
60 |
|
|
if (simParams->getUseSphericalBoundaryConditions()) { |
61 |
|
|
sphericalBoundaryConditions_ = true; |
62 |
|
|
if (simParams->haveLangevinBufferRadius()) { |
63 |
|
|
langevinBufferRadius_ = simParams->getLangevinBufferRadius(); |
64 |
|
|
} else { |
65 |
|
|
sprintf( painCave.errMsg, |
66 |
|
|
"langevinBufferRadius must be specified " |
67 |
|
|
"when useSphericalBoundaryConditions is turned on.\n"); |
68 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
69 |
gezelter |
945 |
painCave.isFatal = 1; |
70 |
|
|
simError(); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
if (simParams->haveFrozenBufferRadius()) { |
74 |
|
|
frozenBufferRadius_ = simParams->getFrozenBufferRadius(); |
75 |
|
|
} else { |
76 |
|
|
sprintf( painCave.errMsg, |
77 |
|
|
"frozenBufferRadius must be specified " |
78 |
|
|
"when useSphericalBoundaryConditions is turned on.\n"); |
79 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
80 |
gezelter |
945 |
painCave.isFatal = 1; |
81 |
|
|
simError(); |
82 |
|
|
} |
83 |
tim |
895 |
|
84 |
gezelter |
945 |
if (frozenBufferRadius_ < langevinBufferRadius_) { |
85 |
|
|
sprintf( painCave.errMsg, |
86 |
|
|
"frozenBufferRadius has been set smaller than the " |
87 |
|
|
"langevinBufferRadius. This is probably an error.\n"); |
88 |
gezelter |
1390 |
painCave.severity = OPENMD_WARNING; |
89 |
gezelter |
945 |
painCave.isFatal = 0; |
90 |
|
|
simError(); |
91 |
|
|
} |
92 |
|
|
} |
93 |
gezelter |
956 |
|
94 |
|
|
// Build the hydroProp map: |
95 |
gezelter |
981 |
std::map<std::string, HydroProp*> hydroPropMap; |
96 |
gezelter |
956 |
|
97 |
tim |
895 |
Molecule* mol; |
98 |
|
|
StuntDouble* integrableObject; |
99 |
gezelter |
956 |
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 |
gezelter |
945 |
integrableObject = mol->nextIntegrableObject(j)) { |
108 |
gezelter |
956 |
|
109 |
|
|
if (integrableObject->isRigidBody()) { |
110 |
|
|
RigidBody* rb = static_cast<RigidBody*>(integrableObject); |
111 |
|
|
if (rb->getNumAtoms() > 1) needHydroPropFile = true; |
112 |
gezelter |
945 |
} |
113 |
|
|
|
114 |
|
|
} |
115 |
tim |
895 |
} |
116 |
gezelter |
956 |
|
117 |
|
|
|
118 |
|
|
if (needHydroPropFile) { |
119 |
|
|
if (simParams->haveHydroPropFile()) { |
120 |
|
|
hydroPropMap = parseFrictionFile(simParams->getHydroPropFile()); |
121 |
|
|
} else { |
122 |
|
|
sprintf( painCave.errMsg, |
123 |
gezelter |
1237 |
"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 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
127 |
gezelter |
956 |
painCave.isFatal = 1; |
128 |
|
|
simError(); |
129 |
|
|
} |
130 |
tim |
971 |
|
131 |
|
|
for (mol = info->beginMolecule(i); mol != NULL; |
132 |
|
|
mol = info->nextMolecule(i)) { |
133 |
|
|
for (integrableObject = mol->beginIntegrableObject(j); |
134 |
|
|
integrableObject != NULL; |
135 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
136 |
|
|
|
137 |
gezelter |
981 |
std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType()); |
138 |
tim |
971 |
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 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
144 |
tim |
971 |
painCave.isFatal = 1; |
145 |
|
|
simError(); |
146 |
|
|
} |
147 |
|
|
} |
148 |
gezelter |
956 |
} |
149 |
|
|
} else { |
150 |
gezelter |
981 |
|
151 |
|
|
std::map<std::string, HydroProp*> hydroPropMap; |
152 |
gezelter |
956 |
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)) { |
157 |
|
|
Shape* currShape = NULL; |
158 |
xsun |
1185 |
|
159 |
|
|
if (integrableObject->isAtom()){ |
160 |
|
|
Atom* atom = static_cast<Atom*>(integrableObject); |
161 |
|
|
AtomType* atomType = atom->getAtomType(); |
162 |
gezelter |
1710 |
GayBerneAdapter gba = GayBerneAdapter(atomType); |
163 |
|
|
if (gba.isGayBerne()) { |
164 |
|
|
currShape = new Ellipsoid(V3Zero, gba.getL() / 2.0, |
165 |
|
|
gba.getD() / 2.0, |
166 |
|
|
Mat3x3d::identity()); |
167 |
xsun |
1185 |
} else { |
168 |
gezelter |
1710 |
LennardJonesAdapter lja = LennardJonesAdapter(atomType); |
169 |
|
|
if (lja.isLennardJones()){ |
170 |
|
|
currShape = new Sphere(atom->getPos(), lja.getSigma()/2.0); |
171 |
xsun |
1185 |
} else { |
172 |
gezelter |
1237 |
int aNum = etab.GetAtomicNum((atom->getType()).c_str()); |
173 |
|
|
if (aNum != 0) { |
174 |
|
|
currShape = new Sphere(atom->getPos(), etab.GetVdwRad(aNum)); |
175 |
gezelter |
956 |
} else { |
176 |
|
|
sprintf( painCave.errMsg, |
177 |
xsun |
1185 |
"Could not find atom type in default element.txt\n"); |
178 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
179 |
gezelter |
956 |
painCave.isFatal = 1; |
180 |
|
|
simError(); |
181 |
xsun |
1185 |
} |
182 |
gezelter |
956 |
} |
183 |
|
|
} |
184 |
|
|
} |
185 |
chuckv |
1293 |
|
186 |
|
|
if (!simParams->haveTargetTemp()) { |
187 |
|
|
sprintf(painCave.errMsg, "You can't use LangevinDynamics without a targetTemp!\n"); |
188 |
|
|
painCave.isFatal = 1; |
189 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
190 |
chuckv |
1293 |
simError(); |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
if (!simParams->haveViscosity()) { |
194 |
|
|
sprintf(painCave.errMsg, "You can't use LangevinDynamics without a viscosity!\n"); |
195 |
|
|
painCave.isFatal = 1; |
196 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
197 |
chuckv |
1293 |
simError(); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
|
201 |
gezelter |
981 |
HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp()); |
202 |
|
|
std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType()); |
203 |
gezelter |
956 |
if (iter != hydroPropMap.end()) |
204 |
|
|
hydroProps_.push_back(iter->second); |
205 |
|
|
else { |
206 |
gezelter |
981 |
currHydroProp->complete(); |
207 |
|
|
hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp)); |
208 |
|
|
hydroProps_.push_back(currHydroProp); |
209 |
gezelter |
956 |
} |
210 |
|
|
} |
211 |
|
|
} |
212 |
|
|
} |
213 |
gezelter |
1390 |
variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt(); |
214 |
gezelter |
981 |
} |
215 |
gezelter |
956 |
|
216 |
gezelter |
981 |
std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) { |
217 |
|
|
std::map<std::string, HydroProp*> props; |
218 |
tim |
895 |
std::ifstream ifs(filename.c_str()); |
219 |
|
|
if (ifs.is_open()) { |
220 |
gezelter |
945 |
|
221 |
tim |
895 |
} |
222 |
gezelter |
945 |
|
223 |
tim |
895 |
const unsigned int BufferSize = 65535; |
224 |
|
|
char buffer[BufferSize]; |
225 |
|
|
while (ifs.getline(buffer, BufferSize)) { |
226 |
gezelter |
981 |
HydroProp* currProp = new HydroProp(buffer); |
227 |
|
|
props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp)); |
228 |
tim |
895 |
} |
229 |
gezelter |
981 |
|
230 |
tim |
895 |
return props; |
231 |
|
|
} |
232 |
gezelter |
981 |
|
233 |
gezelter |
1464 |
void LDForceManager::postCalculation(){ |
234 |
tim |
895 |
SimInfo::MoleculeIterator i; |
235 |
|
|
Molecule::IntegrableObjectIterator j; |
236 |
|
|
Molecule* mol; |
237 |
|
|
StuntDouble* integrableObject; |
238 |
xsun |
1185 |
RealType mass; |
239 |
tim |
895 |
Vector3d pos; |
240 |
|
|
Vector3d frc; |
241 |
|
|
Mat3x3d A; |
242 |
tim |
904 |
Mat3x3d Atrans; |
243 |
tim |
895 |
Vector3d Tb; |
244 |
|
|
Vector3d ji; |
245 |
|
|
unsigned int index = 0; |
246 |
gezelter |
945 |
bool doLangevinForces; |
247 |
|
|
bool freezeMolecule; |
248 |
|
|
int fdf; |
249 |
gezelter |
983 |
|
250 |
chuckv |
1120 |
fdf = 0; |
251 |
gezelter |
983 |
|
252 |
tim |
895 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
253 |
gezelter |
970 |
|
254 |
|
|
doLangevinForces = true; |
255 |
|
|
freezeMolecule = false; |
256 |
|
|
|
257 |
gezelter |
945 |
if (sphericalBoundaryConditions_) { |
258 |
|
|
|
259 |
|
|
Vector3d molPos = mol->getCom(); |
260 |
tim |
963 |
RealType molRad = molPos.length(); |
261 |
chuckv |
1120 |
|
262 |
gezelter |
945 |
doLangevinForces = false; |
263 |
|
|
|
264 |
|
|
if (molRad > langevinBufferRadius_) { |
265 |
|
|
doLangevinForces = true; |
266 |
|
|
freezeMolecule = false; |
267 |
|
|
} |
268 |
|
|
if (molRad > frozenBufferRadius_) { |
269 |
|
|
doLangevinForces = false; |
270 |
|
|
freezeMolecule = true; |
271 |
|
|
} |
272 |
|
|
} |
273 |
|
|
|
274 |
gezelter |
956 |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
275 |
|
|
integrableObject = mol->nextIntegrableObject(j)) { |
276 |
gezelter |
945 |
|
277 |
gezelter |
956 |
if (freezeMolecule) |
278 |
|
|
fdf += integrableObject->freeze(); |
279 |
|
|
|
280 |
chuckv |
1120 |
if (doLangevinForces) { |
281 |
xsun |
1185 |
mass = integrableObject->getMass(); |
282 |
tim |
895 |
if (integrableObject->isDirectional()){ |
283 |
gezelter |
1237 |
|
284 |
|
|
// preliminaries for directional objects: |
285 |
|
|
|
286 |
xsun |
1216 |
A = integrableObject->getA(); |
287 |
|
|
Atrans = A.transpose(); |
288 |
|
|
Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR(); |
289 |
xsun |
1185 |
|
290 |
gezelter |
1237 |
//apply random force and torque at center of resistance |
291 |
xsun |
1185 |
|
292 |
gezelter |
945 |
Vector3d randomForceBody; |
293 |
|
|
Vector3d randomTorqueBody; |
294 |
|
|
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
295 |
xsun |
1216 |
Vector3d randomForceLab = Atrans * randomForceBody; |
296 |
|
|
Vector3d randomTorqueLab = Atrans * randomTorqueBody; |
297 |
gezelter |
945 |
integrableObject->addFrc(randomForceLab); |
298 |
xsun |
1216 |
integrableObject->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab )); |
299 |
gezelter |
1237 |
|
300 |
|
|
Mat3x3d I = integrableObject->getI(); |
301 |
|
|
Vector3d omegaBody; |
302 |
|
|
|
303 |
|
|
// What remains contains velocity explicitly, but the velocity required |
304 |
|
|
// is at the full step: v(t + h), while we have initially the velocity |
305 |
|
|
// at the half step: v(t + h/2). We need to iterate to converge the |
306 |
|
|
// friction force and friction torque vectors. |
307 |
|
|
|
308 |
|
|
// this is the velocity at the half-step: |
309 |
gezelter |
945 |
|
310 |
gezelter |
1237 |
Vector3d vel =integrableObject->getVel(); |
311 |
|
|
Vector3d angMom = integrableObject->getJ(); |
312 |
|
|
|
313 |
|
|
//estimate velocity at full-step using everything but friction forces: |
314 |
|
|
|
315 |
|
|
frc = integrableObject->getFrc(); |
316 |
gezelter |
1390 |
Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc; |
317 |
gezelter |
1237 |
|
318 |
|
|
Tb = integrableObject->lab2Body(integrableObject->getTrq()); |
319 |
gezelter |
1390 |
Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb; |
320 |
gezelter |
1237 |
|
321 |
|
|
Vector3d omegaLab; |
322 |
|
|
Vector3d vcdLab; |
323 |
|
|
Vector3d vcdBody; |
324 |
|
|
Vector3d frictionForceBody; |
325 |
|
|
Vector3d frictionForceLab(0.0); |
326 |
|
|
Vector3d oldFFL; // used to test for convergence |
327 |
|
|
Vector3d frictionTorqueBody(0.0); |
328 |
|
|
Vector3d oldFTB; // used to test for convergence |
329 |
|
|
Vector3d frictionTorqueLab; |
330 |
|
|
RealType fdot; |
331 |
|
|
RealType tdot; |
332 |
|
|
|
333 |
|
|
//iteration starts here: |
334 |
|
|
|
335 |
|
|
for (int k = 0; k < maxIterNum_; k++) { |
336 |
|
|
|
337 |
|
|
if (integrableObject->isLinear()) { |
338 |
|
|
int linearAxis = integrableObject->linearAxis(); |
339 |
|
|
int l = (linearAxis +1 )%3; |
340 |
|
|
int m = (linearAxis +2 )%3; |
341 |
|
|
omegaBody[l] = angMomStep[l] /I(l, l); |
342 |
|
|
omegaBody[m] = angMomStep[m] /I(m, m); |
343 |
|
|
|
344 |
|
|
} else { |
345 |
|
|
omegaBody[0] = angMomStep[0] /I(0, 0); |
346 |
|
|
omegaBody[1] = angMomStep[1] /I(1, 1); |
347 |
|
|
omegaBody[2] = angMomStep[2] /I(2, 2); |
348 |
|
|
} |
349 |
|
|
|
350 |
|
|
omegaLab = Atrans * omegaBody; |
351 |
|
|
|
352 |
|
|
// apply friction force and torque at center of resistance |
353 |
|
|
|
354 |
|
|
vcdLab = velStep + cross(omegaLab, rcrLab); |
355 |
|
|
vcdBody = A * vcdLab; |
356 |
|
|
frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody); |
357 |
|
|
oldFFL = frictionForceLab; |
358 |
|
|
frictionForceLab = Atrans * frictionForceBody; |
359 |
|
|
oldFTB = frictionTorqueBody; |
360 |
|
|
frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody); |
361 |
|
|
frictionTorqueLab = Atrans * frictionTorqueBody; |
362 |
|
|
|
363 |
|
|
// re-estimate velocities at full-step using friction forces: |
364 |
|
|
|
365 |
gezelter |
1390 |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab); |
366 |
|
|
angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody); |
367 |
gezelter |
1237 |
|
368 |
|
|
// check for convergence (if the vectors have converged, fdot and tdot will both be 1.0): |
369 |
|
|
|
370 |
|
|
fdot = dot(frictionForceLab, oldFFL) / frictionForceLab.lengthSquare(); |
371 |
|
|
tdot = dot(frictionTorqueBody, oldFTB) / frictionTorqueBody.lengthSquare(); |
372 |
|
|
|
373 |
|
|
if (fabs(1.0 - fdot) <= forceTolerance_ && fabs(1.0 - tdot) <= forceTolerance_) |
374 |
|
|
break; // iteration ends here |
375 |
|
|
} |
376 |
|
|
|
377 |
|
|
integrableObject->addFrc(frictionForceLab); |
378 |
|
|
integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab)); |
379 |
|
|
|
380 |
|
|
|
381 |
tim |
895 |
} else { |
382 |
gezelter |
945 |
//spherical atom |
383 |
gezelter |
1237 |
|
384 |
gezelter |
945 |
Vector3d randomForce; |
385 |
|
|
Vector3d randomTorque; |
386 |
|
|
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
387 |
gezelter |
1237 |
integrableObject->addFrc(randomForce); |
388 |
|
|
|
389 |
|
|
// What remains contains velocity explicitly, but the velocity required |
390 |
|
|
// is at the full step: v(t + h), while we have initially the velocity |
391 |
|
|
// at the half step: v(t + h/2). We need to iterate to converge the |
392 |
|
|
// friction force vector. |
393 |
|
|
|
394 |
|
|
// this is the velocity at the half-step: |
395 |
gezelter |
945 |
|
396 |
gezelter |
1237 |
Vector3d vel =integrableObject->getVel(); |
397 |
|
|
|
398 |
|
|
//estimate velocity at full-step using everything but friction forces: |
399 |
|
|
|
400 |
|
|
frc = integrableObject->getFrc(); |
401 |
gezelter |
1390 |
Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc; |
402 |
gezelter |
1237 |
|
403 |
|
|
Vector3d frictionForce(0.0); |
404 |
|
|
Vector3d oldFF; // used to test for convergence |
405 |
|
|
RealType fdot; |
406 |
|
|
|
407 |
|
|
//iteration starts here: |
408 |
|
|
|
409 |
|
|
for (int k = 0; k < maxIterNum_; k++) { |
410 |
|
|
|
411 |
|
|
oldFF = frictionForce; |
412 |
|
|
frictionForce = -hydroProps_[index]->getXitt() * velStep; |
413 |
|
|
|
414 |
|
|
// re-estimate velocities at full-step using friction forces: |
415 |
|
|
|
416 |
gezelter |
1390 |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce); |
417 |
gezelter |
1237 |
|
418 |
|
|
// check for convergence (if the vector has converged, fdot will be 1.0): |
419 |
|
|
|
420 |
|
|
fdot = dot(frictionForce, oldFF) / frictionForce.lengthSquare(); |
421 |
|
|
|
422 |
|
|
if (fabs(1.0 - fdot) <= forceTolerance_) |
423 |
|
|
break; // iteration ends here |
424 |
|
|
} |
425 |
|
|
|
426 |
|
|
integrableObject->addFrc(frictionForce); |
427 |
|
|
|
428 |
tim |
895 |
} |
429 |
gezelter |
956 |
} |
430 |
gezelter |
945 |
|
431 |
gezelter |
956 |
++index; |
432 |
tim |
895 |
|
433 |
|
|
} |
434 |
gezelter |
956 |
} |
435 |
chuckv |
1120 |
|
436 |
gezelter |
945 |
info_->setFdf(fdf); |
437 |
gezelter |
983 |
veloMunge->removeComDrift(); |
438 |
|
|
// Remove angular drift if we are not using periodic boundary conditions. |
439 |
|
|
if(!simParams->getUsePeriodicBoundaryConditions()) |
440 |
|
|
veloMunge->removeAngularDrift(); |
441 |
|
|
|
442 |
gezelter |
1464 |
ForceManager::postCalculation(); |
443 |
tim |
895 |
} |
444 |
|
|
|
445 |
tim |
963 |
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) { |
446 |
tim |
904 |
|
447 |
tim |
906 |
|
448 |
tim |
963 |
Vector<RealType, 6> Z; |
449 |
|
|
Vector<RealType, 6> generalForce; |
450 |
tim |
904 |
|
451 |
tim |
895 |
Z[0] = randNumGen_.randNorm(0, variance); |
452 |
|
|
Z[1] = randNumGen_.randNorm(0, variance); |
453 |
|
|
Z[2] = randNumGen_.randNorm(0, variance); |
454 |
|
|
Z[3] = randNumGen_.randNorm(0, variance); |
455 |
|
|
Z[4] = randNumGen_.randNorm(0, variance); |
456 |
|
|
Z[5] = randNumGen_.randNorm(0, variance); |
457 |
tim |
904 |
|
458 |
gezelter |
981 |
generalForce = hydroProps_[index]->getS()*Z; |
459 |
tim |
904 |
|
460 |
tim |
895 |
force[0] = generalForce[0]; |
461 |
|
|
force[1] = generalForce[1]; |
462 |
|
|
force[2] = generalForce[2]; |
463 |
|
|
torque[0] = generalForce[3]; |
464 |
|
|
torque[1] = generalForce[4]; |
465 |
|
|
torque[2] = generalForce[5]; |
466 |
|
|
|
467 |
xsun |
1185 |
} |
468 |
tim |
895 |
|
469 |
|
|
} |