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