backgroundMeshDecompositionTemplates.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) 2013-2022 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 
27 #include "pointConversion.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class PointType>
34 (
35  List<PointType>& points
36 ) const
37 {
38  labelList toProc(processorPosition(points));
39 
40  autoPtr<distributionMap> map(buildMap(toProc));
41 
42  map().distribute(points);
43 
44  return map;
45 }
46 
47 
48 template<class PointType>
50 (
51  const List<PointType>& pts
52 ) const
53 {
54  DynamicList<label> toCandidateProc;
55  DynamicList<point> testPoints;
56  labelList ptBlockStart(pts.size(), -1);
57  labelList ptBlockSize(pts.size(), -1);
58 
59  label nTotalCandidates = 0;
60 
61  forAll(pts, pI)
62  {
63  pointFromPoint pt = topoint(pts[pI]);
64 
65  label nCandidates = 0;
66 
67  forAll(allBackgroundMeshBounds_, proci)
68  {
69  if (allBackgroundMeshBounds_[proci].contains(pt))
70  {
71  toCandidateProc.append(proci);
72  testPoints.append(pt);
73 
74  nCandidates++;
75  }
76  }
77 
78  ptBlockStart[pI] = nTotalCandidates;
79  ptBlockSize[pI] = nCandidates;
80 
81  nTotalCandidates += nCandidates;
82  }
83 
84  // Needed for reverseDistribute
85  label preDistributionToCandidateProcSize = toCandidateProc.size();
86 
87  autoPtr<distributionMap> map(buildMap(toCandidateProc));
88 
89  map().distribute(testPoints);
90 
91  List<bool> pointOnCandidate(testPoints.size(), false);
92 
93  // Test candidate points on candidate processors
94  forAll(testPoints, tPI)
95  {
96  pointOnCandidate[tPI] = positionOnThisProcessor(testPoints[tPI]);
97  }
98 
99  map().reverseDistribute
100  (
101  preDistributionToCandidateProcSize,
102  pointOnCandidate
103  );
104 
105  labelList ptProc(pts.size(), -1);
106 
107  DynamicList<label> failedPointIndices;
108  DynamicList<point> failedPoints;
109 
110  forAll(pts, pI)
111  {
112  // Extract the sub list of results for this point
113 
114  SubList<bool> ptProcResults
115  (
116  pointOnCandidate,
117  ptBlockSize[pI],
118  ptBlockStart[pI]
119  );
120 
121  forAll(ptProcResults, pPRI)
122  {
123  if (ptProcResults[pPRI])
124  {
125  ptProc[pI] = toCandidateProc[ptBlockStart[pI] + pPRI];
126 
127  break;
128  }
129  }
130 
131  if (ptProc[pI] < 0)
132  {
133  pointFromPoint pt = topoint(pts[pI]);
134 
135  if (!globalBackgroundBounds_.contains(pt))
136  {
138  << "The position " << pt
139  << " is not in any part of the background mesh "
140  << globalBackgroundBounds_ << endl
141  << "A background mesh with a wider margin around "
142  << "the geometry may help."
143  << exit(FatalError);
144  }
145 
146  if (debug)
147  {
149  << "The position " << pt
150  << " was not found in the background mesh "
151  << globalBackgroundBounds_ << ", finding nearest."
152  << endl;
153  }
154 
155  failedPointIndices.append(pI);
156  failedPoints.append(pt);
157  }
158  }
159 
160  labelList ptNearestProc(processorNearestPosition(failedPoints));
161 
162  forAll(failedPoints, fPI)
163  {
164  label pI = failedPointIndices[fPI];
165 
166  ptProc[pI] = ptNearestProc[fPI];
167  }
168 
169  return ptProc;
170 }
171 
172 
173 // ************************************************************************* //
bool positionOnThisProcessor(const point &pt) const
Is the given position inside the domain of this decomposition.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
pointFromPoint topoint(const Point &P)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
labelList processorNearestPosition(const List< point > &pts) const
What is the nearest processor to the given position?
List< label > labelList
A List of labels.
Definition: labelList.H:56
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:394
labelList processorPosition(const List< PointType > &pts) const
What processor is the given position on?
static autoPtr< distributionMap > buildMap(const List< label > &toProc)
Build a distributionMap for the supplied destination processor data.
#define WarningInFunction
Report a warning using Foam::Warning.
autoPtr< distributionMap > distributePoints(List< PointType > &points) const
Distribute supplied the points to the appropriate processor.