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 -------------------------------------------------------------------------------
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 "regionSplit2D.H"
29 #include "polyMesh.H"
30 #include "PatchEdgeFaceWave.H"
31 #include "edgeTopoDistanceData.H"
32 
33 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
34 
35 Foam::regionSplit2D::regionSplit2D
36 (
37  const polyMesh& mesh,
39  const boolList& blockedFaces,
40  const label offset
41 )
42 :
43  labelList(patch.size(), -1),
44  nRegions_(0)
45 {
46  globalIndex globalFaces(blockedFaces.size());
47  label regionI = globalFaces.toGlobal(0);
48  List<edgeTopoDistanceData<label>> allEdgeInfo(patch.nEdges());
49  List<edgeTopoDistanceData<label>> allFaceInfo(patch.size());
50  DynamicList<label> changedEdges;
52  label nBlockedFaces = 0;
53  forAll(blockedFaces, faceI)
54  {
55  if (blockedFaces[faceI])
56  {
57  const labelList& fEdges = patch.faceEdges()[faceI];
58  forAll(fEdges, feI)
59  {
60  changedEdges.append(fEdges[feI]);
61 
62  // Append globally unique value
63  changedRegions.append
64  (
66  (
67  0, // distance
68  regionI // passive data
69  )
70  );
71  }
72  nBlockedFaces++;
73  regionI++;
74  }
75  else
76  {
77  // Block all non-seeded faces from the walk
78  allFaceInfo[faceI] = edgeTopoDistanceData<label>
79  (
80  0, // distance
81  -2 // passive data
82  );
83  }
84  }
85 
86  // Early exit if there are no blocked faces
87  if (returnReduce(nBlockedFaces, sumOp<label>()) == 0)
88  {
89  return;
90  }
91 
93  <
96  >
97  (
98  mesh,
99  patch,
100  changedEdges,
101  changedRegions,
102  allEdgeInfo,
103  allFaceInfo,
104  returnReduce(patch.nEdges(), sumOp<label>())
105  );
106 
107 
108  // Map from regions to local compact indexing
109  // - only for regions that originate from this processor
110  Map<label> regionToCompactAddr(changedRegions.size());
111  label compactRegionI = 0;
112  forAll(allFaceInfo, faceI)
113  {
114  label regionI = allFaceInfo[faceI].data();
115  if
116  (
117  globalFaces.isLocal(regionI)
118  && regionToCompactAddr.insert(regionI, compactRegionI)
119  )
120  {
121  compactRegionI++;
122  }
123  }
124 
125  // In-place renumber the local regionI to global (compact) regionI
126  globalIndex giCompact(compactRegionI);
127  forAllIters(regionToCompactAddr, iter)
128  {
129  *iter = giCompact.toGlobal(*iter);
130  }
131 
132  // Ensure regionToCompactAddr consistent across all processors
133  // - not concerned about the op (keys are unique)
134  // - map size will be the number of regions in the set of faces
135  Pstream::mapCombineGather(regionToCompactAddr, minEqOp<label>());
136  Pstream::mapCombineScatter(regionToCompactAddr);
137 
138  nRegions_ = regionToCompactAddr.size();
139 
140  // Set the region index per face
141  forAll(allFaceInfo, faceI)
142  {
143  label regionI = allFaceInfo[faceI].data();
144  if (regionI >= 0)
145  {
146  this->operator[](faceI) = regionToCompactAddr[regionI] + offset;
147  }
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
153 
155 {}
156 
157 
158 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::regionSplit2D::~regionSplit2D
~regionSplit2D()
Destructor.
Definition: regionSplit2D.C:154
Foam::DynamicList< label >
Foam::PatchEdgeFaceWave
Wave propagation of information along patch. Every iteration information goes through one layer of fa...
Definition: PatchEdgeFaceWave.H:72
Foam::Map< label >
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::minEqOp
Definition: ops.H:81
PatchEdgeFaceWave.H
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
Foam::edgeTopoDistanceData
For use with PatchEdgeFaceWave. Determines topological distance to starting edges....
Definition: edgeTopoDistanceData.H:55
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
edgeTopoDistanceData.H
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::indirectPrimitivePatch
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field.
Definition: indirectPrimitivePatch.H:49
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< bool >
regionSplit2D.H
Foam::globalIndex::toGlobal
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:164
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:85