axisAngleRotation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "axisAngleRotation.H"
29 #include "dictionary.H"
30 #include "quaternion.H"
31 #include "unitConversion.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  namespace coordinateRotations
39  {
40  defineTypeName(axisAngle);
42  (
43  coordinateRotation,
44  axisAngle,
45  dictionary
46  );
47  }
48 }
49 
50 
51 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 
53 void Foam::coordinateRotations::axisAngle::checkSpec()
54 {
55  if (mag(angle_) < VSMALL || mag(axis_) < SMALL)
56  {
57  clear(); // identity rotation
58  }
59 }
60 
61 
62 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
63 
65 (
66  const vector& axis,
67  const scalar angle,
68  bool degrees
69 )
70 {
71  if (mag(angle) < VSMALL || mag(axis) < SMALL)
72  {
73  return sphericalTensor::I; // identity rotation
74  }
75 
76  return quaternion(axis, (degrees ? degToRad(angle) : angle)).R();
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 :
85  axis_ (0,0,1), // e3 = global Z
86  angle_(Zero),
87  degrees_(true)
88 {}
89 
90 
92 :
94  axis_(crot.axis_),
95  angle_(crot.angle_),
96  degrees_(crot.degrees_)
97 {
98  checkSpec();
99 }
100 
101 
103 (
104  const vector& axis,
105  scalar angle,
106  bool degrees
107 )
108 :
110  axis_(axis),
111  angle_(angle),
112  degrees_(degrees)
113 {
114  checkSpec();
115 }
116 
117 
119 (
120  const vector::components axis,
121  scalar angle,
122  bool degrees
123 )
124 :
126  axis_(Zero),
127  angle_(angle),
128  degrees_(degrees)
129 {
130  axis_[axis] = 1;
131 }
132 
133 
135 :
136  axisAngle
137  (
138  dict.get<vector>("axis"),
139  dict.get<scalar>("angle"),
140  dict.getOrDefault("degrees", true)
141  )
142 {}
143 
144 
145 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
146 
148 {
149  axis_ = vector(0,0,1); // e3 = global Z
150  angle_ = Zero;
151 }
152 
153 
155 {
156  return rotation(axis_, angle_, degrees_);
157 }
158 
159 
161 {
162  os << "rotation axis: " << axis_
163  << " angle(" << (degrees_ ? "deg" : "rad") << "): " << angle_;
164 }
165 
166 
168 (
169  const word& keyword,
170  Ostream& os
171 ) const
172 {
173  os.beginBlock(keyword);
174 
175  os.writeEntry("type", type());
176  os.writeEntry("axis", axis_);
177  os.writeEntry("angle", angle_);
178  if (!degrees_)
179  {
180  os.writeEntry("degrees", "false");
181  }
182 
183  os.endBlock();
184 }
185 
186 
187 // ************************************************************************* //
Foam::Tensor
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: complexI.H:275
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
quaternion.H
Foam::coordinateRotations::axisAngle::writeEntry
virtual void writeEntry(const word &keyword, Ostream &os) const
Write dictionary entry.
Definition: axisAngleRotation.C:168
Foam::coordinateRotations::addToRunTimeSelectionTable
addToRunTimeSelectionTable(coordinateRotation, axisAngle, dictionary)
Foam::coordinateRotations::axisAngle
A coordinateRotation specified by a rotation axis and a rotation angle about that axis.
Definition: axisAngleRotation.H:99
unitConversion.H
Unit conversion functions.
Foam::Vector< scalar >::components
components
Component labeling enumeration.
Definition: Vector.H:81
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
Foam::coordinateRotations::axisAngle::rotation
static tensor rotation(const vector &axis, const scalar angle, bool degrees=false)
The rotation tensor for given axis/angle.
Definition: axisAngleRotation.C:65
Foam::coordinateRotations::axisAngle::axisAngle
axisAngle()
Default construct. Axis = Z, angle = 0.
Definition: axisAngleRotation.C:82
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:78
Foam::coordinateRotations::defineTypeName
defineTypeName(axes)
axisAngleRotation.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::coordinateRotations::axisAngle::write
virtual void write(Ostream &os) const
Write information.
Definition: axisAngleRotation.C:160
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::degToRad
constexpr scalar degToRad(const scalar deg) noexcept
Conversion from degrees to radians.
Definition: unitConversion.H:48
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
dictionary.H
Foam::coordinateRotations::axisAngle::R
virtual tensor R() const
Definition: axisAngleRotation.C:154
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::quaternion::R
tensor R() const
The rotation tensor corresponding to the quaternion.
Definition: quaternionI.H:354
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::SphericalTensor< scalar >::I
static const SphericalTensor I
Definition: SphericalTensor.H:77
Foam::coordinateRotations::axisAngle::clear
virtual void clear()
Reset specification.
Definition: axisAngleRotation.C:147