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-2021 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 {
38  defineTypeNameAndDebug(rigidBodyState, 0);
39 
41  (
42  functionObject,
43  rigidBodyState,
44  dictionary
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  names_(motion().movingBodyNames())
62 {
63  read(dict);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
77 {
78  const fvMeshMovers::motionSolver& mover =
79  refCast<const fvMeshMovers::motionSolver>(mesh_.mover());
80 
81  return (refCast<const RBD::rigidBodyMotion>(mover.motion()));
82 }
83 
84 
86 {
88 
89  angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
90 
91  resetNames(names_);
92 
93  return true;
94 }
95 
96 
98 {
99  writeHeader(this->files()[i], "Motion State");
100  writeHeaderValue(this->files()[i], "Angle Units", angleFormat_);
101  writeCommented(this->files()[i], "Time");
102 
103  this->files()[i]<< tab
104  << "Centre of rotation" << tab
105  << "Orientation" << tab
106  << "Linear velocity" << tab
107  << "Angular velocity" << endl;
108 
109 }
110 
111 
113 {
114  return true;
115 }
116 
117 
119 {
120  logFiles::write();
121 
122  if (Pstream::master())
123  {
124  const RBD::rigidBodyMotion& motion = this->motion();
125 
126  forAll(names_, i)
127  {
128  const label bodyID = motion.bodyID(names_[i]);
129 
130  const spatialTransform CofR(motion.X0(bodyID));
131  const spatialVector vCofR(motion.v(bodyID, Zero));
132 
133  vector rotationAngle
134  (
135  quaternion(CofR.E()).eulerAngles(quaternion::XYZ)
136  );
137 
138  vector angularVelocity(vCofR.w());
139 
140  if (angleFormat_ == "degrees")
141  {
142  rotationAngle.x() = radToDeg(rotationAngle.x());
143  rotationAngle.y() = radToDeg(rotationAngle.y());
144  rotationAngle.z() = radToDeg(rotationAngle.z());
145 
146  angularVelocity.x() = radToDeg(angularVelocity.x());
147  angularVelocity.y() = radToDeg(angularVelocity.y());
148  angularVelocity.z() = radToDeg(angularVelocity.z());
149  }
150 
151  writeTime(files()[i]);
152  files()[i]
153  << tab
154  << CofR.r() << tab
155  << rotationAngle << tab
156  << vCofR.l() << tab
157  << angularVelocity << endl;
158  }
159  }
160 
161  return true;
162 }
163 
164 
165 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:167
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
static const char tab
Definition: Ostream.H:259
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
Unit conversion functions.
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const RBD::rigidBodyMotion & motion() const
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
Six degree of freedom motion for a rigid body.
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
A class for handling words, derived from string.
Definition: word.H:59
rigidBodyState(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
static const zero Zero
Definition: zero.H:97
const Cmpt & x() const
Definition: VectorI.H:75
defineTypeNameAndDebug(Qdot, 0)
virtual bool write()
Write the rigidBodyState.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual ~rigidBodyState()
Destructor.
virtual bool execute()
Execute, currently does nothing.
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
label bodyID(const word &name) const
Return the ID of the body with the given name.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool read(const dictionary &)
Read the rigidBodyState data.
spatialTransform X0(const label bodyId) const
Return the current transform to the global frame for the given body.
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57
virtual void writeFileHeader(const label i=0)
overloaded writeFileHeader from writeFile