faceZoneSet.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 "faceZoneSet.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(faceZoneSet, 0);
40 
41 addToRunTimeSelectionTable(topoSet, faceZoneSet, word);
42 addToRunTimeSelectionTable(topoSet, faceZoneSet, size);
43 addToRunTimeSelectionTable(topoSet, faceZoneSet, set);
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  labelList order;
51  sortedOrder(addressing_, order);
52  addressing_ = UIndirectList<label>(addressing_, order)();
53  flipMap_ = UIndirectList<bool>(flipMap_, order)();
54 
56  faceSet::resize(2*addressing_.size());
57  forAll(addressing_, i)
58  {
59  faceSet::insert(addressing_[i]);
60  }
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 
67 (
68  const polyMesh& mesh,
69  const word& name,
70  readOption r,
71  writeOption w
72 )
73 :
74  faceSet(mesh, name, 1000), // do not read faceSet
75  mesh_(mesh),
76  addressing_(0),
77  flipMap_(0)
78 {
79  const faceZoneMesh& faceZones = mesh.faceZones();
80  label zoneID = faceZones.findZoneID(name);
81 
82  if
83  (
84  (r == IOobject::MUST_READ)
86  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
87  )
88  {
89  const faceZone& fz = faceZones[zoneID];
90  addressing_ = fz;
91  flipMap_ = fz.flipMap();
92  }
93 
94  updateSet();
95 
96  check(mesh.nFaces());
97 }
98 
99 
101 (
102  const polyMesh& mesh,
103  const word& name,
104  const label size,
105  writeOption w
106 )
107 :
108  faceSet(mesh, name, size, w),
109  mesh_(mesh),
110  addressing_(0),
111  flipMap_(0)
112 {
113  updateSet();
114 }
115 
116 
118 (
119  const polyMesh& mesh,
120  const word& name,
121  const topoSet& set,
122  writeOption w
123 )
124 :
125  faceSet(mesh, name, set.size(), w),
126  mesh_(mesh),
127  addressing_(refCast<const faceZoneSet>(set).addressing()),
128  flipMap_(refCast<const faceZoneSet>(set).flipMap())
129 {
130  updateSet();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
135 
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
142 void faceZoneSet::invert(const label maxLen)
143 {
144  // Count
145  label n = 0;
146 
147  for (label facei = 0; facei < maxLen; facei++)
148  {
149  if (!found(facei))
150  {
151  n++;
152  }
153  }
154 
155  // Fill
156  addressing_.setSize(n);
157  flipMap_.setSize(n);
158  n = 0;
159 
160  for (label facei = 0; facei < maxLen; facei++)
161  {
162  if (!found(facei))
163  {
164  addressing_[n] = facei;
165  flipMap_[n] = false; //? or true?
166  n++;
167  }
168  }
169  updateSet();
170 }
171 
172 
173 void faceZoneSet::subset(const topoSet& set)
174 {
175  label nConflict = 0;
176 
177  DynamicList<label> newAddressing(addressing_.size());
178  DynamicList<bool> newFlipMap(flipMap_.size());
179 
180  Map<label> faceToIndex(addressing_.size());
181  forAll(addressing_, i)
182  {
183  faceToIndex.insert(addressing_[i], i);
184  }
185 
186  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
187 
188  forAll(fSet.addressing(), i)
189  {
190  label facei = fSet.addressing()[i];
191 
192  Map<label>::const_iterator iter = faceToIndex.find(facei);
193 
194  if (iter != faceToIndex.end())
195  {
196  label index = iter();
197 
198  if (fSet.flipMap()[i] != flipMap_[index])
199  {
200  nConflict++;
201  }
202  newAddressing.append(facei);
203  newFlipMap.append(flipMap_[index]);
204  }
205  }
206 
207  if (nConflict > 0)
208  {
210  << "subset : there are " << nConflict
211  << " faces with different orientation in faceZonesSets "
212  << name() << " and " << set.name() << endl;
213  }
214 
215  addressing_.transfer(newAddressing);
216  flipMap_.transfer(newFlipMap);
217  updateSet();
218 }
219 
220 
221 void faceZoneSet::addSet(const topoSet& set)
222 {
223  label nConflict = 0;
224 
225  DynamicList<label> newAddressing(addressing_);
226  DynamicList<bool> newFlipMap(flipMap_);
227 
228  Map<label> faceToIndex(addressing_.size());
229  forAll(addressing_, i)
230  {
231  faceToIndex.insert(addressing_[i], i);
232  }
233 
234  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
235 
236  forAll(fSet.addressing(), i)
237  {
238  label facei = fSet.addressing()[i];
239 
240  Map<label>::const_iterator iter = faceToIndex.find(facei);
241 
242  if (iter != faceToIndex.end())
243  {
244  label index = iter();
245 
246  if (fSet.flipMap()[i] != flipMap_[index])
247  {
248  nConflict++;
249  }
250  }
251  else
252  {
253  newAddressing.append(facei);
254  newFlipMap.append(fSet.flipMap()[i]);
255  }
256  }
257 
258  if (nConflict > 0)
259  {
261  << "addSet : there are " << nConflict
262  << " faces with different orientation in faceZonesSets "
263  << name() << " and " << set.name() << endl;
264  }
265 
266  addressing_.transfer(newAddressing);
267  flipMap_.transfer(newFlipMap);
268  updateSet();
269 }
270 
271 
273 {
274  label nConflict = 0;
275 
276  DynamicList<label> newAddressing(addressing_.size());
277  DynamicList<bool> newFlipMap(flipMap_.size());
278 
279  const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
280 
281  Map<label> faceToIndex(fSet.addressing().size());
282  forAll(fSet.addressing(), i)
283  {
284  faceToIndex.insert(fSet.addressing()[i], i);
285  }
286 
287  forAll(addressing_, i)
288  {
289  label facei = addressing_[i];
290 
291  Map<label>::const_iterator iter = faceToIndex.find(facei);
292 
293  if (iter != faceToIndex.end())
294  {
295  label index = iter();
296 
297  if (fSet.flipMap()[index] != flipMap_[i])
298  {
299  nConflict++;
300  }
301  }
302  else
303  {
304  // Not found in fSet so add
305  newAddressing.append(facei);
306  newFlipMap.append(fSet.flipMap()[i]);
307  }
308  }
309 
310  if (nConflict > 0)
311  {
313  << "deleteSet : there are " << nConflict
314  << " faces with different orientation in faceZonesSets "
315  << name() << " and " << set.name() << endl;
316  }
317 
318  addressing_.transfer(newAddressing);
319  flipMap_.transfer(newFlipMap);
320  updateSet();
321 }
322 
323 
324 void faceZoneSet::sync(const polyMesh& mesh)
325 {}
326 
327 
329 {
330  return mesh.nFaces();
331 }
332 
333 
335 (
339 ) const
340 {
341  // Write shadow faceSet
342  word oldTypeName = typeName;
343  const_cast<word&>(type()) = faceSet::typeName;
344  bool ok = faceSet::writeObject(s, v, c);
345  const_cast<word&>(type()) = oldTypeName;
346 
347  // Modify faceZone
348  faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
349  label zoneID = faceZones.findZoneID(name());
350 
351  if (zoneID == -1)
352  {
353  zoneID = faceZones.size();
354 
355  faceZones.setSize(zoneID+1);
356  faceZones.set
357  (
358  zoneID,
359  new faceZone
360  (
361  name(),
362  addressing_,
363  flipMap_,
364  zoneID,
365  faceZones
366  )
367  );
368  }
369  else
370  {
371  faceZones[zoneID].resetAddressing(addressing_, flipMap_);
372  }
373  faceZones.clearAddressing();
374 
375  return ok && faceZones.write();
376 }
377 
378 
380 {
381  // faceZone
382  labelList newAddressing(addressing_.size());
383  boolList newFlipMap(flipMap_.size());
384 
385  label n = 0;
386  forAll(addressing_, i)
387  {
388  label facei = addressing_[i];
389  label newFacei = morphMap.reverseFaceMap()[facei];
390  if (newFacei >= 0)
391  {
392  newAddressing[n] = newFacei;
393  newFlipMap[n] = flipMap_[i];
394  n++;
395  }
396  }
397  newAddressing.setSize(n);
398  newFlipMap.setSize(n);
399 
400  addressing_.transfer(newAddressing);
401  flipMap_.transfer(newFlipMap);
402 
403  updateSet();
404 }
405 
406 
408 (
409  Ostream& os,
410  const primitiveMesh& mesh,
411  const label maxLen
412 ) const
413 {
414  faceSet::writeDebug(os, mesh, maxLen);
415 }
416 
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 } // End namespace Foam
421 
422 // ************************************************************************* //
const labelList & addressing() const
Definition: faceZoneSet.H:107
faceZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: faceZoneSet.C:67
#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
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.
const boolList & flipMap() const
Return face flip map.
Definition: faceZone.H:253
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: faceSet.C:165
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: faceZoneSet.C:142
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: faceZoneSet.C:408
label size() const
Return number of elements in table.
const boolList & flipMap() const
Definition: faceZoneSet.H:118
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
bool insert(const label &key)
Insert a new entry.
Definition: HashSet.H:116
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: faceZoneSet.C:272
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: faceZoneSet.C:379
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.
virtual ~faceZoneSet()
Destructor.
Definition: faceZoneSet.C:136
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:138
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:341
const labelList & reverseFaceMap() const
Reverse face map.
Definition: mapPolyMesh.H:495
A class for handling words, derived from string.
Definition: word.H:59
label size() const
Return the number of elements in the list.
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 faceZone.
Definition: faceZoneSet.C:335
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
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
faceSet(const IOobject &obj)
Construct from IOobject.
Definition: faceSet.C:49
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: faceZoneSet.C:173
defineTypeNameAndDebug(combustionModel, 0)
virtual void sync(const polyMesh &mesh)
Sync faceZoneSet across coupled patches.
Definition: faceZoneSet.C:324
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: faceZoneSet.C:328
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition: faceZoneSet.C:48
Like faceSet but updates faceZone when writing.
Definition: faceZoneSet.H:49
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
label nFaces() const
void setSize(const label)
Reset size of List.
Definition: List.C:295
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: faceZoneSet.C:221
A List with indirect addressing.
Definition: fvMatrix.H:106
Version number type.
Definition: IOstream.H:96
virtual bool write() const
Write using setting from DB.
label n
void resize(const label newSize)
Resize the hash table for efficiency.
const faceZoneMesh & faceZones() const
Return face zone mesh.
Definition: polyMesh.H:463
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:365
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
void clearStorage()
Clear the table entries and the table itself.