zoneDistribute.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) 2020 DLR
9  Copyright (C) 2020-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 \*---------------------------------------------------------------------------*/
28 
29 #include "zoneDistribute.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
44  stencil_(zoneCPCStencil::New(mesh)),
45  globalNumbering_(stencil_.globalNumbering()),
46  send_(UPstream::nProcs()),
47  pBufs_(UPstream::commsTypes::nonBlocking)
48 {
49  // Don't clear storage on persistent buffer
50  pBufs_.allowClearRecv(false);
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * //
55 
57 {
58  auto* ptr = mesh.thisDb().getObjectPtr<zoneDistribute>("zoneDistribute");
59 
60  if (!ptr)
61  {
62  ptr = new zoneDistribute(mesh);
63  regIOobject::store(ptr);
64  }
65 
66  return *ptr;
67 }
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 {
75 }
76 
77 
79 (
80  const boolList& zone,
81  bool updateStencil
82 )
83 {
84  zoneCPCStencil& stencil = zoneCPCStencil::New(mesh_);
85 
86  if (updateStencil)
87  {
88  stencil.updateStencil(zone);
89  }
90 
91  if (UPstream::parRun())
92  {
93  List<labelHashSet> needed(UPstream::nProcs());
94 
95  // Bin according to originating (sending) processor
96  for (const label celli : stencil.needsComm())
97  {
98  if (zone[celli])
99  {
100  for (const label gblIdx : stencil_[celli])
101  {
102  const label proci = globalNumbering_.whichProcID(gblIdx);
103 
104  if (proci != Pstream::myProcNo())
105  {
106  needed[proci].insert(gblIdx);
107  }
108  }
109  }
110  }
111 
112  // Stream the send data into PstreamBuffers,
113  // which we also use to track the current topology.
114 
115  pBufs_.clear();
116 
117  for (const int proci : pBufs_.allProcs())
118  {
119  const auto& indices = needed[proci];
120 
121  if (proci != UPstream::myProcNo() && !indices.empty())
122  {
123  // Serialize as List
124  UOPstream toProc(proci, pBufs_);
125  toProc << indices.sortedToc();
126  }
127  }
128 
129  pBufs_.finishedSends(sendConnections_, sendProcs_, recvProcs_);
130 
131  for (const int proci : pBufs_.allProcs())
132  {
133  send_[proci].clear();
134 
135  if (proci != UPstream::myProcNo() && pBufs_.recvDataCount(proci))
136  {
137  UIPstream fromProc(proci, pBufs_);
138  fromProc >> send_[proci];
139  }
140  }
141  }
142 }
143 
144 
145 // ************************************************************************* //
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
bool store()
Register object with its registry and transfer ownership to the registry.
Definition: regIOobjectI.H:36
computes a cell point cell stencil in a narrow band. resizes in case of topological change ...
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
Definition: UPstream.H:1074
const labelHashSet & needsComm() noexcept
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:376
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:85
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Definition: UPstream.H:1065
static zoneDistribute & New(const fvMesh &)
Selector.
dynamicFvMesh & mesh
bool allowClearRecv() const noexcept
Is clearStorage of individual receive buffer by external hooks allowed? (default: true) ...
Base class for mesh zones.
Definition: zone.H:59
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
zoneDistribute(const fvMesh &)
Construct from fvMesh.
static zoneCPCStencil & New(const fvMesh &)
void updateStencil(const boolList &zone)
defineTypeNameAndDebug(combustionModel, 0)
void setUpCommforZone(const boolList &zone, bool updateStencil=true)
Update stencil with boolList the size has to match mesh nCells.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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...
Inter-processor communications stream.
Definition: UPstream.H:60
Namespace for OpenFOAM.