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-2026 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 "sixDoFRigidBodyMotion.H"
29 #include "quaternion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
39 
41  (
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  angleUnits_("[rad]"),
62  angularVelocityUnits_("[rad/s]")
63 {
64  read(dict);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 {
79 
80  angleUnits_.readIfPresent("angleUnits", dict);
81  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
82 
83  resetName(typeName);
84 
85  return true;
86 }
87 
88 
90 {
91  OFstream& file = this->file();
92 
93  writeHeader(file, "Motion State");
94  writeHeaderValue(file, "Angle Units", angleUnits_);
95  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
96  writeCommented(file, "Time");
97 
98  file<< tab
99  << "centreOfRotation" << tab
100  << "centreOfMass" << tab
101  << "rotation" << tab
102  << "velocity" << tab
103  << "omega" << endl;
104 }
105 
106 
108 {
109  return true;
110 }
111 
112 
114 Foam::functionObjects::sixDoFRigidBodyState::motion() const
115 {
116  const fvMeshMovers::pointMeshMover& mover =
117  refCast<const fvMeshMovers::pointMeshMover>(mesh_.mover());
118 
119  return (refCast<const sixDoFRigidBodyMotion>(mover.mover()));
120 }
121 
122 
124 {
125  return motion().v();
126 }
127 
128 
131 {
132  return motion().omega();
133 }
134 
135 
136 const Foam::unitSet&
138 {
139  return angularVelocityUnits_;
140 }
141 
142 
144 {
145  logFiles::write();
146 
147  if (Pstream::master())
148  {
149  const sixDoFRigidBodyMotion& motion = this->motion();
150 
151  const vector theta =
153  const vector omega(motion.omega());
154 
155  writeTime(file());
156  file()
157  << tab
158  << motion.centreOfRotation() << tab
159  << motion.centreOfMass() << tab
160  << angleUnits_.toUser(theta) << tab
161  << motion.v() << tab
162  << angularVelocityUnits_.toUser(omega) << endl;
163  }
164 
165  return true;
166 }
167 
168 
169 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Output to file stream.
Definition: OFstream.H:87
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
virtual void writeFileHeader(const label i=0)
overloaded writeFileHeader from writeFile
const unitSet & angularVelocityUnits() const
Return the units in which to write the angular velocities.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the sixDoFRigidBodyState.
virtual bool read(const dictionary &)
Read the sixDoFRigidBodyState data.
Wrapper class so that a pointMeshMover can be instantiated to move an fvMesh.
const Foam::pointMeshMover & mover() const
Return the pointMeshMover.
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.
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
Definition: unitSet.H:68
A class for handling words, derived from string.
Definition: word.H:63
const scalar omega
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, 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:288
static const char tab
Definition: Ostream.H:296
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict