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 points.
28 \*---------------------------------------------------------------------------*/
30 #include "pointZone.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "pointZoneMesh.H"
34 #include "primitiveMesh.H"
35 #include "demandDrivenData.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(pointZone, 0);
42 defineRunTimeSelectionTable(pointZone, dictionary);
43 addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 const Foam::Map<Foam::label>& Foam::pointZone::pointLookupMap() const
50 if (!pointLookupMapPtr_)
55 return *pointLookupMapPtr_;
59 void Foam::pointZone::calcPointLookupMap() const
63 Info<< "void pointZone::calcPointLookupMap() const : "
64 << "Calculating point lookup map"
68 if (pointLookupMapPtr_)
72 "void pointZone::calcPointLookupMap() const"
73 ) << "point lookup map already calculated"
77 const labelList& addr = *this;
79 pointLookupMapPtr_ = new Map<label>(2*addr.size());
80 Map<label>& plm = *pointLookupMapPtr_;
84 plm.insert(addr[pointI], pointI);
89 Info<< "void pointZone::calcPointLookupMap() const : "
90 << "Finished calculating point lookup map"
96 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::pointZone::pointZone
102 const labelList& addr,
104 const pointZoneMesh& zm
111 pointLookupMapPtr_(NULL)
115 Foam::pointZone::pointZone
118 const Xfer<labelList>& addr,
120 const pointZoneMesh& zm
127 pointLookupMapPtr_(NULL)
131 // Construct from dictionary
132 Foam::pointZone::pointZone
135 const dictionary& dict,
137 const pointZoneMesh& zm
140 labelList(dict.lookup("pointLabels")),
144 pointLookupMapPtr_(NULL)
148 // Construct given the original zone and resetting the
149 // point list and zone mesh information
150 Foam::pointZone::pointZone
153 const labelList& addr,
155 const pointZoneMesh& zm
162 pointLookupMapPtr_(NULL)
166 Foam::pointZone::pointZone
169 const Xfer<labelList>& addr,
171 const pointZoneMesh& zm
178 pointLookupMapPtr_(NULL)
182 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 Foam::pointZone::~pointZone()
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
194 const Map<label>& plm = pointLookupMap();
196 Map<label>::const_iterator plmIter = plm.find(globalPointID);
198 if (plmIter == plm.end())
209 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
215 void Foam::pointZone::clearAddressing()
217 deleteDemandDrivenData(pointLookupMapPtr_);
221 bool Foam::pointZone::checkDefinition(const bool report) const
223 const labelList& addr = *this;
225 bool boundaryError = false;
229 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
231 boundaryError = true;
237 "bool pointZone::checkDefinition("
238 "const bool report) const"
239 ) << "Zone " << name()
240 << " contains invalid point label " << addr[i] << nl
241 << "Valid point labels are 0.."
242 << zoneMesh_.mesh().points().size()-1 << endl;
246 return boundaryError;
250 void Foam::pointZone::write(Ostream& os) const
253 << nl << static_cast<const labelList&>(*this);
257 void Foam::pointZone::writeDict(Ostream& os) const
259 os << nl << name() << nl << token::BEGIN_BLOCK << nl
260 << " type " << type() << token::END_STATEMENT << nl;
262 writeEntry("pointLabels", os);
264 os << token::END_BLOCK << endl;
268 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
270 void Foam::pointZone::operator=(const pointZone& cz)
273 labelList::operator=(cz);
277 void Foam::pointZone::operator=(const labelList& addr)
280 labelList::operator=(addr);
284 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
286 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
289 os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
294 // ************************************************************************* //