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 | Copyright (C) 2011-2012 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 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
37 lookup
38 (
39  "unknown"
40 );
41 
43 lookup
44 (
45  "tet"
46 );
47 
49 lookup
50 (
51  "pyr"
52 );
53 
55 lookup
56 (
57  "prism"
58 );
59 
61 lookup
62 (
63  "hex"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
70 {
72  warnDuplicates("cellZones", mesh.cellZones().names());
73 }
74 
75 
77 {
78  label nZone = monitoringSets_.size();
79  mesh.faceZones().setSize(nZone);
80 
81  if (!nZone)
82  {
83  return;
84  }
85 
86  nZone = 0;
87  for
88  (
89  HashTable<List<label>, word, string::hash>::const_iterator
90  iter = monitoringSets_.begin();
91  iter != monitoringSets_.end();
92  ++iter
93  )
94  {
95  Info<< "faceZone " << nZone
96  << " (size: " << iter().size() << ") name: "
97  << iter.key() << endl;
98 
99  mesh.faceZones().set
100  (
101  nZone,
102  new faceZone
103  (
104  iter.key(),
105  iter(),
106  List<bool>(iter().size(), false),
107  nZone,
108  mesh.faceZones()
109  )
110  );
111 
112  nZone++;
113  }
114  mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
115  warnDuplicates("faceZones", mesh.faceZones().names());
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 
135  (
136  new polyMesh
137  (
138  IOobject
139  (
141  registry.time().constant(),
142  registry
143  ),
144  xferMove(points_),
145  xferMove(meshFaces_),
146  xferMove(cellPolys_)
147  )
148  );
149 
150  // adding patches also checks the mesh
151  mesh().addPatches(polyBoundaryPatches(mesh));
152 
153  warnDuplicates("boundaries", mesh().boundaryMesh().names());
154 
155  addCellZones(mesh());
156  addFaceZones(mesh());
157 
158  return mesh;
159 }
160 
161 
163 (
164  const polyMesh& mesh,
166 ) const
167 {
168  mesh.removeFiles();
169 
170  Info<< "Writing polyMesh" << endl;
172  (
173  fmt,
176  );
177  writeAux(mesh);
178 }
179 
180 
182 {
183  cellFaces_.clear();
184  baffleFaces_.clear();
185  boundaryIds_.clear();
186  baffleIds_.clear();
187 
188  deleteDemandDrivenData(pointCellsPtr_);
189 }
190 
191 
192 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
193 
195 (
196  const fileName& fileOrPrefix,
197  const scalar scaleFactor
198 )
199  :
200  pointCellsPtr_(NULL),
201  nInternalFaces_(0),
202  patchStarts_(0),
203  patchSizes_(0),
204  interfaces_(0),
205  baffleIds_(0),
206  meshFaces_(0),
207  cellPolys_(0),
208  geometryFile_(fileOrPrefix),
209  scaleFactor_(scaleFactor),
210  points_(0),
211  origCellId_(0),
212  boundaryIds_(0),
213  patchTypes_(0),
214  patchNames_(0),
215  patchPhysicalTypes_(0),
216  cellFaces_(0),
217  baffleFaces_(0),
218  cellTableId_(0),
219  cellTable_()
220 {}
221 
222 
223 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
224 
226 {
227  deleteDemandDrivenData(pointCellsPtr_);
228 }
229 
230 
231 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::meshReader::warnDuplicates
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
Foam::meshReader::addCellZones
void addCellZones(polyMesh &) const
Add cellZones based on cellTable Id.
Definition: meshReader.C:69
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshReader::pyrModel
static const cellModel * pyrModel
Definition: meshReader.H:245
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::meshReader::unknownModel
static const cellModel * unknownModel
Pointers to cell shape models.
Definition: meshReader.H:243
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshReader::cellTableId_
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:281
Foam::IOstream::currentVersion
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
polyMesh.H
Foam::meshReader::cellTable_
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:284
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::polyMesh::faceZones
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
cellModeller.H
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:59
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
Foam::meshReader::meshReader
meshReader(const meshReader &)
Disallow default bitwise copy construct.
Foam::Info
messageStream Info
Foam::cellModeller::lookup
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:91
Foam::meshReader::clearExtraStorage
void clearExtraStorage()
Clear extra storage before creation of the mesh to remove.
Definition: meshReader.C:181
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1173
faceSet.H
Foam::meshReader::tetModel
static const cellModel * tetModel
Definition: meshReader.H:244
Foam::meshReader::addFaceZones
void addFaceZones(polyMesh &) const
Add faceZones based on monitoring boundary conditions.
Definition: meshReader.C:76
Foam::meshReader::mesh
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:120
Foam::meshReader::hexModel
static const cellModel * hexModel
Definition: meshReader.H:247
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::meshReader::~meshReader
virtual ~meshReader()
Destructor.
Definition: meshReader.C:225
emptyPolyPatch.H
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::string::hash
Hashing function class, shared by all the derived classes.
Definition: string.H:90
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
Foam::objectRegistry::writeObject
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the objects.
Definition: objectRegistry.C:331
Foam::polyMesh::addPatches
void addPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:878
Foam::List< label >
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePaths.H:130
Foam::IOstream::UNCOMPRESSED
@ UNCOMPRESSED
Definition: IOstream.H:195
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:59
Foam::cellModel
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
meshReader.H
Foam::meshReader::prismModel
static const cellModel * prismModel
Definition: meshReader.H:246
Foam::meshReader::writeMesh
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:163
Foam::cellTable::addCellZones
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:441
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86