MeshObject.H
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-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2023 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 Class
28  Foam::MeshObject
29 
30 Description
31  Templated abstract base-class for optional mesh objects used to automate
32  their allocation to the mesh database and the mesh-modifier event-loop.
33 
34  MeshObject is templated on the type of mesh it is allocated to, the type of
35  the mesh object (TopologicalMeshObject, GeometricMeshObject,
36  MoveableMeshObject, UpdateableMeshObject) and the type of the actual object
37  it is created for example:
38 
39  \verbatim
40  class leastSquaresVectors
41  :
42  public MeshObject<fvMesh, MoveableMeshObject, leastSquaresVectors>
43  {
44  .
45  .
46  .
47  //- Delete the least square vectors when the mesh moves
48  virtual bool movePoints();
49  };
50  \endverbatim
51 
52  MeshObject types:
53 
54  - TopologicalMeshObject: mesh object to be deleted on topology change
55  - GeometricMeshObject: mesh object to be deleted on geometry change
56  - MoveableMeshObject: mesh object to be updated in movePoints
57  - UpdateableMeshObject: mesh object to be updated in updateMesh or
58  movePoints
59 
60 Note
61  movePoints must be provided for MeshObjects of type MoveableMeshObject
62  and both movePoints and updateMesh functions must exist, provided for
63  MeshObjects of type UpdateableMeshObject.
64 
65 SourceFiles
66  meshObject.C
67  MeshObject.C
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef Foam_MeshObject_H
72 #define Foam_MeshObject_H
73 
74 #include "regIOobject.H"
75 #include "objectRegistry.H"
76 
77 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
78 
79 namespace Foam
80 {
81 
82 // Forward Declarations
83 class mapPolyMesh;
84 
85 /*---------------------------------------------------------------------------*\
86  Class MeshObject Declaration
87 \*---------------------------------------------------------------------------*/
88 
89 template<class Mesh, template<class> class MeshObjectType, class Type>
90 class MeshObject
91 :
92  public MeshObjectType<Mesh>
93 {
94 protected:
95 
96  //- Reference to the mesh
97  const Mesh& mesh_;
98 
99 
100 public:
101 
102  // Constructors
103 
104  //- Construct with Type::typeName on Mesh
105  explicit MeshObject(const Mesh& mesh);
106 
107  //- Construct with given object name on Mesh
108  MeshObject(const word& objName, const Mesh& mesh);
109 
110 
111  // Factory Methods
112 
113  //- Get existing or create a new MeshObject. Registered with typeName
114  template<class... Args>
115  static const Type& New(const Mesh& mesh, Args&&... args);
116 
117  //- Get existing or create a new MeshObject using supplied
118  //- registration name
119  template<class... Args>
120  static const Type& New
121  (
122  const word& objName,
123  const Mesh& mesh,
124  Args&&... args
125  );
126 
127 
128  //- Destructor
129  virtual ~MeshObject() = default;
130 
131  //- Static destructor using supplied registration name
132  static bool Delete(const word& objName, const Mesh& mesh);
133 
134  //- Static destructor using Type::typeName
135  static bool Delete(const Mesh& mesh)
136  {
137  return Delete(Type::typeName, mesh);
138  }
139 
140 
141  // Member Functions
142 
143  //- Reference to the mesh
144  const Mesh& mesh() const noexcept
145  {
146  return mesh_;
147  }
148 
149  //- Dummy write
150  virtual bool writeData(Ostream& os) const
151  {
152  return true;
153  }
154 };
155 
156 
157 /*---------------------------------------------------------------------------*\
158  Class meshObject Declaration
159 \*---------------------------------------------------------------------------*/
160 
161 //- The meshObject is a concrete regIOobject
162 class meshObject
163 :
164  public regIOobject
165 {
166 public:
167 
168  //- Runtime declaration and debug switch
169  ClassName("meshObject");
170 
171 
172  // Constructors
173 
174  //- Construct with given object name on a registry
175  meshObject(const word& objName, const objectRegistry& obr);
176 
177 
178  // Static Member Functions
180  template<class Mesh>
181  static void movePoints(objectRegistry& obr);
182 
183  template<class Mesh>
184  static void updateMesh(objectRegistry& obr, const mapPolyMesh& mpm);
185 
186  template<class Mesh, template<class> class MeshObjectType>
187  static void clear(objectRegistry& obr);
188 
189  //- Clear all meshObject derived from FromType up to
190  //- (but not including) ToType.
191  // Used to clear e.g. all non-updateable meshObjects
192  template
193  <
194  class Mesh,
195  template<class> class FromType,
196  template<class> class ToType
197  >
198  static void clearUpto(objectRegistry& obr);
199 };
200 
201 
202 /*---------------------------------------------------------------------------*\
203  Class TopologicalMeshObject Declaration
204 \*---------------------------------------------------------------------------*/
205 
206 template<class Mesh>
208 :
209  public meshObject
210 {
211 public:
212 
213  //- Construct from name and instance on registry
214  TopologicalMeshObject(const word& objName, const objectRegistry& obr)
215  :
216  meshObject(objName, obr)
217  {}
218 };
219 
220 
221 /*---------------------------------------------------------------------------*\
222  Class GeometricMeshObject Declaration
223 \*---------------------------------------------------------------------------*/
224 
225 template<class Mesh>
226 class GeometricMeshObject
227 :
228  public TopologicalMeshObject<Mesh>
229 {
230 public:
232  //- Construct from name and instance on registry
233  GeometricMeshObject(const word& objName, const objectRegistry& obr)
234  :
235  TopologicalMeshObject<Mesh>(objName, obr)
236  {}
237 };
238 
239 
240 /*---------------------------------------------------------------------------*\
241  Class MoveableMeshObject Declaration
242 \*---------------------------------------------------------------------------*/
243 
244 template<class Mesh>
245 class MoveableMeshObject
246 :
247  public GeometricMeshObject<Mesh>
248 {
249 public:
250 
251  //- Construct from name and instance on registry
252  MoveableMeshObject(const word& objName, const objectRegistry& obr)
253  :
254  GeometricMeshObject<Mesh>(objName, obr)
255  {}
256 
257  virtual bool movePoints() = 0;
258 };
259 
260 
261 /*---------------------------------------------------------------------------*\
262  Class UpdateableMeshObject Declaration
263 \*---------------------------------------------------------------------------*/
264 
265 template<class Mesh>
267 :
268  public MoveableMeshObject<Mesh>
269 {
270 public:
271 
272  //- Construct from name and instance on registry
273  UpdateableMeshObject(const word& objName, const objectRegistry& obr)
274  :
275  MoveableMeshObject<Mesh>(objName, obr)
276  {}
277 
278  virtual void updateMesh(const mapPolyMesh& mpm) = 0;
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #ifdef NoRepository
289  #include "MeshObject.C"
290 #endif
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #endif
295 
296 // ************************************************************************* //
static void updateMesh(objectRegistry &obr, const mapPolyMesh &mpm)
Definition: MeshObject.C:186
static void clearUpto(objectRegistry &obr)
Clear all meshObject derived from FromType up to (but not including) ToType.
Definition: MeshObject.C:257
MoveableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:282
static const Type & New(const Mesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
The meshObject is a concrete regIOobject.
Definition: MeshObject.H:179
virtual void updateMesh(const mapPolyMesh &mpm)=0
static void clear(objectRegistry &obr)
Definition: MeshObject.C:226
virtual bool writeData(Ostream &os) const
Dummy write.
Definition: MeshObject.H:165
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
TopologicalMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:240
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
meshObject(const word &objName, const objectRegistry &obr)
Construct with given object name on a registry.
Definition: meshObject.C:34
const Mesh & mesh() const noexcept
Reference to the mesh.
Definition: MeshObject.H:157
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool movePoints()=0
virtual ~MeshObject()=default
Destructor.
const Mesh & mesh_
Reference to the mesh.
Definition: MeshObject.H:94
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
static void movePoints(objectRegistry &obr)
Definition: MeshObject.C:146
ClassName("meshObject")
Runtime declaration and debug switch.
static bool Delete(const word &objName, const Mesh &mesh)
Static destructor using supplied registration name.
Definition: MeshObject.C:121
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
Registry of regIOobjects.
Foam::argList args(argc, argv)
MeshObject(const Mesh &mesh)
Construct with Type::typeName on Mesh.
Definition: MeshObject.C:29
GeometricMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:261
Namespace for OpenFOAM.
UpdateableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:305