--- trunk/src/primitives/Bend.cpp 2005/01/12 22:41:40 246 +++ trunk/src/primitives/Bend.cpp 2008/01/23 16:38:22 1211 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -42,57 +42,59 @@ namespace oopse { #include "primitives/Bend.hpp" namespace oopse { - -/**@todo still a lot left to improve*/ -void Bend::calcForce() { + + /**@todo still a lot left to improve*/ + void Bend::calcForce(RealType& angle) { Vector3d pos1 = atom1_->getPos(); Vector3d pos2 = atom2_->getPos(); Vector3d pos3 = atom3_->getPos(); - + Vector3d r21 = pos1 - pos2; - double d21 = r21.length(); - - double d21inv = 1.0 / d21; - + RealType d21 = r21.length(); + + RealType d21inv = 1.0 / d21; + Vector3d r23 = pos3 - pos2; - double d23 = r23.length(); - - double d23inv = 1.0 / d23; - - double cosTheta = dot(r21, r23) / (d21 * d23); - + RealType d23 = r23.length(); + + RealType d23inv = 1.0 / d23; + + RealType cosTheta = dot(r21, r23) / (d21 * d23); + //check roundoff if (cosTheta > 1.0) { - cosTheta = 1.0; + cosTheta = 1.0; } else if (cosTheta < -1.0) { - cosTheta = -1.0; + cosTheta = -1.0; } + + RealType theta = acos(cosTheta); + + RealType dVdTheta; - double theta = acos(cosTheta); - - double dVdTheta; - bendType_->calcForce(theta, potential_, dVdTheta); - - double sinTheta = sqrt(1.0 - cosTheta * cosTheta); - + + RealType sinTheta = sqrt(1.0 - cosTheta * cosTheta); + if (fabs(sinTheta) < 1.0E-6) { - sinTheta = 1.0E-6; + sinTheta = 1.0E-6; } - - double commonFactor1 = dVdTheta / sinTheta * d21inv; - double commonFactor2 = dVdTheta / sinTheta * d23inv; - + + RealType commonFactor1 = dVdTheta / sinTheta * d21inv; + RealType commonFactor2 = dVdTheta / sinTheta * d23inv; + Vector3d force1 = commonFactor1 * (r23 * d23inv - r21*d21inv*cosTheta); Vector3d force3 = commonFactor2 * (r21 * d21inv - r23*d23inv*cosTheta); - //total force in current bend is zero + // Total force in current bend is zero Vector3d force2 = force1 + force3; force2 *= -1.0; - + atom1_->addFrc(force1); atom2_->addFrc(force2); atom3_->addFrc(force3); -} + + angle = theta /M_PI * 180.0; + } } //end namespace oopse