rigidBodyPoints.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) 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 "rigidBodyPoints.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::rigidBodyPoints::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 {
74  read(dict);
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
79 
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
87 {
89 
90  angleUnits_ = dict.lookupOrDefault<word>("angleUnits", "radians");
91 
92  dict.lookup("body") >> body_;
93 
94  const HashTable<point> pointsTable(dict.lookup("points"));
95  names_.setSize(pointsTable.size());
96  points_.setSize(pointsTable.size());
97 
98  label i = 0;
99  forAllConstIter(HashTable<point>, pointsTable, iter)
100  {
101  names_[i] = iter.key();
102  points_[i++] = iter();
103  }
104 
105  resetNames(names_);
106 
107  return true;
108 }
109 
110 
112 {
113  writeHeader(this->files()[i], "Body point motion");
114  writeHeaderValue(this->files()[i], "Body", body_);
115  writeHeaderValue(this->files()[i], "Point", points_[i]);
116  writeHeaderValue(this->files()[i], "Angle Units", angleUnits_);
117  writeCommented(this->files()[i], "Time");
118 
119  this->files()[i]<< tab
120  << "Position" << tab
121  << "Linear velocity" << tab
122  << "Angular velocity" << tab
123  << "Linear acceleration" << tab
124  << "Angular acceleration" << endl;
125 }
126 
127 
129 {
130  return true;
131 }
132 
133 
135 {
136  logFiles::write();
137 
138  if (Pstream::master())
139  {
140  const RBD::rigidBodyMotion& motion = this->motion();
141 
142  const label bodyID = motion.bodyID(body_);
143 
144  forAll(points_, i)
145  {
146  const vector p(motion.p(bodyID, points_[i]));
147  const spatialVector v(motion.v(bodyID, points_[i]));
148  const spatialVector a(motion.a(bodyID, points_[i]));
149 
150  vector angularVelocity(v.w());
151  vector angularAcceleration(a.w());
152 
153  if (angleUnits_ == "degrees")
154  {
155  angularVelocity.x() = radToDeg(angularVelocity.x());
156  angularVelocity.y() = radToDeg(angularVelocity.y());
157  angularVelocity.z() = radToDeg(angularVelocity.z());
158 
159  angularAcceleration.x() = radToDeg(angularAcceleration.x());
160  angularAcceleration.y() = radToDeg(angularAcceleration.y());
161  angularAcceleration.z() = radToDeg(angularAcceleration.z());
162  }
163 
164  writeTime(files()[i]);
165  files()[i]
166  << tab
167  << p << tab
168  << v.l() << tab
169  << angularVelocity << tab
170  << a.l() << tab
171  << angularAcceleration << endl;
172  }
173  }
174 
175  return true;
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Macros for easy insertion into run-time selection tables.
An STL-conforming hash table.
Definition: HashTable.H:127
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
spatialVector a(const label bodyID, const vector &p) const
Return the acceleration of the given point on the given body.
vector p(const label bodyID, const vector &p) const
Return the current position of the given point on the given body.
label bodyID(const word &name) const
Return the ID of the body with the given name.
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 position, linear and angular velocities and accelerations of a list of points on a body sp...
rigidBodyPoints(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 rigidBodyPoints.
virtual bool read(const dictionary &)
Read the rigidBodyPoints data.
const fvMeshMover & mover() const
Return the mover function class.
Definition: fvMesh.C:1056
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.
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
static const char tab
Definition: Ostream.H:259
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict
volScalarField & p
Unit conversion functions.