39 |
|
* such damages. |
40 |
|
*/ |
41 |
|
#include <fstream> |
42 |
+ |
#include <iostream> |
43 |
|
#include "integrators/LDForceManager.hpp" |
44 |
|
#include "math/CholeskyDecomposition.hpp" |
45 |
|
#include "utils/OOPSEConstant.hpp" |
46 |
+ |
#include "hydrodynamics/Sphere.hpp" |
47 |
+ |
#include "hydrodynamics/Ellipsoid.hpp" |
48 |
+ |
#include "openbabel/mol.hpp" |
49 |
+ |
|
50 |
+ |
using namespace OpenBabel; |
51 |
|
namespace oopse { |
52 |
|
|
53 |
|
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){ |
54 |
< |
Globals* simParams = info->getSimParams(); |
55 |
< |
std::map<std::string, HydroProp> hydroPropMap; |
56 |
< |
if (simParams->haveHydroPropFile()) { |
57 |
< |
hydroPropMap = parseFrictionFile(simParams->getHydroPropFile()); |
58 |
< |
} else { |
59 |
< |
//error |
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 = OOPSE_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 = OOPSE_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 = OOPSE_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); |
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 |
> |
|
115 |
> |
|
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\n" |
122 |
> |
"\tDynamics is specified for rigidBodies which contain more\n" |
123 |
> |
"\tthan one atom. To create a HydroPropFile, run \"Hydro\".\n"); |
124 |
> |
painCave.severity = OOPSE_ERROR; |
125 |
> |
painCave.isFatal = 1; |
126 |
> |
simError(); |
127 |
> |
} |
128 |
> |
|
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 |
> |
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 = OOPSE_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 |
> |
if (integrableObject->isDirectionalAtom()) { |
157 |
> |
DirectionalAtom* dAtom = static_cast<DirectionalAtom*>(integrableObject); |
158 |
> |
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); |
188 |
> |
AtomType* atomType = atom->getAtomType(); |
189 |
> |
if (atomType->isLennardJones()){ |
190 |
> |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
191 |
> |
if (data != NULL) { |
192 |
> |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
193 |
> |
|
194 |
> |
if (ljData != NULL) { |
195 |
> |
LJParam ljParam = ljData->getData(); |
196 |
> |
currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0); |
197 |
> |
} else { |
198 |
> |
sprintf( painCave.errMsg, |
199 |
> |
"Can not cast GenericData to LJParam\n"); |
200 |
> |
painCave.severity = OOPSE_ERROR; |
201 |
> |
painCave.isFatal = 1; |
202 |
> |
simError(); |
203 |
> |
} |
204 |
> |
} |
205 |
|
} else { |
206 |
< |
//error |
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 |
> |
} |
216 |
|
} |
217 |
< |
|
218 |
< |
} |
217 |
> |
} |
218 |
> |
HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp()); |
219 |
> |
std::map<std::string, HydroProp*>::iterator iter = hydroPropMap.find(integrableObject->getType()); |
220 |
> |
if (iter != hydroPropMap.end()) |
221 |
> |
hydroProps_.push_back(iter->second); |
222 |
> |
else { |
223 |
> |
currHydroProp->complete(); |
224 |
> |
hydroPropMap.insert(std::map<std::string, HydroProp*>::value_type(integrableObject->getType(), currHydroProp)); |
225 |
> |
hydroProps_.push_back(currHydroProp); |
226 |
> |
} |
227 |
> |
} |
228 |
> |
} |
229 |
|
} |
230 |
|
variance_ = 2.0 * OOPSEConstant::kb*simParams->getTargetTemp()/simParams->getDt(); |
231 |
< |
} |
232 |
< |
std::map<std::string, HydroProp> LDForceManager::parseFrictionFile(const std::string& filename) { |
233 |
< |
std::map<std::string, HydroProp> props; |
231 |
> |
} |
232 |
> |
|
233 |
> |
std::map<std::string, HydroProp*> LDForceManager::parseFrictionFile(const std::string& filename) { |
234 |
> |
std::map<std::string, HydroProp*> props; |
235 |
|
std::ifstream ifs(filename.c_str()); |
236 |
|
if (ifs.is_open()) { |
237 |
< |
|
237 |
> |
|
238 |
|
} |
239 |
< |
|
239 |
> |
|
240 |
|
const unsigned int BufferSize = 65535; |
241 |
|
char buffer[BufferSize]; |
242 |
|
while (ifs.getline(buffer, BufferSize)) { |
243 |
< |
StringTokenizer tokenizer(buffer); |
244 |
< |
HydroProp currProp; |
86 |
< |
if (tokenizer.countTokens() >= 67) { |
87 |
< |
std::string atomName = tokenizer.nextToken(); |
88 |
< |
currProp.cod[0] = tokenizer.nextTokenAsDouble(); |
89 |
< |
currProp.cod[1] = tokenizer.nextTokenAsDouble(); |
90 |
< |
currProp.cod[2] = tokenizer.nextTokenAsDouble(); |
91 |
< |
|
92 |
< |
currProp.Ddtt(0,0) = tokenizer.nextTokenAsDouble(); |
93 |
< |
currProp.Ddtt(0,1) = tokenizer.nextTokenAsDouble(); |
94 |
< |
currProp.Ddtt(0,2) = tokenizer.nextTokenAsDouble(); |
95 |
< |
currProp.Ddtt(1,0) = tokenizer.nextTokenAsDouble(); |
96 |
< |
currProp.Ddtt(1,1) = tokenizer.nextTokenAsDouble(); |
97 |
< |
currProp.Ddtt(1,2) = tokenizer.nextTokenAsDouble(); |
98 |
< |
currProp.Ddtt(2,0) = tokenizer.nextTokenAsDouble(); |
99 |
< |
currProp.Ddtt(2,1) = tokenizer.nextTokenAsDouble(); |
100 |
< |
currProp.Ddtt(2,2) = tokenizer.nextTokenAsDouble(); |
101 |
< |
|
102 |
< |
currProp.Ddtr(0,0) = tokenizer.nextTokenAsDouble(); |
103 |
< |
currProp.Ddtr(0,1) = tokenizer.nextTokenAsDouble(); |
104 |
< |
currProp.Ddtr(0,2) = tokenizer.nextTokenAsDouble(); |
105 |
< |
currProp.Ddtr(1,0) = tokenizer.nextTokenAsDouble(); |
106 |
< |
currProp.Ddtr(1,1) = tokenizer.nextTokenAsDouble(); |
107 |
< |
currProp.Ddtr(1,2) = tokenizer.nextTokenAsDouble(); |
108 |
< |
currProp.Ddtr(2,0) = tokenizer.nextTokenAsDouble(); |
109 |
< |
currProp.Ddtr(2,1) = tokenizer.nextTokenAsDouble(); |
110 |
< |
currProp.Ddtr(2,2) = tokenizer.nextTokenAsDouble(); |
111 |
< |
|
112 |
< |
currProp.Ddrr(0,0) = tokenizer.nextTokenAsDouble(); |
113 |
< |
currProp.Ddrr(0,1) = tokenizer.nextTokenAsDouble(); |
114 |
< |
currProp.Ddrr(0,2) = tokenizer.nextTokenAsDouble(); |
115 |
< |
currProp.Ddrr(1,0) = tokenizer.nextTokenAsDouble(); |
116 |
< |
currProp.Ddrr(1,1) = tokenizer.nextTokenAsDouble(); |
117 |
< |
currProp.Ddrr(1,2) = tokenizer.nextTokenAsDouble(); |
118 |
< |
currProp.Ddrr(2,0) = tokenizer.nextTokenAsDouble(); |
119 |
< |
currProp.Ddrr(2,1) = tokenizer.nextTokenAsDouble(); |
120 |
< |
currProp.Ddrr(2,2) = tokenizer.nextTokenAsDouble(); |
121 |
< |
|
122 |
< |
currProp.Xidtt(0,0) = tokenizer.nextTokenAsDouble(); |
123 |
< |
currProp.Xidtt(0,1) = tokenizer.nextTokenAsDouble(); |
124 |
< |
currProp.Xidtt(0,2) = tokenizer.nextTokenAsDouble(); |
125 |
< |
currProp.Xidtt(1,0) = tokenizer.nextTokenAsDouble(); |
126 |
< |
currProp.Xidtt(1,1) = tokenizer.nextTokenAsDouble(); |
127 |
< |
currProp.Xidtt(1,2) = tokenizer.nextTokenAsDouble(); |
128 |
< |
currProp.Xidtt(2,0) = tokenizer.nextTokenAsDouble(); |
129 |
< |
currProp.Xidtt(2,1) = tokenizer.nextTokenAsDouble(); |
130 |
< |
currProp.Xidtt(2,2) = tokenizer.nextTokenAsDouble(); |
131 |
< |
|
132 |
< |
currProp.Xidrt(0,0) = tokenizer.nextTokenAsDouble(); |
133 |
< |
currProp.Xidrt(0,1) = tokenizer.nextTokenAsDouble(); |
134 |
< |
currProp.Xidrt(0,2) = tokenizer.nextTokenAsDouble(); |
135 |
< |
currProp.Xidrt(1,0) = tokenizer.nextTokenAsDouble(); |
136 |
< |
currProp.Xidrt(1,1) = tokenizer.nextTokenAsDouble(); |
137 |
< |
currProp.Xidrt(1,2) = tokenizer.nextTokenAsDouble(); |
138 |
< |
currProp.Xidrt(2,0) = tokenizer.nextTokenAsDouble(); |
139 |
< |
currProp.Xidrt(2,1) = tokenizer.nextTokenAsDouble(); |
140 |
< |
currProp.Xidrt(2,2) = tokenizer.nextTokenAsDouble(); |
141 |
< |
|
142 |
< |
currProp.Xidtr(0,0) = tokenizer.nextTokenAsDouble(); |
143 |
< |
currProp.Xidtr(0,1) = tokenizer.nextTokenAsDouble(); |
144 |
< |
currProp.Xidtr(0,2) = tokenizer.nextTokenAsDouble(); |
145 |
< |
currProp.Xidtr(1,0) = tokenizer.nextTokenAsDouble(); |
146 |
< |
currProp.Xidtr(1,1) = tokenizer.nextTokenAsDouble(); |
147 |
< |
currProp.Xidtr(1,2) = tokenizer.nextTokenAsDouble(); |
148 |
< |
currProp.Xidtr(2,0) = tokenizer.nextTokenAsDouble(); |
149 |
< |
currProp.Xidtr(2,1) = tokenizer.nextTokenAsDouble(); |
150 |
< |
currProp.Xidtr(2,2) = tokenizer.nextTokenAsDouble(); |
151 |
< |
|
152 |
< |
currProp.Xidrr(0,0) = tokenizer.nextTokenAsDouble(); |
153 |
< |
currProp.Xidrr(0,1) = tokenizer.nextTokenAsDouble(); |
154 |
< |
currProp.Xidrr(0,2) = tokenizer.nextTokenAsDouble(); |
155 |
< |
currProp.Xidrr(1,0) = tokenizer.nextTokenAsDouble(); |
156 |
< |
currProp.Xidrr(1,1) = tokenizer.nextTokenAsDouble(); |
157 |
< |
currProp.Xidrr(1,2) = tokenizer.nextTokenAsDouble(); |
158 |
< |
currProp.Xidrr(2,0) = tokenizer.nextTokenAsDouble(); |
159 |
< |
currProp.Xidrr(2,1) = tokenizer.nextTokenAsDouble(); |
160 |
< |
currProp.Xidrr(2,2) = tokenizer.nextTokenAsDouble(); |
161 |
< |
props.insert(std::map<std::string, HydroProp>::value_type(atomName, currProp)); |
162 |
< |
} |
243 |
> |
HydroProp* currProp = new HydroProp(buffer); |
244 |
> |
props.insert(std::map<std::string, HydroProp*>::value_type(currProp->getName(), currProp)); |
245 |
|
} |
246 |
|
|
247 |
|
return props; |
248 |
|
} |
249 |
< |
|
250 |
< |
void LDForceManager::postCalculation() { |
249 |
> |
|
250 |
> |
void LDForceManager::postCalculation(bool needStress){ |
251 |
|
SimInfo::MoleculeIterator i; |
252 |
|
Molecule::IntegrableObjectIterator j; |
253 |
|
Molecule* mol; |
259 |
|
Mat3x3d Atrans; |
260 |
|
Vector3d Tb; |
261 |
|
Vector3d ji; |
180 |
– |
double mass; |
262 |
|
unsigned int index = 0; |
263 |
+ |
bool doLangevinForces; |
264 |
+ |
bool freezeMolecule; |
265 |
+ |
int fdf; |
266 |
+ |
|
267 |
+ |
fdf = 0; |
268 |
+ |
|
269 |
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
183 |
– |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
184 |
– |
integrableObject = mol->nextIntegrableObject(j)) { |
270 |
|
|
271 |
< |
vel =integrableObject->getVel(); |
272 |
< |
if (integrableObject->isDirectional()){ |
188 |
< |
//calculate angular velocity in lab frame |
189 |
< |
Mat3x3d I = integrableObject->getI(); |
190 |
< |
Vector3d angMom = integrableObject->getJ(); |
191 |
< |
Vector3d omega; |
271 |
> |
doLangevinForces = true; |
272 |
> |
freezeMolecule = false; |
273 |
|
|
274 |
< |
if (integrableObject->isLinear()) { |
275 |
< |
int linearAxis = integrableObject->linearAxis(); |
276 |
< |
int l = (linearAxis +1 )%3; |
277 |
< |
int m = (linearAxis +2 )%3; |
197 |
< |
omega[l] = angMom[l] /I(l, l); |
198 |
< |
omega[m] = angMom[m] /I(m, m); |
199 |
< |
|
200 |
< |
} else { |
201 |
< |
omega[0] = angMom[0] /I(0, 0); |
202 |
< |
omega[1] = angMom[1] /I(1, 1); |
203 |
< |
omega[2] = angMom[2] /I(2, 2); |
204 |
< |
} |
274 |
> |
if (sphericalBoundaryConditions_) { |
275 |
> |
|
276 |
> |
Vector3d molPos = mol->getCom(); |
277 |
> |
RealType molRad = molPos.length(); |
278 |
|
|
279 |
< |
//apply friction force and torque at center of diffusion |
280 |
< |
A = integrableObject->getA(); |
281 |
< |
Atrans = A.transpose(); |
282 |
< |
Vector3d rcd = Atrans * hydroProps_[index].cod; |
283 |
< |
Vector3d vcd = vel + cross(omega, rcd); |
284 |
< |
vcd = A* vcd; |
285 |
< |
Vector3d frictionForce = -(hydroProps_[index].Xidtt * vcd + hydroProps_[index].Xidrt * omega); |
286 |
< |
frictionForce = Atrans*frictionForce; |
287 |
< |
integrableObject->addFrc(frictionForce); |
288 |
< |
Vector3d frictionTorque = - (hydroProps_[index].Xidtr * vcd + hydroProps_[index].Xidrr * omega); |
289 |
< |
frictionTorque = Atrans*frictionTorque; |
290 |
< |
integrableObject->addTrq(frictionTorque+ cross(rcd, frictionForce)); |
291 |
< |
|
292 |
< |
//apply random force and torque at center of diffustion |
293 |
< |
Vector3d randomForce; |
294 |
< |
Vector3d randomTorque; |
295 |
< |
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
296 |
< |
randomForce = Atrans*randomForce; |
297 |
< |
randomTorque = Atrans* randomTorque; |
298 |
< |
integrableObject->addFrc(randomForce); |
299 |
< |
integrableObject->addTrq(randomTorque + cross(rcd, randomForce )); |
300 |
< |
|
279 |
> |
doLangevinForces = false; |
280 |
> |
|
281 |
> |
if (molRad > langevinBufferRadius_) { |
282 |
> |
doLangevinForces = true; |
283 |
> |
freezeMolecule = false; |
284 |
> |
} |
285 |
> |
if (molRad > frozenBufferRadius_) { |
286 |
> |
doLangevinForces = false; |
287 |
> |
freezeMolecule = true; |
288 |
> |
} |
289 |
> |
} |
290 |
> |
|
291 |
> |
for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
292 |
> |
integrableObject = mol->nextIntegrableObject(j)) { |
293 |
> |
|
294 |
> |
if (freezeMolecule) |
295 |
> |
fdf += integrableObject->freeze(); |
296 |
> |
|
297 |
> |
if (doLangevinForces) { |
298 |
> |
vel =integrableObject->getVel(); |
299 |
> |
if (integrableObject->isDirectional()){ |
300 |
> |
//calculate angular velocity in lab frame |
301 |
> |
Mat3x3d I = integrableObject->getI(); |
302 |
> |
Vector3d angMom = integrableObject->getJ(); |
303 |
> |
Vector3d omega; |
304 |
> |
|
305 |
> |
if (integrableObject->isLinear()) { |
306 |
> |
int linearAxis = integrableObject->linearAxis(); |
307 |
> |
int l = (linearAxis +1 )%3; |
308 |
> |
int m = (linearAxis +2 )%3; |
309 |
> |
omega[l] = angMom[l] /I(l, l); |
310 |
> |
omega[m] = angMom[m] /I(m, m); |
311 |
> |
|
312 |
> |
} else { |
313 |
> |
omega[0] = angMom[0] /I(0, 0); |
314 |
> |
omega[1] = angMom[1] /I(1, 1); |
315 |
> |
omega[2] = angMom[2] /I(2, 2); |
316 |
> |
} |
317 |
> |
|
318 |
> |
//apply friction force and torque at center of resistance |
319 |
> |
A = integrableObject->getA(); |
320 |
> |
Atrans = A.transpose(); |
321 |
> |
Vector3d rcr = Atrans * hydroProps_[index]->getCOR(); |
322 |
> |
Vector3d vcdLab = vel + cross(omega, rcr); |
323 |
> |
Vector3d vcdBody = A* vcdLab; |
324 |
> |
Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omega); |
325 |
> |
Vector3d frictionForceLab = Atrans*frictionForceBody; |
326 |
> |
integrableObject->addFrc(frictionForceLab); |
327 |
> |
Vector3d frictionTorqueBody = - (hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omega); |
328 |
> |
Vector3d frictionTorqueLab = Atrans*frictionTorqueBody; |
329 |
> |
integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab)); |
330 |
> |
|
331 |
> |
//apply random force and torque at center of resistance |
332 |
> |
Vector3d randomForceBody; |
333 |
> |
Vector3d randomTorqueBody; |
334 |
> |
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
335 |
> |
Vector3d randomForceLab = Atrans*randomForceBody; |
336 |
> |
Vector3d randomTorqueLab = Atrans* randomTorqueBody; |
337 |
> |
integrableObject->addFrc(randomForceLab); |
338 |
> |
integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab )); |
339 |
> |
|
340 |
|
} else { |
341 |
< |
//spheric atom |
342 |
< |
Vector3d frictionForce = -(hydroProps_[index].Xidtt *vel); |
343 |
< |
Vector3d randomForce; |
344 |
< |
Vector3d randomTorque; |
345 |
< |
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
346 |
< |
|
347 |
< |
//randomForce /= OOPSEConstant::energyConvert; |
236 |
< |
//randomTorque /= OOPSEConstant::energyConvert; |
237 |
< |
integrableObject->addFrc(frictionForce+randomForce); |
341 |
> |
//spherical atom |
342 |
> |
Vector3d frictionForce = -(hydroProps_[index]->getXitt() * vel); |
343 |
> |
Vector3d randomForce; |
344 |
> |
Vector3d randomTorque; |
345 |
> |
genRandomForceAndTorque(randomForce, randomTorque, index, variance_); |
346 |
> |
|
347 |
> |
integrableObject->addFrc(frictionForce+randomForce); |
348 |
|
} |
349 |
< |
|
349 |
> |
} |
350 |
> |
|
351 |
|
++index; |
352 |
|
|
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
< |
ForceManager::postCalculation(); |
356 |
> |
info_->setFdf(fdf); |
357 |
> |
veloMunge->removeComDrift(); |
358 |
> |
// Remove angular drift if we are not using periodic boundary conditions. |
359 |
> |
if(!simParams->getUsePeriodicBoundaryConditions()) |
360 |
> |
veloMunge->removeAngularDrift(); |
361 |
|
|
362 |
< |
|
248 |
< |
|
362 |
> |
ForceManager::postCalculation(needStress); |
363 |
|
} |
364 |
|
|
365 |
< |
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, double variance) { |
252 |
< |
/* |
253 |
< |
SquareMatrix<double, 6> Dd; |
254 |
< |
SquareMatrix<double, 6> S; |
255 |
< |
Vector<double, 6> Z; |
256 |
< |
Vector<double, 6> generalForce; |
257 |
< |
Dd.setSubMatrix(0, 0, hydroProps_[index].Ddtt); |
258 |
< |
Dd.setSubMatrix(0, 3, hydroProps_[index].Ddtr.transpose()); |
259 |
< |
Dd.setSubMatrix(3, 0, hydroProps_[index].Ddtr); |
260 |
< |
Dd.setSubMatrix(3, 3, hydroProps_[index].Ddrr); |
261 |
< |
CholeskyDecomposition(Dd, S); |
262 |
< |
*/ |
365 |
> |
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) { |
366 |
|
|
264 |
– |
SquareMatrix<double, 6> Xid; |
265 |
– |
SquareMatrix<double, 6> S; |
266 |
– |
Vector<double, 6> Z; |
267 |
– |
Vector<double, 6> generalForce; |
268 |
– |
Xid.setSubMatrix(0, 0, hydroProps_[index].Xidtt); |
269 |
– |
Xid.setSubMatrix(0, 3, hydroProps_[index].Xidrt); |
270 |
– |
Xid.setSubMatrix(3, 0, hydroProps_[index].Xidtr); |
271 |
– |
Xid.setSubMatrix(3, 3, hydroProps_[index].Xidrr); |
272 |
– |
CholeskyDecomposition(Xid, S); |
367 |
|
|
368 |
< |
/* |
369 |
< |
Xid *= variance; |
276 |
< |
Z[0] = randNumGen_.randNorm(0, 1.0); |
277 |
< |
Z[1] = randNumGen_.randNorm(0, 1.0); |
278 |
< |
Z[2] = randNumGen_.randNorm(0, 1.0); |
279 |
< |
Z[3] = randNumGen_.randNorm(0, 1.0); |
280 |
< |
Z[4] = randNumGen_.randNorm(0, 1.0); |
281 |
< |
Z[5] = randNumGen_.randNorm(0, 1.0); |
282 |
< |
*/ |
368 |
> |
Vector<RealType, 6> Z; |
369 |
> |
Vector<RealType, 6> generalForce; |
370 |
|
|
371 |
|
Z[0] = randNumGen_.randNorm(0, variance); |
372 |
|
Z[1] = randNumGen_.randNorm(0, variance); |
376 |
|
Z[5] = randNumGen_.randNorm(0, variance); |
377 |
|
|
378 |
|
|
379 |
< |
generalForce = S*Z; |
379 |
> |
generalForce = hydroProps_[index]->getS()*Z; |
380 |
|
|
381 |
|
force[0] = generalForce[0]; |
382 |
|
force[1] = generalForce[1]; |