ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DirectionalAtom.cpp
Revision: 599
Committed: Mon Jul 14 21:48:43 2003 UTC (20 years, 11 months ago) by mmeineke
File size: 5562 byte(s)
Log Message:
added get and set routines to Atom and DirectionalAtom

File Contents

# Content
1 #include <cmath>
2
3 #include "Atom.hpp"
4
5
6
7 void DirectionalAtom::setA( double the_A[3][3] ){
8
9 Amat[Axx] = the_A[0][0]; Amat[Axy] = the_A[0][1]; Amat[Axz] = the_A[0][2];
10 Amat[Ayx] = the_A[1][0]; Amat[Ayy] = the_A[1][1]; Amat[Ayz] = the_A[1][2];
11 Amat[Azx] = the_A[2][0]; Amat[Azy] = the_A[2][1]; Amat[Azz] = the_A[2][2];
12
13 this->updateU();
14 }
15
16 void DirectionalAtom::setI( double the_I[3][3] ){
17
18 Ixx = the_I[0][0]; Ixy = the_I[0][1]; Ixz = the_I[0][2];
19 Iyx = the_I[1][0]; Iyy = the_I[1][1]; Iyz = the_I[1][2];
20 Izx = the_I[2][0]; Izy = the_I[2][1]; Izz = the_I[2][2];
21 }
22
23 void DirectionalAtom::setQ( double the_q[4] ){
24
25 double q0Sqr, q1Sqr, q2Sqr, q3Sqr;
26
27 q0Sqr = the_q[0] * the_q[0];
28 q1Sqr = the_q[1] * the_q[1];
29 q2Sqr = the_q[2] * the_q[2];
30 q3Sqr = the_q[3] * the_q[3];
31
32
33 Amat[Axx] = q0Sqr + q1Sqr - q2Sqr - q3Sqr;
34 Amat[Axy] = 2.0 * ( the_q[1] * the_q[2] + the_q[0] * the_q[3] );
35 Amat[Axz] = 2.0 * ( the_q[1] * the_q[3] - the_q[0] * the_q[2] );
36
37 Amat[Ayx] = 2.0 * ( the_q[1] * the_q[2] - the_q[0] * the_q[3] );
38 Amat[Ayy] = q0Sqr - q1Sqr + q2Sqr - q3Sqr;
39 Amat[Ayz] = 2.0 * ( the_q[2] * the_q[3] + the_q[0] * the_q[1] );
40
41 Amat[Azx] = 2.0 * ( the_q[1] * the_q[3] + the_q[0] * the_q[2] );
42 Amat[Azy] = 2.0 * ( the_q[2] * the_q[3] - the_q[0] * the_q[1] );
43 Amat[Azz] = q0Sqr - q1Sqr -q2Sqr +q3Sqr;
44
45 this->updateU();
46 }
47
48 void DirectionalAtom::getA( double the_A[3][3] ){
49
50 the_A[0][0] = Amat[Axx];
51 the_A[0][1] = Amat[Axy];
52 the_A[0][2] = Amat[Axz];
53
54 the_A[1][0] = Amat[Ayx];
55 the_A[1][1] = Amat[Ayy];
56 the_A[1][2] = Amat[Ayz];
57
58 the_A[2][0] = Amat[Azx];
59 the_A[2][1] = Amat[Azy];
60 the_A[2][2] = Amat[Azz];
61 }
62
63 void DirectionalAtom::printAmatIndex( void ){
64
65 std::cerr << "Atom[" << index << "] index =>\n"
66 << "[ " << Axx << ", " << Axy << ", " << Axz << " ]\n"
67 << "[ " << Ayx << ", " << Ayy << ", " << Ayz << " ]\n"
68 << "[ " << Azx << ", " << Azy << ", " << Azz << " ]\n";
69 }
70
71
72 void DirectionalAtom::getU( double the_u[3] ){
73
74 the_u[0] = sux;
75 the_u[1] = suy;
76 the_u[2] = suz;
77
78 this->body2Lab( the_u );
79 }
80
81 void DirectionalAtom::getQ( double q[4] ){
82
83 double t, s;
84 double ad1, ad2, ad3;
85
86 t = Amat[Axx] + Amat[Ayy] + Amat[Azz] + 1.0;
87 if( t > 0.0 ){
88
89 s = 0.5 / sqrt( t );
90 q[0] = 0.25 / s;
91 q[1] = (Amat[Ayz] - Amat[Azy]) * s;
92 q[2] = (Amat[Azx] - Amat[Axz]) * s;
93 q[3] = (Amat[Axy] - Amat[Ayx]) * s;
94 }
95 else{
96
97 ad1 = fabs( Amat[Axx] );
98 ad2 = fabs( Amat[Ayy] );
99 ad3 = fabs( Amat[Azz] );
100
101 if( ad1 >= ad2 && ad1 >= ad3 ){
102
103 s = 2.0 * sqrt( 1.0 + Amat[Axx] - Amat[Ayy] - Amat[Azz] );
104 q[0] = (Amat[Ayz] + Amat[Azy]) / s;
105 q[1] = 0.5 / s;
106 q[2] = (Amat[Axy] + Amat[Ayx]) / s;
107 q[3] = (Amat[Axz] + Amat[Azx]) / s;
108 }
109 else if( ad2 >= ad1 && ad2 >= ad3 ){
110
111 s = sqrt( 1.0 + Amat[Ayy] - Amat[Axx] - Amat[Azz] ) * 2.0;
112 q[0] = (Amat[Axz] + Amat[Azx]) / s;
113 q[1] = (Amat[Axy] + Amat[Ayx]) / s;
114 q[2] = 0.5 / s;
115 q[3] = (Amat[Ayz] + Amat[Azy]) / s;
116 }
117 else{
118
119 s = sqrt( 1.0 + Amat[Azz] - Amat[Axx] - Amat[Ayy] ) * 2.0;
120 q[0] = (Amat[Axy] + Amat[Ayx]) / s;
121 q[1] = (Amat[Axz] + Amat[Azx]) / s;
122 q[2] = (Amat[Ayz] + Amat[Azy]) / s;
123 q[3] = 0.5 / s;
124 }
125 }
126 }
127
128
129 void DirectionalAtom::setEuler( double phi, double theta, double psi ){
130
131 Amat[Axx] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi));
132 Amat[Axy] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi));
133 Amat[Axz] = sin(theta) * sin(psi);
134
135 Amat[Ayx] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi));
136 Amat[Ayy] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi));
137 Amat[Ayz] = sin(theta) * cos(psi);
138
139 Amat[Azx] = sin(phi) * sin(theta);
140 Amat[Azy] = -cos(phi) * sin(theta);
141 Amat[Azz] = cos(theta);
142
143 this->updateU();
144 }
145
146
147 void DirectionalAtom::lab2Body( double r[3] ){
148
149 double rl[3]; // the lab frame vector
150
151 rl[0] = r[0];
152 rl[1] = r[1];
153 rl[2] = r[2];
154
155 r[0] = (Amat[Axx] * rl[0]) + (Amat[Axy] * rl[1]) + (Amat[Axz] * rl[2]);
156 r[1] = (Amat[Ayx] * rl[0]) + (Amat[Ayy] * rl[1]) + (Amat[Ayz] * rl[2]);
157 r[2] = (Amat[Azx] * rl[0]) + (Amat[Azy] * rl[1]) + (Amat[Azz] * rl[2]);
158 }
159
160 void DirectionalAtom::body2Lab( double r[3] ){
161
162 double rb[3]; // the body frame vector
163
164 rb[0] = r[0];
165 rb[1] = r[1];
166 rb[2] = r[2];
167
168 r[0] = (Amat[Axx] * rb[0]) + (Amat[Ayx] * rb[1]) + (Amat[Azx] * rb[2]);
169 r[1] = (Amat[Axy] * rb[0]) + (Amat[Ayy] * rb[1]) + (Amat[Azy] * rb[2]);
170 r[2] = (Amat[Axz] * rb[0]) + (Amat[Ayz] * rb[1]) + (Amat[Azz] * rb[2]);
171 }
172
173 void DirectionalAtom::updateU( void ){
174
175 ul[offsetX] = (Amat[Axx] * sux) + (Amat[Ayx] * suy) + (Amat[Azx] * suz);
176 ul[offsetY] = (Amat[Axy] * sux) + (Amat[Ayy] * suy) + (Amat[Azy] * suz);
177 ul[offsetZ] = (Amat[Axz] * sux) + (Amat[Ayz] * suy) + (Amat[Azz] * suz);
178 }
179
180 void DirectionalAtom::getJ( double theJ[3] ){
181
182 theJ[0] = jx;
183 theJ[1] = jy;
184 theJ[2] = jz;
185 }
186
187 void DirectionalAtom::setJ( double theJ[3] ){
188
189 jx = theJ[0];
190 jy = theJ[1];
191 jz = theJ[2];
192 }
193
194 void DirectionalAtom::getTrq( double theT[3] ){
195
196 theT[0] = trq[offsetX];
197 theT[1] = trq[offsetY];
198 theT[2] = trq[offsetZ];
199 }
200
201 void DirectionalAtom::addTrq( double theT[3] ){
202
203 trq[offsetX] += theT[0];
204 trq[offsetY] += theT[1];
205 trq[offsetZ] += theT[2];
206 }
207
208
209 void DirectionalAtom::getI( double the_I[3][3] ){
210
211 the_I[0][0] = Ixx;
212 the_I[0][1] = Ixy;
213 the_I[0][2] = Ixz;
214
215 the_I[1][0] = Iyx;
216 the_I[1][1] = Iyy;
217 the_I[1][2] = Iyz;
218
219 the_I[2][0] = Izx;
220 the_I[2][1] = Izy;
221 the_I[2][2] = Izz;
222 }