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

cellZone.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 Description
00026     A subset of mesh cells.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "cellZone.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "cellZoneMesh.H"
00033 #include "polyMesh.H"
00034 #include "primitiveMesh.H"
00035 #include "IOstream.H"
00036 #include "demandDrivenData.H"
00037 
00038 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042     defineTypeNameAndDebug(cellZone, 0);
00043 
00044     defineRunTimeSelectionTable(cellZone, dictionary);
00045     addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
00046 }
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 const Foam::Map<Foam::label>& Foam::cellZone::cellLookupMap() const
00051 {
00052     if (!cellLookupMapPtr_)
00053     {
00054         calcCellLookupMap();
00055     }
00056 
00057     return *cellLookupMapPtr_;
00058 }
00059 
00060 
00061 void Foam::cellZone::calcCellLookupMap() const
00062 {
00063     if (debug)
00064     {
00065         Info<< "void cellZone::calcCellLookupMap() const : "
00066             << "Calculating cell lookup map"
00067             << endl;
00068     }
00069 
00070     if (cellLookupMapPtr_)
00071     {
00072         FatalErrorIn
00073         (
00074             "void cellZone::calcCellLookupMap() const"
00075         )   << "cell lookup map already calculated"
00076             << abort(FatalError);
00077     }
00078 
00079     const labelList& addr = *this;
00080 
00081     cellLookupMapPtr_ = new Map<label>(2*addr.size());
00082     Map<label>& clm = *cellLookupMapPtr_;
00083 
00084     forAll (addr, cellI)
00085     {
00086         clm.insert(addr[cellI], cellI);
00087     }
00088 
00089     if (debug)
00090     {
00091         Info<< "void cellZone::calcCellLookupMap() const : "
00092             << "Finished calculating cell lookup map"
00093             << endl;
00094     }
00095 }
00096 
00097 
00098 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00099 
00100 // Construct from components
00101 Foam::cellZone::cellZone
00102 (
00103     const word& name,
00104     const labelList& addr,
00105     const label index,
00106     const cellZoneMesh& zm
00107 )
00108 :
00109     labelList(addr),
00110     name_(name),
00111     index_(index),
00112     zoneMesh_(zm),
00113     cellLookupMapPtr_(NULL)
00114 {}
00115 
00116 
00117 Foam::cellZone::cellZone
00118 (
00119     const word& name,
00120     const Xfer<labelList>& addr,
00121     const label index,
00122     const cellZoneMesh& zm
00123 )
00124 :
00125     labelList(addr),
00126     name_(name),
00127     index_(index),
00128     zoneMesh_(zm),
00129     cellLookupMapPtr_(NULL)
00130 {}
00131 
00132 
00133 // Construct from dictionary
00134 Foam::cellZone::cellZone
00135 (
00136     const word& name,
00137     const dictionary& dict,
00138     const label index,
00139     const cellZoneMesh& zm
00140 )
00141 :
00142     labelList(dict.lookup("cellLabels")),
00143     name_(name),
00144     index_(index),
00145     zoneMesh_(zm),
00146     cellLookupMapPtr_(NULL)
00147 {}
00148 
00149 
00150 // Construct given the original zone and resetting the
00151 //  cell list and zone mesh information
00152 Foam::cellZone::cellZone
00153 (
00154     const cellZone& cz,
00155     const labelList& addr,
00156     const label index,
00157     const cellZoneMesh& zm
00158 )
00159 :
00160     labelList(addr),
00161     name_(cz.name()),
00162     index_(index),
00163     zoneMesh_(zm),
00164     cellLookupMapPtr_(NULL)
00165 {}
00166 
00167 Foam::cellZone::cellZone
00168 (
00169     const cellZone& cz,
00170     const Xfer<labelList>& addr,
00171     const label index,
00172     const cellZoneMesh& zm
00173 )
00174 :
00175     labelList(addr),
00176     name_(cz.name()),
00177     index_(index),
00178     zoneMesh_(zm),
00179     cellLookupMapPtr_(NULL)
00180 {}
00181 
00182 
00183 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00184 
00185 Foam::cellZone::~cellZone()
00186 {
00187     clearAddressing();
00188 }
00189 
00190 
00191 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00192 
00193 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
00194 {
00195     const Map<label>& clm = cellLookupMap();
00196 
00197     Map<label>::const_iterator clmIter = clm.find(globalCellID);
00198 
00199     if (clmIter == clm.end())
00200     {
00201         return -1;
00202     }
00203     else
00204     {
00205         return clmIter();
00206     }
00207 }
00208 
00209 
00210 const Foam::cellZoneMesh& Foam::cellZone::zoneMesh() const
00211 {
00212     return zoneMesh_;
00213 }
00214 
00215 
00216 void Foam::cellZone::clearAddressing()
00217 {
00218     deleteDemandDrivenData(cellLookupMapPtr_);
00219 }
00220 
00221 
00222 bool Foam::cellZone::checkDefinition(const bool report) const
00223 {
00224     const labelList& addr = *this;
00225 
00226     bool boundaryError = false;
00227 
00228     forAll(addr, i)
00229     {
00230         if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().nCells())
00231         {
00232             boundaryError = true;
00233 
00234             if (report)
00235             {
00236                 SeriousErrorIn
00237                 (
00238                     "bool cellZone::checkDefinition("
00239                     "const bool report) const"
00240                 )   << "Zone " << name()
00241                     << " contains invalid cell label " << addr[i] << nl
00242                     << "Valid cell labels are 0.."
00243                     << zoneMesh_.mesh().nCells()-1 << endl;
00244             }
00245         }
00246     }
00247     return boundaryError;
00248 }
00249 
00250 
00251 void Foam::cellZone::write(Ostream& os) const
00252 {
00253     os  << nl << name()
00254         << nl << static_cast<const labelList&>(*this);
00255 }
00256 
00257 
00258 void Foam::cellZone::writeDict(Ostream& os) const
00259 {
00260     os  << nl << name() << nl << token::BEGIN_BLOCK << nl
00261         << "    type " << type() << token::END_STATEMENT << nl;
00262 
00263     writeEntry("cellLabels", os);
00264 
00265     os  << token::END_BLOCK << endl;
00266 }
00267 
00268 
00269 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00270 
00271 void Foam::cellZone::operator=(const cellZone& cz)
00272 {
00273     clearAddressing();
00274     labelList::operator=(cz);
00275 }
00276 
00277 
00278 void Foam::cellZone::operator=(const labelList& addr)
00279 {
00280     clearAddressing();
00281     labelList::operator=(addr);
00282 }
00283 
00284 
00285 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00286 
00287 Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& p)
00288 {
00289     p.write(os);
00290     os.check("Ostream& operator<<(Ostream& f, const cellZone& p");
00291     return os;
00292 }
00293 
00294 
00295 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd