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 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 #include "demandDrivenData.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 void Foam::meshReader::addCellZones(polyMesh& mesh) const
39 {
41  warnDuplicates("cellZones", mesh.cellZones().names());
42 }
43 
44 
45 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
46 {
47  label nZone = monitoringSets_.size();
48  mesh.faceZones().setSize(nZone);
49 
50  if (!nZone)
51  {
52  return;
53  }
54 
55  nZone = 0;
56  forAllConstIters(monitoringSets_, iter)
57  {
58  Info<< "faceZone " << nZone
59  << " (size: " << iter().size() << ") name: "
60  << iter.key() << endl;
61 
62  mesh.faceZones().set
63  (
64  nZone,
65  new faceZone
66  (
67  iter.key(),
68  iter(),
69  false, // none are flipped
70  nZone,
71  mesh.faceZones()
72  )
73  );
74 
75  nZone++;
76  }
77  mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
78  warnDuplicates("faceZones", mesh.faceZones().names());
79 }
80 
81 
83 (
84  const objectRegistry& registry
85 )
86 {
87  readGeometry();
88 
89  Info<< "Creating a polyMesh" << endl;
90  createPolyCells();
91 
92  Info<< "Number of internal faces: " << nInternalFaces_ << endl;
93 
94  createPolyBoundary();
95  clearExtraStorage();
96 
98  (
99  IOobject
100  (
102  registry.time().constant(),
103  registry,
106  ),
107  std::move(points_),
108  std::move(meshFaces_),
109  std::move(cellPolys_)
110  );
111  polyMesh& mesh = *meshPtr;
112 
113  // Adding patches also checks the mesh
114  mesh.addPatches(polyBoundaryPatches(mesh));
115 
116  warnDuplicates("boundaries", mesh.boundaryMesh().names());
117 
118  addCellZones(mesh);
119  addFaceZones(mesh);
120 
121  return meshPtr;
122 }
123 
124 
126 (
127  const polyMesh& mesh,
129 ) const
130 {
131  mesh.removeFiles();
132 
133  Info<< "Writing polyMesh" << endl;
135  (
136  fmt,
139  true
140  );
141  writeAux(mesh);
142 }
143 
144 
145 void Foam::meshReader::clearExtraStorage()
146 {
147  cellFaces_.clear();
148  baffleFaces_.clear();
149  boundaryIds_.clear();
150  baffleIds_.clear();
151 
152  deleteDemandDrivenData(pointCellsPtr_);
153 }
154 
155 
156 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
157 
158 Foam::meshReader::meshReader
159 (
160  const fileName& fileOrPrefix,
161  const scalar scaleFactor
162 )
163 :
164  pointCellsPtr_(nullptr),
165  interfaces_(0),
166  baffleIds_(0),
167  cellPolys_(0),
168  monitoringSets_(),
169  // protected
170  geometryFile_(fileOrPrefix),
171  scaleFactor_(scaleFactor),
172  points_(0),
173  origCellId_(0),
174  boundaryIds_(0),
175  patchTypes_(0),
176  patchNames_(0),
177  patchPhysicalTypes_(0),
178  patchStarts_(0),
179  patchSizes_(0),
180  nInternalFaces_(0),
181  meshFaces_(0),
182  cellFaces_(0),
183  baffleFaces_(0),
184  cellTableId_(0),
185  cellTable_()
186 {
187  // Sanity
188  if (scaleFactor_ <= VSMALL)
189  {
190  scaleFactor_ = 1;
191  }
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 
198 {
199  deleteDemandDrivenData(pointCellsPtr_);
200 }
201 
202 
203 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:73
Foam::polyMesh::addPatches
void addPatches(PtrList< polyPatch > &plist, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:930
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:104
meshPtr
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
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:69
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
Foam::fvMesh::writeObject
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write the underlying polyMesh and other data.
Definition: fvMesh.C:914
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:593
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:477
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
Foam::label
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:62
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1271
faceSet.H
Foam::meshReader::mesh
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:83
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::meshReader::~meshReader
virtual ~meshReader()
Destructor.
Definition: meshReader.C:197
emptyPolyPatch.H
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:340
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:88
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::meshReader::writeMesh
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:126
Foam::cellTable::addCellZones
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:440