initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / conversion / meshReader / meshReader.H
blob1d2b875465361da261fbf34e549754fb6ec0135f
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 Namespace
26     Foam::meshReaders
28 Description
29     A namespace for holding various types of mesh readers.
32 Class
33     Foam::meshReader
35 Description
36     This class supports creating polyMeshes with baffles.
38     The derived classes are responsible for providing the protected data.
39     This implementation is somewhat messy, but could/should be restructured
40     to provide a more generalized reader (at the moment it has been written
41     for converting pro-STAR data).
43     The meshReader supports cellTable information (see new user's guide entry).
45 Note
46     The boundary definitions are given as cell/face.
48 SourceFiles
49     calcPointCells.C
50     createPolyBoundary.C
51     createPolyCells.C
52     meshReader.C
53     meshReaderAux.C
55 \*---------------------------------------------------------------------------*/
57 #ifndef meshReader_H
58 #define meshReader_H
60 #include "polyMesh.H"
61 #include "HashTable.H"
62 #include "IOstream.H"
64 #include "cellTable.H"
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 namespace Foam
71 /*---------------------------------------------------------------------------*\
72                         Class meshReader Declaration
73 \*---------------------------------------------------------------------------*/
75 class meshReader
77 protected:
79     //- Identify cell faces in terms of cell Id and face Id
80     class cellFaceIdentifier
81     {
82     public:
83         // Public data
85             //- Cell Id
86             label cell;
88             //- Face Id
89             label face;
92         // Constructors
94             //- Construct null
95             cellFaceIdentifier() : cell(-1), face(-1) {}
97             //- Construct from cell/face components
98             cellFaceIdentifier(label c, label f) : cell(c), face(f) {}
101         // Check
103             //- Used if cell or face are non-negative
104             bool used() const
105             {
106                 return (cell >= 0 && face >= 0);
107             }
109             //- Unused if cell or face are negative
110             bool unused() const
111             {
112                 return (cell < 0 || face < 0);
113             }
116         // Member Operators
118             bool operator!=(const cellFaceIdentifier& cf) const
119             {
120                 return (cell != cf.cell || face != cf.face);
121             }
123             bool operator==(const cellFaceIdentifier& cf) const
124             {
125                 return (cell == cf.cell && face == cf.face);
126             }
128         // IOstream Operators
130             friend Ostream& operator<<
131             (
132                 Ostream& os,
133                 const cellFaceIdentifier& cf
134             )
135             {
136                 os << "(" << cf.cell << "/" << cf.face << ")";
137                 return os;
138             }
139         };
142 private:
144     // Private data
146         //- Point-cell addressing. Used for topological analysis
147         // Warning. This point cell addressing list potentially contains
148         // duplicate cell entries. Use additional checking
149         mutable labelListList* pointCellsPtr_;
151         //- Number of internal faces for polyMesh
152         label nInternalFaces_;
154         //- Polyhedral mesh boundary patch start indices and dimensions
155         labelList patchStarts_;
156         labelList patchSizes_;
158         //- association between two faces
159         List<labelPair> interfaces_;
161         //- list of cells/faces id pairs for each baffle
162         List<List<cellFaceIdentifier> > baffleIds_;
164         //- Global face list for polyMesh
165         faceList meshFaces_;
167         //- Cells as polyhedra for polyMesh
168         cellList cellPolys_;
170         //- Face sets for monitoring
171         HashTable<List<label>, word, string::hash> monitoringSets_;
174     // Private Member Functions
176         //- Disallow default bitwise copy construct
177         meshReader(const meshReader&);
179         //- Disallow default bitwise assignment
180         void operator=(const meshReader&);
182         //- Calculate pointCells
183         void calcPointCells() const;
185         const labelListList& pointCells() const;
187         //- Make polyhedral cells and global faces if the mesh is polyhedral
188         void createPolyCells();
190         //- Add in boundary face
191         void addPolyBoundaryFace
192         (
193             const label cellId,
194             const label cellFaceId,
195             const label nCreatedFaces
196         );
198         //- Add in boundary face
199         void addPolyBoundaryFace
200         (
201             const cellFaceIdentifier& identifier,
202             const label nCreatedFaces
203         );
205         //- Add cellZones based on cellTable Id
206         void addCellZones(polyMesh&) const;
208         //- Add faceZones based on monitoring boundary conditions
209         void addFaceZones(polyMesh&) const;
211         //- Make polyhedral boundary from shape boundary
212         // (adds more faces to the face list)
213         void createPolyBoundary();
215         //- Add polyhedral boundary
216         List<polyPatch*> polyBoundaryPatches(const polyMesh&);
218         //- Clear extra storage before creation of the mesh to remove
219         //  a memory peak
220         void clearExtraStorage();
222         void writeInterfaces(const objectRegistry&) const;
224         //- Write List<label> in constant/polyMesh
225         void writeMeshLabelList
226         (
227             const objectRegistry& registry,
228             const word& propertyName,
229             const labelList& list,
230             IOstream::streamFormat fmt = IOstream::ASCII
231         ) const;
233         //- Return list of faces for every cell
234         faceListList& cellFaces() const
235         {
236             return const_cast<faceListList&>(cellFaces_);
237         }
240 protected:
242     // Protected data
244         //- Pointers to cell shape models
245         static const cellModel* unknownModel;
246         static const cellModel* tetModel;
247         static const cellModel* pyrModel;
248         static const cellModel* prismModel;
249         static const cellModel* hexModel;
251         //- Referenced filename
252         fileName geometryFile_;
254         //- Geometry scaling
255         scalar scaleFactor_;
257         //- Points supporting the mesh
258         pointField points_;
260         //- Lookup original Cell number for a given cell
261         labelList origCellId_;
263         //- Identify boundary faces by cells and their faces
264         //  for each patch
265         List<List<cellFaceIdentifier> > boundaryIds_;
267         //- Boundary patch types
268         wordList patchTypes_;
270         //- Boundary patch names
271         wordList patchNames_;
273         //- Boundary patch physical types
274         wordList patchPhysicalTypes_;
276         //- List of faces for every cell
277         faceListList cellFaces_;
279         //- List of each baffle face
280         faceList baffleFaces_;
282         //- Cell table id for each cell
283         labelList cellTableId_;
285         //- Cell table persistent data saved as a dictionary
286         cellTable cellTable_;
289     // Member Functions
291         //- Subclasses are required to supply this information
292         virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
294 public:
296     // Static Members
298         //- Warn about repeated names
299         static void warnDuplicates(const word& context, const wordList&);
302     // Constructors
304         //- Construct from fileName
305         meshReader(const fileName&, const scalar scaleFactor = 1.0);
308     //- Destructor
309     virtual ~meshReader();
312     // Member Functions
314         //- Create and return polyMesh
315         virtual autoPtr<polyMesh> mesh(const objectRegistry&);
317         //- Write auxiliary information
318         void writeAux(const objectRegistry&) const;
320         //- Write mesh
321         void writeMesh
322         (
323             const polyMesh&,
324             IOstream::streamFormat fmt = IOstream::BINARY
325         ) const;
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 } // End namespace Foam
333 #endif
335 // ************************************************************************* //