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-------------------------------------------------------------------------------
11License
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
33namespace 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);
60 }
61
62 return *ptr;
63}
64
65
66// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67
69{
70 zoneCPCStencil::New(mesh_).updateStencil(zone);
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 {
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
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// ************************************************************************* //
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:91
Buffers for inter-processor communications streams (UOPstream, UIPstream).
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
label recvDataCount(const label proci) const
void finishedSends(const bool wait=true)
Mark sends as done.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Inter-processor communications stream.
Definition: UPstream.H:59
@ nonBlocking
"nonBlocking"
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:302
Type * getObjectPtr(const word &name, const bool recursive=false) const
int myProcNo() const noexcept
Return processor number.
computes a cell point cell stencil in a narrow band. resizes in case of topological change
Class for parallel communication in a narrow band. It either provides a Map with the neighbouring val...
void updateStencil(const boolList &zone)
Updates stencil with boolList the size has to match mesh nCells.
void setUpCommforZone(const boolList &zone, bool updateStencil=true)
Update stencil with boolList the size has to match mesh nCells.
Base class for mesh zones.
Definition: zone.H:67
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Namespace for OpenFOAM.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.