1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 #include "demandDrivenData.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::zone, 0);
35 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
37 const Foam::Map<Foam::label>& Foam::zone::lookupMap() const
44 return *lookupMapPtr_;
48 void Foam::zone::calcLookupMap() const
52 Info<< "void zone::calcLookupMap() const: "
53 << "Calculating lookup map"
59 FatalErrorIn("void zone::calcLookupMap() const")
60 << "Lookup map already calculated" << nl
64 const labelList& addr = *this;
66 lookupMapPtr_ = new Map<label>(2*addr.size());
67 Map<label>& lm = *lookupMapPtr_;
71 lm.insert(addr[i], i);
76 Info<< "void zone::calcLookupMap() const: "
77 << "Finished calculating lookup map"
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 const labelUList& addr,
102 const Xfer<labelList>& addr,
116 const dictionary& dict,
117 const word& labelsName,
121 labelList(dict.lookup(labelsName)),
131 const labelUList& addr,
145 const Xfer<labelList>& addr,
156 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
166 Foam::label Foam::zone::localID(const label globalCellID) const
168 const Map<label>& lm = lookupMap();
170 Map<label>::const_iterator lmIter = lm.find(globalCellID);
172 if (lmIter == lm.end())
183 void Foam::zone::clearAddressing()
185 deleteDemandDrivenData(lookupMapPtr_);
189 bool Foam::zone::checkDefinition(const label maxSize, const bool report) const
191 const labelList& addr = *this;
193 bool hasError = false;
197 if (addr[i] < 0 || addr[i] >= maxSize)
205 "bool zone::checkDefinition("
206 "const label maxSize, const bool report) const"
207 ) << "Zone " << name_
208 << " contains invalid index label " << addr[i] << nl
209 << "Valid index labels are 0.."
210 << maxSize-1 << endl;
214 // w/o report - can stop checking now
224 void Foam::zone::write(Ostream& os) const
227 << nl << static_cast<const labelList&>(*this);
231 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
233 Foam::Ostream& Foam::operator<<(Ostream& os, const zone& z)
236 os.check("Ostream& operator<<(Ostream& f, const zone& z");
241 // ************************************************************************* //