Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / MeshObject / meshObjectBase.H
blob532e991247f622d8d15dd370571ba03eab17a9de
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     meshObjectBase
27 Description
28     Abstract base-class for dynamic mesh objects used to automate
29     their allocation to the mesh database and mesh-related updates
31 SourceFiles
32     meshObjectBase.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef meshObjectBase_H
37 #define meshObjectBase_H
39 #include "typeInfo.H"
40 #include "HashTable.H"
41 #include "objectRegistry.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // Class forward declarations
49 class mapPolyMesh;
51 /*---------------------------------------------------------------------------*\
52                          Class meshObjectBase Declaration
53 \*---------------------------------------------------------------------------*/
55 class meshObjectBase
57 public:
59     //- Runtime type information
60     TypeName("meshObject");
63     // Static functions
65         //- Update topology on all mesh objects
66         template<class Mesh>
67         static void allUpdateTopology(const Mesh& mesh, const mapPolyMesh& mpm)
68         {
69             HashTable<const meshObjectBase*> tbl =
70                 mesh.objectRegistry::template lookupClass<meshObjectBase>();
72             if (Mesh::debug)
73             {
74                 InfoIn
75                 (
76                     "static void meshObjectBase::"
77                     "allUpdateTopology(const Mesh& mesh, "
78                     "const mapPolyMesh& mpm)"
79                 )   << "Mesh objects to update: " << tbl.toc() << endl;
80             }
82             for
83             (
84                 HashTable<const meshObjectBase*>::iterator iter =
85                     tbl.begin();
86                 iter != tbl.end();
87                 ++iter
88             )
89             {
90                 const meshObjectBase& obj = *(iter());
92                 if (Mesh::debug)
93                 {
94                     Info << "Updating object " << obj.type() << endl;
95                 }
97                 obj.updateMesh(mpm);
98             }
100             if (Mesh::debug)
101             {
102                 Info << "Done update topology" << endl;
103             }
104         }
107         //- Move points on all mesh objects
108         template<class Mesh>
109         static void allMovePoints(const Mesh& mesh)
110         {
111             if (mesh.moving())
112             {
113                 HashTable<const meshObjectBase*> tbl =
114                     mesh.objectRegistry::template lookupClass<meshObjectBase>();
116                 if (Mesh::debug)
117                 {
118                     InfoIn
119                     (
120                         "static void meshObjectBase::"
121                         "allMovePoints(const Mesh& mesh)"
122                     )   << "Mesh objects to move: " << tbl.toc() << endl;
123                 }
125                 for
126                 (
127                     HashTable<const meshObjectBase*>::iterator iter =
128                         tbl.begin();
129                     iter != tbl.end();
130                     ++iter
131                 )
132                 {
133                     const meshObjectBase& obj = *(iter());
135                     if (Mesh::debug)
136                     {
137                         Info<< "Moving object "
138                             << " of type " << obj.type() << endl;
139                     }
141                     obj.movePoints();
142                 }
144                 if (Mesh::debug)
145                 {
146                     Info << "Done moving" << endl;
147                 }
148             }
149         }
151         //- Move points on all mesh objects
152         template<class Mesh>
153         static void allDelete(const Mesh& mesh)
154         {
155             HashTable<const meshObjectBase*> tbl =
156                 mesh.objectRegistry::template lookupClass<meshObjectBase>();
158             for
159             (
160                 HashTable<const meshObjectBase*>::iterator iter =
161                     tbl.begin();
162                 iter != tbl.end();
163                 ++iter
164             )
165             {
166                 const meshObjectBase& obj = *(iter());
168                 if (Mesh::debug)
169                 {
170                     Info << "Deleting object " << obj.type() << endl;
172                     obj.deleteObject();
173                 }
174             }
175         }
178     // Destructor
180         virtual ~meshObjectBase()
181         {}
184     // Member Functions
186         //- Update after mesh motion
187         virtual bool movePoints() const = 0;
189         //- Update after topology change
190         virtual bool updateMesh(const mapPolyMesh&) const = 0;
192         //- Delete object from database
193         virtual bool deleteObject() const = 0;
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 } // End namespace Foam
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 #endif
205 // ************************************************************************* //