cellZoneSet.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-2022 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 "cellZoneSet.H"
27 #include "polyTopoChangeMap.H"
28 #include "polyMesh.H"
29 
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 defineTypeNameAndDebug(cellZoneSet, 0);
40 
41 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
42 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
43 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  labelList order;
51  sortedOrder(addressing_, order);
52  inplaceReorder(order, addressing_);
53 
55  cellSet::resize(2*addressing_.size());
56  forAll(addressing_, i)
57  {
58  cellSet::insert(addressing_[i]);
59  }
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
66 (
67  const polyMesh& mesh,
68  const word& name,
69  readOption r,
70  writeOption w
71 )
72 :
73  cellSet(mesh, name, 1000), // do not read cellSet
74  mesh_(mesh),
75  addressing_(0)
76 {
77  const meshCellZones& cellZones = mesh.cellZones();
78  label zoneID = cellZones.findZoneID(name);
79 
80  if
81  (
82  (r == IOobject::MUST_READ)
84  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
85  )
86  {
87  const cellZone& fz = cellZones[zoneID];
88  addressing_ = fz;
89  }
90 
91  updateSet();
92 
93  check(mesh.nCells());
94 }
95 
96 
98 (
99  const polyMesh& mesh,
100  const word& name,
101  const label size,
102  writeOption w
103 )
104 :
105  cellSet(mesh, name, size, w),
106  mesh_(mesh),
107  addressing_(0)
108 {
109  updateSet();
110 }
111 
112 
114 (
115  const polyMesh& mesh,
116  const word& name,
117  const topoSet& set,
118  writeOption w
119 )
120 :
121  cellSet(mesh, name, set.size(), w),
122  mesh_(mesh),
123  addressing_(refCast<const cellZoneSet>(set).addressing())
124 {
125  updateSet();
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
130 
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
137 void cellZoneSet::invert(const label maxLen)
138 {
139  // Count
140  label n = 0;
141 
142  for (label celli = 0; celli < maxLen; celli++)
143  {
144  if (!found(celli))
145  {
146  n++;
147  }
148  }
149 
150  // Fill
151  addressing_.setSize(n);
152  n = 0;
153 
154  for (label celli = 0; celli < maxLen; celli++)
155  {
156  if (!found(celli))
157  {
158  addressing_[n] = celli;
159  n++;
160  }
161  }
162 
163  updateSet();
164 }
165 
166 
167 void cellZoneSet::subset(const topoSet& set)
168 {
169  DynamicList<label> newAddressing(addressing_.size());
170 
171  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
172 
173  forAll(fSet.addressing(), i)
174  {
175  label celli = fSet.addressing()[i];
176 
177  if (found(celli))
178  {
179  newAddressing.append(celli);
180  }
181  }
182 
183  addressing_.transfer(newAddressing);
184  updateSet();
185 }
186 
187 
188 void cellZoneSet::addSet(const topoSet& set)
189 {
190  DynamicList<label> newAddressing(addressing_);
191 
192  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
193 
194  forAll(fSet.addressing(), i)
195  {
196  label celli = fSet.addressing()[i];
197 
198  if (!found(celli))
199  {
200  newAddressing.append(celli);
201  }
202  }
203 
204  addressing_.transfer(newAddressing);
205  updateSet();
206 }
207 
208 
210 {
211  DynamicList<label> newAddressing(addressing_.size());
212 
213  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
214 
215  forAll(addressing_, i)
216  {
217  label celli = addressing_[i];
218 
219  if (!fSet.found(celli))
220  {
221  // Not found in fSet so add
222  newAddressing.append(celli);
223  }
224  }
225 
226  addressing_.transfer(newAddressing);
227  updateSet();
228 }
229 
230 
231 void cellZoneSet::sync(const polyMesh& mesh)
232 {
233  cellSet::sync(mesh);
234 
235  // Take over contents of cellSet into addressing.
236  addressing_ = sortedToc();
237  updateSet();
238 }
239 
240 
242 {
243  return mesh.nCells();
244 }
245 
246 
248 (
252  const bool write
253 ) const
254 {
255  // Write shadow cellSet
256  word oldTypeName = typeName;
257  const_cast<word&>(type()) = cellSet::typeName;
258  bool ok = cellSet::writeObject(s, v, c, write);
259  const_cast<word&>(type()) = oldTypeName;
260 
261  // Modify cellZone
262  meshCellZones& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
263  label zoneID = cellZones.findZoneID(name());
264 
265  if (zoneID == -1)
266  {
267  zoneID = cellZones.size();
268 
269  cellZones.setSize(zoneID+1);
270  cellZones.set
271  (
272  zoneID,
273  new cellZone
274  (
275  name(),
276  addressing_,
277  zoneID,
278  cellZones
279  )
280  );
281  }
282  else
283  {
284  cellZones[zoneID] = addressing_;
285  }
286  cellZones.clearAddressing();
287 
288  return ok && cellZones.write(write);
289 }
290 
291 
293 {
294  // cellZone
295  labelList newAddressing(addressing_.size());
296 
297  label n = 0;
298  forAll(addressing_, i)
299  {
300  label celli = addressing_[i];
301  label newCelli = map.reverseCellMap()[celli];
302  if (newCelli >= 0)
303  {
304  newAddressing[n] = newCelli;
305  n++;
306  }
307  }
308  newAddressing.setSize(n);
309 
310  addressing_.transfer(newAddressing);
311 
312  updateSet();
313 }
314 
315 
317 (
318  Ostream& os,
319  const primitiveMesh& mesh,
320  const label maxLen
321 ) const
322 {
323  cellSet::writeDebug(os, mesh, maxLen);
324 }
325 
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 } // End namespace Foam
330 
331 // ************************************************************************* //
virtual ~cellZoneSet()
Destructor.
Definition: cellZoneSet.C:131
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:125
const word & name() const
Return name.
Definition: IOobject.H:315
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
cellSet(const IOobject &obj)
Construct from IOobject. No checking.
Definition: cellSet.C:48
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:501
cellZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: cellZoneSet.C:66
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellSet.C:232
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nCells() const
Like cellSet but -reads data from cellZone -updates cellZone when writing.
Definition: cellZoneSet.H:49
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: cellZoneSet.C:188
readOption
Enumeration defining the read options.
Definition: IOobject.H:116
bool insert(const label &key)
Insert a new entry.
Definition: HashSet.H:111
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: cellZoneSet.C:209
void check(const label maxLabel)
Check validity of contents.
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Macros for easy insertion into run-time selection tables.
virtual void topoChange(const polyTopoChangeMap &map)
Update any stored data for new labels.
Definition: cellZoneSet.C:292
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition: cellZoneSet.C:48
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
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: cellZoneSet.C:137
defineTypeNameAndDebug(combustionModel, 0)
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellZoneSet.C:317
const labelList & reverseCellMap() const
Reverse cell map.
A subset of mesh cells.
Definition: cellZone.H:61
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
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellZoneSet.C:241
void setSize(const label)
Reset size of List.
Definition: List.C:281
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
const labelList & addressing() const
Definition: cellZoneSet.H:102
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write=true) const
Write cellZone.
Definition: cellZoneSet.C:248
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
label n
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:432
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches; update cellZone from cellSet.
Definition: cellZoneSet.C:231
virtual bool write(const bool write=true) const
Write using setting from DB.
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: cellZoneSet.C:167
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches.
Definition: cellSet.H:140
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
Namespace for OpenFOAM.
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:492