regionSplit2D.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) 2015-2020 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 "regionSplit2D.H"
29#include "polyMesh.H"
30#include "PatchEdgeFaceWave.H"
32
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36static constexpr Foam::label UNASSIGNED = -1;
37static constexpr Foam::label BLOCKED = -2;
38
39
40// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
41
43(
44 const polyMesh& mesh,
45 const indirectPrimitivePatch& patch,
46 const boolList& blockedFaces,
47 const label offset
48)
49:
50 labelList(patch.size(), UNASSIGNED),
51 nRegions_(0)
52{
53 globalIndex globalFaces(blockedFaces.size());
54 label regionI = globalFaces.toGlobal(0);
55 List<edgeTopoDistanceData<label>> allEdgeInfo(patch.nEdges());
56 List<edgeTopoDistanceData<label>> allFaceInfo(patch.size());
57 DynamicList<label> changedEdges;
59
60 label nBlockedFaces = 0;
61 forAll(blockedFaces, facei)
62 {
63 if (blockedFaces.test(facei))
64 {
65 for (const label edgei : patch.faceEdges()[facei])
66 {
67 changedEdges.append(edgei);
68
69 // Append globally unique value
70 changedRegions.append
71 (
73 (
74 0, // distance
75 regionI // passive data
76 )
77 );
78 }
79 nBlockedFaces++;
80 regionI++;
81 }
82 else
83 {
84 // Block all non-seeded faces from the walk
85 allFaceInfo[facei] = edgeTopoDistanceData<label>
86 (
87 0, // distance
88 BLOCKED // passive data
89 );
90 }
91 }
92
93 // Early exit if there are no blocked faces
94 if (returnReduce(nBlockedFaces, sumOp<label>()) == 0)
95 {
96 return;
97 }
98
100 <
103 >
104 (
105 mesh,
106 patch,
107 changedEdges,
108 changedRegions,
109 allEdgeInfo,
110 allFaceInfo,
111 returnReduce(patch.nEdges(), sumOp<label>())
112 );
113
114
115 // Map from regions to local compact indexing
116 // - only for regions that originate from this processor
117 Map<label> regionToCompactAddr(changedRegions.size());
118 label compactRegionI = 0;
119 forAll(allFaceInfo, faceI)
120 {
121 label regionI = allFaceInfo[faceI].data();
122 if
123 (
124 globalFaces.isLocal(regionI)
125 && regionToCompactAddr.insert(regionI, compactRegionI)
126 )
127 {
128 compactRegionI++;
129 }
130 }
131
132 // In-place renumber the local regionI to global (compact) regionI
133 globalIndex giCompact(compactRegionI);
134 forAllIters(regionToCompactAddr, iter)
135 {
136 *iter = giCompact.toGlobal(*iter);
137 }
138
139 // Ensure regionToCompactAddr consistent across all processors
140 // - not concerned about the op (keys are unique)
141 // - map size will be the number of regions in the set of faces
142 Pstream::mapCombineAllGather(regionToCompactAddr, minEqOp<label>());
143
144 nRegions_ = regionToCompactAddr.size();
145
146 // Set the region index per face
147 forAll(allFaceInfo, faceI)
148 {
149 label regionI = allFaceInfo[faceI].data();
150 if (regionI >= 0)
151 {
152 this->operator[](faceI) = regionToCompactAddr[regionI] + offset;
153 }
154 }
155}
156
157
158// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
A list of faces which address into the list of points.
static void mapCombineAllGather(const List< commsStruct > &comms, Container &values, const CombineOp &cop, const int tag, const label comm)
After completion all processors have the same data.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Definition: UList.H:518
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:237
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:299
For use with PatchEdgeFaceWave. Determines topological distance to starting edges....
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:260
bool isLocal(const label i) const
Is on local processor.
Definition: globalIndexI.H:244
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Splits a patch into regions based on a mask field. Result is a globally consistent label list of regi...
Definition: regionSplit2D.H:62
dynamicFvMesh & mesh
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
static constexpr Foam::label UNASSIGNED
Definition: regionSplit2D.C:36
static constexpr Foam::label BLOCKED
Definition: regionSplit2D.C:37
static constexpr Foam::label BLOCKED
Definition: regionSplit.C:44
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260