All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
meshReader.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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  //- Calculate pointCells
176  void calcPointCells() const;
177 
178  const labelListList& pointCells() const;
179 
180  //- Make polyhedral cells and global faces if the mesh is polyhedral
181  void createPolyCells();
182 
183  //- Add in boundary face
184  void addPolyBoundaryFace
185  (
186  const label cellId,
187  const label cellFaceId,
188  const label nCreatedFaces
189  );
190 
191  //- Add in boundary face
192  void addPolyBoundaryFace
193  (
194  const cellFaceIdentifier& identifier,
195  const label nCreatedFaces
196  );
197 
198  //- Add cellZones based on cellTable Id
199  void addCellZones(polyMesh&) const;
200 
201  //- Add faceZones based on monitoring boundary conditions
202  void addFaceZones(polyMesh&) const;
203 
204  //- Make polyhedral boundary from shape boundary
205  // (adds more faces to the face list)
206  void createPolyBoundary();
207 
208  //- Add polyhedral boundary
209  List<polyPatch*> polyBoundaryPatches(const polyMesh&);
210 
211  //- Clear extra storage before creation of the mesh to remove
212  // a memory peak
213  void clearExtraStorage();
214 
215  void writeInterfaces(const objectRegistry&) const;
216 
217  //- Write List<label> in constant/polyMesh
218  void writeMeshLabelList
219  (
220  const objectRegistry& registry,
221  const word& propertyName,
222  const labelList& list,
224  ) const;
225 
226  //- Return list of faces for every cell
227  faceListList& cellFaces() const
228  {
229  return const_cast<faceListList&>(cellFaces_);
230  }
231 
232 
233 protected:
234 
235  // Protected member data
236 
237  //- Pointers to cell shape models
238  static const cellModel* unknownModel;
239  static const cellModel* tetModel;
240  static const cellModel* pyrModel;
241  static const cellModel* prismModel;
242  static const cellModel* hexModel;
243 
244  //- Referenced filename
246 
247  //- Geometry scaling
248  scalar scaleFactor_;
249 
250  //- Points supporting the mesh
252 
253  //- Lookup original Cell number for a given cell
255 
256  //- Identify boundary faces by cells and their faces
257  // for each patch
259 
260  //- Boundary patch types
262 
263  //- Boundary patch names
265 
266  //- Boundary patch physical types
268 
269  //- List of faces for every cell
271 
272  //- List of each baffle face
274 
275  //- Cell table id for each cell
277 
278  //- Cell table persistent data saved as a dictionary
280 
281 
282  // Protected member functions
283 
284  //- Subclasses are required to supply this information
285  virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
286 
287 
288 public:
289 
290  // Static Members
291 
292  //- Warn about repeated names
293  static void warnDuplicates(const word& context, const wordList&);
294 
295 
296  // Constructors
297 
298  //- Construct from fileName
299  meshReader(const fileName&, const scalar scaleFactor = 1.0);
300 
301  //- Disallow default bitwise copy construction
302  meshReader(const meshReader&) = delete;
303 
304 
305  //- Destructor
306  virtual ~meshReader();
307 
308 
309  // Member Functions
310 
311  //- Create and return polyMesh
312  virtual autoPtr<polyMesh> mesh(const objectRegistry&);
313 
314  //- Write auxiliary information
315  void writeAux(const objectRegistry&) const;
316 
317  //- Write mesh
318  void writeMesh
319  (
320  const polyMesh&,
322  ) const;
323 
324 
325  // Member Operators
326 
327  //- Disallow default bitwise assignment
328  void operator=(const meshReader&) = delete;
329 };
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 } // End namespace Foam
335 
336 #endif
337 
338 // ************************************************************************* //
static const cellModel * tetModel
Definition: meshReader.H:238
Hashing function class, shared by all the derived classes.
Definition: string.H:92
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:257
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:266
A class for handling file names.
Definition: fileName.H:79
virtual bool readGeometry(const scalar scaleFactor=1.0)=0
Subclasses are required to supply this information.
wordList patchTypes_
Boundary patch types.
Definition: meshReader.H:260
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:240
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:167
const dimensionedScalar & c
Speed of light in a vacuum.
pointField points_
Points supporting the mesh.
Definition: meshReader.H:250
static const cellModel * unknownModel
Pointers to cell shape models.
Definition: meshReader.H:237
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:253
wordList patchNames_
Boundary patch names.
Definition: meshReader.H:263
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:230
meshReader(const fileName &, const scalar scaleFactor=1.0)
Construct from fileName.
Definition: meshReader.C:200
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
static const cellModel * pyrModel
Definition: meshReader.H:239
An STL-conforming hash table.
Definition: HashTable.H:61
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:121
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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:247
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:278
fileName geometryFile_
Referenced filename.
Definition: meshReader.H:244
faceList baffleFaces_
List of each baffle face.
Definition: meshReader.H:272
static const cellModel * hexModel
Definition: meshReader.H:241
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:275
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:269
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
void operator=(const meshReader &)=delete
Disallow default bitwise assignment.
Namespace for OpenFOAM.