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 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  resetNames(names_);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
78 {
80  refCast<const dynamicMotionSolverFvMesh>(obr_);
81 
82  return (refCast<const RBD::rigidBodyMotion>(mesh.motion()));
83 }
84 
85 
87 {
89  angleFormat_ = dict.lookupOrDefault<word>("angleFormat", "radians");
90 
91  return true;
92 }
93 
94 
96 {
97  writeHeader(this->files()[i], "Motion State");
98  writeHeaderValue(this->files()[i], "Angle Units", angleFormat_);
99  writeCommented(this->files()[i], "Time");
100 
101  this->files()[i]<< tab
102  << "Centre of rotation" << tab
103  << "Orientation" << tab
104  << "Linear velocity" << tab
105  << "Angular velocity" << endl;
106 
107 }
108 
109 
111 {
112  return true;
113 }
114 
115 
117 {
118  logFiles::write();
119 
120  if (Pstream::master())
121  {
122  const RBD::rigidBodyMotion& motion = this->motion();
123 
124  forAll(names_, i)
125  {
126  const label bodyID = motion.bodyID(names_[i]);
127 
128  const spatialTransform CofR(motion.X0(bodyID));
129  const spatialVector vCofR(motion.v(bodyID, Zero));
130 
131  vector rotationAngle
132  (
133  quaternion(CofR.E()).eulerAngles(quaternion::XYZ)
134  );
135 
136  vector angularVelocity(vCofR.w());
137 
138  if (angleFormat_ == "degrees")
139  {
140  rotationAngle.x() = radToDeg(rotationAngle.x());
141  rotationAngle.y() = radToDeg(rotationAngle.y());
142  rotationAngle.z() = radToDeg(rotationAngle.z());
143 
144  angularVelocity.x() = radToDeg(angularVelocity.x());
145  angularVelocity.y() = radToDeg(angularVelocity.y());
146  angularVelocity.z() = radToDeg(angularVelocity.z());
147  }
148 
149  writeTime(files()[i]);
150  files()[i]
151  << tab
152  << CofR.r() << tab
153  << rotationAngle << tab
154  << vCofR.l() << tab
155  << angularVelocity << endl;
156  }
157  }
158 
159  return true;
160 }
161 
162 
163 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:180
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
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
static const char tab
Definition: Ostream.H:264
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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:256
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:68
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.
dynamicFvMesh & mesh
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.
const motionSolver & motion() const
Return the motionSolver.
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.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
The dynamicMotionSolverFvMesh.
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