meshReader.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Namespace
25  Foam::meshReaders
26 
27 Description
28  A namespace for holding various types of mesh readers.
29 
30 
31 Class
32  Foam::meshReader
33 
34 Description
35  This class supports creating polyMeshes with baffles.
36 
37  The derived classes are responsible for providing the protected data.
38  This implementation is somewhat messy, but could/should be restructured
39  to provide a more generalized reader (at the moment it has been written
40  for converting pro-STAR data).
41 
42  The meshReader supports cellTable information (see new user's guide entry).
43 
44 Note
45  The boundary definitions are given as cell/face.
46 
47 SourceFiles
48  calcPointCells.C
49  createPolyBoundary.C
50  createPolyCells.C
51  meshReader.C
52  meshReaderAux.C
53 
54 \*---------------------------------------------------------------------------*/
55 
56 #ifndef meshReader_H
57 #define meshReader_H
58 
59 #include "polyMesh.H"
60 #include "HashTable.H"
61 #include "IOstream.H"
62 
63 #include "cellTable.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 /*---------------------------------------------------------------------------*\
71  Class meshReader Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 class meshReader
75 {
76 protected:
77 
78  //- Identify cell faces in terms of cell Id and face Id
79  class cellFaceIdentifier
80  {
81  public:
82  // Public data
83 
84  //- Cell Id
85  label cell;
86 
87  //- Face Id
88  label face;
89 
90 
91  // Constructors
92 
93  //- Construct null
94  cellFaceIdentifier() : cell(-1), face(-1) {}
95 
96  //- Construct from cell/face components
98 
99 
100  // Check
101 
102  //- Used if cell or face are non-negative
103  bool used() const
104  {
105  return (cell >= 0 && face >= 0);
106  }
107 
108  //- Unused if cell or face are negative
109  bool unused() const
110  {
111  return (cell < 0 || face < 0);
112  }
113 
114 
115  // Member Operators
116 
117  bool operator!=(const cellFaceIdentifier& cf) const
118  {
119  return (cell != cf.cell || face != cf.face);
120  }
121 
122  bool operator==(const cellFaceIdentifier& cf) const
123  {
124  return (cell == cf.cell && face == cf.face);
125  }
126 
127  // IOstream Operators
128 
129  friend Ostream& operator<<
130  (
131  Ostream& os,
132  const cellFaceIdentifier& cf
133  )
134  {
135  os << "(" << cf.cell << "/" << cf.face << ")";
136  return os;
137  }
138  };
139 
140 
141 private:
142 
143  // Private data
144 
145  //- Point-cell addressing. Used for topological analysis
146  // Warning. This point cell addressing list potentially contains
147  // duplicate cell entries. Use additional checking
148  mutable labelListList* pointCellsPtr_;
149 
150  //- Number of internal faces for polyMesh
152 
153  //- Polyhedral mesh boundary patch start indices and dimensions
156 
157  //- Association between two faces
159 
160  //- List of cells/faces id pairs for each baffle
162 
163  //- Global face list for polyMesh
165 
166  //- Cells as polyhedra for polyMesh
168 
169  //- Face sets for monitoring
171 
172 
173  // Private Member Functions
174 
175  //- Disallow default bitwise copy construct
176  meshReader(const meshReader&);
177 
178  //- Disallow default bitwise assignment
179  void operator=(const meshReader&);
180 
181  //- Calculate pointCells
182  void calcPointCells() const;
183 
184  const labelListList& pointCells() const;
185 
186  //- Make polyhedral cells and global faces if the mesh is polyhedral
187  void createPolyCells();
188 
189  //- Add in boundary face
191  (
192  const label cellId,
193  const label cellFaceId,
194  const label nCreatedFaces
195  );
196 
197  //- Add in boundary face
199  (
200  const cellFaceIdentifier& identifier,
201  const label nCreatedFaces
202  );
203 
204  //- Add cellZones based on cellTable Id
205  void addCellZones(polyMesh&) const;
206 
207  //- Add faceZones based on monitoring boundary conditions
208  void addFaceZones(polyMesh&) const;
209 
210  //- Make polyhedral boundary from shape boundary
211  // (adds more faces to the face list)
212  void createPolyBoundary();
213 
214  //- Add polyhedral boundary
216 
217  //- Clear extra storage before creation of the mesh to remove
218  // a memory peak
219  void clearExtraStorage();
220 
221  void writeInterfaces(const objectRegistry&) const;
222 
223  //- Write List<label> in constant/polyMesh
224  void writeMeshLabelList
225  (
226  const objectRegistry& registry,
227  const word& propertyName,
228  const labelList& list,
230  ) const;
231 
232  //- Return list of faces for every cell
233  faceListList& cellFaces() const
234  {
235  return const_cast<faceListList&>(cellFaces_);
236  }
237 
238 
239 protected:
240 
241  // Protected data
242 
243  //- Pointers to cell shape models
244  static const cellModel* unknownModel;
245  static const cellModel* tetModel;
246  static const cellModel* pyrModel;
247  static const cellModel* prismModel;
248  static const cellModel* hexModel;
249 
250  //- Referenced filename
252 
253  //- Geometry scaling
254  scalar scaleFactor_;
255 
256  //- Points supporting the mesh
258 
259  //- Lookup original Cell number for a given cell
261 
262  //- Identify boundary faces by cells and their faces
263  // for each patch
265 
266  //- Boundary patch types
268 
269  //- Boundary patch names
271 
272  //- Boundary patch physical types
274 
275  //- List of faces for every cell
277 
278  //- List of each baffle face
280 
281  //- Cell table id for each cell
283 
284  //- Cell table persistent data saved as a dictionary
286 
287 
288  // Member Functions
289 
290  //- Subclasses are required to supply this information
291  virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
292 
293 public:
294 
295  // Static Members
296 
297  //- Warn about repeated names
298  static void warnDuplicates(const word& context, const wordList&);
299 
300 
301  // Constructors
302 
303  //- Construct from fileName
304  meshReader(const fileName&, const scalar scaleFactor = 1.0);
305 
306 
307  //- Destructor
308  virtual ~meshReader();
309 
310 
311  // Member Functions
312 
313  //- Create and return polyMesh
314  virtual autoPtr<polyMesh> mesh(const objectRegistry&);
315 
316  //- Write auxiliary information
317  void writeAux(const objectRegistry&) const;
318 
319  //- Write mesh
320  void writeMesh
321  (
322  const polyMesh&,
324  ) const;
325 };
326 
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 } // End namespace Foam
331 
332 #endif
333 
334 // ************************************************************************* //
Foam::meshReader::cellFaceIdentifier::used
bool used() const
Used if cell or face are non-negative.
Definition: meshReader.H:102
Foam::meshReader::cellFaceIdentifier::face
label face
Face Id.
Definition: meshReader.H:87
Foam::meshReader::addPolyBoundaryFace
void addPolyBoundaryFace(const label cellId, const label cellFaceId, const label nCreatedFaces)
Add in boundary face.
Definition: createPolyBoundary.C:45
Foam::meshReader::warnDuplicates
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
Foam::meshReader::addCellZones
void addCellZones(polyMesh &) const
Add cellZones based on cellTable Id.
Definition: meshReader.C:69
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
HashTable.H
Foam::meshReader::cellPolys_
cellList cellPolys_
Cells as polyhedra for polyMesh.
Definition: meshReader.H:166
Foam::meshReader::cellFaceIdentifier::cellFaceIdentifier
cellFaceIdentifier()
Construct null.
Definition: meshReader.H:93
Foam::meshReader::monitoringSets_
HashTable< List< label >, word, string::hash > monitoringSets_
Face sets for monitoring.
Definition: meshReader.H:169
Foam::meshReader::readGeometry
virtual bool readGeometry(const scalar scaleFactor=1.0)=0
Subclasses are required to supply this information.
Foam::meshReader::createPolyBoundary
void createPolyBoundary()
Make polyhedral boundary from shape boundary.
Definition: createPolyBoundary.C:99
Foam::meshReader::patchNames_
wordList patchNames_
Boundary patch names.
Definition: meshReader.H:269
Foam::meshReader::pyrModel
static const cellModel * pyrModel
Definition: meshReader.H:245
Foam::meshReader::patchStarts_
labelList patchStarts_
Polyhedral mesh boundary patch start indices and dimensions.
Definition: meshReader.H:153
Foam::meshReader::unknownModel
static const cellModel * unknownModel
Pointers to cell shape models.
Definition: meshReader.H:243
Foam::meshReader::patchTypes_
wordList patchTypes_
Boundary patch types.
Definition: meshReader.H:266
Foam::meshReader::cellFaceIdentifier
Identify cell faces in terms of cell Id and face Id.
Definition: meshReader.H:78
Foam::meshReader::patchPhysicalTypes_
wordList patchPhysicalTypes_
Boundary patch physical types.
Definition: meshReader.H:272
Foam::meshReader::patchSizes_
labelList patchSizes_
Definition: meshReader.H:154
cellTable.H
Foam::meshReader::baffleIds_
List< List< cellFaceIdentifier > > baffleIds_
List of cells/faces id pairs for each baffle.
Definition: meshReader.H:160
Foam::meshReader::cellTableId_
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:281
Foam::meshReader::boundaryIds_
List< List< cellFaceIdentifier > > boundaryIds_
Identify boundary faces by cells and their faces.
Definition: meshReader.H:263
Foam::meshReader::writeInterfaces
void writeInterfaces(const objectRegistry &) const
Definition: meshReaderAux.C:75
polyMesh.H
Foam::meshReader::cellTable_
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:284
Foam::meshReader::baffleFaces_
faceList baffleFaces_
List of each baffle face.
Definition: meshReader.H:278
Foam::meshReader::cellFaceIdentifier::operator==
bool operator==(const cellFaceIdentifier &cf) const
Definition: meshReader.H:121
Foam::meshReader::pointCells
const labelListList & pointCells() const
Definition: calcPointCells.C:161
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::meshReader::cellFaceIdentifier::cellFaceIdentifier
cellFaceIdentifier(label c, label f)
Construct from cell/face components.
Definition: meshReader.H:96
Foam::meshReader::origCellId_
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:259
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::meshReader::cellFaceIdentifier::operator!=
bool operator!=(const cellFaceIdentifier &cf) const
Definition: meshReader.H:116
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::meshReader::operator=
void operator=(const meshReader &)
Disallow default bitwise assignment.
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::meshReader::interfaces_
List< labelPair > interfaces_
Association between two faces.
Definition: meshReader.H:157
Foam::meshReader::meshReader
meshReader(const meshReader &)
Disallow default bitwise copy construct.
Foam::meshReader::clearExtraStorage
void clearExtraStorage()
Clear extra storage before creation of the mesh to remove.
Definition: meshReader.C:181
Foam::cellTable
The cellTable persistent data saved as a Map<dictionary>.
Definition: cellTable.H:77
IOstream.H
Foam::meshReader::tetModel
static const cellModel * tetModel
Definition: meshReader.H:244
Foam::meshReader::scaleFactor_
scalar scaleFactor_
Geometry scaling.
Definition: meshReader.H:253
Foam::meshReader::cellFaceIdentifier::unused
bool unused() const
Unused if cell or face are negative.
Definition: meshReader.H:108
Foam::meshReader::addFaceZones
void addFaceZones(polyMesh &) const
Add faceZones based on monitoring boundary conditions.
Definition: meshReader.C:76
Foam::meshReader::mesh
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:120
Foam::meshReader::hexModel
static const cellModel * hexModel
Definition: meshReader.H:247
Foam::meshReader::cellFaceIdentifier::cell
label cell
Cell Id.
Definition: meshReader.H:84
Foam::IOstream::BINARY
@ BINARY
Definition: IOstream.H:89
Foam::meshReader::~meshReader
virtual ~meshReader()
Destructor.
Definition: meshReader.C:225
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::meshReader::calcPointCells
void calcPointCells() const
Calculate pointCells.
Definition: calcPointCells.C:34
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::meshReader::meshFaces_
faceList meshFaces_
Global face list for polyMesh.
Definition: meshReader.H:163
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::meshReader::writeMeshLabelList
void writeMeshLabelList(const objectRegistry &registry, const word &propertyName, const labelList &list, IOstream::streamFormat fmt=IOstream::ASCII) const
Write List<label> in constant/polyMesh.
Definition: meshReaderAux.C:105
Foam::meshReader
This class supports creating polyMeshes with baffles.
Definition: meshReader.H:73
Foam::string::hash
Hashing function class, shared by all the derived classes.
Definition: string.H:90
Foam::meshReader::writeAux
void writeAux(const objectRegistry &) const
Write auxiliary information.
Definition: meshReaderAux.C:147
Foam::meshReader::pointCellsPtr_
labelListList * pointCellsPtr_
Point-cell addressing. Used for topological analysis.
Definition: meshReader.H:147
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::meshReader::geometryFile_
fileName geometryFile_
Referenced filename.
Definition: meshReader.H:250
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::cellModel
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::meshReader::prismModel
static const cellModel * prismModel
Definition: meshReader.H:246
Foam::meshReader::points_
pointField points_
Points supporting the mesh.
Definition: meshReader.H:256
Foam::meshReader::cellFaces
faceListList & cellFaces() const
Return list of faces for every cell.
Definition: meshReader.H:232
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::meshReader::nInternalFaces_
label nInternalFaces_
Number of internal faces for polyMesh.
Definition: meshReader.H:150
Foam::meshReader::writeMesh
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:163
Foam::meshReader::polyBoundaryPatches
List< polyPatch * > polyBoundaryPatches(const polyMesh &)
Add polyhedral boundary.
Definition: createPolyBoundary.C:373
Foam::meshReader::createPolyCells
void createPolyCells()
Make polyhedral cells and global faces if the mesh is polyhedral.
Definition: createPolyCells.C:40
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Foam::meshReader::cellFaces_
faceListList cellFaces_
List of faces for every cell.
Definition: meshReader.H:275