ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / polyMesh / polyMesh.H
blob4e97886ac8134b87b0efb580d925a1d3ebab9733
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::polyMesh
27 Description
28     Mesh consisting of general polyhedral cells.
30 SourceFiles
31     polyMesh.C
32     polyMeshInitMesh.C
33     polyMeshClear.C
34     polyMeshFromShapeMesh.C
35     polyMeshIO.C
36     polyMeshUpdate.C
37     polyMeshFindCell.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;
66 class polyMeshTetDecomposition;
68 /*---------------------------------------------------------------------------*\
69                           Class polyMesh Declaration
70 \*---------------------------------------------------------------------------*/
72 class polyMesh
74     public objectRegistry,
75     public primitiveMesh
78 public:
80     // Public data types
82         //- Enumeration defining the state of the mesh after a read update.
83         //  Used for post-processing applications, where the mesh
84         //  needs to update based on the files written in time
85         //  directores
86         enum readUpdateState
87         {
88             UNCHANGED,
89             POINTS_MOVED,
90             TOPO_CHANGE,
91             TOPO_PATCH_CHANGE
92         };
95 private:
97     // Permanent data
99         // Primitive mesh data
101             //- Points
102             pointIOField points_;
104             //- Faces
105             faceCompactIOList faces_;
107             //- Face owner
108             labelIOList owner_;
110             //- Face neighbour
111             labelIOList neighbour_;
113             //- Have the primitives been cleared
114             bool clearedPrimitives_;
117             //- Boundary mesh
118             mutable polyBoundaryMesh boundary_;
120             //- Mesh bounding-box.
121             //  Created from points on construction, updated when the mesh moves
122             boundBox bounds_;
124             //- vector of non-constrained directions in mesh
125             //  defined according to the presence of empty and wedge patches
126             mutable Vector<label> geometricD_;
128             //- vector of valid directions in mesh
129             //  defined according to the presence of empty patches
130             mutable Vector<label> solutionD_;
132             //- Base point for face decomposition into tets
133             mutable labelList* tetBasePtIsPtr_;
136         // Zoning information
138             //- Point zones
139             pointZoneMesh pointZones_;
141             //- Face zones
142             faceZoneMesh faceZones_;
144             //- Cell zones
145             cellZoneMesh cellZones_;
148         //- Parallel info
149         mutable globalMeshData* globalMeshDataPtr_;
152         // Mesh motion related data
154             //- Is the mesh moving
155             bool moving_;
157             //- Is the mesh changing (moving and/or topology changing)
158             bool changing_;
160             //- Current time index for mesh motion
161             mutable label curMotionTimeIndex_;
163             //- Old points (for the last mesh motion)
164             mutable pointField* oldPointsPtr_;
167     // Private Member Functions
169         //- Disallow construct as copy
170         polyMesh(const polyMesh&);
172         //- Disallow default bitwise assignment
173         void operator=(const polyMesh&);
175         //- Initialise the polyMesh from the primitive data
176         void initMesh();
178         //- Initialise the polyMesh from the given set of cells
179         void initMesh(cellList& c);
181         //- Calculate the valid directions in the mesh from the boundaries
182         void calcDirections() const;
184         //- Calculate the cell shapes from the primitive
185         //  polyhedral information
186         void calcCellShapes() const;
189         // Helper functions for constructor from cell shapes
191             labelListList cellShapePointCells(const cellShapeList&) const;
193             labelList facePatchFaceCells
194             (
195                 const faceList& patchFaces,
196                 const labelListList& pointCells,
197                 const faceListList& cellsFaceShapes,
198                 const label patchID
199             ) const;
201             void setTopology
202             (
203                 const cellShapeList& cellsAsShapes,
204                 const faceListList& boundaryFaces,
205                 const wordList& boundaryPatchNames,
206                 labelList& patchSizes,
207                 labelList& patchStarts,
208                 label& defaultPatchStart,
209                 label& nFaces,
210                 cellList& cells
211             );
215 public:
217     // Public typedefs
219         typedef polyMesh Mesh;
220         typedef polyBoundaryMesh BoundaryMesh;
223     //- Runtime type information
224     TypeName("polyMesh");
226     //- Return the default region name
227     static word defaultRegion;
229     //- Return the mesh sub-directory name (usually "polyMesh")
230     static word meshSubDir;
233     // Constructors
235         //- Construct from IOobject
236         explicit polyMesh(const IOobject& io);
238         //- Construct without boundary from components.
239         //  Boundary is added using addPatches() member function
240         polyMesh
241         (
242             const IOobject& io,
243             const Xfer<pointField>& points,
244             const Xfer<faceList>& faces,
245             const Xfer<labelList>& owner,
246             const Xfer<labelList>& neighbour,
247             const bool syncPar = true
248         );
250         //- Construct without boundary with cells rather than owner/neighbour.
251         //  Boundary is added using addPatches() member function
252         polyMesh
253         (
254             const IOobject& io,
255             const Xfer<pointField>& points,
256             const Xfer<faceList>& faces,
257             const Xfer<cellList>& cells,
258             const bool syncPar = true
259         );
261         //- Construct from cell shapes
262         polyMesh
263         (
264             const IOobject& io,
265             const Xfer<pointField>& points,
266             const cellShapeList& shapes,
267             const faceListList& boundaryFaces,
268             const wordList& boundaryPatchNames,
269             const wordList& boundaryPatchTypes,
270             const word& defaultBoundaryPatchName,
271             const word& defaultBoundaryPatchType,
272             const wordList& boundaryPatchPhysicalTypes,
273             const bool syncPar = true
274         );
276         //- Construct from cell shapes with patch information in dictionary
277         //  format.
278         polyMesh
279         (
280             const IOobject& io,
281             const Xfer<pointField>& points,
282             const cellShapeList& shapes,
283             const faceListList& boundaryFaces,
284             const wordList& boundaryPatchNames,
285             const PtrList<dictionary>& boundaryDicts,
286             const word& defaultBoundaryPatchName,
287             const word& defaultBoundaryPatchType,
288             const bool syncPar = true
289         );
292     //- Destructor
293     virtual ~polyMesh();
296     // Member Functions
298         // Database
300             //- Override the objectRegistry dbDir for a single-region case
301             virtual const fileName& dbDir() const;
303             //- Return the local mesh directory (dbDir()/meshSubDir)
304             fileName meshDir() const;
306             //- Return the current instance directory for points
307             //  Used in the consruction of gemometric mesh data dependent
308             //  on points
309             const fileName& pointsInstance() const;
311             //- Return the current instance directory for faces
312             const fileName& facesInstance() const;
314             //- Set the instance for mesh files
315             void setInstance(const fileName&);
318         // Access
320             //- Return raw points
321             virtual const pointField& points() const;
323             //- Return raw faces
324             virtual const faceList& faces() const;
326             //- Return face owner
327             virtual const labelList& faceOwner() const;
329             //- Return face neighbour
330             virtual const labelList& faceNeighbour() const;
332             //- Return old points for mesh motion
333             virtual const pointField& oldPoints() const;
335             //- Return boundary mesh
336             const polyBoundaryMesh& boundaryMesh() const
337             {
338                 return boundary_;
339             }
341             //- Return mesh bounding box
342             const boundBox& bounds() const
343             {
344                 return bounds_;
345             }
347             //- Return the vector of geometric directions in mesh.
348             //  Defined according to the presence of empty and wedge patches.
349             //  1 indicates unconstrained direction and -1 a constrained
350             //  direction.
351             const Vector<label>& geometricD() const;
353             //- Return the number of valid geometric dimensions in the mesh
354             label nGeometricD() const;
356             //- Return the vector of solved-for directions in mesh.
357             //  Differs from geometricD in that it includes for wedge cases
358             //  the circumferential direction in case of swirl.
359             //  1 indicates valid direction and -1 an invalid direction.
360             const Vector<label>& solutionD() const;
362             //- Return the number of valid solved-for dimensions in the mesh
363             label nSolutionD() const;
365             //- Return the tetBasePtIs
366             const labelList& tetBasePtIs() const;
368             //- Return point zone mesh
369             const pointZoneMesh& pointZones() const
370             {
371                 return pointZones_;
372             }
374             //- Return face zone mesh
375             const faceZoneMesh& faceZones() const
376             {
377                 return faceZones_;
378             }
380             //- Return cell zone mesh
381             const cellZoneMesh& cellZones() const
382             {
383                 return cellZones_;
384             }
386             //- Return parallel info
387             const globalMeshData& globalData() const;
389             //- Return the object registry
390             const objectRegistry& thisDb() const
391             {
392                 return *this;
393             }
396         // Mesh motion
398             //- Is mesh moving
399             bool moving() const
400             {
401                 return moving_;
402             }
404             //- Set the mesh to be moving
405             bool moving(const bool m)
406             {
407                 bool m0 = moving_;
408                 moving_ = m;
409                 changing_ = changing_ || moving_;
410                 return m0;
411             }
413             //- Is mesh changing (topology changing and/or moving)
414             bool changing() const
415             {
416                 return changing_;
417             }
419             //- Set the mesh to be changing
420             bool changing(const bool c)
421             {
422                 bool c0 = changing_;
423                 changing_ = c;
424                 return c0;
425             }
427             //- Move points, returns volumes swept by faces in motion
428             virtual tmp<scalarField> movePoints(const pointField&);
430             //- Reset motion
431             void resetMotion() const;
434         // Topological change
436             //- Return non-const access to the pointZones
437             pointZoneMesh& pointZones()
438             {
439                 return pointZones_;
440             }
442             //- Return non-const access to the faceZones
443             faceZoneMesh& faceZones()
444             {
445                 return faceZones_;
446             }
448             //- Return non-const access to the cellZones
449             cellZoneMesh& cellZones()
450             {
451                 return cellZones_;
452             }
454             //- Add boundary patches
455             void addPatches
456             (
457                 const List<polyPatch*>&,
458                 const bool validBoundary = true
459             );
461             //- Add mesh zones
462             void addZones
463             (
464                 const List<pointZone*>& pz,
465                 const List<faceZone*>& fz,
466                 const List<cellZone*>& cz
467             );
469             //- Update the mesh based on the mesh files saved in
470             //  time directories
471             virtual readUpdateState readUpdate();
473             //- Update the mesh corresponding to given map
474             virtual void updateMesh(const mapPolyMesh& mpm);
476             //- Remove boundary patches
477             void removeBoundary();
479             //- Reset mesh primitive data. Assumes all patch info correct
480             //  (so does e.g. parallel communication). If not use
481             //  validBoundary=false
482             void resetPrimitives
483             (
484                 const Xfer<pointField>& points,
485                 const Xfer<faceList>& faces,
486                 const Xfer<labelList>& owner,
487                 const Xfer<labelList>& neighbour,
488                 const labelList& patchSizes,
489                 const labelList& patchStarts,
490                 const bool validBoundary = true
491             );
494         //  Storage management
496             //- Clear geometry
497             void clearGeom();
499             //- Clear addressing
500             void clearAddressing();
502             //- Clear all geometry and addressing unnecessary for CFD
503             void clearOut();
505             //- Clear primitive data (points, faces and cells)
506             void clearPrimitives();
508             //- Remove all files from mesh instance
509             void removeFiles(const fileName& instanceDir) const;
511             //- Remove all files from mesh instance()
512             void removeFiles() const;
515         // Helper functions
517             //- Find the cell, tetFaceI and tetPtI for the given position
518             void findCellFacePt
519             (
520                 const point& pt,
521                 label& cellI,
522                 label& tetFaceI,
523                 label& tetPtI
524             ) const;
526             //- Find the tetFaceI and tetPtI for the given position in
527             //  the supplied cell, tetFaceI and tetPtI = -1 if not found
528             void findTetFacePt
529             (
530                 const label cellI,
531                 const point& pt,
532                 label& tetFaceI,
533                 label& tetPtI
534             ) const;
538 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
540 } // End namespace Foam
542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
544 #endif
546 // ************************************************************************* //