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-2019 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  //- Hierarchgeom is aware of processor boundaries
181  virtual bool parallelAware() const
182  {
183  return true;
184  }
185 
186  //- Return for every coordinate the wanted processor number.
187  virtual labelList decompose
188  (
189  const pointField&,
190  const scalarField& weights
191  );
192 
193  //- Without weights. Code for weighted decomposition is a bit complex
194  // so kept separate for now.
195  virtual labelList decompose(const pointField&);
196 
197 
198  //- Return for every coordinate the wanted processor number. Use the
199  // mesh connectivity (if needed)
201  (
202  const polyMesh& mesh,
203  const pointField& cc,
204  const scalarField& cWeights
205  )
206  {
207  return decompose(cc, cWeights);
208  }
209 
210  //- Without weights. Code for weighted decomposition is a bit complex
211  // so kept separate for now.
212  virtual labelList decompose(const polyMesh& mesh, const pointField& cc)
213  {
214  return decompose(cc);
215  }
216 
217  //- Return for every coordinate the wanted processor number. Explicitly
218  // provided connectivity - does not use mesh_.
219  // The connectivity is equal to mesh.cellCells() except for
220  // - in parallel the cell numbers are global cell numbers (starting
221  // from 0 at processor0 and then incrementing all through the
222  // processors)
223  // - the connections are across coupled patches
225  (
226  const labelListList& globalCellCells,
227  const pointField& cc,
228  const scalarField& cWeights
229  )
230  {
231  return decompose(cc, cWeights);
232  }
233 
235  (
236  const labelListList& globalCellCells,
237  const pointField& cc
238  )
239  {
240  return decompose(cc);
241  }
242 
243 
244  // Member Operators
245 
246  //- Disallow default bitwise assignment
247  void operator=(const hierarchGeomDecomp&) = delete;
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
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:74
virtual bool parallelAware() const
Hierarchgeom is aware of processor boundaries.
Namespace for OpenFOAM.