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-2024 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().toc());
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  mesh.faceZones()
109  )
110  );
111 
112  nZone++;
113  }
114  mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
115  warnDuplicates("faceZones", mesh.faceZones().toc());
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 
134  autoPtr<polyMesh> mesh
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  // Un-merge any merged cyclics
154  polyMeshUnMergeCyclics(mesh());
155 
156  warnDuplicates("boundaries", mesh().boundaryMesh().names());
157 
158  addCellZones(mesh());
159  addFaceZones(mesh());
160 
161  return mesh;
162 }
163 
164 
166 (
167  const polyMesh& mesh,
169 ) const
170 {
171  mesh.removeFiles();
172 
173  Info<< "Writing polyMesh" << endl;
174  mesh.writeObject
175  (
176  fmt,
179  true
180  );
181  writeAux(mesh);
182 }
183 
184 
185 void Foam::meshReader::clearExtraStorage()
186 {
187  cellFaces_.clear();
188  baffleFaces_.clear();
189  boundaryIds_.clear();
190  baffleIds_.clear();
191 
192  deleteDemandDrivenData(pointCellsPtr_);
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
197 
199 (
200  const fileName& fileOrPrefix,
201  const scalar scaleFactor
202 )
203  :
204  pointCellsPtr_(nullptr),
205  nInternalFaces_(0),
206  patchStarts_(0),
207  patchSizes_(0),
208  interfaces_(0),
209  baffleIds_(0),
210  meshFaces_(0),
211  cellPolys_(0),
212  geometryFile_(fileOrPrefix),
213  scaleFactor_(scaleFactor),
214  points_(0),
215  origCellId_(0),
216  boundaryIds_(0),
217  patchTypes_(0),
218  patchNames_(0),
219  patchPhysicalTypes_(0),
220  cellFaces_(0),
221  baffleFaces_(0),
222  cellTableId_(0),
223  cellTable_()
224 {}
225 
226 
227 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
228 
230 {
231  deleteDemandDrivenData(pointCellsPtr_);
232 }
233 
234 
235 // ************************************************************************* //
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:229
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:199
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:120
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:166
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:267
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write the underlying polyMesh.
Definition: polyMeshIO.C:460
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1545
Template functions to aid in the implementation of demand driven data.
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
void polyMeshUnMergeCyclics(polyMesh &mesh, const scalar includedAngle=degToRad(165))
Find all patches of type "mergedCyclic" in the given mesh and split them.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
void deleteDemandDrivenData(DataType *&dataPtr)
messageStream Info