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) 2011-2016 OpenFOAM Foundation
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 "mapPolyMesh.H"
28 #include "polyMesh.H"
29 #include "processorPolyPatch.H"
30 #include "cyclicPolyPatch.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  (
86  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
87  )
88  {
89  const pointZone& fz = pointZones[zoneID];
90  addressing_ = fz;
91  }
92 
93  updateSet();
94 
95  check(mesh.nPoints());
96 }
97 
98 
100 (
101  const polyMesh& mesh,
102  const word& name,
103  const label size,
104  writeOption w
105 )
106 :
107  pointSet(mesh, name, size, w),
108  mesh_(mesh),
109  addressing_(0)
110 {
111  updateSet();
112 }
113 
114 
116 (
117  const polyMesh& mesh,
118  const word& name,
119  const topoSet& set,
120  writeOption w
121 )
122 :
123  pointSet(mesh, name, set.size(), w),
124  mesh_(mesh),
125  addressing_(refCast<const pointZoneSet>(set).addressing())
126 {
127  updateSet();
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 void pointZoneSet::invert(const label maxLen)
140 {
141  // Count
142  label n = 0;
143 
144  for (label pointi = 0; pointi < maxLen; pointi++)
145  {
146  if (!found(pointi))
147  {
148  n++;
149  }
150  }
151 
152  // Fill
153  addressing_.setSize(n);
154  n = 0;
155 
156  for (label pointi = 0; pointi < maxLen; pointi++)
157  {
158  if (!found(pointi))
159  {
160  addressing_[n] = pointi;
161  n++;
162  }
163  }
164  updateSet();
165 }
166 
167 
169 {
170  DynamicList<label> newAddressing(addressing_.size());
171 
172  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
173 
174  forAll(fSet.addressing(), i)
175  {
176  label pointi = fSet.addressing()[i];
177 
178  if (found(pointi))
179  {
180  newAddressing.append(pointi);
181  }
182  }
183 
184  addressing_.transfer(newAddressing);
185  updateSet();
186 }
187 
188 
190 {
191  DynamicList<label> newAddressing(addressing_);
192 
193  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
194 
195  forAll(fSet.addressing(), i)
196  {
197  label pointi = fSet.addressing()[i];
198 
199  if (!found(pointi))
200  {
201  newAddressing.append(pointi);
202  }
203  }
204 
205  addressing_.transfer(newAddressing);
206  updateSet();
207 }
208 
209 
211 {
212  DynamicList<label> newAddressing(addressing_.size());
213 
214  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
215 
216  forAll(addressing_, i)
217  {
218  label pointi = addressing_[i];
219 
220  if (!fSet.found(pointi))
221  {
222  // Not found in fSet so add
223  newAddressing.append(pointi);
224  }
225  }
226 
227  addressing_.transfer(newAddressing);
228  updateSet();
229 }
230 
231 
232 void pointZoneSet::sync(const polyMesh& mesh)
233 {}
234 
235 
237 {
238  return mesh.nPoints();
239 }
240 
241 
243 (
247 ) const
248 {
249  // Write shadow pointSet
250  word oldTypeName = typeName;
251  const_cast<word&>(type()) = pointSet::typeName;
252  bool ok = pointSet::writeObject(s, v, c);
253  const_cast<word&>(type()) = oldTypeName;
254 
255  // Modify pointZone
256  pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
257  label zoneID = pointZones.findZoneID(name());
258 
259  if (zoneID == -1)
260  {
261  zoneID = pointZones.size();
262 
263  pointZones.setSize(zoneID+1);
264  pointZones.set
265  (
266  zoneID,
267  new pointZone
268  (
269  name(),
270  addressing_,
271  zoneID,
272  pointZones
273  )
274  );
275  }
276  else
277  {
278  pointZones[zoneID] = addressing_;
279  }
280  pointZones.clearAddressing();
281 
282  return ok && pointZones.write();
283 }
284 
285 
287 {
288  // pointZone
289  labelList newAddressing(addressing_.size());
290 
291  label n = 0;
292  forAll(addressing_, i)
293  {
294  label pointi = addressing_[i];
295  label newPointi = morphMap.reversePointMap()[pointi];
296  if (newPointi >= 0)
297  {
298  newAddressing[n] = newPointi;
299  n++;
300  }
301  }
302  newAddressing.setSize(n);
303 
304  addressing_.transfer(newAddressing);
305 
306  updateSet();
307 }
308 
309 
311 (
312  Ostream& os,
313  const primitiveMesh& mesh,
314  const label maxLen
315 ) const
316 {
317  pointSet::writeDebug(os, mesh, maxLen);
318 }
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 } // End namespace Foam
324 
325 // ************************************************************************* //
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:387
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: pointZoneSet.C:168
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Update any stored data for new labels.
Definition: pointSet.C:160
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
label size() const
Return number of elements in table.
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointZoneSet.C:236
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
bool insert(const label &key)
Insert a new entry.
Definition: HashSet.H:116
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Definition: pointZoneSet.C:50
const labelList & addressing() const
Definition: pointZoneSet.H:105
void check(const label maxLabel)
Check validity of contents.
Definition: topoSet.C:183
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
pointSet(const IOobject &obj)
Construct from IOobject.
Definition: pointSet.C:49
virtual ~pointZoneSet()
Destructor.
Definition: pointZoneSet.C:133
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: pointZoneSet.C:189
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
pointZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: pointZoneSet.C:68
A class for handling words, derived from string.
Definition: word.H:59
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:97
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write using given format, version and compression.
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
bool found(const label &) const
Return true if hashedEntry is found in table.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: pointZoneSet.C:210
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointZoneSet.C:311
defineTypeNameAndDebug(combustionModel, 0)
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
void setSize(const label)
Reset size of List.
Definition: List.C:295
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list...
Definition: pointZone.H:62
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
label newPointi
Definition: readKivaGrid.H:501
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointZoneSet.C:286
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write pointZone.
Definition: pointZoneSet.C:243
Version number type.
Definition: IOstream.H:96
virtual bool write() const
Write using setting from DB.
label nPoints() const
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: pointZoneSet.C:139
label n
void resize(const label newSize)
Resize the hash table for efficiency.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
Definition: pointZoneSet.C:232
const word & name() const
Return name.
Definition: IOobject.H:260
Namespace for OpenFOAM.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:463
void clearStorage()
Clear the table entries and the table itself.
Like pointSet but updates pointZone when writing.
Definition: pointZoneSet.H:49