ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / conversion / meshReader / meshReader.C
blobb6f50c24525da948890767078f08283e2406bb49
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
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"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
37 lookup
39     "unknown"
42 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
43 lookup
45     "tet"
48 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
49 lookup
51     "pyr"
54 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
55 lookup
57     "prism"
60 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
61 lookup
63     "hex"
67 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
69 void Foam::meshReader::addCellZones(polyMesh& mesh) const
71     cellTable_.addCellZones(mesh, cellTableId_);
72     warnDuplicates("cellZones", mesh.cellZones().names());
76 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
78     label nZone = monitoringSets_.size();
79     mesh.faceZones().setSize(nZone);
81     if (!nZone)
82     {
83         return;
84     }
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;
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         );
112         nZone++;
113     }
114     mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
115     warnDuplicates("faceZones", mesh.faceZones().names());
119 Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
121     const objectRegistry& registry
124     readGeometry();
126     Info<< "Creating a polyMesh" << endl;
127     createPolyCells();
129     Info<< "Number of internal faces: " << nInternalFaces_ << endl;
131     createPolyBoundary();
132     clearExtraStorage();
134     autoPtr<polyMesh> mesh
135     (
136         new polyMesh
137         (
138             IOobject
139             (
140                 polyMesh::defaultRegion,
141                 "constant",
142                 registry
143             ),
144             xferMove(points_),
145             xferMove(meshFaces_),
146             xferMove(cellPolys_)
147         )
148     );
150     // adding patches also checks the mesh
151     mesh().addPatches(polyBoundaryPatches(mesh));
153     warnDuplicates("boundaries", mesh().boundaryMesh().names());
155     addCellZones(mesh());
156     addFaceZones(mesh());
158     return mesh;
162 void Foam::meshReader::writeMesh
164     const polyMesh& mesh,
165     IOstream::streamFormat fmt
166 ) const
168     mesh.removeFiles();
170     Info<< "Writing polyMesh" << endl;
171     mesh.writeObject
172     (
173         fmt,
174         IOstream::currentVersion,
175         IOstream::UNCOMPRESSED
176     );
177     writeAux(mesh);
181 void Foam::meshReader::clearExtraStorage()
183     cellFaces_.clear();
184     baffleFaces_.clear();
185     boundaryIds_.clear();
186     baffleIds_.clear();
188     deleteDemandDrivenData(pointCellsPtr_);
192 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
194 Foam::meshReader::meshReader
196     const fileName& fileOrPrefix,
197     const scalar scaleFactor
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_()
223 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
225 Foam::meshReader::~meshReader()
227     deleteDemandDrivenData(pointCellsPtr_);
231 // ************************************************************************* //