1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 // Construct from dictionary
116 Foam::pointZone::pointZone
119 const dictionary& dict,
121 const pointZoneMesh& zm
124 labelList(dict.lookup("pointLabels")),
128 pointLookupMapPtr_(NULL)
132 // Construct given the original zone and resetting the
133 // point list and zone mesh information
134 Foam::pointZone::pointZone
137 const labelList& addr,
139 const pointZoneMesh& zm
146 pointLookupMapPtr_(NULL)
150 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
152 Foam::pointZone::~pointZone()
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
162 const Map<label>& plm = pointLookupMap();
164 Map<label>::const_iterator plmIter = plm.find(globalPointID);
166 if (plmIter == plm.end())
177 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
183 void Foam::pointZone::clearAddressing()
185 deleteDemandDrivenData(pointLookupMapPtr_);
189 bool Foam::pointZone::checkDefinition(const bool report) const
191 const labelList& addr = *this;
193 bool boundaryError = false;
197 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
199 boundaryError = true;
205 "bool pointZone::checkDefinition("
206 "const bool report) const"
207 ) << "Zone " << name()
208 << " contains invalid point label " << addr[i] << nl
209 << "Valid point labels are 0.."
210 << zoneMesh_.mesh().points().size()-1 << endl;
214 return boundaryError;
218 void Foam::pointZone::write(Ostream& os) const
221 << nl << static_cast<const labelList&>(*this);
225 void Foam::pointZone::writeDict(Ostream& os) const
227 os << nl << name() << nl << token::BEGIN_BLOCK << nl
228 << " type " << type() << token::END_STATEMENT << nl;
230 writeEntry("pointLabels", os);
232 os << token::END_BLOCK << endl;
236 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
238 void Foam::pointZone::operator=(const pointZone& cz)
241 labelList::operator=(cz);
245 void Foam::pointZone::operator=(const labelList& addr)
248 labelList::operator=(addr);
252 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
254 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
257 os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
262 // ************************************************************************* //