FreeFOAM The Cross-Platform CFD Toolkit
pointZoneSet.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 \*---------------------------------------------------------------------------*/
25 
26 #include "pointZoneSet.H"
27 #include <OpenFOAM/mapPolyMesh.H>
28 #include <OpenFOAM/polyMesh.H>
31 
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(pointZoneSet, 0);
42 
43 addToRunTimeSelectionTable(topoSet, pointZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, pointZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, pointZoneSet, set);
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 {
52  labelList order;
53  sortedOrder(addressing_, order);
54  inplaceReorder(order, addressing_);
55 
57  pointSet::resize(2*addressing_.size());
58  forAll(addressing_, i)
59  {
60  pointSet::insert(addressing_[i]);
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
68 (
69  const polyMesh& mesh,
70  const word& name,
71  readOption r,
72  writeOption w
73 )
74 :
75  pointSet(mesh, name, 1000), // do not read pointSet
76  mesh_(mesh),
77  addressing_(0)
78 {
79  const pointZoneMesh& pointZones = mesh.pointZones();
80  label zoneID = pointZones.findZoneID(name);
81 
82  if
83  (
84  (r == IOobject::MUST_READ)
85  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
86  )
87  {
88  const pointZone& fz = pointZones[zoneID];
89  addressing_ = fz;
90  }
91 
92  updateSet();
93 
94  check(mesh.nPoints());
95 }
96 
97 
99 (
100  const polyMesh& mesh,
101  const word& name,
102  const label size,
103  writeOption w
104 )
105 :
106  pointSet(mesh, name, size, w),
107  mesh_(mesh),
108  addressing_(0)
109 {
110  updateSet();
111 }
112 
113 
115 (
116  const polyMesh& mesh,
117  const word& name,
118  const topoSet& set,
119  writeOption w
120 )
121 :
122  pointSet(mesh, name, set.size(), w),
123  mesh_(mesh),
124  addressing_(refCast<const pointZoneSet>(set).addressing())
125 {
126  updateSet();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
138 void pointZoneSet::invert(const label maxLen)
139 {
140  label n = 0;
141 
142  for (label pointI = 0; pointI < maxLen; pointI++)
143  {
144  if (!found(pointI))
145  {
146  addressing_[n] = pointI;
147  n++;
148  }
149  }
150  addressing_.setSize(n);
151  updateSet();
152 }
153 
154 
156 {
157  DynamicList<label> newAddressing(addressing_.size());
158 
159  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
160 
161  forAll(fSet.addressing(), i)
162  {
163  label pointI = fSet.addressing()[i];
164 
165  if (found(pointI))
166  {
167  newAddressing.append(pointI);
168  }
169  }
170 
171  addressing_.transfer(newAddressing);
172  updateSet();
173 }
174 
175 
177 {
178  DynamicList<label> newAddressing(addressing_);
179 
180  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
181 
182  forAll(fSet.addressing(), i)
183  {
184  label pointI = fSet.addressing()[i];
185 
186  if (!found(pointI))
187  {
188  newAddressing.append(pointI);
189  }
190  }
191 
192  addressing_.transfer(newAddressing);
193  updateSet();
194 }
195 
196 
198 {
199  DynamicList<label> newAddressing(addressing_.size());
200 
201  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
202 
203  forAll(addressing_, i)
204  {
205  label pointI = addressing_[i];
206 
207  if (!fSet.found(pointI))
208  {
209  // Not found in fSet so add
210  newAddressing.append(pointI);
211  }
212  }
213 
214  addressing_.transfer(newAddressing);
215  updateSet();
216 }
217 
218 
219 void pointZoneSet::sync(const polyMesh& mesh)
220 {}
221 
222 
223 label pointZoneSet::maxSize(const polyMesh& mesh) const
224 {
225  return mesh.nPoints();
226 }
227 
228 
229 //- Write using given format, version and compression
231 (
235 ) const
236 {
237  // Write shadow pointSet
238  word oldTypeName = typeName;
239  const_cast<word&>(type()) = pointSet::typeName;
240  bool ok = pointSet::writeObject(s, v, c);
241  const_cast<word&>(type()) = oldTypeName;
242 
243  // Modify pointZone
244  pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
245  label zoneID = pointZones.findZoneID(name());
246 
247  if (zoneID == -1)
248  {
249  zoneID = pointZones.size();
250 
251  pointZones.setSize(zoneID+1);
252  pointZones.set
253  (
254  zoneID,
255  new pointZone
256  (
257  name(),
258  addressing_,
259  zoneID,
260  pointZones
261  )
262  );
263  }
264  else
265  {
266  pointZones[zoneID] = addressing_;
267  }
268  pointZones.clearAddressing();
269 
270  return ok && pointZones.write();
271 }
272 
273 
275 {
276  // pointZone
277  labelList newAddressing(addressing_.size());
278 
279  label n = 0;
280  forAll(addressing_, i)
281  {
282  label pointI = addressing_[i];
283  label newPointI = morphMap.reversePointMap()[pointI];
284  if (newPointI >= 0)
285  {
286  newAddressing[n] = newPointI;
287  n++;
288  }
289  }
290  newAddressing.setSize(n);
291 
292  addressing_.transfer(newAddressing);
293 
294  updateSet();
295 }
296 
297 
299 (
300  Ostream& os,
301  const primitiveMesh& mesh,
302  const label maxLen
303 ) const
304 {
305  pointSet::writeDebug(os, mesh, maxLen);
306 }
307 
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 } // End namespace Foam
312 
313 // ************************ vim: set sw=4 sts=4 et: ************************ //