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 -------------------------------------------------------------------------------
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.
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 
63 Note
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 
68 SourceFiles
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 
82 namespace Foam
83 {
84 
85 // Forward Declarations
86 class mapPolyMesh;
87 
88 /*---------------------------------------------------------------------------*\
89  Class meshObject Declaration
90 \*---------------------------------------------------------------------------*/
91 
92 //- The meshObject is a concrete regIOobject to register MeshObject items
93 class meshObject
94 :
95  public regIOobject
96 {
97 public:
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);
107 
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 
141 template<class Mesh, template<class> class MeshObjectType, class Type>
142 class MeshObject
143 :
144  public MeshObjectType<Mesh>
145 {
146 protected:
147 
148  //- Reference to the mesh
149  const Mesh& mesh_;
150 
151 
152 public:
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)
192  {
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
199  (
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
214  )
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 
240 template<class Mesh>
241 class TopologicalMeshObject
242 :
243  public meshObject
244 {
245 public:
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 
259 template<class Mesh>
261 :
262  public TopologicalMeshObject<Mesh>
263 {
264 public:
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 \*---------------------------------------------------------------------------*/
278 template<class Mesh>
279 class MoveableMeshObject
280 :
281  public GeometricMeshObject<Mesh>
282 {
283 public:
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 
300 template<class Mesh>
302 :
303  public MoveableMeshObject<Mesh>
304 {
305 public:
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 // ************************************************************************* //
static bool Store(std::unique_ptr< Type > &&ptr)
Transfer ownership of meshObject to registry.
MoveableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:328
static void movePoints(objectRegistry &obr)
Update for mesh motion.
static FOAM_NO_DANGLING_REFERENCE const Type & New(const Mesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
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 ...
The meshObject is a concrete regIOobject to register MeshObject items.
Definition: MeshObject.H:90
virtual void updateMesh(const mapPolyMesh &mpm)=0
Update topology using the given map.
virtual bool writeData(Ostream &os) const
Dummy write.
Definition: MeshObject.H:265
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
#define FOAM_NO_DANGLING_REFERENCE
Definition: stdFoam.H:81
TopologicalMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:286
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:152
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.
const Mesh & mesh() const noexcept
Reference to the mesh.
Definition: MeshObject.H:257
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool movePoints()=0
Update for mesh motion.
virtual ~MeshObject()=default
Destructor.
const Mesh & mesh_
Reference to the mesh.
Definition: MeshObject.H:161
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:265
ClassName("meshObject")
Runtime declaration and debug switch.
static void updateMesh(objectRegistry &obr, const mapPolyMesh &mpm)
Update topology using the given map.
static void clearUpto(objectRegistry &obr)
Clear all meshObject derived from FromType up to (but not including) ToType.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
static bool Delete(const word &objName, const Mesh &mesh)
Static destructor using given registration name.
Registry of regIOobjects.
Foam::argList args(argc, argv)
MeshObject(const Mesh &mesh)
Construct with Type::typeName on Mesh.
GeometricMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:307
Namespace for OpenFOAM.
UpdateableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:354