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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "zoneDistribute.H"
29 #include "dummyTransform.H"
30 #include "emptyPolyPatch.H"
31 #include "processorPolyPatch.H"
32 #include "syncTools.H"
33 #include "wedgePolyPatch.H"
34 
35 #include "globalPoints.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(zoneDistribute, 0);
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 Foam::zoneDistribute::coupledFacesPatch() const
49 {
50  const polyBoundaryMesh& patches = mesh_.boundaryMesh();
51 
52  label nCoupled = 0;
53 
54  for (const polyPatch& pp : patches)
55  {
56  if (isA<processorPolyPatch>(pp))
57  {
58  nCoupled += pp.size();
59  }
60  }
61  labelList coupledFaces(nCoupled);
62  nCoupled = 0;
63 
64  for (const polyPatch& pp : patches)
65  {
66  if (isA<processorPolyPatch>(pp))
67  {
68  label facei = pp.start();
69 
70  forAll(pp, i)
71  {
72  coupledFaces[nCoupled++] = facei++;
73  }
74  }
75  }
76 
78  (
79  IndirectList<face>
80  (
81  mesh_.faces(),
82  coupledFaces
83  ),
84  mesh_.points()
85  );
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
92 :
94  stencil_(mesh),
95  coupledBoundaryPoints_(coupledFacesPatch()().meshPoints()),
96  send_(Pstream::nProcs())
97 {
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * //
102 
104 {
106  (
107  zoneDistribute::typeName
108  );
109 
110  if (!ptr)
111  {
112  ptr = new zoneDistribute(mesh);
113 
114  regIOobject::store(ptr);
115  }
116 
117  return *ptr;
118 }
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 {
125  stencil_.updateStencil(zone);
126 }
127 
128 
130 (
131  const boolList& zone,
132  bool updateStencil
133 )
134 {
135  if (updateStencil)
136  {
137  stencil_.updateStencil(zone);
138  }
139 
140  const labelHashSet comms = stencil_.needsComm();
141 
143 
144  if (Pstream::parRun())
145  {
146  for (const label celli : comms)
147  {
148  if (zone[celli])
149  {
150  for (const label gblIdx : stencil_[celli])
151  {
152  if (!globalNumbering().isLocal(gblIdx))
153  {
154  const label procID =
155  globalNumbering().whichProcID(gblIdx);
156  needed_[procID].insert(gblIdx);
157  }
158  }
159  }
160  }
161 
163 
164  // Stream data into buffer
165  for (label domain = 0; domain < Pstream::nProcs(); domain++)
166  {
167  if (domain != Pstream::myProcNo())
168  {
169  // Put data into send buffer
170  UOPstream toDomain(domain, pBufs);
171 
172  toDomain << needed_[domain];
173  }
174  }
175 
176  // wait until everything is written.
177  pBufs.finishedSends();
178 
179  for (label domain = 0; domain < Pstream::nProcs(); domain++)
180  {
181  send_[domain].clear();
182 
183  if (domain != Pstream::myProcNo())
184  {
185  // get data from send buffer
186  UIPstream fromDomain(domain, pBufs);
187 
188  fromDomain >> send_[domain];
189  }
190  }
191  }
192 }
193 
194 
196 {
197  if (mesh_.topoChanging())
198  {
199  coupledBoundaryPoints_ = coupledFacesPatch()().meshPoints();
200  }
201 }
202 
203 
204 // ************************************************************************* //
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:71
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:1038
Foam::UPstream::commsTypes::nonBlocking
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:260
zoneDistribute.H
wedgePolyPatch.H
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:427
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
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:435
Foam::HashSet< label, Hash< label > >
Foam::UpdateableMeshObject
Definition: MeshObject.H:241
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. This will start receives.
Definition: PstreamBuffers.C:80
Foam::MeshObject< fvMesh, UpdateableMeshObject, zoneDistribute >::mesh_
const fvMesh & mesh_
Definition: MeshObject.H:96
processorPolyPatch.H
Foam::zoneDistribute::updateMesh
virtual void updateMesh(const mapPolyMesh &mpm)
Definition: zoneDistribute.C:195
Foam::zoneDistribute::zoneDistribute
zoneDistribute(const fvMesh &)
Construct from fvMesh.
Definition: zoneDistribute.C:91
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::zoneDistribute::New
static zoneDistribute & New(const fvMesh &)
Definition: zoneDistribute.C:103
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:130
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:445
Foam::zoneDistribute::updateStencil
void updateStencil(const boolList &zone)
Updates stencil with boolList the size has to match mesh nCells.
Definition: zoneDistribute.C:123
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:1063
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::List< bool >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
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)
globalPoints.H