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 -------------------------------------------------------------------------------
11 License
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 
29 #include "sixDoFRigidBodyState.H"
32 #include "unitConversion.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace functionObjects
40 {
41  defineTypeNameAndDebug(sixDoFRigidBodyState, 0);
42 
44  (
45  functionObject,
46  sixDoFRigidBodyState,
47  dictionary
48  );
49 }
50 }
51 
52 const Foam::Enum
53 <
54  Foam::functionObjects::sixDoFRigidBodyState::angleTypes
55 >
56 Foam::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 
82 Foam::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 {
93  read(dict);
94  writeFileHeader(file());
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  (
137  quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
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 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::functionObjects::sixDoFRigidBodyState::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Overloaded writeFileHeader from writeFile.
Definition: sixDoFRigidBodyState.C:65
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::sixDoFRigidBodyMotionSolver
6-DoF solid-body mesh motion solver for an fvMesh.
Definition: sixDoFRigidBodyMotionSolver.H:58
Foam::functionObjects::sixDoFRigidBodyState::execute
virtual bool execute()
Execute, currently does nothing.
Definition: sixDoFRigidBodyState.C:119
sixDoFRigidBodyMotionSolver.H
Foam::functionObjects::sixDoFRigidBodyState::read
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
Definition: sixDoFRigidBodyState.C:100
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
unitConversion.H
Unit conversion functions.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
sixDoFRigidBodyState.H
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::writeFile::writeHeaderValue
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
Definition: writeFileTemplates.C:32
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:298
Foam::radToDeg
constexpr scalar radToDeg(const scalar rad) noexcept
Conversion from radians to degrees.
Definition: unitConversion.H:54
Foam::sixDoFRigidBodyMotionSolver::motion
const sixDoFRigidBodyMotion & motion() const
Return the six DoF motion object.
Definition: sixDoFRigidBodyMotionSolver.C:160
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::quaternion::XYZ
Definition: quaternion.H:108
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::sixDoFRigidBodyState::write
virtual bool write()
Write the sixDoFRigidBodyState.
Definition: sixDoFRigidBodyState.C:125
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::sixDoFRigidBodyMotion
Six degree of freedom motion for a rigid body.
Definition: sixDoFRigidBodyMotion.H:69
Foam::tab
constexpr char tab
Definition: Ostream.H:403
dynamicMotionSolverFvMesh.H
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::Vector< scalar >
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::dynamicMotionSolverFvMesh
The dynamicMotionSolverFvMesh.
Definition: dynamicMotionSolverFvMesh.H:53