initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / polyMesh / zones / pointZone / pointZone.C
blob972588686d608bfb462003ff73730615c5b0618e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 // Construct from dictionary
116 Foam::pointZone::pointZone
118     const word& name,
119     const dictionary& dict,
120     const label index,
121     const pointZoneMesh& zm
124     labelList(dict.lookup("pointLabels")),
125     name_(name),
126     index_(index),
127     zoneMesh_(zm),
128     pointLookupMapPtr_(NULL)
132 // Construct given the original zone and resetting the
133 // point list and zone mesh information
134 Foam::pointZone::pointZone
136     const pointZone& pz,
137     const labelList& addr,
138     const label index,
139     const pointZoneMesh& zm
142     labelList(addr),
143     name_(pz.name()),
144     index_(index),
145     zoneMesh_(zm),
146     pointLookupMapPtr_(NULL)
150 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
152 Foam::pointZone::~pointZone()
154     clearAddressing();
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())
167     {
168         return -1;
169     }
170     else
171     {
172         return plmIter();
173     }
177 const Foam::pointZoneMesh& Foam::pointZone::zoneMesh() const
179     return zoneMesh_;
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;
195     forAll(addr, i)
196     {
197         if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
198         {
199             boundaryError = true;
201             if (report)
202             {
203                 SeriousErrorIn
204                 (
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;
211             }
212         }
213     }
214     return boundaryError;
218 void Foam::pointZone::write(Ostream& os) const
220     os  << nl << name()
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)
240     clearAddressing();
241     labelList::operator=(cz);
245 void Foam::pointZone::operator=(const labelList& addr)
247     clearAddressing();
248     labelList::operator=(addr);
252 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
254 Foam::Ostream& Foam::operator<<(Ostream& os, const pointZone& p)
256     p.write(os);
257     os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
258     return os;
262 // ************************************************************************* //