Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / meshes / polyMesh / zones / pointZone / pointZone.C
blob153b4a16efaa5dba552d05939f4e955282e83be7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Description
25     A subset of mesh points.
27 \*---------------------------------------------------------------------------*/
29 #include "pointZone.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "pointZoneMesh.H"
32 #include "polyMesh.H"
33 #include "primitiveMesh.H"
34 #include "demandDrivenData.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
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_)
50     {
51         calcPointLookupMap();
52     }
54     return *pointLookupMapPtr_;
58 void Foam::pointZone::calcPointLookupMap() const
60     if (debug)
61     {
62         Info<< "void pointZone::calcPointLookupMap() const : "
63             << "Calculating point lookup map"
64             << endl;
65     }
67     if (pointLookupMapPtr_)
68     {
69         FatalErrorIn
70         (
71             "void pointZone::calcPointLookupMap() const"
72         )   << "point lookup map already calculated"
73             << abort(FatalError);
74     }
76     const labelList& addr = *this;
78     pointLookupMapPtr_ = new Map<label>(2*addr.size());
79     Map<label>& plm = *pointLookupMapPtr_;
81     forAll (addr, pointI)
82     {
83         plm.insert(addr[pointI], pointI);
84     }
86     if (debug)
87     {
88         Info<< "void pointZone::calcPointLookupMap() const : "
89             << "Finished calculating point lookup map"
90             << endl;
91     }
95 void Foam::pointZone::clearAddressing()
97     deleteDemandDrivenData(pointLookupMapPtr_);
101 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
103 // Construct from components
104 Foam::pointZone::pointZone
106     const word& name,
107     const labelList& addr,
108     const label index,
109     const pointZoneMesh& zm
112     labelList(addr),
113     name_(name),
114     index_(index),
115     zoneMesh_(zm),
116     pointLookupMapPtr_(NULL)
120 Foam::pointZone::pointZone
122     const word& name,
123     const Xfer<labelList>& addr,
124     const label index,
125     const pointZoneMesh& zm
128     labelList(addr),
129     name_(name),
130     index_(index),
131     zoneMesh_(zm),
132     pointLookupMapPtr_(NULL)
136 // Construct from dictionary
137 Foam::pointZone::pointZone
139     const word& name,
140     const dictionary& dict,
141     const label index,
142     const pointZoneMesh& zm
145     labelList(dict.lookup("pointLabels")),
146     name_(name),
147     index_(index),
148     zoneMesh_(zm),
149     pointLookupMapPtr_(NULL)
153 // Construct given the original zone and resetting the
154 // point list and zone mesh information
155 Foam::pointZone::pointZone
157     const pointZone& pz,
158     const labelList& addr,
159     const label index,
160     const pointZoneMesh& zm
163     labelList(addr),
164     name_(pz.name()),
165     index_(index),
166     zoneMesh_(zm),
167     pointLookupMapPtr_(NULL)
171 Foam::pointZone::pointZone
173     const pointZone& pz,
174     const Xfer<labelList>& addr,
175     const label index,
176     const pointZoneMesh& zm
179     labelList(addr),
180     name_(pz.name()),
181     index_(index),
182     zoneMesh_(zm),
183     pointLookupMapPtr_(NULL)
187 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
189 Foam::pointZone::~pointZone()
191     clearAddressing();
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())
204     {
205         return -1;
206     }
207     else
208     {
209         return plmIter();
210     }
214 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
216     return zoneMesh_;
220 void Foam::pointZone::updateMesh()
222     clearAddressing();
226 bool Foam::pointZone::checkDefinition(const bool report) const
228     const labelList& addr = *this;
230     bool boundaryError = false;
232     forAll(addr, i)
233     {
234         if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().allPoints().size())
235         {
236             boundaryError = true;
238             if (report)
239             {
240                 SeriousErrorIn
241                 (
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;
248             }
249         }
250     }
251     return boundaryError;
255 void Foam::pointZone::write(Ostream& os) const
257     os  << nl << name()
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)
277     clearAddressing();
278     labelList::operator=(cz);
282 void Foam::pointZone::operator=(const labelList& addr)
284     clearAddressing();
285     labelList::operator=(addr);
289 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
291 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
293     p.write(os);
294     os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
295     return os;
299 // ************************************************************************* //