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 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 "faMeshBoundaryHalo.H"
29 #include "faMesh.H"
30 #include "globalIndex.H"
31 #include "Pstream.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(faMeshBoundaryHalo, 0);
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 :
45  mapDistributeBase(comm),
46  inputMeshFaces_(),
47  boundaryToCompact_()
48 {}
49 
50 
52 :
54  inputMeshFaces_(),
55  boundaryToCompact_()
56 {
57  reset(areaMesh);
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 = Pstream::nProcs(comm_);
112  const label myRank = Pstream::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 // ************************************************************************* //
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
globalIndex.H
Foam::Map< label >
faMesh.H
Foam::HashSet< label, Hash< label > >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::faMeshBoundaryHalo::faMeshBoundaryHalo
faMeshBoundaryHalo(const label comm=UPstream::worldComm)
Default construct.
Definition: faMeshBoundaryHalo.C:43
Foam::areaMesh
Mesh data needed to do the Finite Area discretisation.
Definition: areaFaMesh.H:53
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::faMeshBoundaryHalo::clear
void clear()
Clear out all parameters.
Definition: faMeshBoundaryHalo.C:63
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::faMeshBoundaryHalo::reset
void reset(const faMesh &mesh)
Redefine map and connectivity for a mesh.
Definition: faMeshBoundaryHalo.C:85
Foam::UPstream::msgType
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:540
Foam::faMeshBoundaryHalo::haloSize
label haloSize() const
The local data size (output)
Definition: faMeshBoundaryHalo.C:72
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< label >
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:191
Foam::mapDistributeBase
Class containing processor-to-processor mapping information.
Definition: mapDistributeBase.H:103
Foam::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:82
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
faMeshBoundaryHalo.H