Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::MeshObject
29
30Description
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.
38
39 Example usage,
40 \verbatim
41 class leastSquaresVectors
42 :
43 public MeshObject<fvMesh, MoveableMeshObject, leastSquaresVectors>
44 {
45 .
46 .
47 .
48 //- Delete the least square vectors when the mesh moves
49 virtual bool movePoints();
50 };
51 \endverbatim
52
53 The MeshObject types:
54 - TopologicalMeshObject:
55 mesh object to be deleted on topology change
56 - GeometricMeshObject:
57 mesh object to be deleted on geometry change
58 - MoveableMeshObject:
59 mesh object to be updated in movePoints
60 - UpdateableMeshObject:
61 mesh object to be updated in movePoints or updateMesh
62
63Note
64 movePoints must be provided for MeshObjects of type MoveableMeshObject
65 and both movePoints and updateMesh functions must exist, provided for
66 MeshObjects of type UpdateableMeshObject.
67
68SourceFiles
69 meshObject.C
70 MeshObject.C
71
72\*---------------------------------------------------------------------------*/
73
74#ifndef Foam_MeshObject_H
75#define Foam_MeshObject_H
76
77#include "regIOobject.H"
78#include "objectRegistry.H"
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82namespace Foam
83{
84
85// Forward Declarations
86class mapPolyMesh;
87
88/*---------------------------------------------------------------------------*\
89 Class meshObject Declaration
90\*---------------------------------------------------------------------------*/
91
92//- The meshObject is a concrete regIOobject to register MeshObject items
93class meshObject
94:
95 public regIOobject
96{
97public:
98
99 //- Runtime declaration and debug switch
100 ClassName("meshObject");
101
102
103 // Constructors
104
105 //- Construct with given object name on a registry
106 meshObject(const word& objName, const objectRegistry& obr);
108
109 // Static Member Functions
110
111 //- Update for mesh motion
112 template<class Mesh>
113 static void movePoints(objectRegistry& obr);
114
115 //- Update topology using the given map
116 template<class Mesh>
117 static void updateMesh(objectRegistry& obr, const mapPolyMesh& mpm);
118
119 //- Clear/remove all meshObject of MeshObjectType
120 //- via objectRegistry::checkOut()
121 template<class Mesh, template<class> class MeshObjectType>
122 static void clear(objectRegistry& obr);
123
124 //- Clear all meshObject derived from FromType up to
125 //- (but not including) ToType.
126 // Used to clear e.g. all non-updateable meshObjects
127 template
128 <
129 class Mesh,
130 template<class> class FromType,
131 template<class> class ToType
132 >
133 static void clearUpto(objectRegistry& obr);
134};
135
136
137/*---------------------------------------------------------------------------*\
138 Class MeshObject Declaration
139\*---------------------------------------------------------------------------*/
140
141template<class Mesh, template<class> class MeshObjectType, class Type>
142class MeshObject
144 public MeshObjectType<Mesh>
145{
146protected:
147
148 //- Reference to the mesh
149 const Mesh& mesh_;
150
151
152public:
153
154 // Constructors
155
156 //- Construct with Type::typeName on Mesh
157 explicit MeshObject(const Mesh& mesh);
158
159 //- Construct with given object name on Mesh
160 MeshObject(const word& objName, const Mesh& mesh);
162
163 //- Destructor
164 virtual ~MeshObject() = default;
165
166
167 // Factory Methods
168
169 //- Get existing or create MeshObject registered with typeName
170 template<class... Args>
171 FOAM_NO_DANGLING_REFERENCE //< Reference stored in registry
172 static const Type& New(const Mesh& mesh, Args&&... args);
173
174 //- Get existing or create MeshObject with given registration name
175 template<class... Args>
176 FOAM_NO_DANGLING_REFERENCE //< Reference stored in registry
177 static const Type& New
178 (
179 const word& objName,
180 const Mesh& mesh,
181 Args&&... args
182 );
183
184 //- Transfer ownership of meshObject to registry.
185 static bool Store(std::unique_ptr<Type>&& ptr);
186
187 //- Static destructor using given registration name
188 static bool Delete(const word& objName, const Mesh& mesh);
189
190 //- Static destructor using Type::typeName
191 static bool Delete(const Mesh& mesh)
193 return Delete(Type::typeName, mesh);
194 }
195
196 //- Release ownership of meshObject (with given registration name)
197 //- from registry. Returns nullptr if not found or not owned.
198 static std::unique_ptr<Type> Release
200 const word& objName,
201 const Mesh& mesh,
203 bool checkout = true
204 );
205
206
207 //- Release ownership of meshObject (with Type::typeName name)
208 //- from registry.
209 static std::unique_ptr<Type> Release
210 (
211 const Mesh& mesh,
213 bool checkout = true
215 {
216 return Release(Type::typeName, mesh, checkout);
217 }
218
220 // Member Functions
221
222 //- Reference to the mesh
223 const Mesh& mesh() const noexcept
224 {
225 return mesh_;
226 }
227
228 //- Dummy write
229 virtual bool writeData(Ostream& os) const
230 {
231 return true;
232 }
233};
234
235
236/*---------------------------------------------------------------------------*\
237 Class TopologicalMeshObject Declaration
238\*---------------------------------------------------------------------------*/
239
240template<class Mesh>
242:
243 public meshObject
244{
245public:
246
247 //- Construct from name and instance on registry
248 TopologicalMeshObject(const word& objName, const objectRegistry& obr)
249 :
250 meshObject(objName, obr)
251 {}
252};
253
254
255/*---------------------------------------------------------------------------*\
256 Class GeometricMeshObject Declaration
257\*---------------------------------------------------------------------------*/
258
259template<class Mesh>
261:
262 public TopologicalMeshObject<Mesh>
263{
264public:
266 //- Construct from name and instance on registry
267 GeometricMeshObject(const word& objName, const objectRegistry& obr)
268 :
269 TopologicalMeshObject<Mesh>(objName, obr)
270 {}
271};
272
273
274/*---------------------------------------------------------------------------*\
275 Class MoveableMeshObject Declaration
276\*---------------------------------------------------------------------------*/
278template<class Mesh>
280:
281 public GeometricMeshObject<Mesh>
282{
283public:
284
285 //- Construct from name and instance on registry
286 MoveableMeshObject(const word& objName, const objectRegistry& obr)
287 :
288 GeometricMeshObject<Mesh>(objName, obr)
289 {}
290
291 //- Update for mesh motion
292 virtual bool movePoints() = 0;
293};
294
295
296/*---------------------------------------------------------------------------*\
297 Class UpdateableMeshObject Declaration
298\*---------------------------------------------------------------------------*/
299
300template<class Mesh>
302:
303 public MoveableMeshObject<Mesh>
304{
305public:
306
307 //- Construct from name and instance on registry
308 UpdateableMeshObject(const word& objName, const objectRegistry& obr)
309 :
310 MoveableMeshObject<Mesh>(objName, obr)
311 {}
312
313 //- Update topology using the given map
314 virtual void updateMesh(const mapPolyMesh& mpm) = 0;
315};
316
317
318// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320} // End namespace Foam
321
322// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323
324#ifdef NoRepository
325 #include "MeshObject.txx"
326#endif
327
328// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329
330#endif
331
332// ************************************************************************* //
GeometricMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition MeshObject.H:307
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition MeshObject.H:155
MeshObject(const Mesh &mesh)
Construct with Type::typeName on Mesh.
virtual ~MeshObject()=default
Destructor.
static bool Store(std::unique_ptr< Type > &&ptr)
Transfer ownership of meshObject to registry.
static FOAM_NO_DANGLING_REFERENCE const Type & New(const Mesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
static bool Delete(const word &objName, const Mesh &mesh)
Static destructor using given registration name.
virtual bool writeData(Ostream &os) const
Dummy write.
Definition MeshObject.H:265
static FOAM_NO_DANGLING_REFERENCE const Type & New(const word &objName, const Mesh &mesh, Args &&... args)
Get existing or create MeshObject with given registration name.
static bool Delete(const Mesh &mesh)
Static destructor using Type::typeName.
Definition MeshObject.H:219
static std::unique_ptr< Type > Release(const word &objName, const Mesh &mesh, bool checkout=true)
Release ownership of meshObject (with given registration name) from registry. Returns nullptr if not ...
static std::unique_ptr< Type > Release(const Mesh &mesh, bool checkout=true)
Release ownership of meshObject (with Type::typeName name) from registry.
Definition MeshObject.H:242
MeshObject(const word &objName, const Mesh &mesh)
Construct with given object name on Mesh.
virtual bool movePoints()=0
Update for mesh motion.
MoveableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition MeshObject.H:328
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
TopologicalMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition MeshObject.H:286
virtual void updateMesh(const mapPolyMesh &mpm)=0
Update topology using the given map.
UpdateableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition MeshObject.H:354
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
The meshObject is a concrete regIOobject to register MeshObject items.
Definition MeshObject.H:93
static void clearUpto(objectRegistry &obr)
Clear all meshObject derived from FromType up to (but not including) ToType.
static void clear(objectRegistry &obr)
Clear/remove all meshObject of MeshObjectType via objectRegistry::checkOut().
meshObject(const word &objName, const objectRegistry &obr)
Construct with given object name on a registry.
static void updateMesh(objectRegistry &obr, const mapPolyMesh &mpm)
Update topology using the given map.
ClassName("meshObject")
Runtime declaration and debug switch.
static void movePoints(objectRegistry &obr)
Update for mesh motion.
Registry of regIOobjects.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A class for handling words, derived from Foam::string.
Definition word.H:66
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
surface1 clear()
type
Types of root.
Definition Roots.H:53
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265
Foam::argList args(argc, argv)
#define FOAM_NO_DANGLING_REFERENCE
Definition stdFoam.H:80