www.mooseframework.org
Functions
RotationMatrix Namespace Reference

Utility functions to return rotations matrics. More...

Functions

template<bool is_ad = false>
GenericRealTensorValue< is_ad > rotVecToZ (GenericRealVectorValue< is_ad > vec)
 provides a rotation matrix that will rotate the vector vec to the z axis (the "2" direction) More...
 
template<bool is_ad = false>
GenericRealTensorValue< is_ad > rotVec1ToVec2 (GenericRealVectorValue< is_ad > vec1, GenericRealVectorValue< is_ad > vec2)
 provides a rotation matrix that will rotate the vector vec1 to vec2 More...
 
template<bool is_ad = false>
GenericRealTensorValue< is_ad > rotVec2DToX (const GenericRealVectorValue< is_ad > &vec)
 provides a rotation matrix that will rotate the vector vec1 to the [1,0,0], assuming vec1[2]==0 More...
 

Detailed Description

Utility functions to return rotations matrics.

Function Documentation

◆ rotVec1ToVec2()

template<bool is_ad = false>
GenericRealTensorValue<is_ad> RotationMatrix::rotVec1ToVec2 ( GenericRealVectorValue< is_ad >  vec1,
GenericRealVectorValue< is_ad >  vec2 
)

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

Definition at line 65 of file RotationMatrix.h.

67 {
68  GenericRealTensorValue<is_ad> rot1_to_z = rotVecToZ<is_ad>(vec1);
69  GenericRealTensorValue<is_ad> rot2_to_z = rotVecToZ<is_ad>(vec2);
70  return rot2_to_z.transpose() * rot1_to_z;
71 }
typename Moose::GenericType< RealTensorValue, is_ad > GenericRealTensorValue
Definition: MooseTypes.h:565

◆ rotVec2DToX()

template<bool is_ad = false>
GenericRealTensorValue<is_ad> RotationMatrix::rotVec2DToX ( const GenericRealVectorValue< is_ad > &  vec)

provides a rotation matrix that will rotate the vector vec1 to the [1,0,0], assuming vec1[2]==0

Definition at line 76 of file RotationMatrix.h.

78 {
79  const GenericReal<is_ad> theta = std::atan2(vec(1), vec(0));
80  const GenericReal<is_ad> st = std::sin(theta);
81  const GenericReal<is_ad> ct = std::cos(theta);
82  return GenericRealTensorValue<is_ad>(ct, st, 0., -st, ct, 0., 0., 0., 1.);
83 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
typename Moose::GenericType< RealTensorValue, is_ad > GenericRealTensorValue
Definition: MooseTypes.h:565
typename Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:559

◆ rotVecToZ()

template<bool is_ad = false>
GenericRealTensorValue<is_ad> RotationMatrix::rotVecToZ ( GenericRealVectorValue< is_ad >  vec)

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

Definition at line 24 of file RotationMatrix.h.

Referenced by SolutionUserObject::SolutionUserObject().

26 {
27  // ensure that vec is normalised
28  vec /= std::sqrt(vec * vec);
29 
30  // construct v0 and v1 to be orthonormal to vec
31  // and form a RH basis, that is, so v1 x vec = v0
32 
33  // Use Gram-Schmidt method to find v1.
35  // Need a prototype for v1 first, and this is done by looking at the smallest component of vec
36  GenericRealVectorValue<is_ad> w(std::abs(vec(0)), std::abs(vec(1)), std::abs(vec(2)));
37  if ((w(2) >= w(1) && w(1) >= w(0)) || (w(1) >= w(2) && w(2) >= w(0)))
38  // vec(0) is the smallest component
39  v1(0) = 1;
40  else if ((w(2) >= w(0) && w(0) >= w(1)) || (w(0) >= w(2) && w(2) >= w(1)))
41  // vec(1) is the smallest component
42  v1(1) = 1;
43  else
44  // vec(2) is the smallest component
45  v1(2) = 1;
46  // now Gram-Schmidt
47  v1 -= (v1 * vec) * vec;
48  v1 /= std::sqrt(v1 * v1);
49 
50  // now use v0 = v1 x vec
52  v0(0) = v1(1) * vec(2) - v1(2) * vec(1);
53  v0(1) = v1(2) * vec(0) - v1(0) * vec(2);
54  v0(2) = v1(0) * vec(1) - v1(1) * vec(0);
55 
56  // the desired rotation matrix is just
58  v0(0), v0(1), v0(2), v1(0), v1(1), v1(2), vec(0), vec(1), vec(2));
59  return rot;
60 }
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
typename Moose::GenericType< RealTensorValue, is_ad > GenericRealTensorValue
Definition: MooseTypes.h:565
typename Moose::GenericType< RealVectorValue, is_ad > GenericRealVectorValue
Definition: MooseTypes.h:563