Loading...
Searching...
No Matches
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"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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
82Foam::functionObjects::sixDoFRigidBodyState::sixDoFRigidBodyState
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{
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
120{
121 return true;
122}
123
124
126{
129
130 const sixDoFRigidBodyMotionSolver& motionSolver_ =
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:57
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
const Cmpt & x() const noexcept
Access to the vector x component.
Definition Vector.H:135
const Cmpt & z() const noexcept
Access to the vector z component.
Definition Vector.H:145
const Cmpt & y() const noexcept
Access to the vector y component.
Definition Vector.H:140
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
The dynamicMotionSolverFvMesh.
Abstract base-class for Time/database function objects.
virtual bool read(const dictionary &dict)
Read and set the function object if its data have changed.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
fvMeshFunctionObject(const fvMeshFunctionObject &)=delete
No copy construct.
const objectRegistry & obr_
Reference to the region objectRegistry.
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:113
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition writeFile.C:344
virtual OFstream & file()
Return access to the file (if only 1).
Definition writeFile.C:270
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition writeFile.C:318
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
Definition writeFile.C:354
Quaternion class used to perform rotations in 3D space.
Definition quaternion.H:54
vector eulerAngles(const eulerOrder order) const
Return the Euler rotation angles corresponding to the specified rotation order.
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:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr scalar radToDeg() noexcept
Multiplication factor for radians to degrees conversion.
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
constexpr char tab
The tab '\t' character(0x09).
Definition Ostream.H:49
dictionary dict
Unit conversion functions.