dynamicMotionSolverListFvMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "motionSolver.H"
32 #include "pointMesh.H"
33 #include "volFields.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(dynamicMotionSolverListFvMesh, 0);
41  (
42  dynamicFvMesh,
43  dynamicMotionSolverListFvMesh,
44  IOobject
45  );
47  (
48  dynamicFvMesh,
49  dynamicMotionSolverListFvMesh,
50  doInit
51  );
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 Foam::dynamicMotionSolverListFvMesh::dynamicMotionSolverListFvMesh
58 (
59  const IOobject& io,
60  const bool doInit
61 )
62 :
63  dynamicFvMesh(io, doInit),
64  motionSolvers_()
65 {
66  if (doInit)
67  {
68  init(false); // do not initialise lower levels
69  }
70 }
71 
72 
74 (
75  const bool doInit,
76  const bool mandatory
77 )
78 {
79  if (doInit)
80  {
81  dynamicFvMesh::init(doInit);
82  }
83 
84  IOobject ioDict
85  (
86  "dynamicMeshDict",
87  time().constant(),
88  *this,
92  );
93 
94  IOdictionary dict(ioDict);
95 
96  label i = 0;
97 
98  const auto* dictptr = dict.findDict("solvers");
99  if (dictptr)
100  {
101  const dictionary& solverDict = *dictptr;
102 
103  motionSolvers_.setSize(solverDict.size());
104 
105  for (const entry& dEntry : solverDict)
106  {
107  if (dEntry.isDict())
108  {
109  IOobject io(ioDict);
112  io.rename(dEntry.dict().dictName());
113 
114  IOdictionary IOsolverDict
115  (
116  io,
117  dEntry.dict()
118  );
119 
120  motionSolvers_.set
121  (
122  i++,
123  motionSolver::New(*this, IOsolverDict)
124  );
125  }
126  }
127  motionSolvers_.setSize(i);
128  }
129  else if (mandatory)
130  {
131  motionSolvers_.setSize(1);
132  motionSolvers_.set(i++, motionSolver::New(*this, dict));
133  }
134 
135  // Assume something changed
136  return true;
137 }
138 
139 
140 bool Foam::dynamicMotionSolverListFvMesh::init(const bool doInit)
141 {
142  // Fall-back to always constructing motionSolver
143  return init(doInit, true);
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148 
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
155 
157 (
158  const mapPolyMesh& mpm
159 )
160 {
162 
163  // Update the motionSolvers for any topo change ...
164  for (auto& ms : motionSolvers_)
165  {
166  ms.updateMesh(mpm);
167  }
168 }
169 
170 
172 {
173  if (motionSolvers_.size())
174  {
175  // Accumulated displacement
176  pointField disp(motionSolvers_[0].newPoints() - fvMesh::points());
177 
178  for (label i = 1; i < motionSolvers_.size(); i++)
179  {
180  disp += motionSolvers_[i].newPoints() - fvMesh::points();
181  }
182 
183  fvMesh::movePoints(points() + disp);
184 
185  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
186 
187  if (Uptr)
188  {
190  }
191  }
192 
193  return true;
194 }
195 
196 
197 // ************************************************************************* //
dictionary dict
readOption readOpt() const noexcept
Get the read option.
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:677
virtual bool update()
Update the mesh for both mesh motion and topology change.
virtual bool movePoints()
Do what is necessary if the mesh has moved.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicFvMesh.C:84
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:143
Ignore writing from objectRegistry::writeObject()
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Macros for easy insertion into run-time selection tables.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
writeOption writeOpt() const noexcept
Get the write option.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const pointField & points
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map. Triggered by topo change.
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:74
Nothing to be read.
Automatically write from objectRegistry::writeObject()
void correctBoundaryConditions()
Correct boundary field.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
Namespace for OpenFOAM.
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map.
Definition: fvMesh.C:764
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:124