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  //- Cell labels for all cells with a face on a cyclic boundary
119  bitSet cyclicBoundaryCells_;
120 
121  //- Holds for each cell on cyclic patch the centres of the cells in its
122  // point neighbour stencil.
123  // Used in getCyclicPatches to identify neigbhour patch ID of point
124  // neighbours on other side of a processorPolyPatch.
125  autoPtr<Map<vectorField>> cyclicCentres_;
126 
127 
128  // Private Member Functions
129 
130  //- Return local volField value at (cell or face) index
131  template<typename Type>
132  Type getLocalValue
133  (
134  const VolumeField<Type>& phi,
135  const label localIdx
136  ) const;
137 
138  //- Gives patchNumber and patchFaceNumber for a given
139  //- Geometric volume field
140  template<typename Type>
141  Type faceValue
142  (
143  const VolumeField<Type>& phi,
144  const label localIdx
145  ) const;
146 
147 
148 public:
149 
150  //- Runtime information
151  TypeName("zoneDistribute");
152 
153 
154  // Constructors
155 
156  //- Construct from fvMesh
157  explicit zoneDistribute(const fvMesh&);
158 
159  //- Selector
160  static zoneDistribute& New(const fvMesh&);
161 
162 
163  //- Destructor
164  virtual ~zoneDistribute() = default;
165 
166 
167  // Member Functions
168 
169  //- Update stencil with boolList the size has to match mesh nCells
170  void setUpCommforZone(const boolList& zone, bool updateStencil=true);
171 
172  //- Updates stencil with boolList the size has to match mesh nCells
173  void updateStencil(const boolList& zone);
174 
175  //- Stencil reference
177  {
178  return stencil_;
179  }
180 
181  //- Addressing reference
182  const globalIndex& globalNumbering() const noexcept
183  {
184  return globalNumbering_;
185  }
186 
187  //- Finds and returns list of all cyclic patch labels to which celli's
188  // point neighbour cell, globalIdx, belongs. celli and globalIdx touch
189  // in at least one point on these patches. globalIdx typically belongs
190  // to stencil_[celli]. The returned label list is used to transform
191  // positions across cyclic boundaries e.g. to be able to calculate
192  // distances between cell centres and interface centres in plicRDF
193  // across such boundaries.
195  (
196  const label celli,
197  const label globalIdx,
198  const vector globalIdxCellCentre
199  ) const;
200 
201  //- Gives patchNumber and patchFaceNumber for a given
202  //- Geometric volume field
203  template<typename Type>
204  Type getValue
205  (
206  const VolumeField<Type>& phi,
207  const Map<Type>& valuesFromOtherProc,
208  const label gblIdx
209  ) const;
210 
212  (
213  const VolumeField<vector>& positions,
214  const Map<vector>& valuesFromOtherProc,
215  const label gblIdx,
216  const List<label> cyclicPatchID = List<label>()
217  ) const;
218 
219  //- Returns stencil and provides a Map with globalNumbering
220  template<typename Type>
222  (
223  const boolList& zone,
224  const VolumeField<Type>& phi
225  );
226 
227  //- Returns stencil and provides a Map with globalNumbering
228  // Note: Not used currently (v2412) but needed for future surface
229  // tension modelling.
230  template<typename Type>
232  (
233  const boolList& zone,
234  const VolumeField<Type>& phi,
235  const bool& checkTransformation = false
236  );
237 
238  //- Returns stencil and provides a Map with globalNumbering
239  template<typename Type>
241  (
242  const boolList& zone,
243  const VolumeField<Type>& phi
244  );
245 };
246 
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 } // End namespace Foam
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #ifdef NoRepository
257 #include "zoneDistributeI.H"
258 #endif
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
const labelListList & getStencil() noexcept
Stencil reference.
vector getPosition(const VolumeField< vector > &positions, const Map< vector > &valuesFromOtherProc, const label gblIdx, const List< label > cyclicPatchID=List< label >()) const
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:286
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: scalarImpl.H:255
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Buffers for inter-processor communications streams (UOPstream, UIPstream).
List< label > getCyclicPatches(const label celli, const label globalIdx, const vector globalIdxCellCentre) const
Finds and returns list of all cyclic patch labels to which celli&#39;s.
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.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Class for parallel communication in a narrow band. It either provides a Map with the neighbouring val...
Map< Field< Type > > getPositionFields(const boolList &zone, const VolumeField< Type > &phi, const bool &checkTransformation=false)
Returns stencil and provides a Map with globalNumbering.
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.