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(const dictionary& methodDict);
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
169  (
170  const dictionary& decompositionDict,
171  const dictionary& methodDict
172  );
173 
174  //- Disallow default bitwise copy construction
175  hierarchical(const hierarchical&) = delete;
176 
177 
178  //- Destructor
179  virtual ~hierarchical()
180  {}
181 
182 
183  // Member Functions
184 
185  //- Return for every coordinate the wanted processor number.
186  virtual labelList decompose
187  (
188  const pointField&,
189  const scalarField& weights
190  );
191 
192  //- Without weights. Code for weighted decomposition is a bit complex
193  // so kept separate for now.
194  virtual labelList decompose(const pointField&);
195 
196 
197  //- Return for every coordinate the wanted processor number. Use the
198  // mesh connectivity (if needed)
199  virtual labelList decompose
200  (
201  const polyMesh& mesh,
202  const pointField& cellCentres,
203  const scalarField& cellWeights
204  )
205  {
206  return decompose(cellCentres, cellWeights);
207  }
208 
209  //- Without weights. Code for weighted decomposition is a bit complex
210  // so kept separate for now.
211  virtual labelList decompose
212  (
213  const polyMesh& mesh,
214  const pointField& cellCentres
215  )
216  {
217  return decompose(cellCentres);
218  }
219 
220  //- Return for every coordinate the wanted processor number. Explicitly
221  // provided connectivity - does not use mesh_.
222  // The connectivity is equal to mesh.cellCells() except for
223  // - in parallel the cell numbers are global cell numbers (starting
224  // from 0 at processor0 and then incrementing all through the
225  // processors)
226  // - the connections are across coupled patches
227  virtual labelList decompose
228  (
229  const labelListList& globalCellCells,
230  const pointField& cellCentres,
231  const scalarField& cellWeights
232  )
233  {
234  return decompose(cellCentres, cellWeights);
235  }
236 
237  virtual labelList decompose
238  (
239  const labelListList& globalCellCells,
240  const pointField& cc
241  )
242  {
243  return decompose(cc);
244  }
245 
246 
247  // Member Operators
248 
249  //- Disallow default bitwise assignment
250  void operator=(const hierarchical&) = delete;
251 };
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace decompositionMethods
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
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, const dictionary &methodDict)
Construct given the decomposition dictionary.
Definition: hierarchical.C:778
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:732
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
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