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 
36 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
37 lookup
38 (
39  "unknown"
40 );
41 
42 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
43 lookup
44 (
45  "tet"
46 );
47 
48 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
49 lookup
50 (
51  "pyr"
52 );
53 
54 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
55 lookup
56 (
57  "prism"
58 );
59 
60 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
61 lookup
62 (
63  "hex"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::meshReader::addCellZones(polyMesh& mesh) const
70 {
72  warnDuplicates("cellZones", mesh.cellZones().names());
73 }
74 
75 
76 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
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;
171  mesh.writeObject
172  (
173  fmt,
176  );
177  writeAux(mesh);
178 }
179 
180 
181 void Foam::meshReader::clearExtraStorage()
182 {
183  cellFaces_.clear();
185  boundaryIds_.clear();
186  baffleIds_.clear();
187 
188  deleteDemandDrivenData(pointCellsPtr_);
189 }
190 
191 
192 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
193 
194 Foam::meshReader::meshReader
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),
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 // ************************************************************************* //
const Time & time() const
Return time.
List< List< cellFaceIdentifier > > boundaryIds_
Identify boundary faces by cells and their faces.
Definition: meshReader.H:263
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
wordList patchPhysicalTypes_
Boundary patch physical types.
Definition: meshReader.H:272
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
Definition: cellModeller.C:88
A class for handling file names.
Definition: fileName.H:69
virtual bool readGeometry(const scalar scaleFactor=1.0)=0
Subclasses are required to supply this information.
void writeAux(const objectRegistry &) const
Write auxiliary information.
wordList patchTypes_
Boundary patch types.
Definition: meshReader.H:266
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Definition: boundaryMesh.H:59
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
void addCellZones(polyMesh &, const labelList &tableIds) const
Classify tableIds into cellZones according to the cellTable.
Definition: cellTable.C:441
pointField points_
Points supporting the mesh.
Definition: meshReader.H:256
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:259
wordList patchNames_
Boundary patch names.
Definition: meshReader.H:269
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:356
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write the objects.
virtual ~meshReader()
Destructor.
Definition: meshReader.C:225
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
virtual autoPtr< polyMesh > mesh(const objectRegistry &)
Create and return polyMesh.
Definition: meshReader.C:120
scalar scaleFactor_
Geometry scaling.
Definition: meshReader.H:253
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:284
fileName geometryFile_
Referenced filename.
Definition: meshReader.H:250
Template functions to aid in the implementation of demand driven data.
faceList baffleFaces_
List of each baffle face.
Definition: meshReader.H:278
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:281
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
Definition: cellModel.H:64
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Registry of regIOobjects.
faceListList cellFaces_
List of faces for every cell.
Definition: meshReader.H:275
void deleteDemandDrivenData(DataPtr &dataPtr)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void writeMesh(const polyMesh &, IOstream::streamFormat fmt=IOstream::BINARY) const
Write mesh.
Definition: meshReader.C:163
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1170