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 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 cellSet& cSet,
62  bitSet& selectedFace,
63  bitSet& doFlip
64 ) const
65 {
66  selectedFace.setSize(mesh_.nFaces());
67  selectedFace = false;
68 
69  doFlip.setSize(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 = cSet.found(own[facei]);
85  const bool neiFound = cSet.found(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] = cSet.found(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 = cSet.found(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 :
152  names_(one{}, setName),
153  flip_(flip)
154 {}
155 
156 
158 (
159  const polyMesh& mesh,
160  const dictionary& dict
161 )
162 :
163  topoSetFaceZoneSource(mesh),
164  names_(),
165  flip_(dict.getOrDefault("flip", false))
166 {
167  // Look for 'sets' or 'set'
168  if (!dict.readIfPresent("sets", names_))
169  {
170  names_.resize(1);
171  dict.readEntry("set", names_.first());
172  }
173 }
174 
175 
177 (
178  const polyMesh& mesh,
179  Istream& is
180 )
181 :
182  topoSetFaceZoneSource(mesh),
183  names_(one{}, word(checkIs(is))),
184  flip_(false)
185 {}
186 
187 
188 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
189 
191 (
192  const topoSetSource::setAction action,
193  topoSet& set
194 ) const
195 {
196  if (!isA<faceZoneSet>(set))
197  {
199  << "Operation only allowed on a faceZoneSet." << endl;
200  return;
201  }
202  else
203  {
204  faceZoneSet& zoneSet = refCast<faceZoneSet>(set);
205 
206  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
207  {
208  if (verbose_)
209  {
210  if (flip_)
211  {
212  Info<< " Adding all faces on outside of cellSet "
213  << flatOutput(names_)
214  << "; orientation pointing into cellSet" << endl;
215  }
216  else
217  {
218  Info<< " Adding all faces on outside of cellSet "
219  << flatOutput(names_)
220  << "; orientation pointing away from cellSet" << endl;
221  }
222  }
223 
224  bitSet selectedFace(mesh_.nFaces());
225  bitSet doFlip(mesh_.nFaces());
226  for (const word& setName : names_)
227  {
228  // Load the sets
229  cellSet cSet(mesh_, setName);
230  // Select outside faces
231  selectFaces(cSet, selectedFace, doFlip);
232  }
233 
234  // Start off from copy
235  DynamicList<label> newAddressing(zoneSet.addressing());
236  DynamicList<bool> newFlipMap(zoneSet.flipMap());
237 
238  for (const label facei : selectedFace)
239  {
240  if (!zoneSet.found(facei))
241  {
242  newAddressing.append(facei);
243  newFlipMap.append(doFlip[facei]);
244  }
245  }
246 
247  zoneSet.addressing().transfer(newAddressing);
248  zoneSet.flipMap().transfer(newFlipMap);
249  zoneSet.updateSet();
250  }
251  else if (action == topoSetSource::SUBTRACT)
252  {
253  if (verbose_)
254  {
255  Info<< " Removing all faces on outside of cellSet "
256  << flatOutput(names_)
257  << " ..." << endl;
258  }
259 
260  bitSet selectedFace(mesh_.nFaces());
261  bitSet doFlip(mesh_.nFaces());
262  for (const word& setName : names_)
263  {
264  // Load the sets
265  cellSet cSet(mesh_, setName);
266  // Select outside faces
267  selectFaces(cSet, selectedFace, doFlip);
268  }
269 
270  // Start off empty
271  DynamicList<label> newAddressing(zoneSet.addressing().size());
272  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
273 
274  for (const label facei : selectedFace)
275  {
276  newAddressing.append(facei);
277  newFlipMap.append(doFlip[facei]);
278  }
279  zoneSet.addressing().transfer(newAddressing);
280  zoneSet.flipMap().transfer(newFlipMap);
281  zoneSet.updateSet();
282  }
283  }
284 }
285 
286 
287 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:584
dictionary dict
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1110
Create a new set and ADD elements to it.
Add elements to current set.
T & first()
Access first element of the list, position [0].
Definition: UList.H:798
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
label nFaces() const noexcept
Number of mesh faces.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
dynamicFvMesh & mesh
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:1104
label nInternalFaces() const noexcept
Number of internal faces.
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: PtrList.H:163
const polyMesh & mesh_
Reference to the mesh.
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
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...
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
Namespace for OpenFOAM.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:485
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:57
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225