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-2019 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 
68 \*---------------------------------------------------------------------------*/
69 
70 #ifndef MeshObject_H
71 #define MeshObject_H
72 
73 #include "regIOobject.H"
74 #include "objectRegistry.H"
75 
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 
78 namespace Foam
79 {
80 
81 // Forward declarations
82 class mapPolyMesh;
83 
84 /*---------------------------------------------------------------------------*\
85  Class MeshObject Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 template<class Mesh, template<class> class MeshObjectType, class Type>
89 class MeshObject
90 :
91  public MeshObjectType<Mesh>
92 {
93 
94 protected:
95 
96  // Reference to Mesh
97  const Mesh& mesh_;
98 
99 
100 public:
101 
102  // Constructors
103 
104  //- Construct on Mesh type
105  explicit MeshObject(const Mesh& mesh);
106 
107  // Selectors
108 
109  //- Get existing or create a new MeshObject
110  template<class... Args>
111  static const Type& New(const Mesh& mesh, Args&&... args);
112 
113 
114  //- Destructor
115  virtual ~MeshObject() = default;
116 
117  //- Static destructor
118  static bool Delete(const Mesh& mesh);
119 
120 
121  // Member Functions
122 
123  const Mesh& mesh() const
124  {
125  return mesh_;
126  }
127 
128  virtual bool writeData(Ostream& os) const
129  {
130  return true;
131  }
132 };
133 
134 
135 /*---------------------------------------------------------------------------*\
136  Class meshObject Declaration
137 \*---------------------------------------------------------------------------*/
138 
139 class meshObject
140 :
141  public regIOobject
142 {
143 public:
144 
145  // Declare name of the class and its debug switch
146  ClassName("meshObject");
147 
148  // Constructors
149 
150  //- Construct from name and instance on registry
151  meshObject(const word& typeName, const objectRegistry& obr);
152 
153 
154  // Static Member Functions
155 
156  template<class Mesh>
157  static void movePoints(objectRegistry& obr);
158 
159  template<class Mesh>
160  static void updateMesh(objectRegistry& obr, const mapPolyMesh& mpm);
161 
162  template<class Mesh, template<class> class MeshObjectType>
163  static void clear(objectRegistry& obr);
164 
165  //- Clear all meshObject derived from FromType up to
166  //- (but not including) ToType.
167  // Used to clear e.g. all non-updateable meshObjects
168  template
169  <
170  class Mesh,
171  template<class> class FromType,
172  template<class> class ToType
173  >
174  static void clearUpto(objectRegistry& obr);
175 };
176 
177 
178 /*---------------------------------------------------------------------------*\
179  Class TopologicalMeshObject Declaration
180 \*---------------------------------------------------------------------------*/
181 
182 template<class Mesh>
184 :
185  public meshObject
186 {
187 public:
188 
189  //- Construct from name and instance on registry
190  TopologicalMeshObject(const word& typeName, const objectRegistry& obr)
191  :
192  meshObject(typeName, obr)
193  {}
194 };
195 
196 
197 /*---------------------------------------------------------------------------*\
198  Class GeometricMeshObject Declaration
199 \*---------------------------------------------------------------------------*/
200 
201 template<class Mesh>
203 :
204  public TopologicalMeshObject<Mesh>
205 {
206 public:
207 
208  //- Construct from name and instance on registry
209  GeometricMeshObject(const word& typeName, const objectRegistry& obr)
210  :
211  TopologicalMeshObject<Mesh>(typeName, obr)
212  {}
213 };
214 
215 
216 /*---------------------------------------------------------------------------*\
217  Class MoveableMeshObject Declaration
218 \*---------------------------------------------------------------------------*/
219 
220 template<class Mesh>
221 class MoveableMeshObject
222 :
223  public GeometricMeshObject<Mesh>
224 {
225 public:
226 
227  //- Construct from name and instance on registry
228  MoveableMeshObject(const word& typeName, const objectRegistry& obr)
229  :
230  GeometricMeshObject<Mesh>(typeName, obr)
231  {}
232 
233  virtual bool movePoints() = 0;
234 };
235 
236 
237 /*---------------------------------------------------------------------------*\
238  Class UpdateableMeshObject Declaration
239 \*---------------------------------------------------------------------------*/
240 
241 template<class Mesh>
243 :
244  public MoveableMeshObject<Mesh>
245 {
246 public:
247 
248  //- Construct from name and instance on registry
249  UpdateableMeshObject(const word& typeName, const objectRegistry& obr)
250  :
251  MoveableMeshObject<Mesh>(typeName, obr)
252  {}
253 
254  virtual void updateMesh(const mapPolyMesh& mpm) = 0;
255 };
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #ifdef NoRepository
265  #include "MeshObject.C"
266 #endif
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #endif
271 
272 // ************************************************************************* //
regIOobject.H
Foam::meshObject::updateMesh
static void updateMesh(objectRegistry &obr, const mapPolyMesh &mpm)
Definition: MeshObject.C:146
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::meshObject::clear
static void clear(objectRegistry &obr)
Definition: MeshObject.C:186
Foam::GeometricMeshObject
Definition: MeshObject.H:201
Foam::MeshObject::MeshObject
MeshObject(const Mesh &mesh)
Construct on Mesh type.
Definition: MeshObject.C:36
Foam::MeshObject::New
static const Type & New(const Mesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
objectRegistry.H
Foam::MoveableMeshObject
Definition: MeshObject.H:220
Foam::MeshObject::writeData
virtual bool writeData(Ostream &os) const
Definition: MeshObject.H:127
Foam::UpdateableMeshObject
Definition: MeshObject.H:241
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::MeshObject::mesh
const Mesh & mesh() const
Definition: MeshObject.H:122
Foam::MoveableMeshObject::MoveableMeshObject
MoveableMeshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:227
MeshObject.C
Foam::UpdateableMeshObject::UpdateableMeshObject
UpdateableMeshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:248
Foam::MeshObject::~MeshObject
virtual ~MeshObject()=default
Destructor.
Foam::MoveableMeshObject::movePoints
virtual bool movePoints()=0
Foam::MeshObject::mesh_
const Mesh & mesh_
Definition: MeshObject.H:96
Foam::meshObject::movePoints
static void movePoints(objectRegistry &obr)
Definition: MeshObject.C:106
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::GeometricMeshObject::GeometricMeshObject
GeometricMeshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:208
Foam::meshObject
Definition: MeshObject.H:138
Foam::MeshObject::Delete
static bool Delete(const Mesh &mesh)
Static destructor.
Definition: MeshObject.C:82
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
Foam::meshObject::ClassName
ClassName("meshObject")
Foam::meshObject::clearUpto
static void clearUpto(objectRegistry &obr)
Definition: MeshObject.C:217
Foam::TopologicalMeshObject::TopologicalMeshObject
TopologicalMeshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:189
Foam::TopologicalMeshObject
Definition: MeshObject.H:182
Foam::meshObject::meshObject
meshObject(const word &typeName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: meshObject.C:41
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
args
Foam::argList args(argc, argv)
Foam::UpdateableMeshObject::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)=0