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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
36namespace Foam
37{
38namespace coordinateRotations
39{
40
43 (
47 );
48
49} // End namespace coordinateRotation
50} // End namespace Foam
51
52
53// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54
55void Foam::coordinateRotations::axisAngle::checkSpec()
56{
57 if (mag(angle_) < VSMALL || mag(axis_) < SMALL)
58 {
59 clear(); // identity rotation
60 }
61}
62
63
64// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
65
67(
68 const vector& axis,
69 const scalar angle,
70 bool degrees
71)
72{
73 if (mag(angle) < VSMALL || mag(axis) < SMALL)
74 {
75 return sphericalTensor::I; // identity rotation
76 }
77
78 return quaternion(axis, (degrees ? degToRad(angle) : angle)).R();
79}
80
81
83(
84 const vector::components axis,
85 const scalar angle,
86 bool degrees
87)
88{
89 vector rotAxis(Zero);
90 rotAxis[axis] = 1;
91
92 return axisAngle::rotation(rotAxis, angle, degrees);
93}
94
95
96// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
97
99:
101 axis_ (0,0,1), // e3 = global Z
102 angle_(Zero),
103 degrees_(true)
104{}
105
106
108:
110 axis_(crot.axis_),
111 angle_(crot.angle_),
112 degrees_(crot.degrees_)
113{
114 checkSpec();
115}
116
117
119(
120 const vector& axis,
121 scalar angle,
122 bool degrees
123)
124:
126 axis_(axis),
127 angle_(angle),
128 degrees_(degrees)
129{
130 checkSpec();
131}
132
133
135(
136 const vector::components axis,
137 scalar angle,
138 bool degrees
139)
140:
142 axis_(Zero),
143 angle_(angle),
144 degrees_(degrees)
145{
146 axis_[axis] = 1;
147}
148
149
151:
153 (
154 dict.get<vector>("axis"),
155 dict.get<scalar>("angle"),
156 dict.getOrDefault("degrees", true)
157 )
158{}
159
160
161// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
162
164{
165 axis_ = vector(0,0,1); // e3 = global Z
166 angle_ = Zero;
167}
168
169
171{
172 return rotation(axis_, angle_, degrees_);
173}
174
175
177{
178 os << "rotation axis: " << axis_
179 << " angle(" << (degrees_ ? "deg" : "rad") << "): " << angle_;
180}
181
182
184(
185 const word& keyword,
186 Ostream& os
187) const
188{
189 os.beginBlock(keyword);
190
191 os.writeEntry("type", type());
192 os.writeEntry("axis", axis_);
193 os.writeEntry("angle", angle_);
194 if (!degrees_)
195 {
196 os.writeEntry("degrees", "false");
197 }
198
199 os.endBlock();
200}
201
202
203// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static const SphericalTensor I
User specification of a coordinate rotation.
A coordinateRotation specified by a rotation axis and a rotation angle about that axis.
axisAngle()
Default construct. Axis = Z, angle = 0.
virtual void writeEntry(const word &keyword, Ostream &os) const
Write dictionary entry.
virtual void clear()
Reset specification.
virtual const coordinateRotation & rotation() const
The rotation specification.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
Extracts the components of elements of a field and outputs the result into new fields,...
Definition: components.H:188
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:58
tensor R() const
The rotation tensor corresponding to the quaternion.
Definition: quaternionI.H:358
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeName(Type)
Define the typeName.
Definition: className.H:96
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
constexpr scalar degToRad() noexcept
Multiplication factor for degrees to radians conversion.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Vector< scalar > vector
Definition: vector.H:61
dictionary dict
Unit conversion functions.