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-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 "rigidBodyState.H"
28 #include "motionSolver.H"
29 #include "unitConversion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
39 
41  (
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
53 Foam::functionObjects::rigidBodyState::motion() const
54 {
55  const fvMeshMovers::motionSolver& mover =
56  refCast<const fvMeshMovers::motionSolver>(mesh_.mover());
57 
58  return (refCast<const RBD::rigidBodyMotion>(mover.motion()));
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
65 (
66  const word& name,
67  const Time& runTime,
68  const dictionary& dict
69 )
70 :
71  fvMeshFunctionObject(name, runTime, dict),
72  logFiles(obr_, name),
73  names_(motion().movingBodyNames())
74 {
75  read(dict);
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
80 
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
90 
91  angleUnits_ = dict.lookupOrDefaultBackwardsCompatible<word>
92  (
93  {"angleUnits", "angleFormat"},
94  "radians"
95  );
96 
97  resetNames(names_);
98 
99  return true;
100 }
101 
102 
104 {
105  writeHeader(this->files()[i], "Motion State");
106  writeHeaderValue(this->files()[i], "Angle Units", angleUnits_);
107  writeCommented(this->files()[i], "Time");
108 
109  this->files()[i]<< tab
110  << "Centre of rotation" << tab
111  << "Orientation" << tab
112  << "Linear velocity" << tab
113  << "Angular velocity" << endl;
114 
115 }
116 
117 
119 {
120  return true;
121 }
122 
123 
125 {
126  logFiles::write();
127 
128  if (Pstream::master())
129  {
130  const RBD::rigidBodyMotion& motion = this->motion();
131 
132  forAll(names_, i)
133  {
134  const label bodyID = motion.bodyID(names_[i]);
135 
136  const spatialTransform CofR(motion.X0(bodyID));
137  const spatialVector vCofR(motion.v(bodyID, Zero));
138 
139  vector rotationAngle
140  (
142  );
143 
144  vector angularVelocity(vCofR.w());
145 
146  if (angleUnits_ == "degrees")
147  {
148  rotationAngle.x() = radToDeg(rotationAngle.x());
149  rotationAngle.y() = radToDeg(rotationAngle.y());
150  rotationAngle.z() = radToDeg(rotationAngle.z());
151 
152  angularVelocity.x() = radToDeg(angularVelocity.x());
153  angularVelocity.y() = radToDeg(angularVelocity.y());
154  angularVelocity.z() = radToDeg(angularVelocity.z());
155  }
156 
157  writeTime(files()[i]);
158  files()[i]
159  << tab
160  << CofR.r() << tab
161  << rotationAngle << tab
162  << vCofR.l() << tab
163  << angularVelocity << endl;
164  }
165  }
166 
167  return true;
168 }
169 
170 
171 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
label bodyID(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
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...
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:167
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:1058
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
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:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char tab
Definition: Ostream.H:259
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
dictionary dict
Unit conversion functions.