cellZoneSet.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 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 "mapPolyMesh.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 cellZoneMesh& 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 
234 
236 {
237  return mesh.nCells();
238 }
239 
240 
241 //- Write using given format, version and compression
243 (
247 ) const
248 {
249  // Write shadow cellSet
250  word oldTypeName = typeName;
251  const_cast<word&>(type()) = cellSet::typeName;
252  bool ok = cellSet::writeObject(s, v, c);
253  const_cast<word&>(type()) = oldTypeName;
254 
255  // Modify cellZone
256  cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
257  label zoneID = cellZones.findZoneID(name());
258 
259  if (zoneID == -1)
260  {
261  zoneID = cellZones.size();
262 
263  cellZones.setSize(zoneID+1);
264  cellZones.set
265  (
266  zoneID,
267  new cellZone
268  (
269  name(),
270  addressing_,
271  zoneID,
272  cellZones
273  )
274  );
275  }
276  else
277  {
278  cellZones[zoneID] = addressing_;
279  }
280  cellZones.clearAddressing();
281 
282  return ok && cellZones.write();
283 }
284 
285 
287 {
288  // cellZone
289  labelList newAddressing(addressing_.size());
290 
291  label n = 0;
292  forAll(addressing_, i)
293  {
294  label cellI = addressing_[i];
295  label newCellI = morphMap.reverseCellMap()[cellI];
296  if (newCellI >= 0)
297  {
298  newAddressing[n] = newCellI;
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  cellSet::writeDebug(os, mesh, maxLen);
318 }
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 } // End namespace Foam
324 
325 // ************************************************************************* //
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
const labelList & addressing() const
Definition: cellZoneSet.H:102
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:142
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: cellZoneSet.C:167
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
bool set(const label) const
Is element set.
Definition: PtrListI.H:107
Like cellSet but updates cellZone when writing.
Definition: cellZoneSet.H:49
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:390
A subset of mesh cells.
Definition: cellZone.H:61
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write using given format, version and compression.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
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
Write maxLen items with label and coordinates.
Definition: cellSet.C:232
A collection of cell labels.
Definition: cellSet.H:48
A class for handling words, derived from string.
Definition: word.H:59
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 resize(const label newSize)
Resize the hash table for efficiency.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
label nCells() const
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write cellZone.
Definition: cellZoneSet.C:243
Namespace for OpenFOAM.
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition: cellZoneSet.C:48
void clearStorage()
Clear the table entries and the table itself.
virtual bool write() const
Write using setting from DB.
label n
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:400
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
void setSize(const label)
Reset size of List.
Definition: List.C:318
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: cellZoneSet.C:188
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
#define forAll(list, i)
Definition: UList.H:421
Macros for easy insertion into run-time selection tables.
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: cellZoneSet.C:286
label size() const
Return number of elements in table.
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellZoneSet.C:311
const word & name() const
Return name.
Definition: IOobject.H:260
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellZoneSet.C:235
void check(const label maxLabel)
Check validity of contents.
Definition: topoSet.C:194
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
cellZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: cellZoneSet.C:66
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: cellZoneSet.C:209
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:354
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:528
virtual ~cellZoneSet()
Destructor.
Definition: cellZoneSet.C:131
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:97
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: cellZoneSet.C:137
Version number type.
Definition: IOstream.H:96
virtual void sync(const polyMesh &mesh)
Sync cellZoneSet across coupled patches.
Definition: cellZoneSet.C:231
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
bool found(const label &) const
Return true if hashedEntry is found in table.
defineTypeNameAndDebug(combustionModel, 0)
bool insert(const label &key)
Insert a new entry.
Definition: HashSet.H:116