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