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-2026 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 
39  (
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 Foam::functionObjects::rigidBodyPoints::motion() const
52 {
53  const fvMeshMovers::pointMeshMover& mover =
54  refCast<const fvMeshMovers::pointMeshMover>(mesh_.mover());
55 
56  return (refCast<const RBD::rigidBodyMotion>(mover.mover()));
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 (
64  const word& name,
65  const Time& runTime,
66  const dictionary& dict
67 )
68 :
69  fvMeshFunctionObject(name, runTime, dict),
70  logFiles(obr_, name),
71  angularVelocityUnits_("[rad/s]"),
72  angularAccelerationUnits_("[rad/s^2]")
73 {
74  read(dict);
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
79 
81 {}
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
87 {
89 
90  angularVelocityUnits_.readIfPresent("angularVelocityUnits", dict);
91  angularAccelerationUnits_.readIfPresent("angularAccelerationUnits", dict);
92 
93  dict.lookup("body") >> body_;
94 
95  const HashTable<point> pointsTable(dict.lookup("points"));
96  names_.setSize(pointsTable.size());
97  points_.setSize(pointsTable.size());
98 
99  label i = 0;
100  forAllConstIter(HashTable<point>, pointsTable, iter)
101  {
102  names_[i] = iter.key();
103  points_[i++] = iter();
104  }
105 
106  resetNames(names_);
107 
108  return true;
109 }
110 
111 
113 {
114  OFstream& file = this->files()[i];
115 
116  writeHeader(file, "Body point motion");
117  writeHeaderValue(file, "Body", body_);
118  writeHeaderValue(file, "Point", points_[i]);
119  writeHeaderValue(file, "Angular Velocity Units", angularVelocityUnits_);
120  writeHeaderValue
121  (
122  file,
123  "Angular Acceleration Units",
124  angularAccelerationUnits_
125  );
126  writeCommented(file, "Time");
127 
128  file<< tab
129  << "Position" << tab
130  << "Linear velocity" << tab
131  << "Angular velocity" << tab
132  << "Linear acceleration" << tab
133  << "Angular acceleration" << endl;
134 }
135 
136 
138 {
139  return true;
140 }
141 
142 
144 {
145  logFiles::write();
146 
147  if (Pstream::master())
148  {
149  const RBD::rigidBodyMotion& motion = this->motion();
150 
151  const label bodyID = motion.bodyIndex(body_);
152 
153  forAll(points_, i)
154  {
155  const vector p(motion.p(bodyID, points_[i]));
156  const spatialVector v(motion.v(bodyID, points_[i]));
157  const spatialVector a(motion.a(bodyID, points_[i]));
158 
159  writeTime(files()[i]);
160  files()[i]
161  << tab
162  << p << tab
163  << v.l() << tab
164  << angularVelocityUnits_.toUser(v.w()) << tab
165  << a.l() << tab
166  << angularAccelerationUnits_.toUser(a.w()) << endl;
167  }
168  }
169 
170  return true;
171 }
172 
173 
174 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
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:87
const spatialVector & v(const label i) const
Return the spatial velocity of body i.
const spatialVector & a(const label i) const
Return the spatial acceleration of body i.
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:1125
A class for handling words, derived from string.
Definition: word.H:63
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, 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:288
static const char tab
Definition: Ostream.H:296
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict
volScalarField & p