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 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 #include "dummyTransform.H"
31 #include "emptyPolyPatch.H"
32 #include "processorPolyPatch.H"
33 #include "syncTools.H"
34 #include "wedgePolyPatch.H"
35 
36 #include "globalPoints.H"
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42  defineTypeNameAndDebug(zoneDistribute, 0);
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 Foam::zoneDistribute::coupledFacesPatch() const
50 {
51  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
52 
53  label nCoupled = 0;
54 
55  for (const polyPatch& pp : patches)
56  {
57  if (isA<processorPolyPatch>(pp))
58  {
59  nCoupled += pp.size();
60  }
61  }
62  labelList coupledFaces(nCoupled);
63  nCoupled = 0;
64 
65  for (const polyPatch& pp : patches)
66  {
67  if (isA<processorPolyPatch>(pp))
68  {
69  label facei = pp.start();
70 
71  forAll(pp, i)
72  {
73  coupledFaces[nCoupled++] = facei++;
74  }
75  }
76  }
77 
79  (
80  IndirectList<face>
81  (
82  mesh_.faces(),
83  coupledFaces
84  ),
85  mesh_.points()
86  );
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
93 :
95  coupledBoundaryPoints_(coupledFacesPatch()().meshPoints()),
96  send_(Pstream::nProcs()),
97  stencil_(zoneCPCStencil::New(mesh)),
98  gblIdx_(stencil_.globalNumbering())
99 {
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * //
104 
106 {
107  auto* ptr = mesh.thisDb().getObjectPtr<zoneDistribute>("zoneDistribute");
108 
109  if (!ptr)
110  {
111  ptr = new zoneDistribute(mesh);
112  regIOobject::store(ptr);
113  }
114 
115  return *ptr;
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  zoneCPCStencil::New(mesh_).updateStencil(zone);
124 }
125 
126 
127 void Foam::zoneDistribute::setUpCommforZone(const boolList& zone,bool updateStencil)
128 {
129  zoneCPCStencil& stencil = zoneCPCStencil::New(mesh_);
130 
131  if (updateStencil)
132  {
133  stencil.updateStencil(zone);
134  }
135 
136  const labelHashSet comms = stencil.needsComm();
137 
139 
140  if (Pstream::parRun())
141  {
142  for (const label celli : comms)
143  {
144  if (zone[celli])
145  {
146  for (const label gblIdx : stencil_[celli])
147  {
148  if (!gblIdx_.isLocal(gblIdx))
149  {
150  const label procID = gblIdx_.whichProcID (gblIdx);
151  needed[procID].insert(gblIdx);
152  }
153  }
154  }
155  }
156 
158 
159  // Stream data into buffer
160  for (const int domain : Pstream::allProcs())
161  {
162  if (domain != Pstream::myProcNo())
163  {
164  // Put data into send buffer
165  UOPstream toDomain(domain, pBufs);
166 
167  toDomain << needed[domain];
168  }
169  }
170 
171  // wait until everything is written.
172  pBufs.finishedSends();
173 
174  for (const int domain : Pstream::allProcs())
175  {
176  send_[domain].clear();
177 
178  if (domain != Pstream::myProcNo())
179  {
180  // get data from send buffer
181  UIPstream fromDomain(domain, pBufs);
182 
183  fromDomain >> send_[domain];
184  }
185  }
186  }
187 }
188 
189 
190 
191 
192 // ************************************************************************* //
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::objectRegistry::getObjectPtr
Type * getObjectPtr(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:423
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::UOPstream
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:57
Foam::fvMesh::thisDb
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
Definition: fvMesh.H:292
zoneDistribute.H
wedgePolyPatch.H
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::zone
Base class for mesh zones.
Definition: zone.H:63
dummyTransform.H
Dummy transform to be used with syncTools.
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::HashSet< label, Hash< label > >
syncTools.H
Foam::regIOobject::store
bool store()
Definition: regIOobjectI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done.
Definition: PstreamBuffers.C:73
Foam::MeshObject< fvMesh, TopologicalMeshObject, zoneDistribute >::mesh_
const fvMesh & mesh_
Definition: MeshObject.H:96
processorPolyPatch.H
Foam::zoneCPCStencil::New
static zoneCPCStencil & New(const fvMesh &)
Definition: zoneCPCStencil.C:135
Foam::zoneDistribute::zoneDistribute
zoneDistribute(const fvMesh &)
Construct from fvMesh.
Definition: zoneDistribute.C:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::zoneDistribute::New
static zoneDistribute & New(const fvMesh &)
Definition: zoneDistribute.C:105
emptyPolyPatch.H
Foam::zoneDistribute::setUpCommforZone
void setUpCommforZone(const boolList &zone, bool updateStencil=true)
Update stencil with boolList the size has to match mesh nCells.
Definition: zoneDistribute.C:127
Foam::zoneDistribute::updateStencil
void updateStencil(const boolList &zone)
Updates stencil with boolList the size has to match mesh nCells.
Definition: zoneDistribute.C:121
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1094
Foam::UPstream::allProcs
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
Definition: UPstream.H:508
Foam::UPstream::commsTypes::nonBlocking
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::zoneDistribute
Class for parallel communication in a narrow band. It either provides a Map with the neighbouring val...
Definition: zoneDistribute.H:64
Foam::Pstream
Inter-processor communications stream.
Definition: Pstream.H:56
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< bool >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::TopologicalMeshObject
Definition: MeshObject.H:182
Foam::MeshObject
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: MeshObject.H:88
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:445
globalPoints.H
Foam::zoneCPCStencil
computes a cell point cell stencil in a narrow band. resizes in case of topological change
Definition: zoneCPCStencil.H:58