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