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 Typedefs
86 
87  typedef MeshObject
88  <
89  fvMesh,
93 
94 
95  // Private Data
96 
97  //- Reference to the zone stencil
98  zoneCPCStencil& stencil_;
99 
100  //- Global number into index of cells/faces
101  const globalIndex& globalNumbering_;
102 
103  //- Global cell/face index to send for processor-to-processor comms
104  List<labelList> send_;
105 
106  //- Parallel [cache]: send connectivity (true/false)
107  bitSet sendConnections_;
108 
109  //- Parallel [cache]: send data to these ranks
110  DynamicList<label> sendProcs_;
111 
112  //- Parallel [cache]: recv data from these ranks
113  DynamicList<label> recvProcs_;
114 
115  //- Persistent set of exchange buffers
116  PstreamBuffers pBufs_;
117 
118 
119  // Private Member Functions
120 
121  //- Return local volField value at (cell or face) index
122  template<typename Type>
123  Type getLocalValue
124  (
125  const VolumeField<Type>& phi,
126  const label localIdx
127  ) const;
128 
129  //- Gives patchNumber and patchFaceNumber for a given
130  //- Geometric volume field
131  template<typename Type>
132  Type faceValue
133  (
134  const VolumeField<Type>& phi,
135  const label localIdx
136  ) const;
137 
138 
139 public:
140 
141  //- Runtime information
142  TypeName("zoneDistribute");
143 
144 
145  // Constructors
146 
147  //- Construct from fvMesh
148  explicit zoneDistribute(const fvMesh&);
149 
150  //- Selector
151  static zoneDistribute& New(const fvMesh&);
152 
153 
154  //- Destructor
155  virtual ~zoneDistribute() = default;
156 
157 
158  // Member Functions
159 
160  //- Update stencil with boolList the size has to match mesh nCells
161  void setUpCommforZone(const boolList& zone, bool updateStencil=true);
162 
163  //- Updates stencil with boolList the size has to match mesh nCells
164  void updateStencil(const boolList& zone);
165 
166  //- Stencil reference
168  {
169  return stencil_;
170  }
171 
172  //- Addressing reference
173  const globalIndex& globalNumbering() const noexcept
174  {
175  return globalNumbering_;
176  }
177 
178  //- Gives patchNumber and patchFaceNumber for a given
179  //- Geometric volume field
180  template<typename Type>
181  Type getValue
182  (
183  const VolumeField<Type>& phi,
184  const Map<Type>& valuesFromOtherProc,
185  const label gblIdx
186  ) const;
187 
188  //- Returns stencil and provides a Map with globalNumbering
189  template<typename Type>
191  (
192  const boolList& zone,
193  const VolumeField<Type>& phi
194  );
195 
196  //- Returns stencil and provides a Map with globalNumbering
197  template<typename Type>
199  (
200  const boolList& zone,
201  const VolumeField<Type>& phi
202  );
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 #ifdef NoRepository
215 #include "zoneDistributeI.H"
216 #endif
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #endif
221 
222 // ************************************************************************* //
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.
TopologicalMeshObject(const word &objName, const objectRegistry &obr)
Construct from name and instance on registry.
Definition: MeshObject.H:284
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:152
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.