ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/primitives/Bend.cpp
Revision: 1857
Committed: Mon Dec 6 20:15:02 2004 UTC (19 years, 8 months ago) by tim
File size: 1336 byte(s)
Log Message:
short range interaction for butane is correct.Still something wrong with long range one

File Contents

# User Rev Content
1 tim 1746 #include "primitives/Bend.hpp"
2    
3     namespace oopse {
4    
5     /**@todo still a lot left to improve*/
6     void Bend::calcForce() {
7     Vector3d pos1 = atom1_->getPos();
8     Vector3d pos2 = atom2_->getPos();
9     Vector3d pos3 = atom3_->getPos();
10    
11 tim 1857 Vector3d r21 = pos1 - pos2;
12     double d21 = r21.length();
13 tim 1746
14 tim 1857 double d21inv = 1.0 / d21;
15 tim 1746
16 tim 1857 Vector3d r23 = pos3 - pos2;
17     double d23 = r23.length();
18 tim 1746
19 tim 1857 double d23inv = 1.0 / d23;
20 tim 1746
21 tim 1857 double cosTheta = dot(r21, r23) / (d21 * d23);
22 tim 1746
23     //check roundoff
24     if (cosTheta > 1.0) {
25     cosTheta = 1.0;
26     } else if (cosTheta < -1.0) {
27     cosTheta = -1.0;
28     }
29    
30     double theta = acos(cosTheta);
31    
32 tim 1857 double dVdTheta;
33 tim 1746
34 tim 1857 bendType_->calcForce(theta, potential_, dVdTheta);
35 tim 1746
36     double sinTheta = sqrt(1.0 - cosTheta * cosTheta);
37    
38 tim 1857 if (fabs(sinTheta) < 1.0E-6) {
39     sinTheta = 1.0E-6;
40 tim 1746 }
41    
42 tim 1857 double commonFactor1 = dVdTheta / sinTheta * d21inv;
43     double commonFactor2 = dVdTheta / sinTheta * d23inv;
44 tim 1746
45 tim 1857 Vector3d force1 = commonFactor1 * (r23 * d23inv - r21*d21inv*cosTheta);
46     Vector3d force3 = commonFactor2 * (r21 * d21inv - r23*d23inv*cosTheta);
47 tim 1746
48     //total force in current bend is zero
49     Vector3d force2 = force1 + force3;
50     force2 *= -1.0;
51    
52     atom1_->addFrc(force1);
53     atom2_->addFrc(force2);
54     atom3_->addFrc(force3);
55     }
56    
57     } //end namespace oopse