meshReader.C
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-2020 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 \*---------------------------------------------------------------------------*/
25 
26 #include "meshReader.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 #include "faceSet.H"
30 #include "emptyPolyPatch.H"
31 #include "cellModeller.H"
32 #include "demandDrivenData.H"
33 #include "polyMeshUnMergeCyclics.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
38 lookup
39 (
40  "unknown"
41 );
42 
43 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
44 lookup
45 (
46  "tet"
47 );
48 
49 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
50 lookup
51 (
52  "pyr"
53 );
54 
55 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
56 lookup
57 (
58  "prism"
59 );
60 
61 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
62 lookup
63 (
64  "hex"
65 );
66 
67 
68 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
69 
70 void Foam::meshReader::addCellZones(polyMesh& mesh) const
71 {
73  warnDuplicates("cellZones", mesh.cellZones().names());
74 }
75 
76 
77 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
78 {
79  label nZone = monitoringSets_.size();
80  mesh.faceZones().setSize(nZone);
81 
82  if (!nZone)
83  {
84  return;
85  }
86 
87  nZone = 0;
88  for
89  (
90  HashTable<List<label>, word, string::hash>::const_iterator
91  iter = monitoringSets_.begin();
92  iter != monitoringSets_.end();
93  ++iter
94  )
95  {
96  Info<< "faceZone " << nZone
97  << " (size: " << iter().size() << ") name: "
98  << iter.key() << endl;
99 
100  mesh.faceZones().set
101  (
102  nZone,
103  new faceZone
104  (
105  iter.key(),
106  iter(),
107  List<bool>(iter().size(), false),
108  nZone,
109  mesh.faceZones()
110  )
111  );
112 
113  nZone++;
114  }
115  mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
116  warnDuplicates("faceZones", mesh.faceZones().names());
117 }
118 
119 
121 (
122  const objectRegistry& registry
123 )
124 {
125  readGeometry();
126 
127  Info<< "Creating a polyMesh" << endl;
128  createPolyCells();
129 
130  Info<< "Number of internal faces: " << nInternalFaces_ << endl;
131 
132  createPolyBoundary();
133  clearExtraStorage();
134 
136  (
137  new polyMesh
138  (
139  IOobject
140  (
142  registry.time().constant(),
143  registry
144  ),
145  move(points_),
146  move(meshFaces_),
147  move(cellPolys_)
148  )
149  );
150 
151  // adding patches also checks the mesh
152  mesh().addPatches(polyBoundaryPatches(mesh));
153 
154  // Un-merge any merged cyclics
156 
157  warnDuplicates("boundaries", mesh().boundaryMesh().names());
158 
159  addCellZones(mesh());
160  addFaceZones(mesh());
161 
162  return mesh;
163 }
164 
165 
167 (
168  const polyMesh& mesh,
170 ) const
171 {
172  mesh.removeFiles();
173 
174  Info<< "Writing polyMesh" << endl;
175  mesh.writeObject
176  (
177  fmt,
180  true
181  );
182  writeAux(mesh);
183 }
184 
185 
186 void Foam::meshReader::clearExtraStorage()
187 {
188  cellFaces_.clear();
190  boundaryIds_.clear();
191  baffleIds_.clear();
192 
193  deleteDemandDrivenData(pointCellsPtr_);
194 }
195 
196 
197 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
198 
200 (
201  const fileName& fileOrPrefix,
202  const scalar scaleFactor
203 )
204  :
205  pointCellsPtr_(nullptr),
206  nInternalFaces_(0),
207  patchStarts_(0),
208  patchSizes_(0),
209  interfaces_(0),
210  baffleIds_(0),
211  meshFaces_(0),
212  cellPolys_(0),
213  geometryFile_(fileOrPrefix),
214  scaleFactor_(scaleFactor),
215  points_(0),
216  origCellId_(0),
217  boundaryIds_(0),
218  patchTypes_(0),
219  patchNames_(0),
221  cellFaces_(0),
222  baffleFaces_(0),
223  cellTableId_(0),
224  cellTable_()
225 {}
226 
227 
228 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
229 
231 {
232  deleteDemandDrivenData(pointCellsPtr_);
233 }
234 
235 
236 // ************************************************************************* //
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
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
Definition: cellModeller.C:100
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 word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
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:250
void polyMeshUnMergeCyclics(polyMesh &mesh, const scalar includedAngle=165)
Find all patches of type "mergedCyclic" in the given mesh and split them.
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:253
wordList patchNames_
Boundary patch names.
Definition: meshReader.H:263
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1424
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:125
virtual ~meshReader()
Destructor.
Definition: meshReader.C:230
meshReader(const fileName &, const scalar scaleFactor=1.0)
Construct from fileName.
Definition: meshReader.C:200
const word & constant() const
Return constant name.
Definition: TimePaths.H:123
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:121
const Time & time() const
Return time.
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
Template functions to aid in the implementation of demand driven data.
faceList baffleFaces_
List of each baffle face.
Definition: meshReader.H:272
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:275
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
messageStream Info
void writeAux(const objectRegistry &) const
Write auxiliary information.
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:441
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
void deleteDemandDrivenData(DataPtr &dataPtr)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write) const
Write the objects.