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 
61  mesh.faceZones().set
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  // Adding patches also checks the mesh
113  mesh.addPatches(polyBoundaryPatches(mesh));
114 
115  warnDuplicates("boundaries", mesh.boundaryMesh().names());
116 
117  addCellZones(mesh);
118  addFaceZones(mesh);
119 
120  return meshPtr;
121 }
122 
123 
125 (
126  const polyMesh& mesh,
127  IOstreamOption streamOpt
128 ) const
129 {
130  mesh.removeFiles();
131 
132  Info<< "Writing polyMesh" << endl;
133  mesh.writeObject(streamOpt, true);
134  writeAux(mesh);
135 }
136 
137 
138 void Foam::meshReader::clearExtraStorage()
139 {
140  cellFaces_.clear();
141  baffleFaces_.clear();
142  boundaryIds_.clear();
143  baffleIds_.clear();
144 
145  pointCellsPtr_.reset(nullptr);
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
151 Foam::meshReader::meshReader
152 (
153  const fileName& fileOrPrefix,
154  const scalar scaleFactor
155 )
156 :
157  pointCellsPtr_(nullptr),
158  interfaces_(0),
159  baffleIds_(0),
160  cellPolys_(0),
161  monitoringSets_(),
162  // protected
163  geometryFile_(fileOrPrefix),
164  scaleFactor_(scaleFactor),
165  points_(0),
166  origCellId_(0),
167  boundaryIds_(0),
168  patchTypes_(0),
169  patchNames_(0),
170  patchPhysicalTypes_(0),
171  patchStarts_(0),
172  patchSizes_(0),
173  nInternalFaces_(0),
174  meshFaces_(0),
175  cellFaces_(0),
176  baffleFaces_(0),
177  cellTableId_(0),
178  cellTable_()
179 {
180  // Sanity
181  if (scaleFactor_ <= VSMALL)
182  {
183  scaleFactor_ = 1;
184  }
185 }
186 
187 
188 // ************************************************************************* //
Foam::polyMesh::addPatches
void addPatches(PtrList< polyPatch > &plist, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:961
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
meshPtr
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::meshReader::warnDuplicates
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:37
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:318
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::meshReader::cellTableId_
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:251
polyMesh.H
Foam::meshReader::cellTable_
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:254
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:555
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::meshReader::writeMesh
void writeMesh(const polyMesh &, IOstreamOption streamOpt=IOstreamOption(IOstreamOption::BINARY)) const
Write mesh.
Definition: meshReader.C:125
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1325
faceSet.H
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:486
Foam::meshReader::mesh
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:82
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
emptyPolyPatch.H
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:305
Time.H
Foam::autoPtr< Foam::polyMesh >
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
meshReader.H
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
Foam::cellTable::addCellZones
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:440
Foam::fvMesh::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write the underlying polyMesh and other data.
Definition: fvMesh.C:1018