rigidBodyState.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) 2019-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 "rigidBodyState.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 
39  (
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 Foam::functionObjects::rigidBodyState::motion() const
52 {
53  const fvMeshMovers::pointMeshMover& mover =
54  refCast<const fvMeshMovers::pointMeshMover>(mesh_.mover());
55 
56  return (refCast<const RBD::rigidBodyMotion>(mover.mover()));
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const Time& runTime,
66  const dictionary& dict
67 )
68 :
69  fvMeshFunctionObject(name, runTime, dict),
70  logFiles(obr_, name),
71  angleUnits_("[rad]"),
72  angularVelocityUnits_("[rad/s]"),
73  names_(motion().movingBodyNames())
74 {
75  read(dict);
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
80 
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
90 
91  units::table();
92 
93  angleUnits_.readIfPresent("angleUnits", dict);
94  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
95 
96  resetNames(names_);
97 
98  return true;
99 }
100 
101 
103 {
104  OFstream& file = this->files()[i];
105 
106  writeHeader(file, "Motion State");
107  writeHeaderValue(file, "Angle Units", angleUnits_);
108  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
109  writeCommented(file, "Time");
110 
111  file<< tab
112  << "Centre of rotation" << tab
113  << "Orientation" << tab
114  << "Linear velocity" << tab
115  << "Angular velocity" << endl;
116 }
117 
118 
120 {
121  return true;
122 }
123 
124 
126 {
127  logFiles::write();
128 
129  if (Pstream::master())
130  {
131  const RBD::rigidBodyMotion& motion = this->motion();
132 
133  forAll(names_, i)
134  {
135  const label bodyID = motion.bodyIndex(names_[i]);
136 
137  const spatialTransform CofR(motion.X0(bodyID));
138  const spatialVector vCofR(motion.v(bodyID, Zero));
139 
140  const vector theta =
142  const vector omega(vCofR.w());
143 
144  writeTime(files()[i]);
145  files()[i]
146  << tab
147  << CofR.r() << tab
148  << angleUnits_.toUser(theta) << tab
149  << vCofR.l() << tab
150  << angularVelocityUnits_.toUser(omega) << endl;
151  }
152  }
153 
154  return true;
155 }
156 
157 
158 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
Output to file stream.
Definition: OFstream.H:87
const spatialVector & v(const label i) const
Return the spatial velocity of body i.
label bodyIndex(const word &name) const
Return the ID of the body with the given name.
spatialTransform X0(const label bodyId) const
Return the current transform to the global frame for the given body.
Six degree of freedom motion for a rigid body.
Vector< Cmpt > w() const
Return the angular part of the spatial vector as a vector.
Vector< Cmpt > l() const
Return the linear part of the spatial vector as a vector.
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...
const fvMesh & mesh_
Reference to the 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.
Writes the rigid body motion state.
rigidBodyState(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 rigidBodyState.
virtual bool read(const dictionary &)
Read the rigidBodyState data.
const fvMeshMover & mover() const
Return the mover function class.
Definition: fvMesh.C:1125
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
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
const vector & r() const
Return the translation vector.
const tensor & E() const
Return the rotation tensor.
A class for handling words, derived from string.
Definition: word.H:63
const scalar omega
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
const HashTable< unitSet > & table()
Get the table of unit conversions.
Definition: units.C:142
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
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