Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
37void Foam::meshReader::addCellZones(polyMesh& mesh) const
38{
39 cellTable_.addCellZones(mesh, cellTableId_);
40 warnDuplicates("cellZones", mesh.cellZones().names());
41}
42
43
44void 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,
71 )
72 );
73
74 nZone++;
75 }
76 mesh.faceZones().writeOpt(IOobject::AUTO_WRITE);
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
140void Foam::meshReader::clearExtraStorage()
141{
142 cellFaces_.clear();
143 baffleFaces_.clear();
144 boundaryIds_.clear();
145 baffleIds_.clear();
147 pointCellsPtr_.reset(nullptr);
148}
149
150
151// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
152
153Foam::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// ************************************************************************* //
writeOption writeOpt() const noexcept
Get the write option.
@ NO_READ
Nothing to be read.
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
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:171
void setSize(const label n)
Same as resize().
Definition PtrList.H:357
const word & constant() const noexcept
Return constant name.
Definition TimePathsI.H:131
wordList names() const
A list of the zone names.
Definition ZoneMesh.C:463
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
A subset of mesh faces organised as a primitive patch.
Definition faceZone.H:63
A class for handling file names.
Definition fileName.H:75
scalar scaleFactor_
Geometry scaling.
Definition meshReader.H:266
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
List< List< cellFaceIdentifier > > boundaryIds_
Identify boundary faces by cells and their faces.
Definition meshReader.H:283
wordList patchPhysicalTypes_
Boundary patch physical types.
Definition meshReader.H:298
faceList meshFaces_
Global face list for polyMesh.
Definition meshReader.H:314
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition meshReader.C:75
wordList patchNames_
Boundary patch names.
Definition meshReader.H:293
void writeAux(const objectRegistry &) const
Write auxiliary information.
label nInternalFaces_
Number of internal faces for polyMesh.
Definition meshReader.H:309
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition meshReader.H:334
virtual bool readGeometry(const scalar scaleFactor=1.0)=0
Subclasses are required to supply this information.
labelList cellTableId_
Cell table id for each cell.
Definition meshReader.H:329
labelList origCellId_
Lookup original Cell number for a given cell.
Definition meshReader.H:276
pointField points_
Points supporting the mesh.
Definition meshReader.H:271
labelList patchSizes_
Definition meshReader.H:304
void writeMesh(const polyMesh &, IOstreamOption streamOpt=IOstreamOption(IOstreamOption::BINARY)) const
Write mesh.
Definition meshReader.C:120
faceList baffleFaces_
List of each baffle face.
Definition meshReader.H:324
faceListList cellFaces_
List of faces for every cell.
Definition meshReader.H:319
labelList patchStarts_
Polyhedral mesh boundary patch start indices and dimensions.
Definition meshReader.H:303
fileName geometryFile_
Referenced filename.
Definition meshReader.H:261
wordList patchTypes_
Boundary patch types.
Definition meshReader.H:288
Registry of regIOobjects.
const Time & time() const noexcept
Return time registry.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition polyMesh.H:671
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
dynamicFvMesh & mesh
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition stdFoam.H:235