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-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 \*---------------------------------------------------------------------------*/
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 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
37 lookup
38 (
39  "unknown"
40 );
41 
42 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
43 lookup
44 (
45  "tet"
46 );
47 
48 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
49 lookup
50 (
51  "pyr"
52 );
53 
54 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
55 lookup
56 (
57  "prism"
58 );
59 
60 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
61 lookup
62 (
63  "hex"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::meshReader::addCellZones(polyMesh& mesh) const
70 {
72  warnDuplicates("cellZones", mesh.cellZones().names());
73 }
74 
75 
76 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
77 {
78  label nZone = monitoringSets_.size();
79  mesh.faceZones().setSize(nZone);
80 
81  if (!nZone)
82  {
83  return;
84  }
85 
86  nZone = 0;
87  for
88  (
89  HashTable<List<label>, word, string::hash>::const_iterator
90  iter = monitoringSets_.begin();
91  iter != monitoringSets_.end();
92  ++iter
93  )
94  {
95  Info<< "faceZone " << nZone
96  << " (size: " << iter().size() << ") name: "
97  << iter.key() << endl;
98 
99  mesh.faceZones().set
100  (
101  nZone,
102  new faceZone
103  (
104  iter.key(),
105  iter(),
106  List<bool>(iter().size(), false),
107  nZone,
108  mesh.faceZones()
109  )
110  );
111 
112  nZone++;
113  }
114  mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
115  warnDuplicates("faceZones", mesh.faceZones().names());
116 }
117 
118 
120 (
121  const objectRegistry& registry
122 )
123 {
124  readGeometry();
125 
126  Info<< "Creating a polyMesh" << endl;
127  createPolyCells();
128 
129  Info<< "Number of internal faces: " << nInternalFaces_ << endl;
130 
131  createPolyBoundary();
132  clearExtraStorage();
133 
135  (
136  new polyMesh
137  (
138  IOobject
139  (
141  registry.time().constant(),
142  registry
143  ),
144  move(points_),
145  move(meshFaces_),
146  move(cellPolys_)
147  )
148  );
149 
150  // adding patches also checks the mesh
151  mesh().addPatches(polyBoundaryPatches(mesh));
152 
153  warnDuplicates("boundaries", mesh().boundaryMesh().names());
154 
155  addCellZones(mesh());
156  addFaceZones(mesh());
157 
158  return mesh;
159 }
160 
161 
163 (
164  const polyMesh& mesh,
166 ) const
167 {
168  mesh.removeFiles();
169 
170  Info<< "Writing polyMesh" << endl;
171  mesh.writeObject
172  (
173  fmt,
176  true
177  );
178  writeAux(mesh);
179 }
180 
181 
182 void Foam::meshReader::clearExtraStorage()
183 {
184  cellFaces_.clear();
186  boundaryIds_.clear();
187  baffleIds_.clear();
188 
189  deleteDemandDrivenData(pointCellsPtr_);
190 }
191 
192 
193 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
194 
196 (
197  const fileName& fileOrPrefix,
198  const scalar scaleFactor
199 )
200  :
201  pointCellsPtr_(nullptr),
202  nInternalFaces_(0),
203  patchStarts_(0),
204  patchSizes_(0),
205  interfaces_(0),
206  baffleIds_(0),
207  meshFaces_(0),
208  cellPolys_(0),
209  geometryFile_(fileOrPrefix),
210  scaleFactor_(scaleFactor),
211  points_(0),
212  origCellId_(0),
213  boundaryIds_(0),
214  patchTypes_(0),
215  patchNames_(0),
217  cellFaces_(0),
218  baffleFaces_(0),
219  cellTableId_(0),
220  cellTable_()
221 {}
222 
223 
224 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
225 
227 {
228  deleteDemandDrivenData(pointCellsPtr_);
229 }
230 
231 
232 // ************************************************************************* //
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
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Definition: boundaryMesh.H:59
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
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:163
pointField points_
Points supporting the mesh.
Definition: meshReader.H:250
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:124
virtual ~meshReader()
Destructor.
Definition: meshReader.C:226
meshReader(const fileName &, const scalar scaleFactor=1.0)
Construct from fileName.
Definition: meshReader.C:196
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
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:120
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:206
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.