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-2024 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"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
40 
42  (
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const Time& runTime,
57  const dictionary& dict
58 )
59 :
60  fvMeshFunctionObject(name, runTime, dict),
61  logFiles(obr_, name),
62  angleUnits_("[rad]"),
63  angularVelocityUnits_("[rad/s]")
64 {
65  read(dict);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 {
80 
81  angleUnits_.readIfPresent("angleUnits", dict);
82  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
83 
84  resetName(typeName);
85 
86  return true;
87 }
88 
89 
91 {
92  OFstream& file = this->file();
93 
94  writeHeader(file, "Motion State");
95  writeHeaderValue(file, "Angle Units", angleUnits_);
96  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
97  writeCommented(file, "Time");
98 
99  file<< tab
100  << "centreOfRotation" << tab
101  << "centreOfMass" << tab
102  << "rotation" << tab
103  << "velocity" << tab
104  << "omega" << endl;
105 }
106 
107 
109 {
110  return true;
111 }
112 
113 
115 Foam::functionObjects::sixDoFRigidBodyState::motion() const
116 {
117  const fvMeshMovers::motionSolver& mover =
118  refCast<const fvMeshMovers::motionSolver>(mesh_.mover());
119 
120  return (refCast<const sixDoFRigidBodyMotion>(mover.motion()));
121 }
122 
123 
125 {
126  return motion().v();
127 }
128 
129 
132 {
133  return motion().omega();
134 }
135 
136 
139 {
140  return angularVelocityUnits_;
141 }
142 
143 
145 {
146  logFiles::write();
147 
148  if (Pstream::master())
149  {
150  const sixDoFRigidBodyMotion& motion = this->motion();
151 
152  const vector theta =
154  const vector omega(motion.omega());
155 
156  writeTime(file());
157  file()
158  << tab
159  << motion.centreOfRotation() << tab
160  << motion.centreOfMass() << tab
161  << angleUnits_.toUser(theta) << tab
162  << motion.v() << tab
163  << angularVelocityUnits_.toUser(omega) << endl;
164  }
165 
166  return true;
167 }
168 
169 
170 // ************************************************************************* //
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
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
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:173
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.
const unitConversion & angularVelocityUnits() const
Return the units in which to write the angular velocities.
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.
Convenience class to handle the input of constant rotational speed. Reads an omega entry with default...
Definition: omega.H:54
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.
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char tab
Definition: Ostream.H:265
dictionary dict