FreeFOAM The Cross-Platform CFD Toolkit
pointZone.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  A subset of mesh points.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "pointZone.H"
31 #include <OpenFOAM/pointZoneMesh.H>
32 #include <OpenFOAM/polyMesh.H>
33 #include <OpenFOAM/primitiveMesh.H>
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(pointZone, 0);
41  defineRunTimeSelectionTable(pointZone, dictionary);
42  addToRunTimeSelectionTable(pointZone, pointZone, dictionary);
43 }
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 const Foam::Map<Foam::label>& Foam::pointZone::pointLookupMap() const
48 {
49  if (!pointLookupMapPtr_)
50  {
51  calcPointLookupMap();
52  }
53 
54  return *pointLookupMapPtr_;
55 }
56 
57 
58 void Foam::pointZone::calcPointLookupMap() const
59 {
60  if (debug)
61  {
62  Info<< "void pointZone::calcPointLookupMap() const : "
63  << "Calculating point lookup map"
64  << endl;
65  }
66 
67  if (pointLookupMapPtr_)
68  {
70  (
71  "void pointZone::calcPointLookupMap() const"
72  ) << "point lookup map already calculated"
73  << abort(FatalError);
74  }
75 
76  const labelList& addr = *this;
77 
78  pointLookupMapPtr_ = new Map<label>(2*addr.size());
79  Map<label>& plm = *pointLookupMapPtr_;
80 
81  forAll (addr, pointI)
82  {
83  plm.insert(addr[pointI], pointI);
84  }
85 
86  if (debug)
87  {
88  Info<< "void pointZone::calcPointLookupMap() const : "
89  << "Finished calculating point lookup map"
90  << endl;
91  }
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
97 // Construct from components
98 Foam::pointZone::pointZone
99 (
100  const word& name,
101  const labelList& addr,
102  const label index,
103  const pointZoneMesh& zm
104 )
105 :
106  labelList(addr),
107  name_(name),
108  index_(index),
109  zoneMesh_(zm),
110  pointLookupMapPtr_(NULL)
111 {}
112 
113 
114 Foam::pointZone::pointZone
115 (
116  const word& name,
117  const Xfer<labelList>& addr,
118  const label index,
119  const pointZoneMesh& zm
120 )
121 :
122  labelList(addr),
123  name_(name),
124  index_(index),
125  zoneMesh_(zm),
126  pointLookupMapPtr_(NULL)
127 {}
128 
129 
130 // Construct from dictionary
131 Foam::pointZone::pointZone
132 (
133  const word& name,
134  const dictionary& dict,
135  const label index,
136  const pointZoneMesh& zm
137 )
138 :
139  labelList(dict.lookup("pointLabels")),
140  name_(name),
141  index_(index),
142  zoneMesh_(zm),
143  pointLookupMapPtr_(NULL)
144 {}
145 
146 
147 // Construct given the original zone and resetting the
148 // point list and zone mesh information
149 Foam::pointZone::pointZone
150 (
151  const pointZone& pz,
152  const labelList& addr,
153  const label index,
154  const pointZoneMesh& zm
155 )
156 :
157  labelList(addr),
158  name_(pz.name()),
159  index_(index),
160  zoneMesh_(zm),
161  pointLookupMapPtr_(NULL)
162 {}
163 
164 
165 Foam::pointZone::pointZone
166 (
167  const pointZone& pz,
168  const Xfer<labelList>& addr,
169  const label index,
170  const pointZoneMesh& zm
171 )
172 :
173  labelList(addr),
174  name_(pz.name()),
175  index_(index),
176  zoneMesh_(zm),
177  pointLookupMapPtr_(NULL)
178 {}
179 
180 
181 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
182 
184 {
185  clearAddressing();
186 }
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
191 Foam::label Foam::pointZone::whichPoint(const label globalPointID) const
192 {
193  const Map<label>& plm = pointLookupMap();
194 
195  Map<label>::const_iterator plmIter = plm.find(globalPointID);
196 
197  if (plmIter == plm.end())
198  {
199  return -1;
200  }
201  else
202  {
203  return plmIter();
204  }
205 }
206 
207 
209 {
210  return zoneMesh_;
211 }
212 
213 
215 {
216  deleteDemandDrivenData(pointLookupMapPtr_);
217 }
218 
219 
220 bool Foam::pointZone::checkDefinition(const bool report) const
221 {
222  const labelList& addr = *this;
223 
224  bool boundaryError = false;
225 
226  forAll(addr, i)
227  {
228  if (addr[i] < 0 || addr[i] >= zoneMesh_.mesh().points().size())
229  {
230  boundaryError = true;
231 
232  if (report)
233  {
235  (
236  "bool pointZone::checkDefinition("
237  "const bool report) const"
238  ) << "Zone " << name()
239  << " contains invalid point label " << addr[i] << nl
240  << "Valid point labels are 0.."
241  << zoneMesh_.mesh().points().size()-1 << endl;
242  }
243  }
244  }
245  return boundaryError;
246 }
247 
248 
250 {
251  os << nl << name()
252  << nl << static_cast<const labelList&>(*this);
253 }
254 
255 
257 {
258  os << nl << name() << nl << token::BEGIN_BLOCK << nl
259  << " type " << type() << token::END_STATEMENT << nl;
260 
261  writeEntry("pointLabels", os);
262 
263  os << token::END_BLOCK << endl;
264 }
265 
266 
267 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
268 
270 {
271  clearAddressing();
273 }
274 
275 
277 {
278  clearAddressing();
279  labelList::operator=(addr);
280 }
281 
282 
283 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
284 
286 {
287  p.write(os);
288  os.check("Ostream& operator<<(Ostream& f, const pointZone& p");
289  return os;
290 }
291 
292 
293 // ************************ vim: set sw=4 sts=4 et: ************************ //