ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/DirectionalAtom.cpp
Revision: 31
Committed: Tue Jul 16 21:38:22 2002 UTC (21 years, 11 months ago) by mmeineke
File size: 3676 byte(s)
Log Message:
fixed a bug in getA( double the_A[3][3] );

File Contents

# User Rev Content
1 mmeineke 10 #include <cmath>
2    
3     #include "Atom.hpp"
4    
5     void DirectionalAtom::setA( double the_A[3][3] ){
6    
7     Axx = the_A[0][0]; Axy = the_A[0][1]; Axz = the_A[0][2];
8     Ayx = the_A[1][0]; Ayy = the_A[1][1]; Ayz = the_A[1][2];
9     Azx = the_A[2][0]; Azy = the_A[2][1]; Azz = the_A[2][2];
10     }
11    
12     void DirectionalAtom::setI( double the_I[3][3] ){
13    
14     Ixx = the_I[0][0]; Ixy = the_I[0][1]; Ixz = the_I[0][2];
15     Iyx = the_I[1][0]; Iyy = the_I[1][1]; Iyz = the_I[1][2];
16     Izx = the_I[2][0]; Izy = the_I[2][1]; Izz = the_I[2][2];
17     }
18    
19     void DirectionalAtom::setQ( double the_q[4] ){
20    
21     double q0Sqr, q1Sqr, q2Sqr, q3Sqr;
22    
23     q0Sqr = the_q[0] * the_q[0];
24     q1Sqr = the_q[1] * the_q[1];
25     q2Sqr = the_q[2] * the_q[2];
26     q3Sqr = the_q[3] * the_q[3];
27    
28    
29     Axx = q0Sqr + q1Sqr - q2Sqr - q3Sqr;
30     Axy = 2.0 * ( the_q[1] * the_q[2] + the_q[0] * the_q[3] );
31     Axz = 2.0 * ( the_q[1] * the_q[3] - the_q[0] * the_q[2] );
32    
33     Ayx = 2.0 * ( the_q[1] * the_q[2] - the_q[0] * the_q[3] );
34     Ayy = q0Sqr - q1Sqr + q2Sqr - q3Sqr;
35     Ayz = 2.0 * ( the_q[2] * the_q[3] + the_q[0] * the_q[1] );
36    
37     Azx = 2.0 * ( the_q[1] * the_q[3] + the_q[0] * the_q[2] );
38     Azy = 2.0 * ( the_q[2] * the_q[3] - the_q[0] * the_q[1] );
39     Azz = q0Sqr - q1Sqr -q2Sqr +q3Sqr;
40     }
41    
42 mmeineke 30 void DirectionalAtom::getA( double the_A[3][3] ){
43    
44 mmeineke 31 the_A[0][0] = Axx;
45     the_A[0][1] = Axy;
46     the_A[0][2] = Axz;
47 mmeineke 30
48 mmeineke 31 the_A[1][0] = Ayx;
49     the_A[1][1] = Ayy;
50     the_A[1][2] = Ayz;
51 mmeineke 30
52 mmeineke 31 the_A[2][0] = Azx;
53     the_A[2][1] = Azy;
54     the_A[2][2] = Azz;
55 mmeineke 30 }
56    
57    
58 mmeineke 10 void DirectionalAtom::getU( double the_u[3] ){
59    
60     the_u[0] = sux;
61     the_u[1] = suy;
62     the_u[2] = suz;
63    
64     this->body2Lab( the_u );
65     }
66    
67     void DirectionalAtom::getQ( double q[4] ){
68    
69     double t, s;
70     double ad1, ad2, ad3;
71    
72     t = Axx + Ayy + Azz + 1.0;
73     if( t > 0.0 ){
74    
75     s = 0.5 / sqrt( t );
76     q[0] = 0.25 / s;
77     q[1] = (Ayz - Azy) * s;
78     q[2] = (Azx - Axz) * s;
79     q[3] = (Axy - Ayx) * s;
80     }
81     else{
82    
83     ad1 = fabs( Axx );
84     ad2 = fabs( Ayy );
85     ad3 = fabs( Azz );
86    
87     if( ad1 >= ad2 && ad1 >= ad3 ){
88    
89     s = 2.0 * sqrt( 1.0 + Axx - Ayy - Azz );
90     q[0] = (Ayz + Azy) / s;
91     q[1] = 0.5 / s;
92     q[2] = (Axy + Ayx) / s;
93     q[3] = (Axz + Azx) / s;
94     }
95     else if( ad2 >= ad1 && ad2 >= ad3 ){
96    
97     s = sqrt( 1.0 + Ayy - Axx - Azz ) * 2.0;
98     q[0] = (Axz + Azx) / s;
99     q[1] = (Axy + Ayx) / s;
100     q[2] = 0.5 / s;
101     q[3] = (Ayz + Azy) / s;
102     }
103     else{
104    
105     s = sqrt( 1.0 + Azz - Axx - Ayy ) * 2.0;
106     q[0] = (Axy + Ayx) / s;
107     q[1] = (Axz + Azx) / s;
108     q[2] = (Ayz + Azy) / s;
109     q[3] = 0.5 / s;
110     }
111     }
112     }
113    
114    
115     void DirectionalAtom::setEuler( double phi, double theta, double psi ){
116    
117     Axx = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi));
118     Axy = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi));
119     Axz = sin(theta) * sin(psi);
120    
121     Ayx = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi));
122     Ayy = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi));
123     Ayz = sin(theta) * cos(psi);
124    
125     Azx = sin(phi) * sin(theta);
126     Azy = -cos(phi) * sin(theta);
127     Azz = cos(theta);
128     }
129    
130    
131     void DirectionalAtom::lab2Body( double r[3] ){
132    
133     double rl[3]; // the lab frame vector
134    
135     rl[0] = r[0];
136     rl[1] = r[1];
137     rl[2] = r[2];
138    
139     r[0] = (Axx * rl[0]) + (Axy * rl[1]) + (Axz * rl[2]);
140     r[1] = (Ayx * rl[0]) + (Ayy * rl[1]) + (Ayz * rl[2]);
141     r[2] = (Azx * rl[0]) + (Azy * rl[1]) + (Azz * rl[2]);
142     }
143    
144     void DirectionalAtom::body2Lab( double r[3] ){
145    
146     double rb[3]; // the body frame vector
147    
148     rb[0] = r[0];
149     rb[1] = r[1];
150     rb[2] = r[2];
151    
152     r[0] = (Axx * rb[0]) + (Ayx * rb[1]) + (Azx * rb[2]);
153     r[1] = (Axy * rb[0]) + (Ayy * rb[1]) + (Azy * rb[2]);
154     r[2] = (Axz * rb[0]) + (Ayz * rb[1]) + (Azz * rb[2]);
155     }
156