sixDoFRigidBodyState.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "sixDoFRigidBodyState.H"
29 #include "unitConversion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(sixDoFRigidBodyState, 0);
39 
41  (
42  functionObject,
43  sixDoFRigidBodyState,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& name,
55  const Time& runTime,
56  const dictionary& dict
57 )
58 :
59  fvMeshFunctionObject(name, runTime, dict),
60  logFiles(obr_, name)
61 {
62  read(dict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 {
77 
78  angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
79 
80  resetName(typeName);
81 
82  return true;
83 }
84 
85 
87 {
88  OFstream& file = this->file();
89 
90  writeHeader(file, "Motion State");
91  writeHeaderValue(file, "Angle Units", angleFormat_);
92  writeCommented(file, "Time");
93 
94  file<< tab
95  << "centreOfRotation" << tab
96  << "centreOfMass" << tab
97  << "rotation" << tab
98  << "velocity" << tab
99  << "omega" << endl;
100 }
101 
102 
104 {
105  return true;
106 }
107 
108 
110 Foam::functionObjects::sixDoFRigidBodyState::motion() const
111 {
113  refCast<const dynamicMotionSolverFvMesh>(obr_);
114 
115  return (refCast<const sixDoFRigidBodyMotion>(mesh.motion()));
116 }
117 
118 
121 {
122  return motion().v();
123 }
124 
125 
128 {
129  vector angularVelocity(motion().omega());
130 
131  if (angleFormat_ == "degrees")
132  {
133  angularVelocity.x() = radToDeg(angularVelocity.x());
134  angularVelocity.y() = radToDeg(angularVelocity.y());
135  angularVelocity.z() = radToDeg(angularVelocity.z());
136  }
137 
138  return angularVelocity;
139 }
140 
141 
143 {
144  logFiles::write();
145 
146  if (Pstream::master())
147  {
148  const sixDoFRigidBodyMotion& motion = this->motion();
149 
150  vector rotationAngle
151  (
152  quaternion(motion.orientation()).eulerAngles(quaternion::XYZ)
153  );
154 
155  vector angularVelocity(motion.omega());
156 
157  if (angleFormat_ == "degrees")
158  {
159  rotationAngle.x() = radToDeg(rotationAngle.x());
160  rotationAngle.y() = radToDeg(rotationAngle.y());
161  rotationAngle.z() = radToDeg(rotationAngle.z());
162 
163  angularVelocity.x() = radToDeg(angularVelocity.x());
164  angularVelocity.y() = radToDeg(angularVelocity.y());
165  angularVelocity.z() = radToDeg(angularVelocity.z());
166  }
167 
168  writeTime(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 
178  return true;
179 }
180 
181 
182 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
virtual bool write()
Write function.
Definition: logFiles.C:167
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
vector velocity() const
Return the current body velocity.
static const char tab
Definition: Ostream.H:259
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
point centreOfMass() const
Return the current centre of mass.
const point & centreOfRotation() const
Return the current centre of rotation.
Unit conversion functions.
Output to file stream.
Definition: OFstream.H:82
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
const Cmpt & z() const
Definition: VectorI.H:87
vector angularVelocity() const
Return the current body angular velocity.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
const Cmpt & y() const
Definition: VectorI.H:81
virtual bool execute()
Execute, currently does nothing.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
dynamicFvMesh & mesh
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
vector omega() const
Return the angular velocity in the global frame.
A class for handling words, derived from string.
Definition: word.H:59
const tensor & orientation() const
Return the orientation tensor, Q.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
virtual void writeFileHeader(const label i=0)
overloaded writeFileHeader from writeFile
const Cmpt & x() const
Definition: VectorI.H:75
defineTypeNameAndDebug(Qdot, 0)
sixDoFRigidBodyState(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool write()
Write the sixDoFRigidBodyState.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const motionSolver & motion() const
Return the motionSolver.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
The dynamicMotionSolverFvMesh.
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57