meshReader.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "meshReader.H"
30 #include "Time.H"
31 #include "polyMesh.H"
32 #include "faceSet.H"
33 #include "emptyPolyPatch.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void Foam::meshReader::addCellZones(polyMesh& mesh) const
38 {
40  warnDuplicates("cellZones", mesh.cellZones().names());
41 }
42 
43 
44 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
45 {
46  label nZone = monitoringSets_.size();
47  mesh.faceZones().setSize(nZone);
48 
49  if (!nZone)
50  {
51  return;
52  }
53 
54  nZone = 0;
55  forAllConstIters(monitoringSets_, iter)
56  {
57  Info<< "faceZone " << nZone
58  << " (size: " << iter().size() << ") name: "
59  << iter.key() << endl;
60 
62  (
63  nZone,
64  new faceZone
65  (
66  iter.key(),
67  iter(),
68  false, // none are flipped
69  nZone,
70  mesh.faceZones()
71  )
72  );
73 
74  nZone++;
75  }
77  warnDuplicates("faceZones", mesh.faceZones().names());
78 }
79 
80 
82 (
83  const objectRegistry& registry
84 )
85 {
86  readGeometry();
87 
88  Info<< "Creating a polyMesh" << endl;
89  createPolyCells();
90 
91  Info<< "Number of internal faces: " << nInternalFaces_ << endl;
92 
93  createPolyBoundary();
94  clearExtraStorage();
95 
97  (
98  IOobject
99  (
101  registry.time().constant(),
102  registry,
105  ),
106  std::move(points_),
107  std::move(meshFaces_),
108  std::move(cellPolys_)
109  );
110  polyMesh& mesh = *meshPtr;
111 
112  polyPatchList newPatches(polyBoundaryPatches(mesh));
113 
114  // Adding patches also checks the mesh
115  mesh.addPatches(newPatches);
116 
117  warnDuplicates("boundaries", mesh.boundaryMesh().names());
118 
119  addCellZones(mesh);
120  addFaceZones(mesh);
121 
122  return meshPtr;
123 }
124 
125 
127 (
128  const polyMesh& mesh,
129  IOstreamOption streamOpt
130 ) const
131 {
132  mesh.removeFiles();
133 
134  Info<< "Writing polyMesh" << endl;
135  mesh.writeObject(streamOpt, true);
136  writeAux(mesh);
137 }
138 
139 
140 void Foam::meshReader::clearExtraStorage()
141 {
142  cellFaces_.clear();
143  baffleFaces_.clear();
144  boundaryIds_.clear();
145  baffleIds_.clear();
146 
147  pointCellsPtr_.reset(nullptr);
148 }
149 
150 
151 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152 
153 Foam::meshReader::meshReader
154 (
155  const fileName& fileOrPrefix,
156  const scalar scaleFactor
157 )
158 :
159  pointCellsPtr_(nullptr),
160  interfaces_(0),
161  baffleIds_(0),
162  cellPolys_(0),
163  monitoringSets_(),
164  // protected
165  geometryFile_(fileOrPrefix),
166  scaleFactor_(scaleFactor),
167  points_(0),
168  origCellId_(0),
169  boundaryIds_(0),
170  patchTypes_(0),
171  patchNames_(0),
172  patchPhysicalTypes_(0),
173  patchStarts_(0),
174  patchSizes_(0),
175  nInternalFaces_(0),
176  meshFaces_(0),
177  cellFaces_(0),
178  baffleFaces_(0),
179  cellTableId_(0),
180  cellTable_()
181 {
182  // Sanity
183  if (scaleFactor_ <= VSMALL)
184  {
185  scaleFactor_ = 1;
186  }
187 }
188 
189 
190 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:72
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the underlying polyMesh and other data.
Definition: fvMesh.C:1079
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:30
A simple container for options an IOstream can normally have.
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition: polyPatch.H:56
writeOption writeOpt() const noexcept
Get the write option.
dynamicFvMesh & mesh
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1329
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:405
wordList names() const
Return a list of patch names.
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: PtrList.H:159
void writeMesh(const polyMesh &, IOstreamOption streamOpt=IOstreamOption(IOstreamOption::BINARY)) const
Write mesh.
Definition: meshReader.C:120
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:75
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:670
void setSize(const label newLen)
Same as resize()
Definition: PtrList.H:337
scalar scaleFactor_
Geometry scaling.
Definition: meshReader.H:266
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:334
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:329
Nothing to be read.
Automatically write from objectRegistry::writeObject()
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:362
messageStream Info
Information stream (stdout output on master, null elsewhere)
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:433
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
void addPatches(polyPatchList &plist, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:971
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28