sixDoFRigidBodyMotion_pointMeshMover.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) 2013-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 
27 #include "timeIOdictionary.H"
29 #include "forces.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace pointMeshMovers
37 {
39 
41  (
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
53 Foam::pointMeshMovers::sixDoFRigidBodyMotion::transforms0() const
54 {
55  // Assume the external body is stationary
56  return List<septernion>
57  (
59  );
60 }
61 
62 
63 void Foam::pointMeshMovers::sixDoFRigidBodyMotion::moveBodies()
64 {
65  const Time& t = poly().time();
66 
67  if (poly().nPoints() != points0().size())
68  {
70  << "The number of points in the mesh seems to have changed." << endl
71  << "In constant/polyMesh there are " << points0().size()
72  << " points; in the current mesh there are " << poly().nPoints()
73  << " points." << exit(FatalError);
74  }
75 
76  // Store the motion state at the beginning of the time-stepbool
77  bool firstIter = false;
78  if (curTimeIndex_ != t.timeIndex())
79  {
80  newTime();
81  curTimeIndex_ = t.timeIndex();
82  firstIter = true;
83  }
84 
85  dimensionedVector g(g_);
86 
87  if (poly().foundObject<uniformDimensionedVectorField>("g"))
88  {
89  g = poly().lookupObject<uniformDimensionedVectorField>("g");
90  }
91 
92  // scalar ramp = min(max((t.value() - 5)/10, 0), 1);
93  scalar ramp = 1.0;
94 
95  if (test_)
96  {
97  update
98  (
99  firstIter,
100  ramp*(mass()*g.value()),
101  ramp*(mass()*(momentArm() ^ g.value())),
102  t.deltaTValue(),
103  t.deltaT0Value()
104  );
105  }
106  else
107  {
108  functionObjects::forces f
109  (
111  t,
113  (
115  "patches", bodyMeshes_[0].patches(),
116  "rhoInf", rhoInf_,
117  "rho", rhoName_,
118  "CofR", centreOfRotation()
119  )
120  );
121 
122  f.calcForcesMoments();
123 
124  update
125  (
126  firstIter,
127  ramp*(f.forceEff() + mass()*g.value()),
128  ramp
129  *(
130  f.momentEff()
131  + mass()*(momentArm() ^ g.value())
132  ),
133  t.deltaTValue(),
134  t.deltaT0Value()
135  );
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
141 
143 (
144  const polyMesh& mesh,
145  const dictionary& dict
146 )
147 :
148  pointMeshMovers::multiRigidBody(mesh, dict),
150  (
151  dict,
153  (
154  "sixDoFRigidBodyMotionState",
155  mesh.time().name(),
156  "uniform",
157  mesh
158  ).headerOk()
160  (
161  IOobject
162  (
163  "sixDoFRigidBodyMotionState",
164  mesh.time().name(),
165  "uniform",
166  mesh,
167  IOobject::READ_IF_PRESENT,
168  IOobject::NO_WRITE,
169  false
170  )
171  )
172  : dict
173  ),
174  test_(dict.lookupOrDefault<Switch>("test", false)),
175  rhoInf_(1.0),
176  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
177  g_("g", dimAcceleration, dict, vector::zero),
178  curTimeIndex_(-1)
179 {
180  if (rhoName_ == "rhoInf")
181  {
182  rhoInf_ = dict.lookup<scalar>("rhoInf");
183  }
184 }
185 
186 
187 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
188 
190 {}
191 
192 
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 
196 {
198  (
199  IOobject
200  (
201  "sixDoFRigidBodyMotionState",
202  poly().time().name(),
203  "uniform",
204  poly(),
207  false
208  )
209  );
210 
211  state().write(dict);
212 
213  return
215  && dict.regIOobject::writeObject
216  (
219  poly().time().writeCompression(),
220  true
221  );
222 }
223 
224 
225 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
Abstract base class for pointMesh movers.
Motion of the mesh specified as a list of pointMeshMovers.
virtual bool write() const
Write points0 if the mesh topology changed.
Abstract base-class for multiple rigid body mesh motion.
Single rigid body mesh motion in which movement of the bodies is generated by Foam::sixDoFRigidBodyMo...
virtual bool write() const
Write motion state information for restart.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
static const septernion I
Definition: septernion.H:83
septernion transform0() const
Return the transformation relative to the initial time.
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:545
A class for handling words, derived from string.
Definition: word.H:63
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label nPoints
const fvPatchList & patches
const dimensionSet time
const dimensionSet mass
addToRunTimeSelectionTable(pointMeshMover, externalDisplacement, dictionary)
defineTypeNameAndDebug(externalDisplacement, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
const dimensionSet & dimAcceleration
Definition: dimensions.C:156
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
labelList f(nPoints)
dictionary dict
Typedefs for UniformDimensionedField.