1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 A subset of mesh cells.
27 \*---------------------------------------------------------------------------*/
30 #include "addToRunTimeSelectionTable.H"
31 #include "cellZoneMesh.H"
33 #include "primitiveMesh.H"
35 #include "demandDrivenData.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(cellZone, 0);
43 defineRunTimeSelectionTable(cellZone, dictionary);
44 addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 const Foam::Map<Foam::label>& Foam::cellZone::cellLookupMap() const
51 if (!cellLookupMapPtr_)
56 return *cellLookupMapPtr_;
60 void Foam::cellZone::calcCellLookupMap() const
64 Info<< "void cellZone::calcCellLookupMap() const : "
65 << "Calculating cell lookup map"
69 if (cellLookupMapPtr_)
73 "void cellZone::calcCellLookupMap() const"
74 ) << "cell lookup map already calculated"
78 const labelList& addr = *this;
80 cellLookupMapPtr_ = new Map<label>(2*addr.size());
81 Map<label>& clm = *cellLookupMapPtr_;
85 clm.insert(addr[cellI], cellI);
90 Info<< "void cellZone::calcCellLookupMap() const : "
91 << "Finished calculating cell lookup map"
97 void Foam::cellZone::clearAddressing()
99 deleteDemandDrivenData(cellLookupMapPtr_);
103 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 // Construct from components
106 Foam::cellZone::cellZone
109 const labelList& addr,
111 const cellZoneMesh& zm
118 cellLookupMapPtr_(NULL)
122 Foam::cellZone::cellZone
125 const Xfer<labelList>& addr,
127 const cellZoneMesh& zm
134 cellLookupMapPtr_(NULL)
138 // Construct from dictionary
139 Foam::cellZone::cellZone
142 const dictionary& dict,
144 const cellZoneMesh& zm
147 labelList(dict.lookup("cellLabels")),
151 cellLookupMapPtr_(NULL)
155 // Construct given the original zone and resetting the
156 // cell list and zone mesh information
157 Foam::cellZone::cellZone
160 const labelList& addr,
162 const cellZoneMesh& zm
169 cellLookupMapPtr_(NULL)
172 Foam::cellZone::cellZone
175 const Xfer<labelList>& addr,
177 const cellZoneMesh& zm
184 cellLookupMapPtr_(NULL)
188 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 Foam::cellZone::~cellZone()
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
200 const Map<label>& clm = cellLookupMap();
202 Map<label>::const_iterator clmIter = clm.find(globalCellID);
204 if (clmIter == clm.end())
215 const Foam::cellZoneMesh& Foam::cellZone::zoneMesh() const
221 bool Foam::cellZone::checkDefinition(const bool report) const
223 const labelList& addr = *this;
225 bool boundaryError = false;
229 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().nCells())
231 boundaryError = true;
237 "bool cellZone::checkDefinition("
238 "const bool report) const"
239 ) << "Zone " << name()
240 << " contains invalid cell label " << addr[i] << nl
241 << "Valid cell labels are 0.."
242 << zoneMesh_.mesh().nCells()-1 << endl;
246 return boundaryError;
250 void Foam::cellZone::updateMesh()
256 void Foam::cellZone::write(Ostream& os) const
259 << nl << static_cast<const labelList&>(*this);
263 void Foam::cellZone::writeDict(Ostream& os) const
265 os << nl << name() << nl << token::BEGIN_BLOCK << incrIndent << nl
266 << indent << "type " << type() << token::END_STATEMENT << nl;
268 writeEntry("cellLabels", os);
270 os << decrIndent << token::END_BLOCK << endl;
274 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
276 void Foam::cellZone::operator=(const cellZone& cz)
279 labelList::operator=(cz);
283 void Foam::cellZone::operator=(const labelList& addr)
286 labelList::operator=(addr);
290 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
292 Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& p)
295 os.check("Ostream& operator<<(Ostream& f, const cellZone& p");
300 // ************************************************************************* //