OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshReader.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Namespace
00026     Foam::meshReaders
00027 
00028 Description
00029     A namespace for holding various types of mesh readers.
00030 
00031 
00032 Class
00033     Foam::meshReader
00034 
00035 Description
00036     This class supports creating polyMeshes with baffles.
00037 
00038     The derived classes are responsible for providing the protected data.
00039     This implementation is somewhat messy, but could/should be restructured
00040     to provide a more generalized reader (at the moment it has been written
00041     for converting pro-STAR data).
00042 
00043     The meshReader supports cellTable information (see new user's guide entry).
00044 
00045 Note
00046     The boundary definitions are given as cell/face.
00047 
00048 SourceFiles
00049     calcPointCells.C
00050     createPolyBoundary.C
00051     createPolyCells.C
00052     meshReader.C
00053     meshReaderAux.C
00054 
00055 \*---------------------------------------------------------------------------*/
00056 
00057 #ifndef meshReader_H
00058 #define meshReader_H
00059 
00060 #include "polyMesh.H"
00061 #include "HashTable.H"
00062 #include "IOstream.H"
00063 
00064 #include "cellTable.H"
00065 
00066 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00067 
00068 namespace Foam
00069 {
00070 
00071 /*---------------------------------------------------------------------------*\
00072                         Class meshReader Declaration
00073 \*---------------------------------------------------------------------------*/
00074 
00075 class meshReader
00076 {
00077 protected:
00078 
00079     //- Identify cell faces in terms of cell Id and face Id
00080     class cellFaceIdentifier
00081     {
00082     public:
00083         // Public data
00084 
00085             //- Cell Id
00086             label cell;
00087 
00088             //- Face Id
00089             label face;
00090 
00091 
00092         // Constructors
00093 
00094             //- Construct null
00095             cellFaceIdentifier() : cell(-1), face(-1) {}
00096 
00097             //- Construct from cell/face components
00098             cellFaceIdentifier(label c, label f) : cell(c), face(f) {}
00099 
00100 
00101         // Check
00102 
00103             //- Used if cell or face are non-negative
00104             bool used() const
00105             {
00106                 return (cell >= 0 && face >= 0);
00107             }
00108 
00109             //- Unused if cell or face are negative
00110             bool unused() const
00111             {
00112                 return (cell < 0 || face < 0);
00113             }
00114 
00115 
00116         // Member Operators
00117 
00118             bool operator!=(const cellFaceIdentifier& cf) const
00119             {
00120                 return (cell != cf.cell || face != cf.face);
00121             }
00122 
00123             bool operator==(const cellFaceIdentifier& cf) const
00124             {
00125                 return (cell == cf.cell && face == cf.face);
00126             }
00127 
00128         // IOstream Operators
00129 
00130             friend Ostream& operator<<
00131             (
00132                 Ostream& os,
00133                 const cellFaceIdentifier& cf
00134             )
00135             {
00136                 os << "(" << cf.cell << "/" << cf.face << ")";
00137                 return os;
00138             }
00139         };
00140 
00141 
00142 private:
00143 
00144     // Private data
00145 
00146         //- Point-cell addressing. Used for topological analysis
00147         // Warning. This point cell addressing list potentially contains
00148         // duplicate cell entries. Use additional checking
00149         mutable labelListList* pointCellsPtr_;
00150 
00151         //- Number of internal faces for polyMesh
00152         label nInternalFaces_;
00153 
00154         //- Polyhedral mesh boundary patch start indices and dimensions
00155         labelList patchStarts_;
00156         labelList patchSizes_;
00157 
00158         //- association between two faces
00159         List<labelPair> interfaces_;
00160 
00161         //- list of cells/faces id pairs for each baffle
00162         List<List<cellFaceIdentifier> > baffleIds_;
00163 
00164         //- Global face list for polyMesh
00165         faceList meshFaces_;
00166 
00167         //- Cells as polyhedra for polyMesh
00168         cellList cellPolys_;
00169 
00170         //- Face sets for monitoring
00171         HashTable<List<label>, word, string::hash> monitoringSets_;
00172 
00173 
00174     // Private Member Functions
00175 
00176         //- Disallow default bitwise copy construct
00177         meshReader(const meshReader&);
00178 
00179         //- Disallow default bitwise assignment
00180         void operator=(const meshReader&);
00181 
00182         //- Calculate pointCells
00183         void calcPointCells() const;
00184 
00185         const labelListList& pointCells() const;
00186 
00187         //- Make polyhedral cells and global faces if the mesh is polyhedral
00188         void createPolyCells();
00189 
00190         //- Add in boundary face
00191         void addPolyBoundaryFace
00192         (
00193             const label cellId,
00194             const label cellFaceId,
00195             const label nCreatedFaces
00196         );
00197 
00198         //- Add in boundary face
00199         void addPolyBoundaryFace
00200         (
00201             const cellFaceIdentifier& identifier,
00202             const label nCreatedFaces
00203         );
00204 
00205         //- Add cellZones based on cellTable Id
00206         void addCellZones(polyMesh&) const;
00207 
00208         //- Add faceZones based on monitoring boundary conditions
00209         void addFaceZones(polyMesh&) const;
00210 
00211         //- Make polyhedral boundary from shape boundary
00212         // (adds more faces to the face list)
00213         void createPolyBoundary();
00214 
00215         //- Add polyhedral boundary
00216         List<polyPatch*> polyBoundaryPatches(const polyMesh&);
00217 
00218         //- Clear extra storage before creation of the mesh to remove
00219         //  a memory peak
00220         void clearExtraStorage();
00221 
00222         void writeInterfaces(const objectRegistry&) const;
00223 
00224         //- Write List<label> in constant/polyMesh
00225         void writeMeshLabelList
00226         (
00227             const objectRegistry& registry,
00228             const word& propertyName,
00229             const labelList& list,
00230             IOstream::streamFormat fmt = IOstream::ASCII
00231         ) const;
00232 
00233         //- Return list of faces for every cell
00234         faceListList& cellFaces() const
00235         {
00236             return const_cast<faceListList&>(cellFaces_);
00237         }
00238 
00239 
00240 protected:
00241 
00242     // Protected data
00243 
00244         //- Pointers to cell shape models
00245         static const cellModel* unknownModel;
00246         static const cellModel* tetModel;
00247         static const cellModel* pyrModel;
00248         static const cellModel* prismModel;
00249         static const cellModel* hexModel;
00250 
00251         //- Referenced filename
00252         fileName geometryFile_;
00253 
00254         //- Geometry scaling
00255         scalar scaleFactor_;
00256 
00257         //- Points supporting the mesh
00258         pointField points_;
00259 
00260         //- Lookup original Cell number for a given cell
00261         labelList origCellId_;
00262 
00263         //- Identify boundary faces by cells and their faces
00264         //  for each patch
00265         List<List<cellFaceIdentifier> > boundaryIds_;
00266 
00267         //- Boundary patch types
00268         wordList patchTypes_;
00269 
00270         //- Boundary patch names
00271         wordList patchNames_;
00272 
00273         //- Boundary patch physical types
00274         wordList patchPhysicalTypes_;
00275 
00276         //- List of faces for every cell
00277         faceListList cellFaces_;
00278 
00279         //- List of each baffle face
00280         faceList baffleFaces_;
00281 
00282         //- Cell table id for each cell
00283         labelList cellTableId_;
00284 
00285         //- Cell table persistent data saved as a dictionary
00286         cellTable cellTable_;
00287 
00288 
00289     // Member Functions
00290 
00291         //- Subclasses are required to supply this information
00292         virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
00293 
00294 public:
00295 
00296     // Static Members
00297 
00298         //- Warn about repeated names
00299         static void warnDuplicates(const word& context, const wordList&);
00300 
00301 
00302     // Constructors
00303 
00304         //- Construct from fileName
00305         meshReader(const fileName&, const scalar scaleFactor = 1.0);
00306 
00307 
00308     //- Destructor
00309     virtual ~meshReader();
00310 
00311 
00312     // Member Functions
00313 
00314         //- Create and return polyMesh
00315         virtual autoPtr<polyMesh> mesh(const objectRegistry&);
00316 
00317         //- Write auxiliary information
00318         void writeAux(const objectRegistry&) const;
00319 
00320         //- Write mesh
00321         void writeMesh
00322         (
00323             const polyMesh&,
00324             IOstream::streamFormat fmt = IOstream::BINARY
00325         ) const;
00326 };
00327 
00328 
00329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00330 
00331 } // End namespace Foam
00332 
00333 #endif
00334 
00335 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd