rigidBodyMotion_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) 2016-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"
30 #include "OneConstant.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace pointMeshMovers
38 {
39 
41 
43  (
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
55 Foam::pointMeshMovers::rigidBodyMotion::transforms0() const
56 {
57  List<septernion> transforms0(bodyMeshes_.size());
58 
59  forAll(bodyMeshes_, bi)
60  {
61  if (bodyMeshes_[bi].bodyIndex != -1)
62  {
63  // Calculate the septernion equivalent of the transformation
64  transforms0[bi] =
65  septernion(transform0(bodyMeshes_[bi].bodyIndex));
66  }
67  else
68  {
69  // Assume the external body is stationary
70  transforms0[bi] = septernion::I;
71  }
72  }
73 
74  return transforms0;
75 }
76 
77 
78 void Foam::pointMeshMovers::rigidBodyMotion::moveBodies()
79 {
80  const Time& t = poly().time();
81 
82  // Store the motion state at the beginning of the time-step
83  if (curTimeIndex_ != t.timeIndex())
84  {
85  newTime();
86  curTimeIndex_ = t.timeIndex();
87  }
88 
89  const scalar ramp = ramp_->value(t.value());
90 
91  if (poly().foundObject<uniformDimensionedVectorField>("g"))
92  {
93  g() =
94  ramp
95  *poly().lookupObject<uniformDimensionedVectorField>("g").value();
96  }
97 
98  if (test_)
99  {
100  for (label i=0; i<nIter_; i++)
101  {
103  (
104  t.value(),
105  t.deltaTValue(),
106  scalarField(nDoF(), Zero),
107  Field<spatialVector>(nBodies(), Zero)
108  );
109  }
110  }
111  else
112  {
113  Field<spatialVector> fx(nBodies(), Zero);
114 
115  forAll(bodyMeshes_, bi)
116  {
117  const label bodyID = bodyMeshes_[bi].bodyIndex;
118 
119  if (bodyID != -1)
120  {
121  functionObjects::forces f
122  (
124  t,
126  (
128  "patches", bodyMeshes_[bi].patches(),
129  "rhoInf", rhoInf_,
130  "rho", rhoName_,
131  "CofR", vector::zero
132  )
133  );
134 
135  f.calcForcesMoments();
136 
137  fx[bodyID] = ramp*spatialVector(f.momentEff(), f.forceEff());
138  }
139  }
140 
142  (
143  t.value(),
144  t.deltaTValue(),
145  scalarField(nDoF(), Zero),
146  fx
147  );
148  }
149 
150  if (Pstream::master() && report())
151  {
152  forAll(bodyMeshes_, bi)
153  {
154  if (bodyMeshes_[bi].bodyIndex != -1)
155  {
156  status(bodyMeshes_[bi].bodyIndex);
157  }
158  }
159  }
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164 
166 (
167  const polyMesh& mesh,
168  const dictionary& dict
169 )
170 :
171  pointMeshMovers::multiRigidBody(mesh, dict),
172  RBD::rigidBodyMotion
173  (
174  dict,
176  (
177  "rigidBodyMotionState",
178  mesh.time().name(),
179  "uniform",
180  mesh
181  ).headerOk()
183  (
184  IOobject
185  (
186  "rigidBodyMotionState",
187  mesh.time().name(),
188  "uniform",
189  mesh,
190  IOobject::READ_IF_PRESENT,
191  IOobject::NO_WRITE,
192  false
193  )
194  )
195  : dict
196  ),
197  test_(dict.lookupOrDefault<Switch>("test", false)),
198  nIter_(test_ ? dict.lookup<label>("nIter") : 0),
199  rhoInf_(1.0),
200  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
201  ramp_(nullptr),
202  curTimeIndex_(-1)
203 {
204  if (rhoName_ == "rhoInf")
205  {
206  rhoInf_ = dict.lookup<scalar>("rhoInf");
207  }
208 
209  if (dict.found("ramp"))
210  {
211  ramp_ = Function1<scalar>::New("ramp", dimTime, dimless, dict);
212  }
213  else
214  {
215  ramp_ = new Function1s::OneConstant<scalar>("ramp");
216  }
217 
218  forAll(bodyMeshes_, bi)
219  {
220  if (bodyMeshes_[bi].name() != "exterior")
221  {
222  const label bodyID = this->bodyIndex(bodyMeshes_[bi].name());
223 
224  if (bodyID == -1)
225  {
227  << "Body " << bodyMeshes_[bi].name()
228  << " has been merged with another body"
229  " and cannot be assigned a set of patches"
230  << exit(FatalError);
231  }
232 
233  bodyMeshes_[bi].bodyIndex = bodyID;
234  }
235  }
236 }
237 
238 
239 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
240 
242 {}
243 
244 
245 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
246 
248 {
250  (
251  IOobject
252  (
253  "rigidBodyMotionState",
254  poly().time().name(),
255  "uniform",
256  poly(),
259  false
260  )
261  );
262 
263  state().write(dict);
264 
265  return
267  && dict.regIOobject::writeObject
268  (
271  poly().time().writeCompression(),
272  true
273  );
274 }
275 
276 
277 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitSets &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
Templated function that returns the corresponding 1 (one).
Definition: OneConstant.H:59
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
label bodyIndex(const word &name) const
Return the ID of the body with the given name.
const word & name(const label bodyID) const
Return the name of body with the given ID.
rigidBodyMotion()
Construct null.
spatialTransform transform0(const label bodyID) const
Return the transformation of bodyID relative to the initial time.
void solve(const scalar t, const scalar deltaT, const scalarField &tau, const Field< spatialVector > &fx)
Integrate velocities, orientation and position.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
static const Form zero
Definition: VectorSpace.H:118
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.
PtrList< bodyMesh > bodyMeshes_
List of the bodyMeshes containing the patches and point motion.
Multiple rigid body mesh motion in which movement of the bodies is generated by RBD::rigidBodyMotion.
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
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
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
const fvPatchList & patches
const dimensionSet time
addToRunTimeSelectionTable(pointMeshMover, externalDisplacement, dictionary)
defineTypeNameAndDebug(externalDisplacement, 0)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
const dimensionSet & dimless
Definition: dimensions.C:138
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
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const dimensionSet & dimTime
Definition: dimensions.C:142
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
labelList f(nPoints)
dictionary dict
Typedefs for UniformDimensionedField.