hierarchical.H
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-2024 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 Class
25  Foam::decompositionMethods::hierarchical
26 
27 Description
28  Does hierarchical decomposition of points. Works by first sorting the
29  points in x direction into equal sized bins, then in y direction and
30  finally in z direction.
31 
32  Uses single array to hold decomposition which is indexed as if it is a
33  3 dimensional array:
34 
35  finalDecomp[i,j,k] is indexed as
36 
37  i*n[0]*n[1] + j*n[1] + k
38 
39  E.g. if we're sorting 'xyz': the first sort (over the x-component)
40  determines in which x-domain the point goes. Then for each of the x-domains
41  the points are sorted in y direction and each individual x-domain gets
42  split into three y-domains. And similar for the z-direction.
43 
44  Since the domains are of equal size the maximum difference in size is
45  n[0]*n[1] (or n[1]*n[2]?) (small anyway)
46 
47 SourceFiles
48  hierarchical.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef hierarchical_H
53 #define hierarchical_H
54 
55 #include "geometric.H"
56 #include "FixedList.H"
57 #include "direction.H"
58 
59 namespace Foam
60 {
61 namespace decompositionMethods
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class hierarchical Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class hierarchical
69 :
70  public geometric
71 {
72  // Private Data
73 
74  //- Decomposition order in terms of components.
75  FixedList<direction, 3> decompOrder_;
76 
77 
78  // Private Member Functions
79 
80  //- Convert ordering string ("xyz") into list of components.
81  void setDecompOrder();
82 
83  //- Evaluates the weighted sizes for each sorted point.
84  static void calculateSortedWeightedSizes
85  (
86  const labelList& current,
87  const labelList& indices,
88  const scalarField& weights,
89  const label globalCurrentSize,
90 
91  scalarField& sortedWeightedSizes
92  );
93 
94  //- Find index of t in list in between indices left and right
95  static label findLower
96  (
97  const List<scalar>&,
98  const scalar t,
99  const label left,
100  const label right
101  );
102 
103  //- Find midValue (at local index mid) such that the number of
104  // elements between mid and leftIndex are (globally summed) the
105  // wantedSize. Binary search.
106  static void findBinary
107  (
108  const label sizeTol, // size difference considered acceptable
109  const List<scalar>&,
110  const label leftIndex, // index of previous value
111  const scalar leftValue, // value at leftIndex
112  const scalar maxValue, // global max of values
113  const scalar wantedSize, // wanted size
114  label& mid, // index where size of bin is wantedSize
115  scalar& midValue // value at mid
116  );
117 
118  //- Find midValue (at local index mid) such that the number of
119  // elements between mid and leftIndex are (globally summed) the
120  // wantedSize. Binary search.
121  static void findBinary
122  (
123  const label sizeTol, // size difference considered acceptable
124  const List<scalar>& sortedWeightedSizes,
125  const List<scalar>&,
126  const label leftIndex, // index of previous value
127  const scalar leftValue, // value at leftIndex
128  const scalar maxValue, // global max of values
129  const scalar wantedSize, // wanted size
130  label& mid, // index where size of bin is wantedSize
131  scalar& midValue // value at mid
132  );
133 
134  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
135  void sortComponent
136  (
137  const label sizeTol,
138  const pointField&,
139  const labelList& slice, // slice of points to decompose
140  const direction componentIndex, // index in decompOrder_
141  const label prevMult, // multiplication factor
142  labelList& finalDecomp // overall decomposition
143  );
144 
145  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
146  //- Using weighted points.
147  void sortComponent
148  (
149  const label sizeTol,
150  const scalarField& weights,
151  const pointField&,
152  const labelList& slice, // slice of points to decompose
153  const direction componentIndex, // index in decompOrder_
154  const label prevMult, // multiplication factor
155  labelList& finalDecomp // overall decomposition
156  );
157 
158 
159 public:
160 
161  //- Runtime type information
162  TypeName("hierarchical");
163 
164 
165  // Constructors
166 
167  //- Construct given the decomposition dictionary
168  hierarchical(const dictionary& decompositionDict);
169 
170  //- Disallow default bitwise copy construction
171  hierarchical(const hierarchical&) = delete;
172 
173 
174  //- Destructor
175  virtual ~hierarchical()
176  {}
177 
178 
179  // Member Functions
180 
181  //- Return for every coordinate the wanted processor number.
182  virtual labelList decompose
183  (
184  const pointField&,
185  const scalarField& weights
186  );
187 
188  //- Without weights. Code for weighted decomposition is a bit complex
189  // so kept separate for now.
190  virtual labelList decompose(const pointField&);
191 
192 
193  //- Return for every coordinate the wanted processor number. Use the
194  // mesh connectivity (if needed)
195  virtual labelList decompose
196  (
197  const polyMesh& mesh,
198  const pointField& cellCentres,
199  const scalarField& cellWeights
200  )
201  {
202  return decompose(cellCentres, cellWeights);
203  }
204 
205  //- Without weights. Code for weighted decomposition is a bit complex
206  // so kept separate for now.
207  virtual labelList decompose
208  (
209  const polyMesh& mesh,
210  const pointField& cellCentres
211  )
212  {
213  return decompose(cellCentres);
214  }
215 
216  //- Return for every coordinate the wanted processor number. Explicitly
217  // provided connectivity - does not use mesh_.
218  // The connectivity is equal to mesh.cellCells() except for
219  // - in parallel the cell numbers are global cell numbers (starting
220  // from 0 at processor0 and then incrementing all through the
221  // processors)
222  // - the connections are across coupled patches
223  virtual labelList decompose
224  (
225  const labelListList& globalCellCells,
226  const pointField& cellCentres,
227  const scalarField& cellWeights
228  )
229  {
230  return decompose(cellCentres, cellWeights);
231  }
232 
233  virtual labelList decompose
234  (
235  const labelListList& globalCellCells,
236  const pointField& cc
237  )
238  {
239  return decompose(cc);
240  }
241 
242 
243  // Member Operators
244 
245  //- Disallow default bitwise assignment
246  void operator=(const hierarchical&) = delete;
247 };
248 
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 } // End namespace decompositionMethods
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
scalar maxValue
Geometrical domain decomposition.
Definition: geometric.H:52
Does hierarchical decomposition of points. Works by first sorting the points in x direction into equa...
Definition: hierarchical.H:70
hierarchical(const dictionary &decompositionDict)
Construct given the decomposition dictionary.
Definition: hierarchical.C:775
TypeName("hierarchical")
Runtime type information.
void operator=(const hierarchical &)=delete
Disallow default bitwise assignment.
virtual labelList decompose(const pointField &, const scalarField &weights)
Return for every coordinate the wanted processor number.
Definition: hierarchical.C:729
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Namespace for OpenFOAM.
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
uint8_t direction
Definition: direction.H:45