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-2022 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"
28 #include "motionSolver.H"
29 #include "sixDoFRigidBodyMotion.H"
30 #include "quaternion.H"
31 #include "unitConversion.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
41 
43  (
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const word& name,
57  const Time& runTime,
58  const dictionary& dict
59 )
60 :
61  fvMeshFunctionObject(name, runTime, dict),
62  logFiles(obr_, name)
63 {
64  read(dict);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
79 
80  angleUnits_ = dict.lookupOrDefaultBackwardsCompatible<word>
81  (
82  {"angleUnits", "angleFormat"},
83  "radians"
84  );
85 
86  resetName(typeName);
87 
88  return true;
89 }
90 
91 
93 {
94  OFstream& file = this->file();
95 
96  writeHeader(file, "Motion State");
97  writeHeaderValue(file, "Angle Units", angleUnits_);
98  writeCommented(file, "Time");
99 
100  file<< tab
101  << "centreOfRotation" << tab
102  << "centreOfMass" << tab
103  << "rotation" << tab
104  << "velocity" << tab
105  << "omega" << endl;
106 }
107 
108 
110 {
111  return true;
112 }
113 
114 
116 Foam::functionObjects::sixDoFRigidBodyState::motion() const
117 {
118  const fvMeshMovers::motionSolver& mover =
119  refCast<const fvMeshMovers::motionSolver>(mesh_.mover());
120 
121  return (refCast<const sixDoFRigidBodyMotion>(mover.motion()));
122 }
123 
124 
127 {
128  return motion().v();
129 }
130 
131 
134 {
135  vector angularVelocity(motion().omega());
136 
137  if (angleUnits_ == "degrees")
138  {
139  angularVelocity.x() = radToDeg(angularVelocity.x());
140  angularVelocity.y() = radToDeg(angularVelocity.y());
141  angularVelocity.z() = radToDeg(angularVelocity.z());
142  }
143 
144  return angularVelocity;
145 }
146 
147 
149 {
150  logFiles::write();
151 
152  if (Pstream::master())
153  {
154  const sixDoFRigidBodyMotion& motion = this->motion();
155 
156  vector rotationAngle
157  (
159  );
160 
161  vector angularVelocity(motion.omega());
162 
163  if (angleUnits_ == "degrees")
164  {
165  rotationAngle.x() = radToDeg(rotationAngle.x());
166  rotationAngle.y() = radToDeg(rotationAngle.y());
167  rotationAngle.z() = radToDeg(rotationAngle.z());
168 
169  angularVelocity.x() = radToDeg(angularVelocity.x());
170  angularVelocity.y() = radToDeg(angularVelocity.y());
171  angularVelocity.z() = radToDeg(angularVelocity.z());
172  }
173 
174  writeTime(file());
175  file()
176  << tab
177  << motion.centreOfRotation() << tab
178  << motion.centreOfMass() << tab
179  << rotationAngle << tab
180  << motion.v() << tab
181  << angularVelocity << endl;
182  }
183 
184  return true;
185 }
186 
187 
188 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Output to file stream.
Definition: OFstream.H:86
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
virtual bool write()
Write function.
Definition: logFiles.C:167
virtual bool read(const dictionary &)
Read optional controls.
vector velocity() const
Return the current body velocity.
vector angularVelocity() const
Return the current body angular velocity.
sixDoFRigidBodyState(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual void writeFileHeader(const label i=0)
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.
const Foam::motionSolver & motion() const
Return the motionSolver.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:61
vector eulerAngles(const rotationSequence rs) const
Return a vector of euler angles corresponding to the.
Definition: quaternionI.H:373
Six degree of freedom motion for a rigid body.
point centreOfMass() const
Return the current centre of mass.
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 string.
Definition: word.H:62
const scalar omega
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Namespace for OpenFOAM.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const char tab
Definition: Ostream.H:259
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict
Unit conversion functions.