https://mooseframework.inl.gov
EulerAngles.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "libmesh/ignore_warnings.h"
11 #include "EulerAngles.h"
12 #include "MooseRandom.h"
13 
15 {
16  phi1 = 0.0;
17  Phi = 0.0;
18  phi2 = 0.0;
19 }
20 
21 EulerAngles::EulerAngles(const Eigen::Quaternion<Real> & q)
22 {
23  phi1 = std::atan2((q.x() * q.z() + q.w() * q.y()), -(-q.w() * q.x() + q.y() * q.z())) *
24  (180.0 / libMesh::pi);
25  Phi = std::atan2(
26  std::sqrt(1 -
27  std::pow(q.w() * q.w() - q.x() * q.x() - q.y() * q.y() + q.z() * q.z(), 2.0)),
28  q.w() * q.w() - q.x() * q.x() - q.y() * q.y() + q.z() * q.z()) *
29  (180.0 / libMesh::pi);
30  phi2 = std::atan2((q.x() * q.z() - q.w() * q.y()), (q.w() * q.x() + q.y() * q.z())) *
31  (180.0 / libMesh::pi);
32 
33  // Following checks and updates are done only to comply with bunge euler angle definitions, 0.0
34  // <= phi1/phi2 <= 360.0
35  if (phi1 < 0.0)
36  phi1 += 360.0;
37  if (phi2 < 0.0)
38  phi2 += 360.0;
39  if (Phi < 0.0)
40  mooseError("Euler angle out of range.");
41 }
42 
43 Eigen::Quaternion<Real>
45 {
46  Eigen::Quaternion<Real> q;
47 
48  Real cPhi1PlusPhi2, cphi, cPhi1MinusPhi2;
49  Real sPhi1PlusPhi2, sphi, sPhi1MinusPhi2;
50 
56  cPhi1PlusPhi2 = std::cos((phi1 * libMesh::pi / 180.0 + phi2 * libMesh::pi / 180.0) / 2.0);
57  cphi = std::cos(Phi * libMesh::pi / 360.0);
58  cPhi1MinusPhi2 = std::cos((phi1 * libMesh::pi / 180.0 - phi2 * libMesh::pi / 180.0) / 2.0);
59 
60  sPhi1PlusPhi2 = std::sin((phi1 * libMesh::pi / 180.0 + phi2 * libMesh::pi / 180.0) / 2.0);
61  sphi = std::sin(Phi * libMesh::pi / 360.0);
62  sPhi1MinusPhi2 = std::sin((phi1 * libMesh::pi / 180.0 - phi2 * libMesh::pi / 180.0) / 2.0);
63 
64  q.w() = cphi * cPhi1PlusPhi2;
65  q.x() = sphi * cPhi1MinusPhi2;
66  q.y() = sphi * sPhi1MinusPhi2;
67  q.z() = cphi * sPhi1PlusPhi2;
68 
69  return q;
70 }
71 
72 void
74 {
75  phi1 = MooseRandom::rand() * 360.0;
76  Phi = std::acos(1.0 - 2.0 * MooseRandom::rand()) / libMesh::pi * 180.0;
77  phi2 = MooseRandom::rand() * 360;
78 }
79 
80 void
82 {
83  phi1 = random.rand(0) * 360.0;
84  Phi = std::acos(1.0 - 2.0 * random.rand(0)) / libMesh::pi * 180.0;
85  phi2 = random.rand(0) * 360;
86 }
87 #include "libmesh/restore_warnings.h"
void mooseError(Args &&... args)
void random()
Definition: EulerAngles.C:73
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static Real rand()
MooseUnits pow(const MooseUnits &, int)
const Real pi
Eigen::Quaternion< Real > toQuaternion()
Definition: EulerAngles.C:44