zoneDistribute.H
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) 2020 DLR
9  Copyright (C) 2022-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::zoneDistribute
29 
30 Description
31  Class for parallel communication in a narrow band. It either provides a Map
32  with the neighbouring values of the selected region or returns a Map of the
33  required values in global addressing. Also holds a reference to the stencil
34  Before the data transfer the communication has to be set up:
35  exchangeFields_.setUpCommforZone(interfaceCell_);
36  Is used in the plicRDF
37 
38  Original code supplied by Henning Scheufler, DLR (2019)
39 
40  Additional optimization of processor communication
41  provided by Tetsuo AOYAGI, RIST (2022), to use a more compact
42  exchange of sizes with an updated version of PstreamBuffers.
43  This optimization uses additional sendTo/recvFrom member data
44  to track the topological connectivity, acting like an on-the-fly
45  sub-communicator, and respects corner connectivity.
46 
47  -# Initially topological connections are empty (or all false).
48  -# Scan the stencil global cellIds (active zones only) and split
49  into sub-lists according the originating processor (the sender).
50  -# If an originating processor appears/disappears, need to update
51  the connectivity information (requires an all-to-all).
52  -# When possible, the topological send/recv is used in PstreamBuffers
53  finishedSends (minimizes communication).
54  .
55 
56 SourceFiles
57  zoneDistributeI.H
58  zoneDistribute.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Foam_zoneDistribute_H
63 #define Foam_zoneDistribute_H
64 
65 #include "fvMesh.H"
66 #include "globalIndex.H"
67 #include "volFields.H"
68 
69 #include "zoneCPCStencil.H"
70 #include "MeshObject.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 
77 /*---------------------------------------------------------------------------*\
78  Class zoneDistribute Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class zoneDistribute
82 :
83  public MeshObject<fvMesh, TopologicalMeshObject, zoneDistribute>
84 {
85  // Private Data
86 
87  //- Reference to the zone stencil
88  zoneCPCStencil& stencil_;
89 
90  //- Global number into index of cells/faces
91  const globalIndex& globalNumbering_;
92 
93  //- Global cell/face index to send for processor-to-processor comms
94  List<labelList> send_;
95 
96  //- Parallel [cache]: send connectivity (true/false)
97  bitSet sendConnections_;
98 
99  //- Parallel [cache]: send data to these ranks
100  DynamicList<label> sendProcs_;
101 
102  //- Parallel [cache]: recv data from these ranks
103  DynamicList<label> recvProcs_;
104 
105  //- Persistent set of exchange buffers
106  PstreamBuffers pBufs_;
107 
108 
109  // Private Member Functions
110 
111  //- Return local volField value at (cell or face) index
112  template<typename Type>
113  Type getLocalValue
114  (
115  const VolumeField<Type>& phi,
116  const label localIdx
117  ) const;
118 
119  //- Gives patchNumber and patchFaceNumber for a given
120  //- Geometric volume field
121  template<typename Type>
122  Type faceValue
123  (
124  const VolumeField<Type>& phi,
125  const label localIdx
126  ) const;
127 
128 
129 public:
130 
131  //- Runtime information
132  TypeName("zoneDistribute");
133 
134 
135  // Constructors
136 
137  //- Construct from fvMesh
138  explicit zoneDistribute(const fvMesh&);
139 
140  //- Selector
141  static zoneDistribute& New(const fvMesh&);
142 
143 
144  //- Destructor
145  virtual ~zoneDistribute() = default;
146 
147 
148  // Member Functions
149 
150  //- Update stencil with boolList the size has to match mesh nCells
151  void setUpCommforZone(const boolList& zone, bool updateStencil=true);
152 
153  //- Updates stencil with boolList the size has to match mesh nCells
154  void updateStencil(const boolList& zone);
155 
156  //- Stencil reference
158  {
159  return stencil_;
160  }
161 
162  //- Addressing reference
163  const globalIndex& globalNumbering() const noexcept
164  {
165  return globalNumbering_;
166  }
167 
168  //- Gives patchNumber and patchFaceNumber for a given
169  //- Geometric volume field
170  template<typename Type>
171  Type getValue
172  (
173  const VolumeField<Type>& phi,
174  const Map<Type>& valuesFromOtherProc,
175  const label gblIdx
176  ) const;
177 
178  //- Returns stencil and provides a Map with globalNumbering
179  template<typename Type>
181  (
182  const boolList& zone,
183  const VolumeField<Type>& phi
184  );
185 
186  //- Returns stencil and provides a Map with globalNumbering
187  template<typename Type>
189  (
190  const boolList& zone,
191  const VolumeField<Type>& phi
192  );
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #ifdef NoRepository
205 #include "zoneDistributeI.H"
206 #endif
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #endif
211 
212 // ************************************************************************* //
const labelListList & getStencil() noexcept
Stencil reference.
Map< Type > getDatafromOtherProc(const boolList &zone, const VolumeField< Type > &phi)
Returns stencil and provides a Map with globalNumbering.
virtual ~zoneDistribute()=default
Destructor.
Map< Field< Type > > getFields(const boolList &zone, const VolumeField< Type > &phi)
Returns stencil and provides a Map with globalNumbering.
computes a cell point cell stencil in a narrow band. resizes in case of topological change ...
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
static zoneDistribute & New(const fvMesh &)
Selector.
Base class for mesh zones.
Definition: zone.H:59
zoneDistribute(const fvMesh &)
Construct from fvMesh.
const direction noexcept
Definition: Scalar.H:258
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void setUpCommforZone(const boolList &zone, bool updateStencil=true)
Update stencil with boolList the size has to match mesh nCells.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
TypeName("zoneDistribute")
Runtime information.
void updateStencil(const boolList &zone)
Updates stencil with boolList the size has to match mesh nCells.
Class for parallel communication in a narrow band. It either provides a Map with the neighbouring val...
const globalIndex & globalNumbering() const noexcept
Addressing reference.
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.
Type getValue(const VolumeField< Type > &phi, const Map< Type > &valuesFromOtherProc, const label gblIdx) const
Gives patchNumber and patchFaceNumber for a given Geometric volume field.