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-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 "rigidBodyPoints.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::rigidBodyPoints::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  angularVelocityUnits_("[rad/s]"),
73  angularAccelerationUnits_("[rad/s^2]")
74 {
75  read(dict);
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
80 
82 {}
83 
84 
85 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86 
88 {
90 
91  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
92  angularAccelerationUnits_.readIfPresent("angularAccelerationUnits", dict);
93 
94  dict.lookup("body") >> body_;
95 
96  const HashTable<point> pointsTable(dict.lookup("points"));
97  names_.setSize(pointsTable.size());
98  points_.setSize(pointsTable.size());
99 
100  label i = 0;
101  forAllConstIter(HashTable<point>, pointsTable, iter)
102  {
103  names_[i] = iter.key();
104  points_[i++] = iter();
105  }
106 
107  resetNames(names_);
108 
109  return true;
110 }
111 
112 
114 {
115  OFstream& file = this->files()[i];
116 
117  writeHeader(file, "Body point motion");
118  writeHeaderValue(file, "Body", body_);
119  writeHeaderValue(file, "Point", points_[i]);
120  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
121  writeHeaderValue
122  (
123  file,
124  "Angular Acceleration Units",
125  angularAccelerationUnits_
126  );
127  writeCommented(file, "Time");
128 
129  file<< tab
130  << "Position" << tab
131  << "Linear velocity" << tab
132  << "Angular velocity" << tab
133  << "Linear acceleration" << tab
134  << "Angular acceleration" << endl;
135 }
136 
137 
139 {
140  return true;
141 }
142 
143 
145 {
146  logFiles::write();
147 
148  if (Pstream::master())
149  {
150  const RBD::rigidBodyMotion& motion = this->motion();
151 
152  const label bodyID = motion.bodyIndex(body_);
153 
154  forAll(points_, i)
155  {
156  const vector p(motion.p(bodyID, points_[i]));
157  const spatialVector v(motion.v(bodyID, points_[i]));
158  const spatialVector a(motion.a(bodyID, points_[i]));
159 
160  writeTime(files()[i]);
161  files()[i]
162  << tab
163  << p << tab
164  << v.l() << tab
165  << angularVelocityUnits_.toUser(v.w()) << tab
166  << a.l() << tab
167  << angularAccelerationUnits_.toUser(a.w()) << endl;
168  }
169  }
170 
171  return true;
172 }
173 
174 
175 // ************************************************************************* //
#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
Output to file stream.
Definition: OFstream.H:86
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 bodyIndex(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
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 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:1050
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char tab
Definition: Ostream.H:265
dictionary dict
volScalarField & p