www.mooseframework.org
Functions
RotationMatrix Namespace Reference

Utility functions to return rotations matrics. More...

Functions

RealTensorValue rotVecToZ (RealVectorValue vec)
 provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction) More...
 
RealTensorValue rotVec1ToVec2 (RealVectorValue vec1, RealVectorValue vec2)
 provides a rotation matrix that will rotate the vector vec1 to vec2 More...
 

Detailed Description

Utility functions to return rotations matrics.

Function Documentation

RealTensorValue RotationMatrix::rotVec1ToVec2 ( RealVectorValue  vec1,
RealVectorValue  vec2 
)

provides a rotation matrix that will rotate the vector vec1 to vec2

Definition at line 56 of file RotationMatrix.C.

58 {
59  RealTensorValue rot1_to_z = rotVecToZ(vec1);
60  RealTensorValue rot2_to_z = rotVecToZ(vec2);
61  return rot2_to_z.transpose() * rot1_to_z;
62 }
RealTensorValue rotVecToZ(RealVectorValue vec)
provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction) ...
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45
RealTensorValue RotationMatrix::rotVecToZ ( RealVectorValue  vec)

provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction)

Definition at line 18 of file RotationMatrix.C.

Referenced by rotVec1ToVec2(), and SolutionUserObject::SolutionUserObject().

20 {
21  // ensure that vec is normalised
22  vec /= std::sqrt(vec * vec);
23 
24  // construct v0 and v1 to be orthonormal to vec
25  // and form a RH basis, that is, so v1 x vec = v0
26 
27  // Use Gram-Schmidt method to find v1.
28  RealVectorValue v1;
29  // Need a prototype for v1 first, and this is done by looking at the smallest component of vec
30  RealVectorValue w(std::abs(vec(0)), std::abs(vec(1)), std::abs(vec(2)));
31  if ((w(2) >= w(1) && w(1) >= w(0)) || (w(1) >= w(2) && w(2) >= w(0)))
32  // vec(0) is the smallest component
33  v1(0) = 1;
34  else if ((w(2) >= w(0) && w(0) >= w(1)) || (w(0) >= w(2) && w(2) >= w(1)))
35  // vec(1) is the smallest component
36  v1(1) = 1;
37  else
38  // vec(2) is the smallest component
39  v1(2) = 1;
40  // now Gram-Schmidt
41  v1 -= (v1 * vec) * vec;
42  v1 /= std::sqrt(v1 * v1);
43 
44  // now use v0 = v1 x vec
45  RealVectorValue v0;
46  v0(0) = v1(1) * vec(2) - v1(2) * vec(1);
47  v0(1) = v1(2) * vec(0) - v1(0) * vec(2);
48  v0(2) = v1(0) * vec(1) - v1(1) * vec(0);
49 
50  // the desired rotation matrix is just
51  RealTensorValue rot(v0(0), v0(1), v0(2), v1(0), v1(1), v1(2), vec(0), vec(1), vec(2));
52  return rot;
53 }
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45