1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
26 A subset of mesh cells.
28 \*---------------------------------------------------------------------------*/
31 #include "addToRunTimeSelectionTable.H"
32 #include "cellZoneMesh.H"
34 #include "primitiveMesh.H"
36 #include "demandDrivenData.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(cellZone, 0);
44 defineRunTimeSelectionTable(cellZone, dictionary);
45 addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 const Foam::Map<Foam::label>& Foam::cellZone::cellLookupMap() const
52 if (!cellLookupMapPtr_)
57 return *cellLookupMapPtr_;
61 void Foam::cellZone::calcCellLookupMap() const
65 Info<< "void cellZone::calcCellLookupMap() const : "
66 << "Calculating cell lookup map"
70 if (cellLookupMapPtr_)
74 "void cellZone::calcCellLookupMap() const"
75 ) << "cell lookup map already calculated"
79 const labelList& addr = *this;
81 cellLookupMapPtr_ = new Map<label>(2*addr.size());
82 Map<label>& clm = *cellLookupMapPtr_;
86 clm.insert(addr[cellI], cellI);
91 Info<< "void cellZone::calcCellLookupMap() const : "
92 << "Finished calculating cell lookup map"
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 // Construct from components
101 Foam::cellZone::cellZone
104 const labelList& addr,
106 const cellZoneMesh& zm
113 cellLookupMapPtr_(NULL)
117 Foam::cellZone::cellZone
120 const Xfer<labelList>& addr,
122 const cellZoneMesh& zm
129 cellLookupMapPtr_(NULL)
133 // Construct from dictionary
134 Foam::cellZone::cellZone
137 const dictionary& dict,
139 const cellZoneMesh& zm
142 labelList(dict.lookup("cellLabels")),
146 cellLookupMapPtr_(NULL)
150 // Construct given the original zone and resetting the
151 // cell list and zone mesh information
152 Foam::cellZone::cellZone
155 const labelList& addr,
157 const cellZoneMesh& zm
164 cellLookupMapPtr_(NULL)
167 Foam::cellZone::cellZone
170 const Xfer<labelList>& addr,
172 const cellZoneMesh& zm
179 cellLookupMapPtr_(NULL)
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
185 Foam::cellZone::~cellZone()
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
193 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
195 const Map<label>& clm = cellLookupMap();
197 Map<label>::const_iterator clmIter = clm.find(globalCellID);
199 if (clmIter == clm.end())
210 const Foam::cellZoneMesh& Foam::cellZone::zoneMesh() const
216 void Foam::cellZone::clearAddressing()
218 deleteDemandDrivenData(cellLookupMapPtr_);
222 bool Foam::cellZone::checkDefinition(const bool report) const
224 const labelList& addr = *this;
226 bool boundaryError = false;
230 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().nCells())
232 boundaryError = true;
238 "bool cellZone::checkDefinition("
239 "const bool report) const"
240 ) << "Zone " << name()
241 << " contains invalid cell label " << addr[i] << nl
242 << "Valid cell labels are 0.."
243 << zoneMesh_.mesh().nCells()-1 << endl;
247 return boundaryError;
251 void Foam::cellZone::write(Ostream& os) const
254 << nl << static_cast<const labelList&>(*this);
258 void Foam::cellZone::writeDict(Ostream& os) const
260 os << nl << name() << nl << token::BEGIN_BLOCK << nl
261 << " type " << type() << token::END_STATEMENT << nl;
263 writeEntry("cellLabels", os);
265 os << token::END_BLOCK << endl;
269 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
271 void Foam::cellZone::operator=(const cellZone& cz)
274 labelList::operator=(cz);
278 void Foam::cellZone::operator=(const labelList& addr)
281 labelList::operator=(addr);
285 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
287 Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& p)
290 os.check("Ostream& operator<<(Ostream& f, const cellZone& p");
295 // ************************************************************************* //