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