--- trunk/src/primitives/GhostBend.cpp 2005/01/12 22:41:40 246 +++ trunk/src/primitives/GhostBend.cpp 2008/10/21 18:23:31 1309 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -43,55 +43,59 @@ namespace oopse { #include "primitives/DirectionalAtom.hpp" namespace oopse { -/**@todo still a lot left to improve*/ -void GhostBend::calcForce() { + /**@todo still a lot left to improve*/ + void GhostBend::calcForce(RealType& angle) { DirectionalAtom* ghostAtom = static_cast(atom2_); Vector3d pos1 = atom1_->getPos(); Vector3d pos2 = ghostAtom->getPos(); - + Vector3d r12 = pos1 - pos2; - double d12 = r12.length(); - - double d12inv = 1.0 / d12; - + RealType d12 = r12.length(); + + RealType d12inv = 1.0 / d12; + Vector3d r32 = ghostAtom->getElectroFrame().getColumn(2); - double d32 = r32.length(); - - double d32inv = 1.0 / d32; - - double cosTheta = dot(r12, r32) / (d12 * d32); - + RealType d32 = r32.length(); + + RealType d32inv = 1.0 / d32; + + RealType cosTheta = dot(r12, r32) / (d12 * d32); + //check roundoff if (cosTheta > 1.0) { - cosTheta = 1.0; + cosTheta = 1.0; } else if (cosTheta < -1.0) { - cosTheta = -1.0; + cosTheta = -1.0; } - - double theta = acos(cosTheta); - - double firstDerivative; - - bendType_->calcForce(theta, firstDerivative, potential_); - - double sinTheta = sqrt(1.0 - cosTheta * cosTheta); - + + RealType theta = acos(cosTheta); + + RealType firstDerivative; + + bendType_->calcForce(theta, potential_, firstDerivative); + + RealType sinTheta = sqrt(1.0 - cosTheta * cosTheta); + if (fabs(sinTheta) < 1.0E-12) { - sinTheta = 1.0E-12; + sinTheta = 1.0E-12; } - - double commonFactor1 = -firstDerivative / sinTheta * d12inv; - double commonFactor2 = -firstDerivative / sinTheta * d32inv; - + + RealType commonFactor1 = -firstDerivative / sinTheta * d12inv; + RealType commonFactor2 = -firstDerivative / sinTheta * d32inv; + Vector3d force1 = commonFactor1*(r12*(d12inv*cosTheta) - r32*d32inv); Vector3d force3 = commonFactor2*(r32*(d32inv*cosTheta) - r12*d12inv); atom1_->addFrc(force1); ghostAtom->addFrc(-force1); /**@todo test correctness */ - ghostAtom->addTrq(cross(r32, force3) ); + ghostAtom->addTrq(cross(r32, force3) ); -} + atom1_->addParticlePot(potential_); + ghostAtom->addParticlePot(potential_); + angle = theta /M_PI * 180.0; + + } } //end namespace oopse