rigidBodyDisplacement_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 "polyMesh.H"
28 #include "polyTopoChangeMap.H"
29 #include "pointConstraints.H"
30 #include "timeIOdictionary.H"
32 #include "forces.H"
33 #include "OneConstant.H"
34 #include "mathematicalConstants.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace pointMeshMovers
42 {
44 
46  (
50  );
51 }
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 Foam::pointMeshMovers::rigidBodyDisplacement::bodyMesh::bodyMesh
58 (
59  const polyMesh& mesh,
60  const word& name,
61  const label bodyID,
62  const dictionary& dict
63 )
64 :
65  name_(name),
66  bodyIndex_(bodyID),
67  patches_(wordReList(dict.lookup("patches"))),
68  patchSet_(mesh.boundary().patchSet(patches_))
69 {}
70 
71 
73 (
74  const polyMesh& mesh,
75  const dictionary& dict
76 )
77 :
79  RBD::rigidBodyMotion
80  (
81  dict,
83  (
84  "rigidBodyMotionState",
85  mesh.time().name(),
86  "uniform",
87  mesh
88  ).headerOk()
90  (
91  IOobject
92  (
93  "rigidBodyMotionState",
94  mesh.time().name(),
95  "uniform",
96  mesh,
97  IOobject::READ_IF_PRESENT,
98  IOobject::NO_WRITE,
99  false
100  )
101  )
102  : dict
103  ),
104  test_(dict.lookupOrDefault<Switch>("test", false)),
105  nIter_(test_ ? dict.lookup<label>("nIter") : 0),
106  rhoInf_(1.0),
107  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
108  ramp_(nullptr),
109  curTimeIndex_(-1),
110  meshSolverPtr_
111  (
113  (
114  mesh,
116  (
117  IOobject
118  (
119  typedName("meshSolver"),
120  mesh.time().constant(),
121  mesh
122  ),
123  dict.subDict("meshSolver")
124  )
125  )
126  ),
127  meshSolver_(refCast<pointMeshMovers::displacement>(meshSolverPtr_()))
128 {
129  if (rhoName_ == "rhoInf")
130  {
131  rhoInf_ = dict.lookup<scalar>("rhoInf");
132  }
133 
134  if (dict.found("ramp"))
135  {
136  ramp_ = Function1<scalar>::New("ramp", dimTime, dimless, dict);
137  }
138  else
139  {
140  ramp_ = new Function1s::OneConstant<scalar>("ramp");
141  }
142 
143  const dictionary& bodiesDict = dict.subDict("bodies");
144 
145  forAllConstIter(IDLList<entry>, bodiesDict, iter)
146  {
147  const dictionary& bodyDict = iter().dict();
148 
149  if (bodyDict.found("patches"))
150  {
151  const label bodyID = this->bodyIndex(iter().keyword());
152 
153  if (bodyID == -1)
154  {
156  << "Body " << iter().keyword()
157  << " has been merged with another body"
158  " and cannot be assigned a set of patches"
159  << exit(FatalError);
160  }
161 
162  bodyMeshes_.append
163  (
164  new bodyMesh
165  (
166  mesh,
167  iter().keyword(),
168  bodyID,
169  bodyDict
170  )
171  );
172  }
173  }
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
178 
180 {}
181 
182 
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
184 
187 {
188  const Time& t = poly().time();
189 
190  if (poly().nPoints() != meshSolver_.points0().size())
191  {
193  << "The number of points in the mesh seems to have changed." << endl
194  << "In constant/polyMesh there are " << meshSolver_.points0().size()
195  << " points; in the current mesh there are " << poly().nPoints()
196  << " points." << exit(FatalError);
197  }
198 
199  // Store the motion state at the beginning of the time-step
200  if (curTimeIndex_ != t.timeIndex())
201  {
202  newTime();
203  curTimeIndex_ = t.timeIndex();
204  }
205 
206  const scalar ramp = ramp_->value(t.value());
207 
208  if (poly().foundObject<uniformDimensionedVectorField>("g"))
209  {
210  g() =
211  ramp
212  *poly().lookupObject<uniformDimensionedVectorField>("g").value();
213  }
214 
215  if (test_)
216  {
217  for (label i=0; i<nIter_; i++)
218  {
220  (
221  t.value(),
222  t.deltaTValue(),
223  scalarField(nDoF(), Zero),
224  Field<spatialVector>(nBodies(), Zero)
225  );
226  }
227  }
228  else
229  {
230  Field<spatialVector> fx(nBodies(), Zero);
231 
232  forAll(bodyMeshes_, bi)
233  {
234  const label bodyID = bodyMeshes_[bi].bodyIndex_;
235 
237  (
239  t,
241  (
243  "patches", bodyMeshes_[bi].patches_,
244  "rhoInf", rhoInf_,
245  "rho", rhoName_,
246  "CofR", vector::zero
247  )
248  );
249 
250  f.calcForcesMoments();
251 
252  fx[bodyID] = ramp*spatialVector(f.momentEff(), f.forceEff());
253  }
254 
256  (
257  t.value(),
258  t.deltaTValue(),
259  scalarField(nDoF(), Zero),
260  fx
261  );
262  }
263 
264  if (Pstream::master() && report())
265  {
266  forAll(bodyMeshes_, bi)
267  {
268  status(bodyMeshes_[bi].bodyIndex_);
269  }
270  }
271 
272  // Update the displacements
273  forAll(bodyMeshes_, bi)
274  {
275  forAllConstIter(labelHashSet, bodyMeshes_[bi].patchSet_, iter)
276  {
277  const label patchi = iter.key();
278 
279  const pointField patchPoints0
280  (
281  meshSolver_.pointDisplacement().boundaryField()[patchi]
282  .patchInternalField(meshSolver_.points0())
283  );
284 
285  meshSolver_.pointDisplacement().boundaryFieldRef()[patchi] ==
286  (
288  (
289  transform0(bodyMeshes_[bi].bodyIndex_),
290  patchPoints0
291  ) - patchPoints0
292  )();
293  }
294  }
295 
296  return meshSolver_.newPoints();
297 }
298 
299 
301 (
302  const pointField& points
303 )
304 {
305  meshSolverPtr_->movePoints(points);
306 }
307 
308 
310 (
311  const polyTopoChangeMap& map
312 )
313 {
314  meshSolverPtr_->topoChange(map);
315 }
316 
317 
319 (
320  const polyMeshMap& map
321 )
322 {
323  meshSolverPtr_->mapMesh(map);
324 }
325 
326 
328 (
329  const polyDistributionMap& map
330 )
331 {
332  meshSolverPtr_->distribute(map);
333 }
334 
335 
337 {
339  (
340  IOobject
341  (
342  "rigidBodyMotionState",
343  poly().time().name(),
344  "uniform",
345  poly(),
348  false
349  )
350  );
351 
352  state().write(dict);
353 
354  return
356  && dict.regIOobject::writeObject
357  (
360  poly().time().writeCompression(),
361  true
362  );
363 }
364 
365 
366 // ************************************************************************* //
#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.
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
Template class for intrusive linked lists.
Definition: ILList.H:67
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
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
void append(T *)
Append an element at the end of the list.
Definition: PtrListI.H:39
label bodyIndex(const word &name) const
Return the ID of the body with the given name.
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
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
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
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
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:468
static std::tuple< const Entries &... > entries(const Entries &...)
Construct an entries tuple from which to make a dictionary.
const Type & value() const
Return const reference to value.
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:188
const Time & time() const
Return time.
Abstract base class for pointMesh movers.
virtual bool write() const
Optionally write motion state information for restart.
Abstract base class for displacement pointMesh movers.
virtual void topoChange(const polyTopoChangeMap &)
Update local data for topology changes.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
virtual tmp< pointField > newPoints()
Return point location obtained from the current motion field.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const pointField &)
Update local data for geometry changes.
virtual bool write() const
Write motion state information for restart.
rigidBodyDisplacement(const polyMesh &, const dictionary &dict)
Construct from polyMesh and dictionary.
Multiple rigid body mesh motion in which movement of the bodies is generated by RBD::rigidBodyMotion.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
A class for managing temporary objects.
Definition: tmp.H:55
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:545
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
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
label patchi
const pointField & points
label nPoints
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
void transformPoints(vectorField &, const spatialTransform &, const vectorField &)
Transform given vectorField of coordinates with the given spatialTransform.
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
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:141
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 & dimTime
Definition: dimensions.C:142
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
word typedName(Name name)
Return the name of the object within the given type.
Definition: typeInfo.H:188
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
faceListList boundary(nPatches)
labelList f(nPoints)
dictionary dict
Typedefs for UniformDimensionedField.