cellToFaceZone.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2022-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cellToFaceZone.H"
29 #include "polyMesh.H"
30 #include "faceZoneSet.H"
31 #include "cellSet.H"
32 #include "syncTools.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(cellToFaceZone, 0);
40  addToRunTimeSelectionTable(topoSetSource, cellToFaceZone, word);
41  addToRunTimeSelectionTable(topoSetSource, cellToFaceZone, istream);
42 
43  addToRunTimeSelectionTable(topoSetFaceZoneSource, cellToFaceZone, word);
44  addToRunTimeSelectionTable(topoSetFaceZoneSource, cellToFaceZone, istream);
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::cellToFaceZone::usage_
49 (
50  cellToFaceZone::typeName,
51  "\n Usage: cellToFaceZone <slaveCellSet>\n\n"
52  " Select all outside faces in the cellSet."
53  " Orientated so slave side is in cellSet.\n\n"
54 );
55 
56 
57 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
58 
59 void Foam::cellToFaceZone::selectFaces
60 (
61  const bitSet& whichCells,
62  bitSet& selectedFace,
63  bitSet& doFlip
64 ) const
65 {
66  selectedFace.resize_nocopy(mesh_.nFaces());
67  selectedFace = false;
68 
69  doFlip.resize_nocopy(mesh_.nFaces());
70  doFlip = false;
71 
72 
73  // Add all faces whose both neighbours are in set.
74 
75  const label nInt = mesh_.nInternalFaces();
76  const labelList& own = mesh_.faceOwner();
77  const labelList& nei = mesh_.faceNeighbour();
78  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
79 
80 
81  // Check all internal faces
82  for (label facei = 0; facei < nInt; ++facei)
83  {
84  const bool ownFound = whichCells.test(own[facei]);
85  const bool neiFound = whichCells.test(nei[facei]);
86 
87  if (ownFound && !neiFound)
88  {
89  selectedFace.set(facei);
90  doFlip.set(facei, flip_);
91  }
92  else if (!ownFound && neiFound)
93  {
94  selectedFace.set(facei);
95  doFlip.set(facei, !flip_);
96  }
97  }
98 
99  // Get coupled cell status
100  boolList neiInSet(mesh_.nBoundaryFaces(), false);
101 
102  for (const polyPatch& pp : patches)
103  {
104  if (pp.coupled())
105  {
106  label facei = pp.start();
107  forAll(pp, i)
108  {
109  neiInSet[facei-nInt] = whichCells.test(own[facei]);
110  ++facei;
111  }
112  }
113  }
115 
116 
117  // Check all boundary faces
118  for (const polyPatch& pp : patches)
119  {
120  label facei = pp.start();
121  forAll(pp, i)
122  {
123  const bool ownFound = whichCells.test(own[facei]);
124  const bool neiFound = neiInSet[facei-nInt];
125 
126  if (ownFound && !neiFound)
127  {
128  selectedFace.set(facei);
129  doFlip.set(facei, flip_);
130  }
131  else if (!ownFound && neiFound)
132  {
133  selectedFace.set(facei);
134  doFlip.set(facei, !flip_);
135  }
136  ++facei;
137  }
138  }
139 }
140 
141 
142 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
143 
145 (
146  const polyMesh& mesh,
147  const word& setName,
148  const bool flip
149 )
150 :
151  topoSetFaceZoneSource(mesh),
152  names_(Foam::one{}, setName),
153  isZone_(false),
154  flip_(flip)
155 {}
156 
157 
159 (
160  const polyMesh& mesh,
161  const dictionary& dict
162 )
163 :
164  topoSetFaceZoneSource(mesh, dict),
165  names_(),
166  isZone_(topoSetSource::readNames(dict, names_)),
167  flip_(dict.getOrDefault("flip", false))
168 {}
169 
170 
172 (
173  const polyMesh& mesh,
174  Istream& is
175 )
176 :
178  names_(Foam::one{}, word(checkIs(is))),
179  isZone_(false),
180  flip_(false)
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
187 (
188  const topoSetSource::setAction action,
189  topoSet& set
190 ) const
191 {
192  if (!isA<faceZoneSet>(set))
193  {
195  << "Operation only allowed on a faceZoneSet." << endl;
196  return;
197  }
198  else
199  {
200  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
201 
202  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
203  {
204  if (verbose_)
205  {
206  Info<< " Adding all faces on outside of cell "
207  << (isZone_ ? "zones:" : "sets: ")
208  << flatOutput(names_) << "; orientation pointing ";
209 
210  if (flip_)
211  {
212  Info<< "into cell sets" << endl;
213  }
214  else
215  {
216  Info<< "away from cell sets" << endl;
217  }
218  }
219 
220  bitSet selectedFace(mesh_.nFaces());
221  bitSet doFlip(mesh_.nFaces());
222 
223  for (const word& setName : names_)
224  {
225  bitSet whichCells(mesh_.nCells());
226  if (isZone_)
227  {
228  whichCells.set(mesh_.cellZones()[setName]);
229  }
230  else
231  {
232  // Load the sets
233  cellSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
234  whichCells.setMany(loadedSet.begin(), loadedSet.end());
235  }
236 
237  // Select outside faces
238  selectFaces(whichCells, selectedFace, doFlip);
239  }
240 
241  // Start off from copy
242  DynamicList<label> newAddressing(zoneSet.addressing());
243  DynamicList<bool> newFlipMap(zoneSet.flipMap());
244 
245  for (const label facei : selectedFace)
246  {
247  if (!zoneSet.found(facei))
248  {
249  newAddressing.append(facei);
250  newFlipMap.append(doFlip[facei]);
251  }
252  }
253 
254  zoneSet.addressing().transfer(newAddressing);
255  zoneSet.flipMap().transfer(newFlipMap);
256  zoneSet.updateSet();
257  }
258  else if (action == topoSetSource::SUBTRACT)
259  {
260  if (verbose_)
261  {
262  Info<< " Removing all faces on outside of cell "
263  << (isZone_ ? "zones:" : "sets: ")
264  << flatOutput(names_) << " ..." << endl;
265  }
266 
267  bitSet selectedFace(mesh_.nFaces());
268  bitSet doFlip(mesh_.nFaces());
269  for (const word& setName : names_)
270  {
271  bitSet whichCells(mesh_.nCells());
272  if (isZone_)
273  {
274  whichCells.set(mesh_.cellZones()[setName]);
275  }
276  else
277  {
278  // Load the sets
279  cellSet loadedSet(mesh_, setName, IOobject::NO_REGISTER);
280  whichCells.setMany(loadedSet.begin(), loadedSet.end());
281  }
282  // Select outside faces
283  selectFaces(whichCells, selectedFace, doFlip);
284  }
285 
286  // Start off empty
287  DynamicList<label> newAddressing(zoneSet.addressing().size());
288  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
289 
290  for (const label facei : selectedFace)
291  {
292  newAddressing.append(facei);
293  newFlipMap.append(doFlip[facei]);
294  }
295  zoneSet.addressing().transfer(newAddressing);
296  zoneSet.flipMap().transfer(newFlipMap);
297  zoneSet.updateSet();
298  }
299  }
300 }
301 
302 
303 // ************************************************************************* //
const T * test(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: UPtrListI.H:127
dictionary dict
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
Create a new set and ADD elements to it.
Add elements to current set.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues, const bool parRun=UPstream::parRun())
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:524
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label nFaces() const noexcept
Number of mesh faces.
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:609
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
setAction
Enumeration defining various actions.
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1116
label nInternalFaces() const noexcept
Number of internal faces.
const polyMesh & mesh_
Reference to the mesh.
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Subtract elements from current set.
#define WarningInFunction
Report a warning using Foam::Warning.
Class with constructor to add usage string to table.
cellToFaceZone(const polyMesh &mesh, const word &cellSetName, const bool flip)
Construct from components.
const polyBoundaryMesh & patches
messageStream Info
Information stream (stdout output on master, null elsewhere)
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
List< label > labelList
A List of labels.
Definition: List.H:62
label nBoundaryFaces() const noexcept
Number of boundary faces (== nFaces - nInternalFaces)
List< bool > boolList
A List of bools.
Definition: List.H:60
Do not request registration (bool: false)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225