faMeshBoundaryHalo.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) 2021-2022 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 "faMeshBoundaryHalo.H"
29#include "faMesh.H"
30#include "globalIndex.H"
31#include "Pstream.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44:
46 inputMeshFaces_(),
47 boundaryToCompact_()
48{}
49
50
52:
54 inputMeshFaces_(),
55 boundaryToCompact_()
56{
58}
59
60
61// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62
64{
65 static_cast<mapDistributeBase&>(*this) = mapDistributeBase();
66
67 inputMeshFaces_.clear();
68 boundaryToCompact_.clear();
69}
70
71
73{
74 if (Pstream::parRun())
75 {
76 return boundaryToCompact_.size();
77 }
78 else
79 {
80 return inputMeshFaces_.size();
81 }
82}
83
84
86{
87 inputMeshFaces_.clear();
88 boundaryToCompact_.clear();
89
90 const auto& procConnections = areaMesh.boundaryConnections();
91
92 if (!Pstream::parRun())
93 {
94 // Serial - extract halo numbers directly
95
96 inputMeshFaces_.resize(procConnections.size());
97
98 forAll(procConnections, connecti)
99 {
100 // Connected neighbour, non-parallel = must be local
101 const auto& tuple = procConnections[connecti];
102 // const label nbrProci = tuple.first();
103 const label nbrFacei = tuple.second();
104
105 inputMeshFaces_[connecti] = nbrFacei;
106 }
107
108 return;
109 }
110
111 const label nProcs = UPstream::nProcs(comm());
112 const label myRank = UPstream::myProcNo(comm());
113
114 const globalIndex globalFaceNum(areaMesh.mesh().nFaces());
115
116 // Boundary inside faces in polyMesh face ids
117 const labelList insideFaces
118 (
120 (
121 areaMesh.faceLabels(),
122 areaMesh.patch().boundaryFaces()
123 )
124 );
125
126
127 // Slightly circuitous, but allows maximum reuse of mapDistributeBase
128
129 // 1. Construct a connectivity map using global face numbers
130
131 labelListList connectivity(areaMesh.nBoundaryEdges());
132 List<Map<label>> compactMap(nProcs, Map<label>(0));
133
134 // All local mesh faces used
135 labelHashSet localUsed(insideFaces);
136
137 forAll(connectivity, connecti)
138 {
139 labelList& edgeFaces = connectivity[connecti];
140 edgeFaces.resize(2);
141
142 // Owner is the boundary inside face (our side)
143 // Neighbour is the boundary outside face
144
145 // Connected neighbour
146 const auto& tuple = procConnections[connecti];
147 const label nbrProci = tuple.first();
148 const label nbrFacei = tuple.second();
149
150 if (myRank == nbrProci)
151 {
152 // Processor-local connectivity
153 localUsed.insert(nbrFacei);
154 }
155
156 // Global addressing for the connectivity
157 edgeFaces[0] = globalFaceNum.toGlobal(insideFaces[connecti]);
158 edgeFaces[1] = globalFaceNum.toGlobal(nbrProci, nbrFacei);
159 }
160
161 // Create and replace mapping
162 static_cast<mapDistributeBase&>(*this) = mapDistributeBase
163 (
164 globalFaceNum,
165 connectivity,
166 compactMap,
168 comm()
169 );
170
171 // List of local mesh faces referenced.
172 // Includes inside and locally connected outside faces
173
174 inputMeshFaces_ = localUsed.sortedToc();
175
176 boundaryToCompact_.clear();
177 boundaryToCompact_.resize(connectivity.size());
178
179 // After creating the map, connectivity is localized *and*
180 // uses compact numbering!
181
182 // Extract the neighbour connection (compact numbering)
183 forAll(connectivity, connecti)
184 {
185 const labelList& edgeFaces = connectivity[connecti];
186 // const label face0 = edgeFaces[0];
187 const label face1 = edgeFaces[1];
188
189 boundaryToCompact_[connecti] = face1;
190 }
191}
192
193
194// ************************************************************************* //
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Mesh data needed to do the Finite Area discretisation.
Definition: areaFaMesh.H:56
void reset()
Reset to defaults.
Class for obtaining halo face data for the boundary edges. The ordering follows that natural edge ord...
void reset(const faMesh &mesh)
Redefine map and connectivity for a mesh.
void clear()
Clear out all parameters.
label haloSize() const
The local data size (output)
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:100
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
Class containing processor-to-processor mapping information.
int myProcNo() const noexcept
Return processor number.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
Namespace for OpenFOAM.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333