| 45 |
|
#include "utils/OOPSEConstant.hpp" |
| 46 |
|
#include "hydrodynamics/Sphere.hpp" |
| 47 |
|
#include "hydrodynamics/Ellipsoid.hpp" |
| 48 |
< |
#include "openbabel/mol.hpp" |
| 48 |
> |
#include "utils/ElementsTable.hpp" |
| 49 |
|
|
| 50 |
– |
using namespace OpenBabel; |
| 50 |
|
namespace oopse { |
| 51 |
|
|
| 52 |
|
LDForceManager::LDForceManager(SimInfo* info) : ForceManager(info){ |
| 152 |
|
integrableObject != NULL; |
| 153 |
|
integrableObject = mol->nextIntegrableObject(j)) { |
| 154 |
|
Shape* currShape = NULL; |
| 155 |
< |
if (integrableObject->isDirectionalAtom()) { |
| 156 |
< |
DirectionalAtom* dAtom = static_cast<DirectionalAtom*>(integrableObject); |
| 157 |
< |
AtomType* atomType = dAtom->getAtomType(); |
| 155 |
> |
|
| 156 |
> |
if (integrableObject->isAtom()){ |
| 157 |
> |
Atom* atom = static_cast<Atom*>(integrableObject); |
| 158 |
> |
AtomType* atomType = atom->getAtomType(); |
| 159 |
|
if (atomType->isGayBerne()) { |
| 160 |
< |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
| 161 |
< |
|
| 160 |
> |
DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType); |
| 161 |
|
GenericData* data = dAtomType->getPropertyByName("GayBerne"); |
| 162 |
|
if (data != NULL) { |
| 163 |
|
GayBerneParamGenericData* gayBerneData = dynamic_cast<GayBerneParamGenericData*>(data); |
| 165 |
|
if (gayBerneData != NULL) { |
| 166 |
|
GayBerneParam gayBerneParam = gayBerneData->getData(); |
| 167 |
|
currShape = new Ellipsoid(V3Zero, |
| 169 |
– |
gayBerneParam.GB_d / 2.0, |
| 168 |
|
gayBerneParam.GB_l / 2.0, |
| 169 |
+ |
gayBerneParam.GB_d / 2.0, |
| 170 |
|
Mat3x3d::identity()); |
| 171 |
|
} else { |
| 172 |
|
sprintf( painCave.errMsg, |
| 181 |
|
painCave.isFatal = 1; |
| 182 |
|
simError(); |
| 183 |
|
} |
| 184 |
< |
} |
| 185 |
< |
} else { |
| 186 |
< |
Atom* atom = static_cast<Atom*>(integrableObject); |
| 187 |
< |
AtomType* atomType = atom->getAtomType(); |
| 188 |
< |
if (atomType->isLennardJones()){ |
| 189 |
< |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
| 190 |
< |
if (data != NULL) { |
| 191 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
| 192 |
< |
|
| 193 |
< |
if (ljData != NULL) { |
| 194 |
< |
LJParam ljParam = ljData->getData(); |
| 195 |
< |
currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0); |
| 184 |
> |
} else { |
| 185 |
> |
if (atomType->isLennardJones()){ |
| 186 |
> |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
| 187 |
> |
if (data != NULL) { |
| 188 |
> |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
| 189 |
> |
if (ljData != NULL) { |
| 190 |
> |
LJParam ljParam = ljData->getData(); |
| 191 |
> |
currShape = new Sphere(atom->getPos(), ljParam.sigma/2.0); |
| 192 |
> |
} else { |
| 193 |
> |
sprintf( painCave.errMsg, |
| 194 |
> |
"Can not cast GenericData to LJParam\n"); |
| 195 |
> |
painCave.severity = OOPSE_ERROR; |
| 196 |
> |
painCave.isFatal = 1; |
| 197 |
> |
simError(); |
| 198 |
> |
} |
| 199 |
> |
} |
| 200 |
> |
} else { |
| 201 |
> |
int obanum = etab.GetAtomicNum((atom->getType()).c_str()); |
| 202 |
> |
if (obanum != 0) { |
| 203 |
> |
currShape = new Sphere(atom->getPos(), etab.GetVdwRad(obanum)); |
| 204 |
|
} else { |
| 205 |
|
sprintf( painCave.errMsg, |
| 206 |
< |
"Can not cast GenericData to LJParam\n"); |
| 206 |
> |
"Could not find atom type in default element.txt\n"); |
| 207 |
|
painCave.severity = OOPSE_ERROR; |
| 208 |
|
painCave.isFatal = 1; |
| 209 |
|
simError(); |
| 210 |
< |
} |
| 210 |
> |
} |
| 211 |
|
} |
| 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 |
– |
} |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
|
HydroProp* currHydroProp = currShape->getHydroProp(simParams->getViscosity(),simParams->getTargetTemp()); |
| 243 |
|
return props; |
| 244 |
|
} |
| 245 |
|
|
| 246 |
< |
void LDForceManager::postCalculation() { |
| 246 |
> |
void LDForceManager::postCalculation(bool needStress){ |
| 247 |
|
SimInfo::MoleculeIterator i; |
| 248 |
|
Molecule::IntegrableObjectIterator j; |
| 249 |
|
Molecule* mol; |
| 250 |
|
StuntDouble* integrableObject; |
| 251 |
+ |
RealType mass; |
| 252 |
|
Vector3d vel; |
| 253 |
|
Vector3d pos; |
| 254 |
|
Vector3d frc; |
| 256 |
|
Mat3x3d Atrans; |
| 257 |
|
Vector3d Tb; |
| 258 |
|
Vector3d ji; |
| 262 |
– |
RealType mass; |
| 259 |
|
unsigned int index = 0; |
| 260 |
|
bool doLangevinForces; |
| 261 |
|
bool freezeMolecule; |
| 262 |
|
int fdf; |
| 263 |
< |
int nIntegrated; |
| 268 |
< |
int nFrozen; |
| 263 |
> |
|
| 264 |
|
|
| 265 |
+ |
|
| 266 |
|
fdf = 0; |
| 267 |
|
|
| 268 |
|
for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { |
| 295 |
|
|
| 296 |
|
if (doLangevinForces) { |
| 297 |
|
vel =integrableObject->getVel(); |
| 298 |
+ |
mass = integrableObject->getMass(); |
| 299 |
|
if (integrableObject->isDirectional()){ |
| 303 |
– |
//calculate angular velocity in lab frame |
| 300 |
|
Mat3x3d I = integrableObject->getI(); |
| 301 |
|
Vector3d angMom = integrableObject->getJ(); |
| 302 |
< |
Vector3d omega; |
| 302 |
> |
A = integrableObject->getA(); |
| 303 |
> |
Atrans = A.transpose(); |
| 304 |
> |
|
| 305 |
> |
Vector3d omegaBody; |
| 306 |
|
|
| 307 |
|
if (integrableObject->isLinear()) { |
| 308 |
|
int linearAxis = integrableObject->linearAxis(); |
| 309 |
|
int l = (linearAxis +1 )%3; |
| 310 |
|
int m = (linearAxis +2 )%3; |
| 311 |
< |
omega[l] = angMom[l] /I(l, l); |
| 312 |
< |
omega[m] = angMom[m] /I(m, m); |
| 311 |
> |
omegaBody[l] = angMom[l] /I(l, l); |
| 312 |
> |
omegaBody[m] = angMom[m] /I(m, m); |
| 313 |
|
|
| 314 |
|
} else { |
| 315 |
< |
omega[0] = angMom[0] /I(0, 0); |
| 316 |
< |
omega[1] = angMom[1] /I(1, 1); |
| 317 |
< |
omega[2] = angMom[2] /I(2, 2); |
| 315 |
> |
omegaBody[0] = angMom[0] /I(0, 0); |
| 316 |
> |
omegaBody[1] = angMom[1] /I(1, 1); |
| 317 |
> |
omegaBody[2] = angMom[2] /I(2, 2); |
| 318 |
|
} |
| 319 |
< |
|
| 320 |
< |
//apply friction force and torque at center of resistance |
| 321 |
< |
A = integrableObject->getA(); |
| 322 |
< |
Atrans = A.transpose(); |
| 323 |
< |
Vector3d rcr = Atrans * hydroProps_[index]->getCOR(); |
| 324 |
< |
Vector3d vcdLab = vel + cross(omega, rcr); |
| 325 |
< |
Vector3d vcdBody = A* vcdLab; |
| 326 |
< |
Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omega); |
| 327 |
< |
Vector3d frictionForceLab = Atrans*frictionForceBody; |
| 319 |
> |
|
| 320 |
> |
Vector3d omegaLab = Atrans * omegaBody; |
| 321 |
> |
|
| 322 |
> |
// apply friction force and torque at center of resistance |
| 323 |
> |
|
| 324 |
> |
Vector3d rcrLab = Atrans * hydroProps_[index]->getCOR(); |
| 325 |
> |
Vector3d vcdLab = vel + cross(omegaLab, rcrLab); |
| 326 |
> |
|
| 327 |
> |
Vector3d vcdBody = A * vcdLab; |
| 328 |
> |
Vector3d frictionForceBody = -(hydroProps_[index]->getXitt() * vcdBody + hydroProps_[index]->getXirt() * omegaBody); |
| 329 |
> |
|
| 330 |
> |
Vector3d frictionForceLab = Atrans * frictionForceBody; |
| 331 |
|
integrableObject->addFrc(frictionForceLab); |
| 332 |
< |
Vector3d frictionTorqueBody = - (hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omega); |
| 333 |
< |
Vector3d frictionTorqueLab = Atrans*frictionTorqueBody; |
| 334 |
< |
integrableObject->addTrq(frictionTorqueLab+ cross(rcr, frictionForceLab)); |
| 335 |
< |
|
| 332 |
> |
Vector3d frictionTorqueBody = -(hydroProps_[index]->getXitr() * vcdBody + hydroProps_[index]->getXirr() * omegaBody); |
| 333 |
> |
Vector3d frictionTorqueLab = Atrans * frictionTorqueBody; |
| 334 |
> |
integrableObject->addTrq(frictionTorqueLab + cross(rcrLab, frictionForceLab)); |
| 335 |
> |
|
| 336 |
|
//apply random force and torque at center of resistance |
| 337 |
|
Vector3d randomForceBody; |
| 338 |
|
Vector3d randomTorqueBody; |
| 339 |
|
genRandomForceAndTorque(randomForceBody, randomTorqueBody, index, variance_); |
| 340 |
< |
Vector3d randomForceLab = Atrans*randomForceBody; |
| 341 |
< |
Vector3d randomTorqueLab = Atrans* randomTorqueBody; |
| 340 |
> |
Vector3d randomForceLab = Atrans * randomForceBody; |
| 341 |
> |
Vector3d randomTorqueLab = Atrans * randomTorqueBody; |
| 342 |
|
integrableObject->addFrc(randomForceLab); |
| 343 |
< |
integrableObject->addTrq(randomTorqueLab + cross(rcr, randomForceLab )); |
| 343 |
> |
integrableObject->addTrq(randomTorqueLab + cross(rcrLab, randomForceLab )); |
| 344 |
|
|
| 345 |
|
} else { |
| 346 |
|
//spherical atom |
| 364 |
|
if(!simParams->getUsePeriodicBoundaryConditions()) |
| 365 |
|
veloMunge->removeAngularDrift(); |
| 366 |
|
|
| 367 |
< |
ForceManager::postCalculation(); |
| 367 |
> |
ForceManager::postCalculation(needStress); |
| 368 |
|
} |
| 369 |
|
|
| 370 |
|
void LDForceManager::genRandomForceAndTorque(Vector3d& force, Vector3d& torque, unsigned int index, RealType variance) { |
| 372 |
|
|
| 373 |
|
Vector<RealType, 6> Z; |
| 374 |
|
Vector<RealType, 6> generalForce; |
| 373 |
– |
|
| 375 |
|
|
| 376 |
|
Z[0] = randNumGen_.randNorm(0, variance); |
| 377 |
|
Z[1] = randNumGen_.randNorm(0, variance); |
| 380 |
|
Z[4] = randNumGen_.randNorm(0, variance); |
| 381 |
|
Z[5] = randNumGen_.randNorm(0, variance); |
| 382 |
|
|
| 382 |
– |
|
| 383 |
|
generalForce = hydroProps_[index]->getS()*Z; |
| 384 |
|
|
| 385 |
|
force[0] = generalForce[0]; |
| 389 |
|
torque[1] = generalForce[4]; |
| 390 |
|
torque[2] = generalForce[5]; |
| 391 |
|
|
| 392 |
< |
} |
| 392 |
> |
} |
| 393 |
|
|
| 394 |
|
} |