All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
patchToPatchParallelOps.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "patchToPatch.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 (
34  const primitiveOldTimePatch& srcPatch,
35  const vectorField& srcPointNormals,
36  const vectorField& srcPointNormals0,
37  const primitiveOldTimePatch& tgtPatch
38 ) const
39 {
40  // Get the bound boxes for the source patch. Just a single box for now.
41  List<List<treeBoundBox>> srcPatchProcBbs(Pstream::nProcs());
42  if (srcPatch.size())
43  {
44  srcPatchProcBbs[Pstream::myProcNo()] =
46  (
47  1,
48  srcBox(srcPatch, srcPointNormals, srcPointNormals0)
49  );
50  }
51  else
52  {
53  srcPatchProcBbs[Pstream::myProcNo()] = List<treeBoundBox>();
54  }
55 
56  // Distribute the boxes
57  Pstream::gatherList(srcPatchProcBbs);
58  Pstream::scatterList(srcPatchProcBbs);
59 
60  // Send a target face to a process if it overlaps the source patch box
61  // for that process
63  forAll(tgtPatch, tgtFacei)
64  {
65  const treeBoundBox tgtFaceBb = tgtBox(tgtPatch, tgtFacei);
66  forAll(srcPatchProcBbs, proci)
67  {
68  forAll(srcPatchProcBbs[proci], bbi)
69  {
70  if (srcPatchProcBbs[proci][bbi].overlaps(tgtFaceBb))
71  {
72  resultDyn[proci].append(tgtFacei);
73  break;
74  }
75  }
76  }
77  }
78 
79  // Transfer to non-dynamic storage
81  forAll(result, proci)
82  {
83  result[proci].transfer(resultDyn[proci]);
84  }
85 
86  return result;
87 }
88 
89 
91 (
92  const distributionMap& map,
93  const primitiveOldTimePatch& patch,
95 )
96 {
97  static const label thisProci = Pstream::myProcNo();
98 
99  // Exchange per-processor data
100  List<labelList> procLocalFaceis(Pstream::nProcs());
101  List<faceList> procLocalFaces(Pstream::nProcs());
102  List<pointField> procLocalPoints(Pstream::nProcs());
103  List<pointField> procLocalPoints0(Pstream::nProcs());
104  {
106 
107  // Send
108  for (label proci = 0; proci < Pstream::nProcs(); proci++)
109  {
110  const labelList& sendFaceis = map.subMap()[proci];
111 
112  if (proci != thisProci && sendFaceis.size())
113  {
115  (
116  UIndirectList<face>(patch, sendFaceis),
117  patch.points(),
118  patch.points0()
119  );
120 
121  UOPstream(proci, pBufs)()
122  << sendFaceis
123  << subPatch.localFaces()
124  << subPatch.localPoints()
125  << (patch.has0() ? subPatch.localPoints0() : pointField());
126  }
127  }
128 
129  pBufs.finishedSends();
130 
131  // Map local data
132  {
133  const labelList& sendFaceis = map.subMap()[thisProci];
134 
136  (
137  UIndirectList<face>(patch, sendFaceis),
138  patch.points(),
139  patch.points0()
140  );
141 
142  procLocalFaceis[thisProci] = sendFaceis;
143  procLocalFaces[thisProci] = subPatch.localFaces();
144  procLocalPoints[thisProci] = subPatch.localPoints();
145  if (patch.has0())
146  {
147  procLocalPoints0[thisProci] = subPatch.localPoints0();
148  }
149  }
150 
151  // Receive remote data
152  for (label proci = 0; proci < Pstream::nProcs(); proci++)
153  {
154  if (proci != thisProci && map.constructMap()[proci].size())
155  {
156  UIPstream(proci, pBufs)()
157  >> procLocalFaceis[proci]
158  >> procLocalFaces[proci]
159  >> procLocalPoints[proci]
160  >> procLocalPoints0[proci];
161  }
162  }
163  }
164 
165  // Allocate
166  List<remote> localProcFaces;
167  faceList localFaces;
168  pointField localPoints;
169  pointField localPoints0;
170  {
171  label nLocalFaces = 0, nLocalPoints = 0;
172  forAll(procLocalFaceis, proci)
173  {
174  nLocalFaces += procLocalFaces[proci].size();
175  nLocalPoints += procLocalPoints[proci].size();
176  }
177  localProcFaces.setSize(nLocalFaces);
178  localFaces.setSize(nLocalFaces);
179  localPoints.setSize(nLocalPoints);
180  if (patch.has0())
181  {
182  localPoints0.setSize(nLocalPoints);
183  }
184  }
185 
186  // Construct the result
187  label localFacei = 0, localPointi = 0;
188  forAll(procLocalFaces, proci)
189  {
190  const labelList& fis = procLocalFaceis[proci];
191  const faceList& fs = procLocalFaces[proci];
192  forAll(fis, i)
193  {
194  localProcFaces[localFacei] = {proci, fis[i]};
195  localFaces[localFacei] = face(fs[i] + localPointi);
196  localFacei ++;
197  }
198 
199  const pointField& ps = procLocalPoints[proci];
200  const pointField& ps0 = procLocalPoints0[proci];
201  forAll(ps, i)
202  {
203  localPoints[localPointi] = ps[i];
204  if (patch.has0())
205  {
206  localPoints0[localPointi] = ps0[i];
207  }
208  localPointi ++;
209  }
210  }
211 
212  // Construct the local patch
213  localPatchPtr.reset
214  (
215  patch.has0()
217  (
218  localFaces,
219  localPoints,
220  localPoints0
221  )
223  (
224  localFaces,
225  localPoints
226  )
227  );
228 
229  return localProcFaces;
230 }
231 
232 
233 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void reset(const Field< Type > &)
Reset the field values to the given field.
Definition: Field.C:456
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
const Field< PointType > & points0() const
Return reference to old-time global points.
bool has0() const
Return whether or not old-time geometry is available.
const Field< PointType > & localPoints0() const
Return pointField of old-time points in patch.
const Field< PointType > & points() const
Return reference to global points.
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:57
A List with indirect addressing.
Definition: UIndirectList.H:60
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:58
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const labelListList & constructMap() const
From subsetted data to new reconstructed data.
const labelListList & subMap() const
From subsetted data back to original data.
Class containing processor-to-processor mapping information.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
static List< remote > distributePatch(const distributionMap &map, const primitiveOldTimePatch &patch, autoPtr< PrimitiveOldTimePatch< faceList, pointField >> &localPatchPtr)
Distribute a patch given its distribution map.
virtual treeBoundBox srcBox(const face &srcFace, const pointField &srcPoints, const vectorField &srcPointNormals) const =0
Get the bound box for a source face.
labelListList tgtPatchSendFaces(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch) const
Determine which target faces need to be sent to the source.
treeBoundBox tgtBox(const primitiveOldTimePatch &tgtPatch, const label tgtFacei) const
Get the bound box for a target face.
Definition: patchToPatch.C:144
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:90
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42