ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/Bond.cpp
Revision: 11
Committed: Tue Jul 9 18:40:59 2002 UTC (21 years, 11 months ago) by mmeineke
File size: 1553 byte(s)
Log Message:
This commit was generated by cvs2svn to compensate for changes in r10, which
included commits to RCS files with non-trunk default branches.

File Contents

# Content
1 #include "SRI.hpp"
2 #include "Atom.hpp"
3 #include <math.h>
4 #include <iostream>
5 #include <stdlib.h>
6
7
8
9 Bond::Bond(){
10
11 c_constraint = NULL;
12 c_is_constrained = 0;
13 }
14
15 void Bond::set_atoms( Atom &a, Atom &b ){
16
17 c_p_a = &a;
18 c_p_b = &b;
19 }
20
21 void Bond::constrain(double bond_distance){
22
23 double dsqr = bond_distance * bond_distance;
24
25 c_is_constrained = 1;
26
27 c_constraint = new Constraint();
28 c_constraint->set_a( c_p_a->getIndex() );
29 c_constraint->set_b( c_p_b->getIndex() );
30 c_constraint->set_dsqr( dsqr );
31 }
32
33 Bond::~Bond(){
34 delete c_constraint;
35 c_constraint = 0;
36 }
37
38 void Bond::calc_forces(){
39
40 /* return 0 if the bond is constrained and stop wasting cpu */
41
42 if(c_is_constrained){
43
44 c_potential_E = 0.0;
45 return;
46 }
47
48
49 vect r_ab; /*the vector whose origin is a and end is b */
50 double force; /* the force scaling factor. */
51 double Fab_x; /*the x,y, and z components of the force */
52 double Fab_y;
53 double Fab_z;
54
55 /* initialize the vector */
56
57 r_ab.x = c_p_b->getX() - c_p_a->getX();
58 r_ab.y = c_p_b->getY() - c_p_a->getY();
59 r_ab.z = c_p_b->getZ() - c_p_a->getZ();
60 r_ab.length = sqrt((r_ab.x * r_ab.x + r_ab.y * r_ab.y + r_ab.z * r_ab.z));
61
62 /* calculate the force here */
63
64 force = bond_force(r_ab.length);
65
66 Fab_x = -force * r_ab.x / r_ab.length;
67 Fab_y = -force * r_ab.y / r_ab.length;
68 Fab_z = -force * r_ab.z / r_ab.length;
69
70 c_p_a->addFx(Fab_x);
71 c_p_a->addFy(Fab_y);
72 c_p_a->addFz(Fab_z);
73
74 c_p_b->addFx(-Fab_x);
75 c_p_b->addFy(-Fab_y);
76 c_p_b->addFz(-Fab_z);
77
78 return;
79 }