sixDoFRigidBodyState.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) 2017 OpenFOAM Foundation
9 Copyright (C) 2018-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
32#include "unitConversion.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace functionObjects
40{
42
44 (
48 );
49}
50}
51
52const Foam::Enum
53<
54 Foam::functionObjects::sixDoFRigidBodyState::angleTypes
55>
56Foam::functionObjects::sixDoFRigidBodyState::angleTypeNames_
57({
58 { angleTypes::RADIANS, "radians" },
59 { angleTypes::DEGREES, "degrees" },
60});
61
62
63// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
64
66{
67 writeHeader(os, "Motion State");
68 writeHeaderValue(os, "Angle Units", angleTypeNames_[angleFormat_]);
69 writeCommented(os, "Time");
70
71 os << tab
72 << "centreOfRotation" << tab
73 << "centreOfMass" << tab
74 << "rotation" << tab
75 << "velocity" << tab
76 << "omega" << endl;
77}
78
79
80// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81
83(
84 const word& name,
85 const Time& runTime,
86 const dictionary& dict
87)
88:
90 writeFile(mesh_, name, typeName, dict),
91 angleFormat_(angleTypes::RADIANS)
92{
93 read(dict);
95}
96
97
98// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99
101{
103 {
104 angleFormat_ =
105 angleTypeNames_.getOrDefault
106 (
107 "angleFormat",
108 dict,
109 angleTypes::RADIANS
110 );
111
112 return true;
113 }
114
115 return false;
116}
117
118
120{
121 return true;
122}
123
124
126{
128 refCast<const dynamicMotionSolverFvMesh>(obr_);
129
130 const sixDoFRigidBodyMotionSolver& motionSolver_ =
131 refCast<const sixDoFRigidBodyMotionSolver>(mesh.motion());
132
133 const sixDoFRigidBodyMotion& motion = motionSolver_.motion();
134
135 vector rotationAngle
136 (
138 );
139
140 vector angularVelocity(motion.omega());
141
142 switch (angleFormat_)
143 {
144 case angleTypes::RADIANS:
145 {
146 // Nothing to do - already in radians
147 break;
148 }
149 case angleTypes::DEGREES:
150 {
151 rotationAngle.x() = radToDeg(rotationAngle.x());
152 rotationAngle.y() = radToDeg(rotationAngle.y());
153 rotationAngle.z() = radToDeg(rotationAngle.z());
154
155 angularVelocity.x() = radToDeg(angularVelocity.x());
156 angularVelocity.y() = radToDeg(angularVelocity.y());
157 angularVelocity.z() = radToDeg(angularVelocity.z());
158 break;
159 }
160 default:
161 {
163 << "Unhandled enumeration " << angleTypeNames_[angleFormat_]
164 << abort(FatalError);
165 }
166 }
167
168 writeCurrentTime(file());
169 file()
170 << tab
171 << motion.centreOfRotation() << tab
172 << motion.centreOfMass() << tab
173 << rotationAngle << tab
174 << motion.v() << tab
175 << angularVelocity << endl;
176
177 return true;
178}
179
180
181// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
The dynamicMotionSolverFvMesh.
Abstract base-class for Time/database function objects.
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Definition: abort.H:128
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual void writeFileHeader(Ostream &os)
Overloaded writeFileHeader from writeFile.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the sixDoFRigidBodyState.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
Base class for writing single files from the function objects.
Definition: writeFile.H:120
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:295
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:233
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:269
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:58
vector eulerAngles(const eulerOrder order) const
Definition: quaternionI.H:408
6-DoF solid-body mesh motion solver for an fvMesh.
const sixDoFRigidBodyMotion & motion() const
Return the six DoF motion object.
Six degree of freedom motion for a rigid body.
point centreOfMass() const
Return the current centre of mass.
const vector & v() const
Return the current velocity.
const tensor & orientation() const
Return the orientation tensor, Q.
vector omega() const
Return the angular velocity in the global frame.
const point & centreOfRotation() const
Return the current centre of rotation.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr scalar radToDeg() noexcept
Multiplication factor for radians to degrees conversion.
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char tab
The tab '\t' character(0x09)
Definition: Ostream.H:52
dictionary dict
Unit conversion functions.