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-2018 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 
67 Foam::rigidBodyMeshMotionSolver::rigidBodyMeshMotionSolver
68 (
69  const polyMesh& mesh,
70  const IOdictionary& dict
71 )
72 :
73  motionSolver(mesh, dict, typeName),
74  model_
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 = model_.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_ != this->db().time().timeIndex())
191  {
192  model_.newTime();
193  curTimeIndex_ = this->db().time().timeIndex();
194  }
195 
196  if (db().foundObject<uniformDimensionedVectorField>("g"))
197  {
198  model_.g() =
200  }
201 
202  if (test_)
203  {
204  label nIter(readLabel(coeffDict().lookup("nIter")));
205 
206  for (label i=0; i<nIter; i++)
207  {
208  model_.solve
209  (
210  t.value(),
211  t.deltaTValue(),
212  scalarField(model_.nDoF(), Zero),
214  );
215  }
216  }
217  else
218  {
219  Field<spatialVector> fx(model_.nBodies(), Zero);
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", db(), forcesDict);
233  f.calcForcesMoment();
234 
235  fx[bodyID] = spatialVector(f.momentEff(), f.forceEff());
236  }
237 
238  model_.solve
239  (
240  t.value(),
241  t.deltaTValue(),
242  scalarField(model_.nDoF(), Zero),
243  fx
244  );
245  }
246 
247  if (Pstream::master() && model_.report())
248  {
249  forAll(bodyMeshes_, bi)
250  {
251  model_.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  (
270  model_.transformPoints
271  (
272  bodyMeshes_[bi].bodyID_,
273  patchPoints0
274  ) - patchPoints0
275  )();
276  }
277  }
278 
279  meshSolverPtr_->solve();
280 }
281 
282 
284 (
288  const bool valid
289 ) const
290 {
292  (
293  IOobject
294  (
295  "rigidBodyMotionState",
296  mesh().time().timeName(),
297  "uniform",
298  mesh(),
301  false
302  )
303  );
304 
305  model_.state().write(dict);
306  return dict.regIOobject::write();
307 }
308 
309 
311 {
312  if (motionSolver::read())
313  {
314  model_.read(coeffDict());
315 
316  return true;
317  }
318  else
319  {
320  return false;
321  }
322 }
323 
324 
326 {
327  meshSolverPtr_->movePoints(points);
328 }
329 
330 
332 {
333  meshSolverPtr_->updateMesh(mpm);
334 }
335 
336 
337 // ************************************************************************* //
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:890
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:431
Virtual base class for displacement motion solver.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const Boundary & boundaryField() const
Return const-reference to the boundary field.
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.
Definition: Switch.H:60
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:421
Virtual base class for mesh motion solver.
Definition: motionSolver.H:57
virtual vector forceEff() const
Return the total force.
Definition: forces.C:884
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:147
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
bool read(const dictionary &dict)
Read coefficients dictionary and update system parameters,.
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:147
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:814
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:692
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write state using given format, version and compression.
pointVectorField & pointDisplacement()
Return reference to the point motion displacement field.
stressControl lookup("compactNormalStress") >> compactNormalStress
const pointField & points
Pre-declare SubField and related Field type.
Definition: Field.H:57
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
virtual bool read()
Read dynamicMeshDict dictionary.
void write(dictionary &dict) const
Write to dictionary.
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:62
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:41
const Type & value() const
Return const reference to value.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
word timeName
Definition: getTimeIndex.H:3
virtual void calcForcesMoment()
Calculate the forces and moments.
Definition: forces.C:751
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
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:232
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
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
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:30
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const Time & time() const
Return time.
Definition: IOobject.C:367
label timeIndex
Definition: getTimeIndex.H:4
Version number type.
Definition: IOstream.H:96
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:141
A class for managing temporary objects.
Definition: PtrList.H:53
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:361
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
bool report() const
Return the report Switch.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576