initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / polyMesh / zones / pointZone / pointZone.C
blobd1c450691f13dbb565184d95687edc5d4c46ca62
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     A subset of mesh points.
28 \*---------------------------------------------------------------------------*/
30 #include "pointZone.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "pointZoneMesh.H"
33 #include "polyMesh.H"
34 #include "primitiveMesh.H"
35 #include "demandDrivenData.H"
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 namespace Foam
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_)
51     {
52         calcPointLookupMap();
53     }
55     return *pointLookupMapPtr_;
59 void Foam::pointZone::calcPointLookupMap() const
61     if (debug)
62     {
63         Info<< "void pointZone::calcPointLookupMap() const : "
64             << "Calculating point lookup map"
65             << endl;
66     }
68     if (pointLookupMapPtr_)
69     {
70         FatalErrorIn
71         (
72             "void pointZone::calcPointLookupMap() const"
73         )   << "point lookup map already calculated"
74             << abort(FatalError);
75     }
77     const labelList& addr = *this;
79     pointLookupMapPtr_ = new Map<label>(2*addr.size());
80     Map<label>& plm = *pointLookupMapPtr_;
82     forAll (addr, pointI)
83     {
84         plm.insert(addr[pointI], pointI);
85     }
87     if (debug)
88     {
89         Info<< "void pointZone::calcPointLookupMap() const : "
90             << "Finished calculating point lookup map"
91             << endl;
92     }
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 // Construct from components
99 Foam::pointZone::pointZone
101     const word& name,
102     const labelList& addr,
103     const label index,
104     const pointZoneMesh& zm
107     labelList(addr),
108     name_(name),
109     index_(index),
110     zoneMesh_(zm),
111     pointLookupMapPtr_(NULL)
115 Foam::pointZone::pointZone
117     const word& name,
118     const Xfer<labelList>& addr,
119     const label index,
120     const pointZoneMesh& zm
123     labelList(addr),
124     name_(name),
125     index_(index),
126     zoneMesh_(zm),
127     pointLookupMapPtr_(NULL)
131 // Construct from dictionary
132 Foam::pointZone::pointZone
134     const word& name,
135     const dictionary& dict,
136     const label index,
137     const pointZoneMesh& zm
140     labelList(dict.lookup("pointLabels")),
141     name_(name),
142     index_(index),
143     zoneMesh_(zm),
144     pointLookupMapPtr_(NULL)
148 // Construct given the original zone and resetting the
149 // point list and zone mesh information
150 Foam::pointZone::pointZone
152     const pointZone& pz,
153     const labelList& addr,
154     const label index,
155     const pointZoneMesh& zm
158     labelList(addr),
159     name_(pz.name()),
160     index_(index),
161     zoneMesh_(zm),
162     pointLookupMapPtr_(NULL)
166 Foam::pointZone::pointZone
168     const pointZone& pz,
169     const Xfer<labelList>& addr,
170     const label index,
171     const pointZoneMesh& zm
174     labelList(addr),
175     name_(pz.name()),
176     index_(index),
177     zoneMesh_(zm),
178     pointLookupMapPtr_(NULL)
182 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
184 Foam::pointZone::~pointZone()
186     clearAddressing();
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())
199     {
200         return -1;
201     }
202     else
203     {
204         return plmIter();
205     }
209 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
211     return zoneMesh_;
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;
227     forAll(addr, i)
228     {
229         if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
230         {
231             boundaryError = true;
233             if (report)
234             {
235                 SeriousErrorIn
236                 (
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;
243             }
244         }
245     }
246     return boundaryError;
250 void Foam::pointZone::write(Ostream& os) const
252     os  << nl << name()
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)
272     clearAddressing();
273     labelList::operator=(cz);
277 void Foam::pointZone::operator=(const labelList& addr)
279     clearAddressing();
280     labelList::operator=(addr);
284 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
286 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
288     p.write(os);
289     os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
290     return os;
294 // ************************************************************************* //