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 | Copyright (C) 2011-2015 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 inbetween 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 acceptible
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 acceptible
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  //- Disallow default bitwise copy construct and assignment
158  void operator=(const hierarchGeomDecomp&);
160 
161 
162 public:
163 
164  //- Runtime type information
165  TypeName("hierarchical");
166 
167 
168  // Constructors
169 
170  //- Construct given the decomposition dictionary
171  hierarchGeomDecomp(const dictionary& decompositionDict);
172 
173 
174  //- Destructor
175  virtual ~hierarchGeomDecomp()
176  {}
177 
178 
179  // Member Functions
180 
181  //- Hierarchgeom is aware of processor boundaries
182  virtual bool parallelAware() const
183  {
184  return true;
185  }
186 
187  //- Return for every coordinate the wanted processor number.
188  virtual labelList decompose
189  (
190  const pointField&,
191  const scalarField& weights
192  );
193 
194  //- Without weights. Code for weighted decomposition is a bit complex
195  // so kept separate for now.
196  virtual labelList decompose(const pointField&);
197 
198 
199  //- Return for every coordinate the wanted processor number. Use the
200  // mesh connectivity (if needed)
202  (
203  const polyMesh& mesh,
204  const pointField& cc,
205  const scalarField& cWeights
206  )
207  {
208  return decompose(cc, cWeights);
209  }
210 
211  //- Without weights. Code for weighted decomposition is a bit complex
212  // so kept separate for now.
213  virtual labelList decompose(const polyMesh& mesh, const pointField& cc)
214  {
215  return decompose(cc);
216  }
217 
218  //- Return for every coordinate the wanted processor number. Explicitly
219  // provided connectivity - does not use mesh_.
220  // The connectivity is equal to mesh.cellCells() except for
221  // - in parallel the cell numbers are global cell numbers (starting
222  // from 0 at processor0 and then incrementing all through the
223  // processors)
224  // - the connections are across coupled patches
226  (
227  const labelListList& globalCellCells,
228  const pointField& cc,
229  const scalarField& cWeights
230  )
231  {
232  return decompose(cc, cWeights);
233  }
234 
236  (
237  const labelListList& globalCellCells,
238  const pointField& cc
239  )
240  {
241  return decompose(cc);
242  }
243 };
244 
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 } // End namespace Foam
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #endif
253 
254 // ************************************************************************* //
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:46
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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
virtual bool parallelAware() const
Hierarchgeom is aware of processor boundaries.
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...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.