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.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 = 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_.front());
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  Info<< " Adding all faces on outside of cell sets: "
211  << flatOutput(names_) << "; orientation pointing ";
212 
213  if (flip_)
214  {
215  Info<< "into cell sets" << endl;
216  }
217  else
218  {
219  Info<< "away from cell sets" << endl;
220  }
221  }
222 
223  bitSet selectedFace(mesh_.nFaces());
224  bitSet doFlip(mesh_.nFaces());
225  for (const word& setName : names_)
226  {
227  // Load the sets
228  cellSet cSet(mesh_, setName);
229  // Select outside faces
230  selectFaces(cSet, selectedFace, doFlip);
231  }
232 
233  // Start off from copy
234  DynamicList<label> newAddressing(zoneSet.addressing());
235  DynamicList<bool> newFlipMap(zoneSet.flipMap());
236 
237  for (const label facei : selectedFace)
238  {
239  if (!zoneSet.found(facei))
240  {
241  newAddressing.append(facei);
242  newFlipMap.append(doFlip[facei]);
243  }
244  }
245 
246  zoneSet.addressing().transfer(newAddressing);
247  zoneSet.flipMap().transfer(newFlipMap);
248  zoneSet.updateSet();
249  }
250  else if (action == topoSetSource::SUBTRACT)
251  {
252  if (verbose_)
253  {
254  Info<< " Removing all faces on outside of cell sets: "
255  << flatOutput(names_) << " ..." << endl;
256  }
257 
258  bitSet selectedFace(mesh_.nFaces());
259  bitSet doFlip(mesh_.nFaces());
260  for (const word& setName : names_)
261  {
262  // Load the sets
263  cellSet cSet(mesh_, setName);
264  // Select outside faces
265  selectFaces(cSet, selectedFace, doFlip);
266  }
267 
268  // Start off empty
269  DynamicList<label> newAddressing(zoneSet.addressing().size());
270  DynamicList<bool> newFlipMap(zoneSet.flipMap().size());
271 
272  for (const label facei : selectedFace)
273  {
274  newAddressing.append(facei);
275  newFlipMap.append(doFlip[facei]);
276  }
277  zoneSet.addressing().transfer(newAddressing);
278  zoneSet.flipMap().transfer(newFlipMap);
279  zoneSet.updateSet();
280  }
281  }
282 }
283 
284 
285 // ************************************************************************* //
dictionary dict
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
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.
T & front()
Access first element of the list, position [0].
Definition: UListI.H:237
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.
#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:608
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 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:159
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...
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
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
static void swapBoundaryFaceList(const polyMesh &mesh, UList< T > &faceValues)
Swap coupled boundary face values. Uses eqOp.
Definition: syncTools.H:485
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