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-2016 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
97  cellFaceIdentifier(label c, label f) : cell(c), face(f) {}
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
117  bool operator!=(const cellFaceIdentifier& cf) const
118  {
119  return (cell != cf.cell || face != cf.face);
120  }
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
151  label nInternalFaces_;
152 
153  //- Polyhedral mesh boundary patch start indices and dimensions
154  labelList patchStarts_;
155  labelList patchSizes_;
156 
157  //- Association between two faces
158  List<labelPair> interfaces_;
159 
160  //- List of cells/faces id pairs for each baffle
161  List<List<cellFaceIdentifier>> baffleIds_;
162 
163  //- Global face list for polyMesh
164  faceList meshFaces_;
165 
166  //- Cells as polyhedra for polyMesh
167  cellList cellPolys_;
168 
169  //- Face sets for monitoring
170  HashTable<List<label>, word, string::hash> monitoringSets_;
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
190  void addPolyBoundaryFace
191  (
192  const label cellId,
193  const label cellFaceId,
194  const label nCreatedFaces
195  );
196 
197  //- Add in boundary face
198  void addPolyBoundaryFace
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
215  List<polyPatch*> polyBoundaryPatches(const polyMesh&);
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 member 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  // Protected member functions
289 
290  //- Subclasses are required to supply this information
291  virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
292 
293 
294 public:
295 
296  // Static Members
297 
298  //- Warn about repeated names
299  static void warnDuplicates(const word& context, const wordList&);
300 
301 
302  // Constructors
303 
304  //- Construct from fileName
305  meshReader(const fileName&, const scalar scaleFactor = 1.0);
306 
307 
308  //- Destructor
309  virtual ~meshReader();
310 
311 
312  // Member Functions
313 
314  //- Create and return polyMesh
315  virtual autoPtr<polyMesh> mesh(const objectRegistry&);
316 
317  //- Write auxiliary information
318  void writeAux(const objectRegistry&) const;
319 
320  //- Write mesh
321  void writeMesh
322  (
323  const polyMesh&,
325  ) const;
326 };
327 
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 } // End namespace Foam
332 
333 #endif
334 
335 // ************************************************************************* //
static const cellModel * tetModel
Definition: meshReader.H:244
Hashing function class, shared by all the derived classes.
Definition: string.H:90
bool operator!=(const cellFaceIdentifier &cf) const
Definition: meshReader.H:116
List< List< cellFaceIdentifier > > boundaryIds_
Identify boundary faces by cells and their faces.
Definition: meshReader.H:263
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
wordList patchPhysicalTypes_
Boundary patch physical types.
Definition: meshReader.H:272
A class for handling file names.
Definition: fileName.H:69
virtual bool readGeometry(const scalar scaleFactor=1.0)=0
Subclasses are required to supply this information.
wordList patchTypes_
Boundary patch types.
Definition: meshReader.H:266
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
Identify cell faces in terms of cell Id and face Id.
Definition: meshReader.H:78
static const cellModel * prismModel
Definition: meshReader.H:246
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:163
pointField points_
Points supporting the mesh.
Definition: meshReader.H:256
static const cellModel * unknownModel
Pointers to cell shape models.
Definition: meshReader.H:243
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:259
wordList patchNames_
Boundary patch names.
Definition: meshReader.H:269
bool used() const
Used if cell or face are non-negative.
Definition: meshReader.H:102
A class for handling words, derived from string.
Definition: word.H:59
virtual ~meshReader()
Destructor.
Definition: meshReader.C:226
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
static const cellModel * pyrModel
Definition: meshReader.H:245
An STL-conforming hash table.
Definition: HashTable.H:62
The cellTable persistent data saved as a Map<dictionary>.
Definition: cellTable.H:77
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:120
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
labelList f(nPoints)
bool operator==(const cellFaceIdentifier &cf) const
Definition: meshReader.H:121
cellFaceIdentifier()
Construct null.
Definition: meshReader.H:93
scalar scaleFactor_
Geometry scaling.
Definition: meshReader.H:253
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:284
fileName geometryFile_
Referenced filename.
Definition: meshReader.H:250
faceList baffleFaces_
List of each baffle face.
Definition: meshReader.H:278
static const cellModel * hexModel
Definition: meshReader.H:247
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:281
const dimensionedScalar c
Speed of light in a vacuum.
label cellId
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
void writeAux(const objectRegistry &) const
Write auxiliary information.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Registry of regIOobjects.
faceListList cellFaces_
List of faces for every cell.
Definition: meshReader.H:275
bool unused() const
Unused if cell or face are negative.
Definition: meshReader.H:108
This class supports creating polyMeshes with baffles.
Definition: meshReader.H:73
Namespace for OpenFOAM.