Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37namespace Foam
38{
42
45}
46
47
48Foam::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
59void 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;
138 }
139}
140
141
142// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
143
145(
146 const polyMesh& mesh,
147 const word& setName,
148 const bool flip
149)
150:
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:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
iterator end() noexcept
Definition HashSet.C:486
iterator begin()
Definition HashSet.C:453
@ NO_REGISTER
Do not request registration (bool: false).
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition bitSetI.H:502
label setMany(InputIter first, InputIter last)
Set the locations listed by the iterator range, auto-vivify entries if needed.
A collection of cell labels.
Definition cellSet.H:50
A topoSetSource to select faces with only one neighbour (i.e. outside) in a specified cellSet.
cellToFaceZone(const polyMesh &mesh, const word &cellSetName, const bool flip)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Like faceSet but -reads data from faceZone -updates faceZone when writing.
Definition faceZoneSet.H:50
const boolList & flipMap() const noexcept
const labelList & addressing() const noexcept
void updateSet()
Sort addressing and make faceSet part consistent with addressing.
Definition faceZoneSet.C:45
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition one.H:57
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
virtual const labelList & faceOwner() const
Return face owner.
Definition polyMesh.C:1101
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition polyMesh.C:1107
label nInternalFaces() const noexcept
Number of internal faces.
label nFaces() const noexcept
Number of mesh faces.
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
The topoSetFaceZoneSource is a intermediate class for handling topoSet sources for selecting face zon...
topoSetFaceZoneSource(const polyMesh &mesh)
Construct from mesh.
Class with constructor to add usage string to table.
Base class of a source for a topoSet.
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
setAction
Enumeration defining various actions.
@ SUBTRACT
Subtract elements from current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
bool verbose_
Output verbosity (default: true).
const polyMesh & mesh() const noexcept
Reference to the mesh.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
virtual bool found(const label id) const
Has the given index?
Definition topoSet.C:539
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
List< bool > boolList
A List of bools.
Definition List.H:60
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299