OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshReader.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "meshReader.H"
00028 #include "Time.H"
00029 #include "polyMesh.H"
00030 #include "faceSet.H"
00031 #include "emptyPolyPatch.H"
00032 #include "cellModeller.H"
00033 #include "demandDrivenData.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
00038 lookup
00039 (
00040     "unknown"
00041 );
00042 
00043 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
00044 lookup
00045 (
00046     "tet"
00047 );
00048 
00049 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
00050 lookup
00051 (
00052     "pyr"
00053 );
00054 
00055 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
00056 lookup
00057 (
00058     "prism"
00059 );
00060 
00061 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
00062 lookup
00063 (
00064     "hex"
00065 );
00066 
00067 
00068 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00069 
00070 void Foam::meshReader::addCellZones(polyMesh& mesh) const
00071 {
00072     cellTable_.addCellZones(mesh, cellTableId_);
00073     warnDuplicates("cellZones", mesh.cellZones().names());
00074 }
00075 
00076 
00077 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
00078 {
00079     label nZone = monitoringSets_.size();
00080     mesh.faceZones().setSize(nZone);
00081 
00082     if (!nZone)
00083     {
00084         return;
00085     }
00086 
00087     nZone = 0;
00088     for
00089     (
00090         HashTable<List<label>, word, string::hash>::const_iterator
00091         iter = monitoringSets_.begin();
00092         iter != monitoringSets_.end();
00093         ++iter
00094     )
00095     {
00096         Info<< "faceZone " << nZone
00097             << " (size: " << iter().size() << ") name: "
00098             << iter.key() << endl;
00099 
00100         mesh.faceZones().set
00101         (
00102             nZone,
00103             new faceZone
00104             (
00105                 iter.key(),
00106                 iter(),
00107                 List<bool>(iter().size(), false),
00108                 nZone,
00109                 mesh.faceZones()
00110             )
00111         );
00112 
00113         nZone++;
00114     }
00115     mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
00116     warnDuplicates("faceZones", mesh.faceZones().names());
00117 }
00118 
00119 
00120 Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
00121 (
00122     const objectRegistry& registry
00123 )
00124 {
00125     readGeometry();
00126 
00127     Info<< "Creating a polyMesh" << endl;
00128     createPolyCells();
00129 
00130     Info<< "Number of internal faces: " << nInternalFaces_ << endl;
00131 
00132     createPolyBoundary();
00133     clearExtraStorage();
00134 
00135     autoPtr<polyMesh> mesh
00136     (
00137         new polyMesh
00138         (
00139             IOobject
00140             (
00141                 polyMesh::defaultRegion,
00142                 "constant",
00143                 registry
00144             ),
00145             xferMove(points_),
00146             xferMove(meshFaces_),
00147             xferMove(cellPolys_)
00148         )
00149     );
00150 
00151     // adding patches also checks the mesh
00152     mesh().addPatches(polyBoundaryPatches(mesh));
00153 
00154     warnDuplicates("boundaries", mesh().boundaryMesh().names());
00155 
00156     addCellZones(mesh());
00157     addFaceZones(mesh());
00158 
00159     return mesh;
00160 }
00161 
00162 
00163 void Foam::meshReader::writeMesh
00164 (
00165     const polyMesh& mesh,
00166     IOstream::streamFormat fmt
00167 ) const
00168 {
00169     mesh.removeFiles();
00170 
00171     Info<< "Writing polyMesh" << endl;
00172     mesh.writeObject
00173     (
00174         fmt,
00175         IOstream::currentVersion,
00176         IOstream::UNCOMPRESSED
00177     );
00178     writeAux(mesh);
00179 }
00180 
00181 
00182 void Foam::meshReader::clearExtraStorage()
00183 {
00184     cellFaces_.clear();
00185     baffleFaces_.clear();
00186     boundaryIds_.clear();
00187     baffleIds_.clear();
00188 
00189     deleteDemandDrivenData(pointCellsPtr_);
00190 }
00191 
00192 
00193 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00194 
00195 Foam::meshReader::meshReader
00196 (
00197     const fileName& fileOrPrefix,
00198     const scalar scaleFactor
00199 )
00200     :
00201     pointCellsPtr_(NULL),
00202     nInternalFaces_(0),
00203     patchStarts_(0),
00204     patchSizes_(0),
00205     interfaces_(0),
00206     baffleIds_(0),
00207     meshFaces_(0),
00208     cellPolys_(0),
00209     geometryFile_(fileOrPrefix),
00210     scaleFactor_(scaleFactor),
00211     points_(0),
00212     origCellId_(0),
00213     boundaryIds_(0),
00214     patchTypes_(0),
00215     patchNames_(0),
00216     patchPhysicalTypes_(0),
00217     cellFaces_(0),
00218     baffleFaces_(0),
00219     cellTableId_(0),
00220     cellTable_()
00221 {}
00222 
00223 
00224 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00225 
00226 Foam::meshReader::~meshReader()
00227 {
00228     deleteDemandDrivenData(pointCellsPtr_);
00229 }
00230 
00231 
00232 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd