dynamicFvMesh.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) 2011-2012 OpenFOAM Foundation
9  Copyright (C) 2018-2021 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 
29 #include "dynamicFvMesh.H"
30 #include "profiling.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(dynamicFvMesh, 0);
37  defineRunTimeSelectionTable(dynamicFvMesh, IOobject);
38  defineRunTimeSelectionTable(dynamicFvMesh, doInit);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::dynamicFvMesh::readDict()
45 {
46  IOobject dictHeader
47  (
48  "dynamicMeshDict",
49  thisDb().time().constant(),
50  thisDb(),
54  );
55 
56  if (dictHeader.typeHeaderOk<IOdictionary>(false, false))
57  {
58  IOdictionary dict(dictHeader);
59  timeControl_.read(dict);
60 
61  if (!timeControl_.always())
62  {
63  // Feedback about the trigger mechanism
64  Info<< "Controlled mesh update triggered on "
65  << timeControl_.type() << " interval "
66  << timeControl_.interval() << nl;
67  }
68  }
69  else
70  {
71  // Ensure it is indeed pass-through
72  timeControl_.clear();
73  }
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 Foam::dynamicFvMesh::dynamicFvMesh(const IOobject& io, const bool doInit)
80 :
81  fvMesh(io, doInit),
82  timeControl_(io.time(), "update") // assume has no side effects
83 {
84  if (doInit)
85  {
86  init(false); // do not initialise lower levels
87  }
88 }
89 
90 
91 bool Foam::dynamicFvMesh::init(const bool doInit)
92 {
93  if (doInit)
94  {
95  fvMesh::init(doInit);
96  }
97 
98  readDict();
99 
100  // Assume something changed
101  return true;
102 }
103 
104 
105 Foam::dynamicFvMesh::dynamicFvMesh
106 (
107  const IOobject& io,
108  const Foam::zero,
109  bool syncPar
110 )
111 :
112  fvMesh(io, Foam::zero{}, syncPar),
113  timeControl_(io.time(), "update")
114 {
115  readDict();
116 }
117 
118 
119 Foam::dynamicFvMesh::dynamicFvMesh
120 (
121  const IOobject& io,
122  pointField&& points,
123  faceList&& faces,
124  labelList&& allOwner,
125  labelList&& allNeighbour,
126  const bool syncPar
127 )
128 :
129  fvMesh
130  (
131  io,
132  std::move(points),
133  std::move(faces),
134  std::move(allOwner),
135  std::move(allNeighbour),
136  syncPar
137  ),
138  timeControl_(io.time(), "update")
139 {
140  readDict();
141 }
142 
143 
144 Foam::dynamicFvMesh::dynamicFvMesh
145 (
146  const IOobject& io,
147  pointField&& points,
148  faceList&& faces,
149  cellList&& cells,
150  const bool syncPar
151 )
152 :
153  fvMesh
154  (
155  io,
156  std::move(points),
157  std::move(faces),
158  std::move(cells),
159  syncPar
160  ),
161  timeControl_(io.time(), "update")
162 {
163  readDict();
164 }
165 
166 
168 {
169  if (timeControl_.execute())
170  {
171  if (!timeControl_.always())
172  {
173  // Feedback that update has been triggered
174  Info<< "Mesh update triggered based on "
175  << timeControl_.type() << nl;
176  }
177 
178  addProfiling(mesh, "mesh.update()");
179  return this->update();
180  }
181 
182  return false;
183 }
184 
185 
186 // ************************************************************************* //
dictionary dict
void clear()
Reset control to &#39;always&#39; - ie, no intervention.
Definition: timeControl.C:93
void read(const dictionary &dict)
Read from dictionary.
Definition: timeControl.C:102
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Definition: IOdictionary.C:30
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicFvMesh.C:84
Ignore writing from objectRegistry::writeObject()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
#define addProfiling(Name, Descr)
Define profiling trigger with specified name and description string.
dynamicFvMesh & mesh
const cellShapeList & cells
const pointField & points
bool always() const
Return true if the control will always execute - ie, no intervention.
Definition: timeControlI.H:48
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition: IOobject.C:456
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
mesh update()
defineTypeNameAndDebug(combustionModel, 0)
scalar interval() const
Return interval.
Definition: timeControlI.H:58
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
IOobject(const IOobject &)=default
Copy construct.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: fvMesh.C:263
messageStream Info
Information stream (stdout output on master, null elsewhere)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const word & type() const
Return the named control enumeration as its &#39;type&#39;.
Definition: timeControlI.H:36
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)
virtual bool controlledUpdate()
Update the mesh if controller permits.
Namespace for OpenFOAM.