Merge branch 'master' of ssh://opencfd@repo.or.cz/srv/git/OpenFOAM-1.5.x
[OpenFOAM-1.5.x.git] / src / conversion / meshReader / meshReader.C
blob8449c93e2243d41c500ccb374f942d9ef633d291
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "meshReader.H"
28 #include "Time.H"
29 #include "polyMesh.H"
30 #include "faceSet.H"
31 #include "emptyPolyPatch.H"
32 #include "cellModeller.H"
33 #include "demandDrivenData.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
38 lookup
40     "unknown"
43 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
44 lookup
46     "tet"
49 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
50 lookup
52     "pyr"
55 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
56 lookup
58     "prism"
61 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
62 lookup
64     "hex"
68 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
70 void Foam::meshReader::addCellZones(polyMesh& mesh) const
72     cellTable_.addCellZones(mesh, cellTableId_);
73     warnDuplicates("cellZones", mesh.cellZones().names());
77 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
79     label nZone = monitoringSets_.size();
80     mesh.faceZones().setSize(nZone);
82     if (!nZone)
83     {
84         return;
85     }
87     nZone = 0;
88     for
89     (
90         HashTable<List<label>, word, string::hash>::const_iterator
91         iter = monitoringSets_.begin();
92         iter != monitoringSets_.end();
93         ++iter
94     )
95     {
96         Info<< "faceZone " << nZone
97             << " (size: " << iter().size() << ") name: "
98             << iter.key() << endl;
100         mesh.faceZones().set
101         (
102             nZone,
103             new faceZone
104             (
105                 iter.key(),
106                 iter(),
107                 List<bool>(iter().size(), false),
108                 nZone,
109                 mesh.faceZones()
110             )
111         );
113         nZone++;
114     }
115     mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
116     warnDuplicates("faceZones", mesh.faceZones().names());
120 Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
122     const objectRegistry& registry
125     readGeometry();
127     Info<< "Creating a polyMesh" << endl;
128     createPolyCells();
130     Info<< "Number of internal faces: " << nInternalFaces_ << endl;
132     createPolyBoundary();
133     clearExtraStorage();
135     autoPtr<polyMesh> mesh
136     (
137         new polyMesh
138         (
139             IOobject
140             (
141                 polyMesh::defaultRegion,
142                 "constant",
143                 registry
144             ),
145             points(),
146             meshFaces_,
147             cellPolys_
148         )
149     );
151     // adding patches also checks the mesh
152     mesh().addPatches(polyBoundaryPatches(mesh));
154     warnDuplicates("boundaries", mesh().boundaryMesh().names());
156     addCellZones(mesh());
157     addFaceZones(mesh());
159     return mesh;
163 void Foam::meshReader::writeMesh
165     const polyMesh& mesh,
166     IOstream::streamFormat fmt
167 ) const
169     fileName meshDir = mesh.objectRegistry::path()/mesh.meshDir();
171     // remove some directories and files - this should be easier
172     mesh.removeFiles(mesh.instance());
173     if (dir(meshDir/"sets"))
174     {
175         rmDir(meshDir/"sets");
176     }
178     Info<< "Writing polyMesh" << endl;
179     mesh.writeObject
180     (
181         fmt,
182         IOstream::currentVersion,
183         IOstream::UNCOMPRESSED
184     );
185     writeAux(mesh);
189 void Foam::meshReader::clearExtraStorage()
191     cellFaces_.clear();
192     baffleFaces_.clear();
193     boundaryIds_.clear();
194     baffleIds_.clear();
196     deleteDemandDrivenData(pointCellsPtr_);
200 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
202 Foam::meshReader::meshReader
204     const fileName& fileOrPrefix,
205     const scalar scaleFactor
207     :
208     pointCellsPtr_(NULL),
209     nInternalFaces_(0),
210     patchStarts_(0),
211     patchSizes_(0),
212     interfaces_(0),
213     baffleIds_(0),
214     meshFaces_(0),
215     cellPolys_(0),
216     geometryFile_(fileOrPrefix),
217     scaleFactor_(scaleFactor),
218     points_(0),
219     origCellId_(0),
220     boundaryIds_(0),
221     patchTypes_(0),
222     patchNames_(0),
223     patchPhysicalTypes_(0),
224     cellFaces_(0),
225     baffleFaces_(0),
226     cellTableId_(0),
227     cellTable_()
231 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
233 Foam::meshReader::~meshReader()
235     deleteDemandDrivenData(pointCellsPtr_);
239 // ************************************************************************* //