FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "meshReader.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <meshTools/faceSet.H>
00030 #include <OpenFOAM/emptyPolyPatch.H>
00031 #include <OpenFOAM/cellModeller.H>
00032 #include <OpenFOAM/demandDrivenData.H>
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 const Foam::cellModel* Foam::meshReader::unknownModel = Foam::cellModeller::
00037 lookup
00038 (
00039     "unknown"
00040 );
00041 
00042 const Foam::cellModel* Foam::meshReader::tetModel = Foam::cellModeller::
00043 lookup
00044 (
00045     "tet"
00046 );
00047 
00048 const Foam::cellModel* Foam::meshReader::pyrModel = Foam::cellModeller::
00049 lookup
00050 (
00051     "pyr"
00052 );
00053 
00054 const Foam::cellModel* Foam::meshReader::prismModel = Foam::cellModeller::
00055 lookup
00056 (
00057     "prism"
00058 );
00059 
00060 const Foam::cellModel* Foam::meshReader::hexModel = Foam::cellModeller::
00061 lookup
00062 (
00063     "hex"
00064 );
00065 
00066 
00067 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00068 
00069 void Foam::meshReader::addCellZones(polyMesh& mesh) const
00070 {
00071     cellTable_.addCellZones(mesh, cellTableId_);
00072     warnDuplicates("cellZones", mesh.cellZones().names());
00073 }
00074 
00075 
00076 void Foam::meshReader::addFaceZones(polyMesh& mesh) const
00077 {
00078     label nZone = monitoringSets_.size();
00079     mesh.faceZones().setSize(nZone);
00080 
00081     if (!nZone)
00082     {
00083         return;
00084     }
00085 
00086     nZone = 0;
00087     for
00088     (
00089         HashTable<List<label>, word, string::hash>::const_iterator
00090         iter = monitoringSets_.begin();
00091         iter != monitoringSets_.end();
00092         ++iter
00093     )
00094     {
00095         Info<< "faceZone " << nZone
00096             << " (size: " << iter().size() << ") name: "
00097             << iter.key() << endl;
00098 
00099         mesh.faceZones().set
00100         (
00101             nZone,
00102             new faceZone
00103             (
00104                 iter.key(),
00105                 iter(),
00106                 List<bool>(iter().size(), false),
00107                 nZone,
00108                 mesh.faceZones()
00109             )
00110         );
00111 
00112         nZone++;
00113     }
00114     mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;
00115     warnDuplicates("faceZones", mesh.faceZones().names());
00116 }
00117 
00118 
00119 Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
00120 (
00121     const objectRegistry& registry
00122 )
00123 {
00124     readGeometry();
00125 
00126     Info<< "Creating a polyMesh" << endl;
00127     createPolyCells();
00128 
00129     Info<< "Number of internal faces: " << nInternalFaces_ << endl;
00130 
00131     createPolyBoundary();
00132     clearExtraStorage();
00133 
00134     autoPtr<polyMesh> mesh
00135     (
00136         new polyMesh
00137         (
00138             IOobject
00139             (
00140                 polyMesh::defaultRegion,
00141                 "constant",
00142                 registry
00143             ),
00144             xferMove(points_),
00145             xferMove(meshFaces_),
00146             xferMove(cellPolys_)
00147         )
00148     );
00149 
00150     // adding patches also checks the mesh
00151     mesh().addPatches(polyBoundaryPatches(mesh));
00152 
00153     warnDuplicates("boundaries", mesh().boundaryMesh().names());
00154 
00155     addCellZones(mesh());
00156     addFaceZones(mesh());
00157 
00158     return mesh;
00159 }
00160 
00161 
00162 void Foam::meshReader::writeMesh
00163 (
00164     const polyMesh& mesh,
00165     IOstream::streamFormat fmt
00166 ) const
00167 {
00168     mesh.removeFiles();
00169 
00170     Info<< "Writing polyMesh" << endl;
00171     mesh.writeObject
00172     (
00173         fmt,
00174         IOstream::currentVersion,
00175         IOstream::UNCOMPRESSED
00176     );
00177     writeAux(mesh);
00178 }
00179 
00180 
00181 void Foam::meshReader::clearExtraStorage()
00182 {
00183     cellFaces_.clear();
00184     baffleFaces_.clear();
00185     boundaryIds_.clear();
00186     baffleIds_.clear();
00187 
00188     deleteDemandDrivenData(pointCellsPtr_);
00189 }
00190 
00191 
00192 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00193 
00194 Foam::meshReader::meshReader
00195 (
00196     const fileName& fileOrPrefix,
00197     const scalar scaleFactor
00198 )
00199     :
00200     pointCellsPtr_(NULL),
00201     nInternalFaces_(0),
00202     patchStarts_(0),
00203     patchSizes_(0),
00204     interfaces_(0),
00205     baffleIds_(0),
00206     meshFaces_(0),
00207     cellPolys_(0),
00208     geometryFile_(fileOrPrefix),
00209     scaleFactor_(scaleFactor),
00210     points_(0),
00211     origCellId_(0),
00212     boundaryIds_(0),
00213     patchTypes_(0),
00214     patchNames_(0),
00215     patchPhysicalTypes_(0),
00216     cellFaces_(0),
00217     baffleFaces_(0),
00218     cellTableId_(0),
00219     cellTable_()
00220 {}
00221 
00222 
00223 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00224 
00225 Foam::meshReader::~meshReader()
00226 {
00227     deleteDemandDrivenData(pointCellsPtr_);
00228 }
00229 
00230 
00231 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines