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,
91  false
92  );
93 
94  IOdictionary dict(ioDict);
95 
96  label i = 0;
97  if (dict.found("solvers"))
98  {
99  const dictionary& solvertDict = dict.subDict("solvers");
100 
101  motionSolvers_.setSize(solvertDict.size());
102 
103  for (const entry& dEntry : solvertDict)
104  {
105  if (dEntry.isDict())
106  {
107  IOobject io(ioDict);
110  io.rename(dEntry.dict().dictName());
111 
112  IOdictionary IOsolverDict
113  (
114  io,
115  dEntry.dict()
116  );
117 
118  motionSolvers_.set
119  (
120  i++,
121  motionSolver::New(*this, IOsolverDict)
122  );
123  }
124  }
125  motionSolvers_.setSize(i);
126  }
127  else if (mandatory)
128  {
129  motionSolvers_.setSize(1);
130  motionSolvers_.set(i++, motionSolver::New(*this, dict));
131  }
132 
133  // Assume something changed
134  return true;
135 }
136 
137 
138 bool Foam::dynamicMotionSolverListFvMesh::init(const bool doInit)
139 {
140  // Fall-back to always constructing motionSolver
141  return init(doInit, true);
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
146 
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 
155 (
156  const mapPolyMesh& mpm
157 )
158 {
160 
161  // Update the motionSolvers for any topo change ...
162  for (auto& ms : motionSolvers_)
163  {
164  ms.updateMesh(mpm);
165  }
166 }
167 
168 
170 {
171  if (motionSolvers_.size())
172  {
173  // Accumulated displacement
174  pointField disp(motionSolvers_[0].newPoints() - fvMesh::points());
175 
176  for (label i = 1; i < motionSolvers_.size(); i++)
177  {
178  disp += motionSolvers_[i].newPoints() - fvMesh::points();
179  }
180 
181  fvMesh::movePoints(points() + disp);
182 
183  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
184 
185  if (Uptr)
186  {
188  }
189  }
190 
191  return true;
192 }
193 
194 
195 // ************************************************************************* //
dictionary dict
readOption readOpt() const noexcept
Get the read option.
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:626
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:85
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:453
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.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:100
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1066
writeOption writeOpt() const noexcept
Get the write option.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
const pointField & points
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map. Triggered by topo change.
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
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.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
Namespace for OpenFOAM.
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map.
Definition: fvMesh.C:734