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 |
gezelter |
1850 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (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 |
gezelter |
1769 |
StuntDouble* sd; |
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 |
gezelter |
1769 |
|
106 |
|
|
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
107 |
|
|
sd = mol->nextIntegrableObject(j)) { |
108 |
gezelter |
956 |
|
109 |
gezelter |
1769 |
if (sd->isRigidBody()) { |
110 |
|
|
RigidBody* rb = static_cast<RigidBody*>(sd); |
111 |
gezelter |
956 |
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 |
|
|
|
134 |
gezelter |
1769 |
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 |
tim |
971 |
if (iter != hydroPropMap.end()) { |
139 |
|
|
hydroProps_.push_back(iter->second); |
140 |
|
|
} else { |
141 |
|
|
sprintf( painCave.errMsg, |
142 |
gezelter |
1769 |
"Can not find resistance tensor for atom [%s]\n", sd->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 |
gezelter |
1769 |
|
155 |
|
|
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
156 |
|
|
sd = mol->nextIntegrableObject(j)) { |
157 |
|
|
|
158 |
gezelter |
956 |
Shape* currShape = NULL; |
159 |
xsun |
1185 |
|
160 |
gezelter |
1769 |
if (sd->isAtom()){ |
161 |
|
|
Atom* atom = static_cast<Atom*>(sd); |
162 |
xsun |
1185 |
AtomType* atomType = atom->getAtomType(); |
163 |
gezelter |
1710 |
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 |
xsun |
1185 |
} else { |
169 |
gezelter |
1710 |
LennardJonesAdapter lja = LennardJonesAdapter(atomType); |
170 |
|
|
if (lja.isLennardJones()){ |
171 |
|
|
currShape = new Sphere(atom->getPos(), lja.getSigma()/2.0); |
172 |
xsun |
1185 |
} else { |
173 |
gezelter |
1237 |
int aNum = etab.GetAtomicNum((atom->getType()).c_str()); |
174 |
|
|
if (aNum != 0) { |
175 |
|
|
currShape = new Sphere(atom->getPos(), etab.GetVdwRad(aNum)); |
176 |
gezelter |
956 |
} else { |
177 |
|
|
sprintf( painCave.errMsg, |
178 |
xsun |
1185 |
"Could not find atom type in default element.txt\n"); |
179 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
180 |
gezelter |
956 |
painCave.isFatal = 1; |
181 |
|
|
simError(); |
182 |
xsun |
1185 |
} |
183 |
gezelter |
956 |
} |
184 |
|
|
} |
185 |
|
|
} |
186 |
chuckv |
1293 |
|
187 |
|
|
if (!simParams->haveTargetTemp()) { |
188 |
|
|
sprintf(painCave.errMsg, "You can't use LangevinDynamics without a targetTemp!\n"); |
189 |
|
|
painCave.isFatal = 1; |
190 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
191 |
chuckv |
1293 |
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 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
198 |
chuckv |
1293 |
simError(); |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
|
202 |
gezelter |
981 |
HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp()); |
203 |
gezelter |
1769 |
std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(sd->getType()); |
204 |
gezelter |
956 |
if (iter != hydroPropMap.end()) |
205 |
|
|
hydroProps_.push_back(iter->second); |
206 |
|
|
else { |
207 |
gezelter |
981 |
currHydroProp->complete(); |
208 |
gezelter |
1769 |
hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(sd->getType(), currHydroProp)); |
209 |
gezelter |
981 |
hydroProps_.push_back(currHydroProp); |
210 |
gezelter |
956 |
} |
211 |
gezelter |
1874 |
delete currShape; |
212 |
gezelter |
956 |
} |
213 |
|
|
} |
214 |
|
|
} |
215 |
gezelter |
1390 |
variance_ = 2.0 * PhysicalConstants::kb*simParams->getTargetTemp()/simParams->getDt(); |
216 |
gezelter |
981 |
} |
217 |
gezelter |
956 |
|
218 |
gezelter |
981 |
std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) { |
219 |
|
|
std::map<std::string, HydroProp*> props; |
220 |
tim |
895 |
std::ifstream ifs(filename.c_str()); |
221 |
|
|
if (ifs.is_open()) { |
222 |
gezelter |
945 |
|
223 |
tim |
895 |
} |
224 |
gezelter |
945 |
|
225 |
tim |
895 |
const unsigned int BufferSize = 65535; |
226 |
|
|
char buffer[BufferSize]; |
227 |
|
|
while (ifs.getline(buffer, BufferSize)) { |
228 |
gezelter |
981 |
HydroProp* currProp = new HydroProp(buffer); |
229 |
|
|
props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp)); |
230 |
tim |
895 |
} |
231 |
gezelter |
981 |
|
232 |
tim |
895 |
return props; |
233 |
|
|
} |
234 |
gezelter |
981 |
|
235 |
gezelter |
1464 |
void LDForceManager::postCalculation(){ |
236 |
tim |
895 |
SimInfo::MoleculeIterator i; |
237 |
|
|
Molecule::IntegrableObjectIterator j; |
238 |
|
|
Molecule* mol; |
239 |
gezelter |
1769 |
StuntDouble* sd; |
240 |
xsun |
1185 |
RealType mass; |
241 |
tim |
895 |
Vector3d pos; |
242 |
|
|
Vector3d frc; |
243 |
|
|
Mat3x3d A; |
244 |
tim |
904 |
Mat3x3d Atrans; |
245 |
tim |
895 |
Vector3d Tb; |
246 |
|
|
Vector3d ji; |
247 |
|
|
unsigned int index = 0; |
248 |
gezelter |
945 |
bool doLangevinForces; |
249 |
|
|
bool freezeMolecule; |
250 |
|
|
int fdf; |
251 |
gezelter |
983 |
|
252 |
chuckv |
1120 |
fdf = 0; |
253 |
gezelter |
983 |
|
254 |
tim |
895 |
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
255 |
gezelter |
970 |
|
256 |
|
|
doLangevinForces = true; |
257 |
|
|
freezeMolecule = false; |
258 |
|
|
|
259 |
gezelter |
945 |
if (sphericalBoundaryConditions_) { |
260 |
|
|
|
261 |
|
|
Vector3d molPos = mol->getCom(); |
262 |
tim |
963 |
RealType molRad = molPos.length(); |
263 |
chuckv |
1120 |
|
264 |
gezelter |
945 |
doLangevinForces = false; |
265 |
|
|
|
266 |
|
|
if (molRad > langevinBufferRadius_) { |
267 |
|
|
doLangevinForces = true; |
268 |
|
|
freezeMolecule = false; |
269 |
|
|
} |
270 |
|
|
if (molRad > frozenBufferRadius_) { |
271 |
|
|
doLangevinForces = false; |
272 |
|
|
freezeMolecule = true; |
273 |
|
|
} |
274 |
|
|
} |
275 |
|
|
|
276 |
gezelter |
1769 |
for (sd = mol->beginIntegrableObject(j); sd != NULL; |
277 |
|
|
sd = mol->nextIntegrableObject(j)) { |
278 |
gezelter |
945 |
|
279 |
gezelter |
956 |
if (freezeMolecule) |
280 |
gezelter |
1769 |
fdf += sd->freeze(); |
281 |
gezelter |
956 |
|
282 |
chuckv |
1120 |
if (doLangevinForces) { |
283 |
gezelter |
1769 |
mass = sd->getMass(); |
284 |
|
|
if (sd->isDirectional()){ |
285 |
gezelter |
1237 |
|
286 |
|
|
// preliminaries for directional objects: |
287 |
|
|
|
288 |
gezelter |
1769 |
A = sd->getA(); |
289 |
xsun |
1216 |
Atrans = A.transpose(); |
290 |
|
|
Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR(); |
291 |
xsun |
1185 |
|
292 |
gezelter |
1237 |
//apply random force and torque at center of resistance |
293 |
xsun |
1185 |
|
294 |
gezelter |
945 |
Vector3d randomForceBody; |
295 |
|
|
Vector3d randomTorqueBody; |
296 |
|
|
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
297 |
xsun |
1216 |
Vector3d randomForceLab = Atrans * randomForceBody; |
298 |
|
|
Vector3d randomTorqueLab = Atrans * randomTorqueBody; |
299 |
gezelter |
1769 |
sd->addFrc(randomForceLab); |
300 |
|
|
sd->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab )); |
301 |
gezelter |
1237 |
|
302 |
gezelter |
1769 |
Mat3x3d I = sd->getI(); |
303 |
gezelter |
1237 |
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 |
gezelter |
945 |
|
312 |
gezelter |
1769 |
Vector3d vel =sd->getVel(); |
313 |
|
|
Vector3d angMom = sd->getJ(); |
314 |
gezelter |
1237 |
|
315 |
|
|
//estimate velocity at full-step using everything but friction forces: |
316 |
|
|
|
317 |
gezelter |
1769 |
frc = sd->getFrc(); |
318 |
gezelter |
1390 |
Vector3d velStep = vel + (dt2_ /mass * PhysicalConstants::energyConvert) * frc; |
319 |
gezelter |
1237 |
|
320 |
gezelter |
1769 |
Tb = sd->lab2Body(sd->getTrq()); |
321 |
gezelter |
1390 |
Vector3d angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * Tb; |
322 |
gezelter |
1237 |
|
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 |
gezelter |
1769 |
if (sd->isLinear()) { |
340 |
|
|
int linearAxis = sd->linearAxis(); |
341 |
gezelter |
1237 |
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 |
gezelter |
1390 |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForceLab); |
368 |
|
|
angMomStep = angMom + (dt2_ * PhysicalConstants::energyConvert) * (Tb + frictionTorqueBody); |
369 |
gezelter |
1237 |
|
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 |
gezelter |
1769 |
sd->addFrc(frictionForceLab); |
380 |
|
|
sd->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab)); |
381 |
gezelter |
1237 |
|
382 |
|
|
|
383 |
tim |
895 |
} else { |
384 |
gezelter |
945 |
//spherical atom |
385 |
gezelter |
1237 |
|
386 |
gezelter |
945 |
Vector3d randomForce; |
387 |
|
|
Vector3d randomTorque; |
388 |
|
|
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
389 |
gezelter |
1769 |
sd->addFrc(randomForce); |
390 |
gezelter |
1237 |
|
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 |
gezelter |
945 |
|
398 |
gezelter |
1769 |
Vector3d vel =sd->getVel(); |
399 |
gezelter |
1237 |
|
400 |
|
|
//estimate velocity at full-step using everything but friction forces: |
401 |
|
|
|
402 |
gezelter |
1769 |
frc = sd->getFrc(); |
403 |
gezelter |
1390 |
Vector3d velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * frc; |
404 |
gezelter |
1237 |
|
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 |
gezelter |
1390 |
velStep = vel + (dt2_ / mass * PhysicalConstants::energyConvert) * (frc + frictionForce); |
419 |
gezelter |
1237 |
|
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 |
gezelter |
1769 |
sd->addFrc(frictionForce); |
429 |
gezelter |
1237 |
|
430 |
tim |
895 |
} |
431 |
gezelter |
956 |
} |
432 |
gezelter |
945 |
|
433 |
gezelter |
956 |
++index; |
434 |
tim |
895 |
|
435 |
|
|
} |
436 |
gezelter |
956 |
} |
437 |
chuckv |
1120 |
|
438 |
gezelter |
945 |
info_->setFdf(fdf); |
439 |
gezelter |
983 |
veloMunge->removeComDrift(); |
440 |
|
|
// Remove angular drift if we are not using periodic boundary conditions. |
441 |
|
|
if(!simParams->getUsePeriodicBoundaryConditions()) |
442 |
|
|
veloMunge->removeAngularDrift(); |
443 |
|
|
|
444 |
gezelter |
1464 |
ForceManager::postCalculation(); |
445 |
tim |
895 |
} |
446 |
|
|
|
447 |
tim |
963 |
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) { |
448 |
tim |
904 |
|
449 |
tim |
906 |
|
450 |
tim |
963 |
Vector<RealType, 6> Z; |
451 |
|
|
Vector<RealType, 6> generalForce; |
452 |
tim |
904 |
|
453 |
tim |
895 |
Z[0] = randNumGen_.randNorm(0, variance); |
454 |
|
|
Z[1] = randNumGen_.randNorm(0, variance); |
455 |
|
|
Z[2] = randNumGen_.randNorm(0, variance); |
456 |
|
|
Z[3] = randNumGen_.randNorm(0, variance); |
457 |
|
|
Z[4] = randNumGen_.randNorm(0, variance); |
458 |
|
|
Z[5] = randNumGen_.randNorm(0, variance); |
459 |
tim |
904 |
|
460 |
gezelter |
981 |
generalForce = hydroProps_[index]->getS()*Z; |
461 |
tim |
904 |
|
462 |
tim |
895 |
force[0] = generalForce[0]; |
463 |
|
|
force[1] = generalForce[1]; |
464 |
|
|
force[2] = generalForce[2]; |
465 |
|
|
torque[0] = generalForce[3]; |
466 |
|
|
torque[1] = generalForce[4]; |
467 |
|
|
torque[2] = generalForce[5]; |
468 |
|
|
|
469 |
xsun |
1185 |
} |
470 |
tim |
895 |
|
471 |
|
|
} |