hierarchGeomDecomp.H
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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::hierarchGeomDecomp
29
30Description
31 Does hierarchical decomposition of points, selectable as \c hierarchical.
32
33 Works by first sorting the points in x direction into equal sized bins,
34 then in y direction and finally in z direction.
35
36 Uses single array to hold decomposition which is indexed as if it is a
37 3 dimensional array:
38
39 finalDecomp[i,j,k] is indexed as
40
41 i*n[0]*n[1] + j*n[1] + k
42
43 E.g. if we're sorting 'xyz': the first sort (over the x-component)
44 determines in which x-domain the point goes. Then for each of the x-domains
45 the points are sorted in y direction and each individual x-domain gets
46 split into three y-domains. And similar for the z-direction.
47
48 Since the domains are of equal size the maximum difference in size is
49 n[0]*n[1] (or n[1]*n[2]?) (small anyway)
50
51 Method coefficients:
52 \table
53 Property | Description | Required | Default
54 n | (nx ny nz) | yes |
55 order | order of operation | no | xyz
56 delta | delta (jitter) for rotation matrix | no | 0.001
57 transform | cartesian coordinate transformation | no |
58 \endtable
59
60SourceFiles
61 hierarchGeomDecomp.C
62
63\*---------------------------------------------------------------------------*/
64
65#ifndef hierarchGeomDecomp_H
66#define hierarchGeomDecomp_H
67
68#include "geomDecomp.H"
69
70namespace Foam
71{
72
73/*---------------------------------------------------------------------------*\
74 Class hierarchGeomDecomp Declaration
75\*---------------------------------------------------------------------------*/
76
77class hierarchGeomDecomp
78:
79 public geomDecomp
80{
81 // Private Member Functions
82
83 //- Find index of value in list between
84 //- first (inclusive) and last (exclusive)
85 static label findLower
86 (
87 const UList<scalar>& list,
88 const scalar val,
89 const label first,
90 const label last
91 );
92
93 //- Evaluates the weighted sizes for each sorted point.
94 static void calculateSortedWeightedSizes
95 (
96 const labelList& current,
97 const labelList& indices,
98 const scalarField& weights,
99 const label globalCurrentSize,
100
101 scalarField& sortedWeightedSizes
102 );
103
104 //- Find midValue (at local index mid) such that the number of
105 // elements between mid and leftIndex are (globally summed) the
106 // wantedSize. Binary search.
107 //
108 // \Return False if the binary search completed
109 static bool findBinary
110 (
111 const label sizeTol, // size difference considered acceptable
112 const List<scalar>&,
113 const label leftIndex, // index of previous value
114 const scalar leftValue, // value at leftIndex
115 const scalar maxValue, // global max of values
116 const scalar wantedSize, // wanted size
117 label& mid, // index where size of bin is wantedSize
118 scalar& midValue // value at mid
119 );
120
121 //- Find midValue (at local index mid) such that the number of
122 // elements between mid and leftIndex are (globally summed) the
123 // wantedSize. Binary search.
124 static bool findBinary
125 (
126 const label sizeTol, // size difference considered acceptable
127 const List<scalar>& sortedWeightedSizes,
128 const List<scalar>&,
129 const label leftIndex, // index of previous value
130 const scalar leftValue, // value at leftIndex
131 const scalar maxValue, // global max of values
132 const scalar wantedSize, // wanted size
133 label& mid, // index where size of bin is wantedSize
134 scalar& midValue // value at mid
135 );
136
137 //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
138 // \return the number of warnings from findBinary
139 label sortComponent
140 (
141 const label sizeTol,
142 const pointField&,
143 const labelList& slice, // slice of points to decompose
144 const direction componentIndex, // index in decompOrder_
145 const label prevMult, // multiplication factor
146 labelList& finalDecomp // overall decomposition
147 ) const;
148
149 //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
150 //- Using weighted points.
151 // \return the number of warnings from findBinary
152 label sortComponent
153 (
154 const label sizeTol,
155 const scalarField& weights,
156 const pointField&,
157 const labelList& slice, // slice of points to decompose
158 const direction componentIndex, // index in decompOrder_
159 const label prevMult, // multiplication factor
160 labelList& finalDecomp // overall decomposition
161 ) const;
162
163
164public:
165
166 //- No copy construct
167 hierarchGeomDecomp(const hierarchGeomDecomp&) = delete;
168
169 //- No copy assignment
170 void operator=(const hierarchGeomDecomp&) = delete;
171
172 //- Runtime type information
173 TypeName("hierarchical");
174
175
176 // Constructors
177
178 //- Construct given decomposition dictionary and optional region name
179 explicit hierarchGeomDecomp
180 (
181 const dictionary& decompDict,
182 const word& regionName = ""
183 );
184
185
186 //- Destructor
187 virtual ~hierarchGeomDecomp() = default;
188
189
190 // Member Functions
192 //- Hierarchical is aware of processor boundaries
193 virtual bool parallelAware() const
195 return true;
196 }
198 //- Return for every coordinate the wanted processor number.
199 virtual labelList decompose
200 (
201 const pointField&,
202 const scalarField& weights
203 ) const;
204
205 //- Decompose with uniform weights.
206 // Code for weighted decomposition is a bit complex,
207 // so kept separate for now.
208 virtual labelList decompose(const pointField&) const;
209
210
211 //- Return for every coordinate the wanted processor number.
212 // Use the mesh connectivity (if needed).
213 virtual labelList decompose
214 (
215 const polyMesh& mesh,
216 const pointField& cc,
217 const scalarField& cWeights
218 ) const
219 {
221 return decompose(cc, cWeights);
222 }
223
224 //- Decompose with uniform weights.
225 // Code for weighted decomposition is a bit complex,
226 // so kept separate for now.
227 virtual labelList decompose
228 (
229 const polyMesh& mesh,
230 const pointField& cc
231 ) const
232 {
234 return decompose(cc);
235 }
236
237 //- Return for every coordinate the wanted processor number.
238 // Explicitly provided connectivity - does not use mesh_.
239 // The connectivity is equal to mesh.cellCells() except for
240 // - in parallel the cell numbers are global cell numbers (starting
241 // from 0 at processor0 and then incrementing all through the
242 // processors)
243 // - the connections are across coupled patches
244 virtual labelList decompose
245 (
246 const labelListList& globalCellCells, // unused
247 const pointField& cc,
248 const scalarField& cWeights
249 ) const
250 {
251 return decompose(cc, cWeights);
252 }
253
254 virtual labelList decompose
255 (
256 const labelListList& globalCellCells, // unused
257 const pointField& cc
258 ) const
259 {
260 return decompose(cc);
261 }
262};
263
264
265// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266
267} // End namespace Foam
269// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270
271#endif
272
273// ************************************************************************* //
scalar maxValue
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Base for geometrical domain decomposition methods.
Definition: geomDecomp.H:89
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:131
Does hierarchical decomposition of points, selectable as hierarchical.
hierarchGeomDecomp(const hierarchGeomDecomp &)=delete
No copy construct.
virtual labelList decompose(const labelListList &globalCellCells, const pointField &cc) const
Like decompose but with uniform weights on the cells.
virtual bool parallelAware() const
Hierarchical is aware of processor boundaries.
virtual labelList decompose(const polyMesh &mesh, const pointField &cc) const
Decompose with uniform weights.
TypeName("hierarchical")
Runtime type information.
virtual labelList decompose(const pointField &, const scalarField &weights) const
Return for every coordinate the wanted processor number.
virtual ~hierarchGeomDecomp()=default
Destructor.
void operator=(const hierarchGeomDecomp &)=delete
No copy assignment.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
Definition: polyMesh.C:872
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
Foam::word regionName(Foam::polyMesh::defaultRegion)
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
uint8_t direction
Definition: direction.H:56
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73