initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / polyMesh / polyMesh.H
blobecb805ad7f0d7912a916bbd302cf9d96da219f77
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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.
120             //  Created from points on construction, updated when the mesh moves
121             boundBox bounds_;
123             //- vector of non-constrained directions in mesh
124             //  defined according to the presence of empty and wedge patches
125             mutable Vector<label> geometricD_;
127             //- vector of valid directions in mesh
128             //  defined according to the presence of empty patches
129             mutable Vector<label> solutionD_;
132         // Zoning information
134             //- Point zones
135             pointZoneMesh pointZones_;
137             //- Face zones
138             faceZoneMesh faceZones_;
140             //- Cell zones
141             cellZoneMesh cellZones_;
144         //- Parallel info
145         mutable globalMeshData* globalMeshDataPtr_;
148         // Mesh motion related data
150             //- Is the mesh moving
151             bool moving_;
153             //- Is the mesh changing (moving and/or topology changing)
154             bool changing_;
156             //- Current time index for mesh motion
157             mutable label curMotionTimeIndex_;
159             //- Old points (for the last mesh motion)
160             mutable pointField* oldPointsPtr_;
163     // Private member functions
165         //- Disallow construct as copy
166         polyMesh(const polyMesh&);
168         //- Disallow default bitwise assignment
169         void operator=(const polyMesh&);
171         //- Initialise the polyMesh from the primitive data
172         void initMesh();
174         //- Initialise the polyMesh from the given set of cells
175         void initMesh(cellList& c);
177         //- Calculate the valid directions in the mesh from the boundaries
178         void calcDirections() const;
180         //- Calculate the cell shapes from the primitive
181         //  polyhedral information
182         void calcCellShapes() const;
185         // Helper functions for constructor from cell shapes
187             labelListList cellShapePointCells(const cellShapeList&) const;
189             labelList facePatchFaceCells
190             (
191                 const faceList& patchFaces,
192                 const labelListList& pointCells,
193                 const faceListList& cellsFaceShapes,
194                 const label patchID
195             ) const;
198 public:
200     // Public typedefs
202         typedef polyMesh Mesh;
203         typedef polyBoundaryMesh BoundaryMesh;
206     //- Runtime type information
207     TypeName("polyMesh");
209     //- Return the default region name
210     static word defaultRegion;
212     //- Return the mesh sub-directory name (usually "polyMesh")
213     static word meshSubDir;
216     // Constructors
218         //- Construct from IOobject
219         explicit polyMesh(const IOobject& io);
221         //- Construct without boundary from components.
222         //  Boundary is added using addPatches() member function
223         polyMesh
224         (
225             const IOobject& io,
226             const Xfer<pointField>& points,
227             const Xfer<faceList>& faces,
228             const Xfer<labelList>& owner,
229             const Xfer<labelList>& neighbour,
230             const bool syncPar = true
231         );
233         //- Construct without boundary with cells rather than owner/neighbour.
234         //  Boundary is added using addPatches() member function
235         polyMesh
236         (
237             const IOobject& io,
238             const Xfer<pointField>& points,
239             const Xfer<faceList>& faces,
240             const Xfer<cellList>& cells,
241             const bool syncPar = true
242         );
244         //- Construct from cell shapes
245         polyMesh
246         (
247             const IOobject& io,
248             const Xfer<pointField>& points,
249             const cellShapeList& shapes,
250             const faceListList& boundaryFaces,
251             const wordList& boundaryPatchNames,
252             const wordList& boundaryPatchTypes,
253             const word& defaultBoundaryPatchName,
254             const word& defaultBoundaryPatchType,
255             const wordList& boundaryPatchPhysicalTypes,
256             const bool syncPar = true
257         );
260     // Destructor
262         virtual ~polyMesh();
265     // Member Functions
267         // Database
269             //- Override the objectRegistry dbDir for a single-region case
270             virtual const fileName& dbDir() const;
272             //- Return the local mesh directory (dbDir()/meshSubDir)
273             fileName meshDir() const;
275             //- Return the current instance directory for points
276             //  Used in the consruction of gemometric mesh data dependent
277             //  on points
278             const fileName& pointsInstance() const;
280             //- Return the current instance directory for faces
281             const fileName& facesInstance() const;
283             //- Set the instance for mesh files
284             void setInstance(const fileName&);
287         // Access
289             //- Return raw points
290             virtual const pointField& points() const;
292             //- Return raw faces
293             virtual const faceList& faces() const;
295             //- Return face owner
296             virtual const labelList& faceOwner() const;
298             //- Return face neighbour
299             virtual const labelList& faceNeighbour() const;
301             //- Return old points for mesh motion
302             virtual const pointField& oldPoints() const;
304             //- Return boundary mesh
305             const polyBoundaryMesh& boundaryMesh() const
306             {
307                 return boundary_;
308             }
310             //- Return mesh bounding box
311             const boundBox& bounds() const
312             {
313                 return bounds_;
314             }
316             //- Return the vector of geometric directions in mesh.
317             //  Defined according to the presence of empty and wedge patches.
318             //  1 indicates unconstrained direction and -1 a constrained
319             //  direction.
320             const Vector<label>& geometricD() const;
322             //- Return the number of valid geometric dimensions in the mesh
323             label nGeometricD() const;
325             //- Return the vector of solved-for directions in mesh.
326             //  Differs from geometricD in that it includes for wedge cases
327             //  the circumferential direction in case of swirl.
328             //  1 indicates valid direction and -1 an invalid direction.
329             const Vector<label>& solutionD() const;
331             //- Return the number of valid solved-for dimensions in the mesh
332             label nSolutionD() const;
334             //- Return point zone mesh
335             const pointZoneMesh& pointZones() const
336             {
337                 return pointZones_;
338             }
340             //- Return face zone mesh
341             const faceZoneMesh& faceZones() const
342             {
343                 return faceZones_;
344             }
346             //- Return cell zone mesh
347             const cellZoneMesh& cellZones() const
348             {
349                 return cellZones_;
350             }
352             //- Return parallel info
353             const globalMeshData& globalData() const;
355             //- Return the object registry
356             const objectRegistry& thisDb() const
357             {
358                 return *this;
359             }
361         // Mesh motion
363             //- Is mesh moving
364             bool moving() const
365             {
366                 return moving_;
367             }
369             //- Set the mesh to be moving
370             bool moving(const bool m)
371             {
372                 bool m0 = moving_;
373                 moving_ = m;
374                 changing_ = changing_ || moving_;
375                 return m0;
376             }
378             //- Is mesh changing (topology changing and/or moving)
379             bool changing() const
380             {
381                 return changing_;
382             }
384             //- Set the mesh to be changing
385             bool changing(const bool c)
386             {
387                 bool c0 = changing_;
388                 changing_ = c;
389                 return c0;
390             }
392             //- Move points, returns volumes swept by faces in motion
393             virtual tmp<scalarField> movePoints(const pointField&);
395             //- Reset motion
396             void resetMotion() const;
399         // Topological change
401             //- Return non-const access to the pointZones
402             pointZoneMesh& pointZones()
403             {
404                 return pointZones_;
405             }
407             //- Return non-const access to the faceZones
408             faceZoneMesh& faceZones()
409             {
410                 return faceZones_;
411             }
413             //- Return non-const access to the cellZones
414             cellZoneMesh& cellZones()
415             {
416                 return cellZones_;
417             }
419             //- Add boundary patches
420             void addPatches
421             (
422                 const List<polyPatch*>&,
423                 const bool validBoundary = true
424             );
426             //- Add mesh zones
427             void addZones
428             (
429                 const List<pointZone*>& pz,
430                 const List<faceZone*>& fz,
431                 const List<cellZone*>& cz
432             );
434             //- Update the mesh based on the mesh files saved in
435             //  time directories
436             virtual readUpdateState readUpdate();
438             //- Update the mesh corresponding to given map
439             virtual void updateMesh(const mapPolyMesh& mpm);
441             //- Remove boundary patches
442             void removeBoundary();
444             //- Reset mesh primitive data. Assumes all patch info correct
445             //  (so does e.g. parallel communication). If not use
446             //  validBoundary=false
447             //  (still assumes patchStarts[0] = nInternalFaces and last
448             //  patch ends at nActiveFaces) and change patches with addPatches.
449             void resetPrimitives
450             (
451                 const Xfer<pointField>& points,
452                 const Xfer<faceList>& faces,
453                 const Xfer<labelList>& owner,
454                 const Xfer<labelList>& neighbour,
455                 const labelList& patchSizes,
456                 const labelList& patchStarts,
457                 const bool validBoundary = true
458             );
461         //  Storage management
463             //- Clear geometry
464             void clearGeom();
466             //- Clear addressing
467             void clearAddressing();
469             //- Clear all geometry and addressing unnecessary for CFD
470             void clearOut();
472             //- Clear primitive data (points, faces and cells)
473             void clearPrimitives();
475             //- Remove all files from mesh instance
476             void removeFiles(const fileName& instanceDir) const;
478             //- Remove all files from mesh instance()
479             void removeFiles() const;
483 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 } // End namespace Foam
487 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
489 #endif
491 // ************************************************************************* //