pointZoneSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 meshPointZones& 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  pointSet::sync(mesh);
235 
236  // Take over contents of pointSet into addressing.
237  addressing_ = sortedToc();
238  updateSet();
239 }
240 
241 
243 {
244  return mesh.nPoints();
245 }
246 
247 
249 (
253  const bool write
254 ) const
255 {
256  // Write shadow pointSet
257  word oldTypeName = typeName;
258  const_cast<word&>(type()) = pointSet::typeName;
259  bool ok = pointSet::writeObject(s, v, c, write);
260  const_cast<word&>(type()) = oldTypeName;
261 
262  // Modify pointZone
263  meshPointZones& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
264  label zoneID = pointZones.findZoneID(name());
265 
266  if (zoneID == -1)
267  {
268  zoneID = pointZones.size();
269 
270  pointZones.setSize(zoneID+1);
271  pointZones.set
272  (
273  zoneID,
274  new pointZone
275  (
276  name(),
277  addressing_,
278  zoneID,
279  pointZones
280  )
281  );
282  }
283  else
284  {
285  pointZones[zoneID] = addressing_;
286  }
287  pointZones.clearAddressing();
288 
289  return ok && pointZones.write(write);
290 }
291 
292 
294 {
295  // pointZone
296  labelList newAddressing(addressing_.size());
297 
298  label n = 0;
299  forAll(addressing_, i)
300  {
301  label pointi = addressing_[i];
302  label newPointi = morphMap.reversePointMap()[pointi];
303  if (newPointi >= 0)
304  {
305  newAddressing[n] = newPointi;
306  n++;
307  }
308  }
309  newAddressing.setSize(n);
310 
311  addressing_.transfer(newAddressing);
312 
313  updateSet();
314 }
315 
316 
318 (
319  Ostream& os,
320  const primitiveMesh& mesh,
321  const label maxLen
322 ) const
323 {
324  pointSet::writeDebug(os, mesh, maxLen);
325 }
326 
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 } // End namespace Foam
331 
332 // ************************************************************************* //
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointZoneSet.C:242
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
writeOption
Enumeration defining the write options.
Definition: IOobject.H:119
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:458
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
const word & name() const
Return name.
Definition: IOobject.H:303
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
bool set(const label) const
Is element set.
Definition: PtrListI.H:65
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write=true) const
Write pointZone.
Definition: pointZoneSet.C:249
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
readOption
Enumeration defining the read options.
Definition: IOobject.H:110
bool insert(const label &key)
Insert a new entry.
Definition: HashSet.H:111
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Definition: pointZoneSet.C:50
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointZoneSet.C:318
void check(const label maxLabel)
Check validity of contents.
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
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
const meshPointZones & pointZones() const
Return point zones.
Definition: polyMesh.H:470
virtual ~pointZoneSet()
Destructor.
Definition: pointZoneSet.C:133
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: pointZoneSet.C:189
pointZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: pointZoneSet.C:68
bool found(const label &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
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:178
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:296
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
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:54
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: pointZoneSet.C:210
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void setSize(const label)
Reset size of List.
Definition: List.C:281
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list...
Definition: pointZone.H:62
const labelList & addressing() const
Definition: pointZoneSet.H:106
label newPointi
Definition: readKivaGrid.H:501
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointZoneSet.C:293
List< label > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Version number type.
Definition: IOstream.H:96
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: pointZoneSet.C:139
label n
label nPoints() const
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:432
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Definition: pointSet.C:113
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Update any stored data for new labels.
Definition: pointSet.C:160
virtual bool write(const bool write=true) const
Write using setting from DB.
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
Definition: pointZoneSet.C:232
Namespace for OpenFOAM.
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:492
Like pointSet but -reads data from pointZone -updates pointZone when writing.
Definition: pointZoneSet.H:50