rigidBodyMeshMotionSolver.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-2019 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 
28 #include "polyMesh.H"
29 #include "pointPatchDist.H"
30 #include "pointConstraints.H"
32 #include "forces.H"
33 #include "mathematicalConstants.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(rigidBodyMeshMotionSolver, 0);
40 
42  (
43  motionSolver,
44  rigidBodyMeshMotionSolver,
45  dictionary
46  );
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
52 Foam::rigidBodyMeshMotionSolver::bodyMesh::bodyMesh
53 (
54  const polyMesh& mesh,
55  const word& name,
56  const label bodyID,
57  const dictionary& dict
58 )
59 :
60  name_(name),
61  bodyID_(bodyID),
62  patches_(wordReList(dict.lookup("patches"))),
63  patchSet_(mesh.boundaryMesh().patchSet(patches_))
64 {}
65 
66 
68 (
69  const polyMesh& mesh,
70  const dictionary& dict
71 )
72 :
73  motionSolver(mesh, dict, typeName),
75  (
76  coeffDict(),
77  IOobject
78  (
79  "rigidBodyMotionState",
80  mesh.time().timeName(),
81  "uniform",
82  mesh
83  ).typeHeaderOk<IOdictionary>(true)
84  ? IOdictionary
85  (
86  IOobject
87  (
88  "rigidBodyMotionState",
89  mesh.time().timeName(),
90  "uniform",
91  mesh,
94  false
95  )
96  )
97  : coeffDict()
98  ),
99  test_(coeffDict().lookupOrDefault<Switch>("test", false)),
100  rhoInf_(1.0),
101  rhoName_(coeffDict().lookupOrDefault<word>("rho", "rho")),
102  curTimeIndex_(-1),
103  meshSolverPtr_
104  (
106  (
107  mesh,
109  (
110  IOobject
111  (
112  "rigidBodyMotionSolver:meshSolver",
113  mesh.time().constant(),
114  mesh
115  ),
116  coeffDict().subDict("meshSolver")
117  )
118  )
119  ),
120  meshSolver_(refCast<displacementMotionSolver>(meshSolverPtr_()))
121 {
122  if (rhoName_ == "rhoInf")
123  {
124  rhoInf_ = readScalar(coeffDict().lookup("rhoInf"));
125  }
126 
127  const dictionary& bodiesDict = coeffDict().subDict("bodies");
128 
129  forAllConstIter(IDLList<entry>, bodiesDict, iter)
130  {
131  const dictionary& bodyDict = iter().dict();
132 
133  if (bodyDict.found("patches"))
134  {
135  const label bodyID = this->bodyID(iter().keyword());
136 
137  if (bodyID == -1)
138  {
140  << "Body " << iter().keyword()
141  << " has been merged with another body"
142  " and cannot be assigned a set of patches"
143  << exit(FatalError);
144  }
145 
146  bodyMeshes_.append
147  (
148  new bodyMesh
149  (
150  mesh,
151  iter().keyword(),
152  bodyID,
153  bodyDict
154  )
155  );
156  }
157  }
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
162 
164 {}
165 
166 
167 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
168 
171 {
172  return meshSolverPtr_->curPoints();
173 }
174 
175 
177 {
178  const Time& t = mesh().time();
179 
180  if (mesh().nPoints() != meshSolver_.points0().size())
181  {
183  << "The number of points in the mesh seems to have changed." << endl
184  << "In constant/polyMesh there are " << meshSolver_.points0().size()
185  << " points; in the current mesh there are " << mesh().nPoints()
186  << " points." << exit(FatalError);
187  }
188 
189  // Store the motion state at the beginning of the time-step
190  if (curTimeIndex_ != t.timeIndex())
191  {
192  newTime();
193  curTimeIndex_ = t.timeIndex();
194  }
195 
196  if (mesh().foundObject<uniformDimensionedVectorField>("g"))
197  {
198  g() =
200  }
201 
202  if (test_)
203  {
204  label nIter(readLabel(coeffDict().lookup("nIter")));
205 
206  for (label i=0; i<nIter; i++)
207  {
209  (
210  t.value(),
211  t.deltaTValue(),
212  scalarField(nDoF(), Zero),
214  );
215  }
216  }
217  else
218  {
220 
221  forAll(bodyMeshes_, bi)
222  {
223  const label bodyID = bodyMeshes_[bi].bodyID_;
224 
225  dictionary forcesDict;
226  forcesDict.add("type", functionObjects::forces::typeName);
227  forcesDict.add("patches", bodyMeshes_[bi].patches_);
228  forcesDict.add("rhoInf", rhoInf_);
229  forcesDict.add("rho", rhoName_);
230  forcesDict.add("CofR", vector::zero);
231 
232  functionObjects::forces f("forces", t, forcesDict);
233  f.calcForcesMoment();
234 
235  fx[bodyID] = spatialVector(f.momentEff(), f.forceEff());
236  }
237 
239  (
240  t.value(),
241  t.deltaTValue(),
242  scalarField(nDoF(), Zero),
243  fx
244  );
245  }
246 
247  if (Pstream::master() && report())
248  {
249  forAll(bodyMeshes_, bi)
250  {
251  status(bodyMeshes_[bi].bodyID_);
252  }
253  }
254 
255  // Update the displacements
256  forAll(bodyMeshes_, bi)
257  {
258  forAllConstIter(labelHashSet, bodyMeshes_[bi].patchSet_, iter)
259  {
260  label patchi = iter.key();
261 
262  pointField patchPoints0
263  (
264  meshSolver_.pointDisplacement().boundaryField()[patchi]
265  .patchInternalField(meshSolver_.points0())
266  );
267 
268  meshSolver_.pointDisplacement().boundaryFieldRef()[patchi] ==
269  (
271  (
272  bodyMeshes_[bi].bodyID_,
273  patchPoints0
274  ) - patchPoints0
275  )();
276  }
277  }
278 
279  meshSolverPtr_->solve();
280 }
281 
282 
284 {
285  meshSolverPtr_->movePoints(points);
286 }
287 
288 
290 {
291  meshSolverPtr_->updateMesh(mpm);
292 }
293 
294 
296 {
298  (
299  IOobject
300  (
301  "rigidBodyMotionState",
302  mesh().time().timeName(),
303  "uniform",
304  mesh(),
307  false
308  )
309  );
310 
311  state().write(dict);
312 
313  return
314  dict.regIOobject::writeObject
315  (
318  mesh().time().writeCompression(),
319  true
320  )
321  && motionSolver::write();
322 }
323 
324 
325 // ************************************************************************* //
void newTime()
Store the motion state at the beginning of the time-step.
Template class for intrusive linked lists.
Definition: ILList.H:50
virtual vector momentEff() const
Return the total moment.
Definition: forces.C:882
void append(T *)
Append an element at the end of the list.
Definition: PtrListI.H:39
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:438
Virtual base class for displacement motion solver.
virtual bool write() const
Write motion state information for restart.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const Boundary & boundaryField() const
Return const-reference to the boundary field.
rigidBodyMeshMotionSolver(const polyMesh &, const dictionary &dict)
Construct from polyMesh and dictionary.
tmp< pointField > transformPoints(const label bodyID, const pointField &initialPoints) const
Transform the given initial pointField of the specified body.
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:106
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
void status(const label bodyID) const
Report the status of the motion of the given body.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
virtual bool write() const
Optionally write motion state information for restart.
Definition: motionSolver.C:156
static autoPtr< motionSolver > New(const polyMesh &, const dictionary &)
Select constructed from polyMesh and dictionary.
Definition: motionSolver.C:62
Virtual base class for mesh motion solver.
Definition: motionSolver.H:55
virtual vector forceEff() const
Return the total force.
Definition: forces.C:876
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
virtual tmp< pointField > curPoints() const
Return point location obtained from the current motion field.
label nBodies() const
Return the number of bodies in the model (bodies().size())
const dictionary & coeffDict() const
Const access to the coefficients dictionary.
Definition: motionSolver.H:129
const rigidBodyModelState & state() const
Return the motion state.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual void movePoints(const pointField &)
Update local data for geometry changes.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:821
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:699
pointVectorField & pointDisplacement()
Return reference to the point motion displacement field.
Six degree of freedom motion for a rigid body.
stressControl lookup("compactNormalStress") >> compactNormalStress
const pointField & points
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
label nPoints
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
void write(dictionary &dict) const
Write to dictionary.
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:41
const Type & value() const
Return const reference to value.
word timeName
Definition: getTimeIndex.H:3
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:743
static const zero Zero
Definition: zero.H:97
virtual void updateMesh(const mapPolyMesh &)
Update local data for topology changes.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
label readLabel(Istream &is)
Definition: label.H:64
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
void solve(const scalar t, const scalar deltaT, const scalarField &tau, const Field< spatialVector > &fx)
Integrate velocities, orientation and position.
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
label nDoF() const
Return the number of degrees of freedom of the model.
const vector & g() const
Return the acceleration due to gravity.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
label patchi
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
label nPoints() const
label bodyID(const word &name) const
Return the ID of the body with the given name.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
Calculates the forces and moments by integrating the pressure and skin-friction forces over a given l...
Definition: forces.H:195
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:123
A class for managing temporary objects.
Definition: PtrList.H:53
pointField & points0()
Return reference to the reference field.
virtual void solve()
Solve for motion.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
motionSolver(const polyMesh &mesh, const dictionary &, const word &type)
Construct from polyMesh and dictionary and type.
Definition: motionSolver.C:41
bool report() const
Return the report Switch.
Namespace for OpenFOAM.