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-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 "rigidBodyState.H"
28 #include "motionSolver.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
38 
40  (
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
52 Foam::functionObjects::rigidBodyState::motion() const
53 {
54  const fvMeshMovers::motionSolver& mover =
55  refCast<const fvMeshMovers::motionSolver>(mesh_.mover());
56 
57  return (refCast<const RBD::rigidBodyMotion>(mover.motion()));
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
64 (
65  const word& name,
66  const Time& runTime,
67  const dictionary& dict
68 )
69 :
70  fvMeshFunctionObject(name, runTime, dict),
71  logFiles(obr_, name),
72  angleUnits_("[rad]"),
73  angularVelocityUnits_("[rad/s]"),
74  names_(motion().movingBodyNames())
75 {
76  read(dict);
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
89 {
91 
92  units();
93 
94  angleUnits_.readIfPresent("angleUnits", dict);
95  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
96 
97  resetNames(names_);
98 
99  return true;
100 }
101 
102 
104 {
105  OFstream& file = this->files()[i];
106 
107  writeHeader(file, "Motion State");
108  writeHeaderValue(file, "Angle Units", angleUnits_);
109  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
110  writeCommented(file, "Time");
111 
112  file<< tab
113  << "Centre of rotation" << tab
114  << "Orientation" << tab
115  << "Linear velocity" << tab
116  << "Angular velocity" << endl;
117 }
118 
119 
121 {
122  return true;
123 }
124 
125 
127 {
128  logFiles::write();
129 
130  if (Pstream::master())
131  {
132  const RBD::rigidBodyMotion& motion = this->motion();
133 
134  forAll(names_, i)
135  {
136  const label bodyID = motion.bodyIndex(names_[i]);
137 
138  const spatialTransform CofR(motion.X0(bodyID));
139  const spatialVector vCofR(motion.v(bodyID, Zero));
140 
141  const vector theta =
143  const vector omega(vCofR.w());
144 
145  writeTime(files()[i]);
146  files()[i]
147  << tab
148  << CofR.r() << tab
149  << angleUnits_.toUser(theta) << tab
150  << vCofR.l() << tab
151  << angularVelocityUnits_.toUser(omega) << endl;
152  }
153  }
154 
155  return true;
156 }
157 
158 
159 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Output to file stream.
Definition: OFstream.H:86
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
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 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...
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:1050
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: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.
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char tab
Definition: Ostream.H:265
const HashTable< unitConversion > & units()
Get the table of unit conversions.
dictionary dict