initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / polyMesh / polyMesh.H
blob4cf32e07a92fa70d59e137e25918b9b13fa74f23
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::polyMesh
28 Description
29     Mesh consisting of general polyhedral cells.
31 SourceFiles
32     polyMesh.C
33     polyMeshInitMesh.C
34     polyMeshClear.C
35     polyMeshFromShapeMesh.C
36     polyMeshIO.C
37     polyMeshUpdate.C
39 \*---------------------------------------------------------------------------*/
41 #ifndef polyMesh_H
42 #define polyMesh_H
44 #include "objectRegistry.H"
45 #include "primitiveMesh.H"
46 #include "pointField.H"
47 #include "faceList.H"
48 #include "cellList.H"
49 #include "cellShapeList.H"
50 #include "pointIOField.H"
51 #include "faceIOList.H"
52 #include "labelIOList.H"
53 #include "polyBoundaryMesh.H"
54 #include "boundBox.H"
55 #include "pointZoneMesh.H"
56 #include "faceZoneMesh.H"
57 #include "cellZoneMesh.H"
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 namespace Foam
64 class globalMeshData;
65 class mapPolyMesh;
67 /*---------------------------------------------------------------------------*\
68                           Class polyMesh Declaration
69 \*---------------------------------------------------------------------------*/
71 class polyMesh
73     public objectRegistry,
74     public primitiveMesh
77 public:
79     // Public data types
81         //- Enumeration defining the state of the mesh after a read update.
82         //  Used for post-processing applications, where the mesh
83         //  needs to update based on the files written in time
84         //  directores
85         enum readUpdateState
86         {
87             UNCHANGED,
88             POINTS_MOVED,
89             TOPO_CHANGE,
90             TOPO_PATCH_CHANGE
91         };
94 private:
96     // Permanent data
98         // Primitive mesh data
100             //- Points
101             pointIOField points_;
103             //- Faces
104             faceIOList faces_;
106             //- Face owner
107             labelIOList owner_;
109             //- Face neighbour
110             labelIOList neighbour_;
112             //- Have the primitives been cleared
113             bool clearedPrimitives_;
116             //- Boundary mesh
117             mutable polyBoundaryMesh boundary_;
119             //- Mesh bounding-box. created from points on construction
120             //  and updated when the mesh moves
121             boundBox bounds_;
123             //- vector of valid directions in mesh
124             //  defined according to the presence of empty patches
125             mutable Vector<label> directions_;
128         // Zoning information
130             //- Point zones
131             pointZoneMesh pointZones_;
133             //- Face zones
134             faceZoneMesh faceZones_;
136             //- Cell zones
137             cellZoneMesh cellZones_;
140         //- Parallel info
141         mutable globalMeshData* globalMeshDataPtr_;
144         // Mesh motion related data
146             //- Is the mesh moving
147             bool moving_;
149             //- Is the mesh changing (moving and/or topology changing)
150             bool changing_;
152             //- Current time index for mesh motion
153             mutable label curMotionTimeIndex_;
155             //- Old points (for the last mesh motion)
156             mutable pointField* oldPointsPtr_;
159     // Private member functions
161         //- Disallow construct as copy
162         polyMesh(const polyMesh&);
164         //- Disallow default bitwise assignment
165         void operator=(const polyMesh&);
167         //- Initialise the polyMesh from the primitive data
168         void initMesh();
170         //- Initialise the polyMesh from the given set of cells
171         void initMesh(cellList& c);
173         //- Calculate the valid directions in the mesh from the boundaries
174         void calcDirections() const;
176         //- Calculate the cell shapes from the primitive
177         //  polyhedral information
178         void calcCellShapes() const;
181         // Helper functions for constructor from cell shapes
183             labelListList cellShapePointCells(const cellShapeList&) const;
185             labelList facePatchFaceCells
186             (
187                 const faceList& patchFaces,
188                 const labelListList& pointCells,
189                 const faceListList& cellsFaceShapes,
190                 const label patchID
191             ) const;
194 public:
196     // Public typedefs
198         typedef polyMesh Mesh;
199         typedef polyBoundaryMesh BoundaryMesh;
202     //- Runtime type information
203     TypeName("polyMesh");
205     //- Return the default region name
206     static word defaultRegion;
208     //- Return the mesh sub-directory name (usually "polyMesh")
209     static word meshSubDir;
212     // Constructors
214         //- Construct from IOobject
215         explicit polyMesh(const IOobject& io);
217         //- Construct from components without boundary.
218         //  Boundary is added using addPatches() member function
219         polyMesh
220         (
221             const IOobject& io,
222             const pointField& points,
223             const faceList& faces,
224             const labelList& owner,
225             const labelList& neighbour,
226             const bool syncPar = true
227         );
229         //- Construct from components with cells rather than owner
230         //  and neighbourwithout boundary.
231         //  Boundary is added using addPatches() member function
232         polyMesh
233         (
234             const IOobject& io,
235             const pointField& points,
236             const faceList& faces,
237             const cellList& cells,
238             const bool syncPar = true
239         );
241         //- Construct from cell shapes
242         polyMesh
243         (
244             const IOobject& io,
245             const pointField& points,
246             const cellShapeList& shapes,
247             const faceListList& boundaryFaces,
248             const wordList& boundaryPatchNames,
249             const wordList& boundaryPatchTypes,
250             const word& defaultBoundaryPatchName,
251             const word& defaultBoundaryPatchType,
252             const wordList& boundaryPatchPhysicalTypes,
253             const bool syncPar = true
254         );
257     // Destructor
259         virtual ~polyMesh();
262     // Member Functions
264         // Database
266             //- Over-ride the objectRegistry dbDir
267             //  if this is single-region case
268             virtual const fileName& dbDir() const;
270             //- Return the local mesh directory (dbDir()/meshSubDir)
271             fileName meshDir() const;
273             //- Return the current instance directory for points
274             //  Used in the consruction of gemometric mesh data dependent
275             //  on points
276             const fileName& pointsInstance() const;
278             //- Return the current instance directory for faces
279             const fileName& facesInstance() const;
281             //- Set the instance for mesh files
282             void setInstance(const fileName&);
285         // Access
287             //- Return raw points
288             virtual const pointField& points() const;
290             //- Return raw faces
291             virtual const faceList& faces() const;
293             //- Return face owner
294             virtual const labelList& faceOwner() const;
296             //- Return face neighbour
297             virtual const labelList& faceNeighbour() const;
299             //- Return old points for mesh motion
300             virtual const pointField& oldPoints() const;
302             //- Return boundary mesh
303             const polyBoundaryMesh& boundaryMesh() const
304             {
305                 return boundary_;
306             }
308             //- Return mesh bounding box
309             const boundBox& bounds() const
310             {
311                 return bounds_;
312             }
314             //- Return the vector of valid directions in mesh
315             //  defined according to the presence of empty patches.
316             //  1 indicates valid direction and -1 an invalid direction.
317             const Vector<label>& directions() const;
319             //- Return the number of valid geoemtric dimensions in the mesh
320             label nGeometricD() const;
322             //- Return the number of valid solution dimensions in the mesh
323             //  For wedge cases this includes the circumferential direction
324             //  in case of swirl
325             label nSolutionD() const;
327             //- Return point zone mesh
328             const pointZoneMesh& pointZones() const
329             {
330                 return pointZones_;
331             }
333             //- Return face zone mesh
334             const faceZoneMesh& faceZones() const
335             {
336                 return faceZones_;
337             }
339             //- Return cell zone mesh
340             const cellZoneMesh& cellZones() const
341             {
342                 return cellZones_;
343             }
345             //- Return parallel info
346             const globalMeshData& globalData() const;
349         // Mesh motion
351             //- Is mesh moving
352             bool moving() const
353             {
354                 return moving_;
355             }
357             //- Set the mesh to be moving
358             bool moving(const bool m)
359             {
360                 bool m0 = moving_;
361                 moving_ = m;
362                 changing_ = changing_ || moving_;
363                 return m0;
364             }
366             //- Is mesh changing (topology changing and/or moving)
367             bool changing() const
368             {
369                 return changing_;
370             }
372             //- Set the mesh to be changing
373             bool changing(const bool c)
374             {
375                 bool c0 = changing_;
376                 changing_ = c;
377                 return c0;
378             }
380             //- Move points, returns volumes swept by faces in motion
381             virtual tmp<scalarField> movePoints(const pointField&);
383             //- Reset motion
384             void resetMotion() const;
387         // Topological change
389             //- Return non-const access to the pointZones
390             pointZoneMesh& pointZones()
391             {
392                 return pointZones_;
393             }
395             //- Return non-const access to the faceZones
396             faceZoneMesh& faceZones()
397             {
398                 return faceZones_;
399             }
401             //- Return non-const access to the cellZones
402             cellZoneMesh& cellZones()
403             {
404                 return cellZones_;
405             }
407             //- Add boundary patches
408             void addPatches
409             (
410                 const List<polyPatch*>&,
411                 const bool validBoundary = true
412             );
414             //- Add mesh zones
415             void addZones
416             (
417                 const List<pointZone*>& pz,
418                 const List<faceZone*>& fz,
419                 const List<cellZone*>& cz
420             );
422             //- Update the mesh based on the mesh files saved in
423             //  time directories
424             virtual readUpdateState readUpdate();
426             //- Update the mesh corresponding to given map
427             virtual void updateMesh(const mapPolyMesh& mpm);
429             //- Remove boundary patches
430             void removeBoundary();
432             //- Reset mesh primitive data. Assumes all patch info correct
433             //  (so does e.g. parallel communication). If not use
434             //  validBoundary=false
435             //  (still assumes patchStarts[0] = nInternalFaces and last
436             //  patch ends at nActiveFaces) and change patches with addPatches.
437             void resetPrimitives
438             (
439                 const label nUsedFaces,
440                 const pointField& points,
441                 const faceList& faces,
442                 const labelList& owner,
443                 const labelList& neighbour,
444                 const labelList& patchSizes,
445                 const labelList& patchStarts,
446                 const bool validBoundary = true
447             );
450         //  Storage management
452             //- Clear geometry
453             void clearGeom();
455             //- Clear addressing
456             void clearAddressing();
458             //- Clear all geometry and addressing unnecessary for CFD
459             void clearOut();
461             //- Clear primitive data (points, faces and cells)
462             void clearPrimitives();
464             //- Remove all files from mesh instance
465             void removeFiles(const fileName& instanceDir) const;
467             //- Remove all files from mesh instance()
468             void removeFiles() const;
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
474 } // End namespace Foam
476 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
478 #endif
480 // ************************************************************************* //