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-2024 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  static const Type& New(const Mesh& mesh, Args&&... args);
172 
173  //- Get existing or create MeshObject with given registration name
174  template<class... Args>
175  static const Type& New
176  (
177  const word& objName,
178  const Mesh& mesh,
179  Args&&... args
180  );
181 
182  //- Transfer ownership of meshObject to registry.
183  static bool Store(std::unique_ptr<Type>&& ptr);
184 
185  //- Static destructor using given registration name
186  static bool Delete(const word& objName, const Mesh& mesh);
187 
188  //- Static destructor using Type::typeName
189  static bool Delete(const Mesh& mesh)
190  {
191  return Delete(Type::typeName, mesh);
192  }
193 
194  //- Release ownership of meshObject (with given registration name)
195  //- from registry. Returns nullptr if not found or not owned.
196  static std::unique_ptr<Type> Release
197  (
198  const word& objName,
199  const Mesh& mesh,
201  const bool checkout = false
202  );
203 
204 
205  //- Release ownership of meshObject (with Type::typeName name)
206  //- from registry.
207  static std::unique_ptr<Type> Release
208  (
209  const Mesh& mesh,
211  const bool checkout = false
212  )
213  {
214  return Release(Type::typeName, mesh, checkout);
215  }
216 
218  // Member Functions
219 
220  //- Reference to the mesh
221  const Mesh& mesh() const noexcept
222  {
223  return mesh_;
224  }
225 
226  //- Dummy write
227  virtual bool writeData(Ostream& os) const
228  {
229  return true;
230  }
231 };
232 
233 
234 /*---------------------------------------------------------------------------*\
235  Class TopologicalMeshObject Declaration
236 \*---------------------------------------------------------------------------*/
237 
238 template<class Mesh>
239 class TopologicalMeshObject
240 :
241  public meshObject
242 {
243 public:
244 
245  //- Construct from name and instance on registry
246  TopologicalMeshObject(const word& objName, const objectRegistry& obr)
247  :
248  meshObject(objName, obr)
249  {}
250 };
251 
252 
253 /*---------------------------------------------------------------------------*\
254  Class GeometricMeshObject Declaration
255 \*---------------------------------------------------------------------------*/
256 
257 template<class Mesh>
259 :
260  public TopologicalMeshObject<Mesh>
261 {
262 public:
264  //- Construct from name and instance on registry
265  GeometricMeshObject(const word& objName, const objectRegistry& obr)
266  :
267  TopologicalMeshObject<Mesh>(objName, obr)
268  {}
269 };
270 
271 
272 /*---------------------------------------------------------------------------*\
273  Class MoveableMeshObject Declaration
274 \*---------------------------------------------------------------------------*/
276 template<class Mesh>
277 class MoveableMeshObject
278 :
279  public GeometricMeshObject<Mesh>
280 {
281 public:
282 
283  //- Construct from name and instance on registry
284  MoveableMeshObject(const word& objName, const objectRegistry& obr)
285  :
286  GeometricMeshObject<Mesh>(objName, obr)
287  {}
288 
289  //- Update for mesh motion
290  virtual bool movePoints() = 0;
291 };
292 
293 
294 /*---------------------------------------------------------------------------*\
295  Class UpdateableMeshObject Declaration
296 \*---------------------------------------------------------------------------*/
297 
298 template<class Mesh>
300 :
301  public MoveableMeshObject<Mesh>
302 {
303 public:
304 
305  //- Construct from name and instance on registry
306  UpdateableMeshObject(const word& objName, const objectRegistry& obr)
307  :
308  MoveableMeshObject<Mesh>(objName, obr)
309  {}
310 
311  //- Update topology using the given map
312  virtual void updateMesh(const mapPolyMesh& mpm) = 0;
313 };
314 
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 } // End namespace Foam
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #ifdef NoRepository
323  #include "MeshObject.C"
324 #endif
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 #endif
329 
330 // ************************************************************************* //
static void updateMesh(objectRegistry &obr, const mapPolyMesh &mpm)
Update topology using the given map.
Definition: MeshObject.C:268
static void clearUpto(objectRegistry &obr)
Clear all meshObject derived from FromType up to (but not including) ToType.
Definition: MeshObject.C:339
MoveableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:326
static const Type & New(const Mesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
Definition: MeshObject.C:53
The meshObject is a concrete regIOobject to register MeshObject items.
Definition: MeshObject.H:90
static bool Store(std::unique_ptr< Type > &&ptr)
Transfer ownership of meshObject to registry.
Definition: MeshObject.C:196
virtual void updateMesh(const mapPolyMesh &mpm)=0
Update topology using the given map.
static void clear(objectRegistry &obr)
Clear/remove all meshObject of MeshObjectType via objectRegistry::checkOut()
Definition: MeshObject.C:308
virtual bool writeData(Ostream &os) const
Dummy write.
Definition: MeshObject.H:263
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
TopologicalMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:284
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:152
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:255
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: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
static std::unique_ptr< Type > Release(const word &objName, const Mesh &mesh, const bool checkout=false)
Release ownership of meshObject (with given registration name) from registry. Returns nullptr if not ...
Definition: MeshObject.C:146
static void movePoints(objectRegistry &obr)
Update for mesh motion.
Definition: MeshObject.C:228
ClassName("meshObject")
Runtime declaration and debug switch.
static bool Delete(const word &objName, const Mesh &mesh)
Static destructor using given registration name.
Definition: MeshObject.C:120
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
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:305
Namespace for OpenFOAM.
UpdateableMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:352