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-2020 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 :
93  coordinateRotation(crot),
94  axis_(crot.axis_),
95  angle_(crot.angle_),
96  degrees_(crot.degrees_)
97 {
98  checkSpec();
99 }
100 
101 
103 :
104  coordinateRotation(std::move(crot)),
105  axis_(std::move(crot.axis_)),
106  angle_(std::move(crot.angle_)),
107  degrees_(crot.degrees_)
108 {
109  checkSpec();
110 }
111 
112 
114 (
115  const vector& axis,
116  scalar angle,
117  bool degrees
118 )
119 :
121  axis_(axis),
122  angle_(angle),
123  degrees_(degrees)
124 {
125  checkSpec();
126 }
127 
128 
130 (
131  const vector::components axis,
132  scalar angle,
133  bool degrees
134 )
135 :
137  axis_(Zero),
138  angle_(angle),
139  degrees_(degrees)
140 {
141  axis_[axis] = 1;
142 }
143 
144 
146 :
147  axisAngle
148  (
149  dict.get<vector>("axis"),
150  dict.get<scalar>("angle"),
151  dict.getOrDefault("degrees", true)
152  )
153 {}
154 
155 
156 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
157 
159 {
160  axis_ = vector(0,0,1); // e3 = global Z
161  angle_ = Zero;
162 }
163 
164 
166 {
167  return rotation(axis_, angle_, degrees_);
168 }
169 
170 
172 {
173  os << "rotation axis: " << axis_
174  << " angle(" << (degrees_ ? "deg" : "rad") << "): " << angle_;
175 }
176 
177 
179 (
180  const word& keyword,
181  Ostream& os
182 ) const
183 {
184  os.beginBlock(keyword);
185 
186  os.writeEntry("type", type());
187  os.writeEntry("axis", axis_);
188  os.writeEntry("angle", angle_);
189  if (!degrees_)
190  {
191  os.writeEntry("degrees", "false");
192  }
193 
194  os.endBlock();
195 }
196 
197 
198 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:179
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::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
Foam::Vector::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()
Construct null.
Definition: axisAngleRotation.C:82
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:77
Foam::coordinateRotations::defineTypeName
defineTypeName(axes)
axisAngleRotation.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::coordinateRotations::axisAngle::write
virtual void write(Ostream &os) const
Write information.
Definition: axisAngleRotation.C:171
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:165
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
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:158