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-2022 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 {}
48 
49 
50 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * //
51 
53 {
54  auto* ptr = mesh.thisDb().getObjectPtr<zoneDistribute>("zoneDistribute");
55 
56  if (!ptr)
57  {
58  ptr = new zoneDistribute(mesh);
59  regIOobject::store(ptr);
60  }
61 
62  return *ptr;
63 }
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
69 {
71 }
72 
73 
75 (
76  const boolList& zone,
77  bool updateStencil
78 )
79 {
80  zoneCPCStencil& stencil = zoneCPCStencil::New(mesh_);
81 
82  if (updateStencil)
83  {
84  stencil.updateStencil(zone);
85  }
86 
87  if (UPstream::parRun())
88  {
89  List<labelHashSet> needed(UPstream::nProcs());
90 
91  // Bin according to originating (sending) processor
92  for (const label celli : stencil.needsComm())
93  {
94  if (zone[celli])
95  {
96  for (const label gblIdx : stencil_[celli])
97  {
98  const label proci = globalNumbering_.whichProcID(gblIdx);
99 
100  if (proci != Pstream::myProcNo())
101  {
102  needed[proci].insert(gblIdx);
103  }
104  }
105  }
106  }
107 
108  // Stream the send data into PstreamBuffers,
109  // which we also use to track the current topology.
110 
111  PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking);
112 
113  for (const int proci : UPstream::allProcs())
114  {
115  if (proci != UPstream::myProcNo() && !needed[proci].empty())
116  {
117  // Serialize as List
118  UOPstream toProc(proci, pBufs);
119  toProc << needed[proci].sortedToc();
120  }
121  }
122 
123  pBufs.finishedSends(sendConnections_, sendProcs_, recvProcs_);
124 
125  for (const int proci : pBufs.allProcs())
126  {
127  send_[proci].clear();
128 
129  if (proci != UPstream::myProcNo() && pBufs.recvDataCount(proci))
130  {
131  UIPstream fromProc(proci, pBufs);
132  fromProc >> send_[proci];
133  }
134  }
135  }
136 }
137 
138 
139 // ************************************************************************* //
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Definition: UPstream.H:748
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:639
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)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:688
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const labelHashSet & needsComm() noexcept
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:377
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:84
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
Definition: UPstream.H:656
static zoneDistribute & New(const fvMesh &)
Selector.
dynamicFvMesh & mesh
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:79
"nonBlocking" : (MPI_Isend, MPI_Irecv)
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:54
Namespace for OpenFOAM.