Loading...
Searching...
No Matches
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-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 "regionSplit2D.H"
29#include "polyMesh.H"
31#include "patchEdgeFaceRegion.H"
32
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36static constexpr Foam::label UNASSIGNED = -1;
37static constexpr Foam::label BLOCKED = -2;
38
39
40// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
41
42Foam::regionSplit2D::regionSplit2D
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<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
56 List<patchEdgeFaceRegion> allFaceInfo(patch.size());
57 DynamicList<label> changedEdges;
59 label nBlockedFaces = 0;
60 forAll(blockedFaces, facei)
61 {
62 if (blockedFaces.test(facei))
63 {
64 for (const label edgei : patch.faceEdges()[facei])
65 {
66 changedEdges.append(edgei);
67
68 // Append globally unique value
69 changedRegions.append(regioni);
70 }
71 nBlockedFaces++;
72 regioni++;
73 }
74 else
75 {
76 // Block all non-seeded faces from the walk
77 allFaceInfo[facei] = BLOCKED;
78 }
79 }
80
81 // Early exit if there are no blocked faces
82 if (!returnReduceOr(nBlockedFaces))
83 {
84 return;
85 }
86
88 <
91 >
92 (
93 mesh,
94 patch,
95 changedEdges,
96 changedRegions,
97 allEdgeInfo,
99 returnReduce(patch.nEdges(), sumOp<label>())
100 );
101
102
103 // Map from regions to local compact indexing
104 // - only for regions that originate from this processor
105 Map<label> regionToCompactAddr(changedRegions.size());
106 label compactRegioni = 0;
107 forAll(allFaceInfo, facei)
108 {
109 const label regioni = allFaceInfo[facei].region();
110 if
111 (
112 globalFaces.isLocal(regioni)
113 && regionToCompactAddr.insert(regioni, compactRegioni)
114 )
115 {
116 compactRegioni++;
117 }
118 }
119
120 // In-place renumber the local regionI to global (compact) regioni
121 {
122 const label myProcOffset = globalIndex::calcOffset(compactRegioni);
123 forAllIters(regionToCompactAddr, iter)
124 {
125 iter.val() += myProcOffset;
126 }
127 }
128
129
130 // Ensure regionToCompactAddr consistent across all processors
131 // - not concerned about the op (keys are unique)
132 // - map size will be the number of regions in the set of faces
133 Pstream::mapCombineReduce(regionToCompactAddr, minEqOp<label>());
134
135 nRegions_ = regionToCompactAddr.size();
136
137 // Set the region index per face
138 forAll(allFaceInfo, facei)
139 {
140 const label regioni = allFaceInfo[facei].region();
141 if (regioni >= 0)
142 {
143 this->operator[](facei) = regionToCompactAddr[regioni] + offset;
144 }
145 }
146}
147
148
149// ************************************************************************* //
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.
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
static void mapCombineReduce(Container &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::mapReduce with an in-place cop.
bool test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition UList.H:852
void size(const label n)
Definition UList.H:118
label & operator[](const label i)
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
static IntType calcOffset(IntType localSize, const label comm=UPstream::worldComm)
Based on the local input size(s), calculate a globally-consistent local start offset.
bool isLocal(const label proci, const label i) const
Is on processor proci.
label toGlobal(const label proci, const label i) const
From local to global on proci.
Transport of region for use in PatchEdgeFaceWave.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
dynamicFvMesh & mesh
List< wallPoints > allFaceInfo(mesh_.nFaces())
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
List< label > labelList
A List of labels.
Definition List.H:62
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
List< bool > boolList
A List of bools.
Definition List.H:60
static constexpr Foam::label UNASSIGNED
Definition regionSplit.C:36
static constexpr Foam::label BLOCKED
Definition regionSplit.C:37
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition stdFoam.H:214