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 points.
27 \*---------------------------------------------------------------------------*/
29 #include "pointZone.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "pointZoneMesh.H"
33 #include "primitiveMesh.H"
34 #include "demandDrivenData.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(pointZone, 0);
41 defineRunTimeSelectionTable(pointZone, dictionary);
42 addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 const Foam::Map<Foam::label>& Foam::pointZone::pointLookupMap() const
49 if (!pointLookupMapPtr_)
54 return *pointLookupMapPtr_;
58 void Foam::pointZone::calcPointLookupMap() const
62 Info<< "void pointZone::calcPointLookupMap() const : "
63 << "Calculating point lookup map"
67 if (pointLookupMapPtr_)
71 "void pointZone::calcPointLookupMap() const"
72 ) << "point lookup map already calculated"
76 const labelList& addr = *this;
78 pointLookupMapPtr_ = new Map<label>(2*addr.size());
79 Map<label>& plm = *pointLookupMapPtr_;
83 plm.insert(addr[pointI], pointI);
88 Info<< "void pointZone::calcPointLookupMap() const : "
89 << "Finished calculating point lookup map"
95 void Foam::pointZone::clearAddressing()
97 deleteDemandDrivenData(pointLookupMapPtr_);
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
103 // Construct from components
104 Foam::pointZone::pointZone
107 const labelList& addr,
109 const pointZoneMesh& zm
116 pointLookupMapPtr_(NULL)
120 Foam::pointZone::pointZone
123 const Xfer<labelList>& addr,
125 const pointZoneMesh& zm
132 pointLookupMapPtr_(NULL)
136 // Construct from dictionary
137 Foam::pointZone::pointZone
140 const dictionary& dict,
142 const pointZoneMesh& zm
145 labelList(dict.lookup("pointLabels")),
149 pointLookupMapPtr_(NULL)
153 // Construct given the original zone and resetting the
154 // point list and zone mesh information
155 Foam::pointZone::pointZone
158 const labelList& addr,
160 const pointZoneMesh& zm
167 pointLookupMapPtr_(NULL)
171 Foam::pointZone::pointZone
174 const Xfer<labelList>& addr,
176 const pointZoneMesh& zm
183 pointLookupMapPtr_(NULL)
187 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
189 Foam::pointZone::~pointZone()
195 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
199 const Map<label>& plm = pointLookupMap();
201 Map<label>::const_iterator plmIter = plm.find(globalPointID);
203 if (plmIter == plm.end())
214 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
220 void Foam::pointZone::updateMesh()
226 bool Foam::pointZone::checkDefinition(const bool report) const
228 const labelList& addr = *this;
230 bool boundaryError = false;
234 if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().allPoints().size())
236 boundaryError = true;
242 "bool pointZone::checkDefinition("
243 "const bool report) const"
244 ) << "Zone " << name()
245 << " contains invalid point label " << addr[i] << nl
246 << "Valid point labels are 0.."
247 << zoneMesh_.mesh().allPoints().size() - 1 << endl;
251 return boundaryError;
255 void Foam::pointZone::write(Ostream& os) const
258 << nl << static_cast<const labelList&>(*this);
262 void Foam::pointZone::writeDict(Ostream& os) const
264 os << nl << name() << nl << token::BEGIN_BLOCK << incrIndent << nl
265 << indent << "type " << type() << token::END_STATEMENT << nl;
267 writeEntry("pointLabels", os);
269 os << decrIndent << token::END_BLOCK << endl;
273 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
275 void Foam::pointZone::operator=(const pointZone& cz)
278 labelList::operator=(cz);
282 void Foam::pointZone::operator=(const labelList& addr)
285 labelList::operator=(addr);
289 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
291 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
294 os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
299 // ************************************************************************* //