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 
38 lookup
39 (
40  "unknown"
41 );
42 
44 lookup
45 (
46  "tet"
47 );
48 
50 lookup
51 (
52  "pyr"
53 );
54 
56 lookup
57 (
58  "prism"
59 );
60 
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 
135  autoPtr<polyMesh> mesh
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
155  polyMeshUnMergeCyclics(mesh());
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();
189  baffleFaces_.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),
220  patchPhysicalTypes_(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 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
static const word & constant()
Return constant name.
Definition: TimePaths.H:122
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:65
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
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:441
A class for handling file names.
Definition: fileName.H:82
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
virtual ~meshReader()
Destructor.
Definition: meshReader.C:230
static const cellModel * prismModel
Definition: meshReader.H:239
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
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:277
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:274
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:167
static const cellModel * hexModel
Definition: meshReader.H:240
static const cellModel * tetModel
Definition: meshReader.H:237
static const cellModel * pyrModel
Definition: meshReader.H:238
Registry of regIOobjects.
const Time & time() const
Return time.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:266
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write the underlying polyMesh.
Definition: polyMeshIO.C:519
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1593
Template functions to aid in the implementation of demand driven data.
void polyMeshUnMergeCyclics(polyMesh &mesh, const scalar includedAngle=165)
Find all patches of type "mergedCyclic" in the given mesh and split them.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
void deleteDemandDrivenData(DataPtr &dataPtr)