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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::hierarchGeomDecomp
29 
30 Description
31  Does hierarchical decomposition of points, selectable as \c hierarchical.
32 
33  Works by first sorting the points in x direction into equal sized bins,
34  then in y direction and finally in z direction.
35 
36  Uses single array to hold decomposition which is indexed as if it is a
37  3 dimensional array:
38 
39  finalDecomp[i,j,k] is indexed as
40 
41  i*n[0]*n[1] + j*n[1] + k
42 
43  E.g. if we're sorting 'xyz': the first sort (over the x-component)
44  determines in which x-domain the point goes. Then for each of the x-domains
45  the points are sorted in y direction and each individual x-domain gets
46  split into three y-domains. And similar for the z-direction.
47 
48  Since the domains are of equal size the maximum difference in size is
49  n[0]*n[1] (or n[1]*n[2]?) (small anyway)
50 
51  Method coefficients:
52  \table
53  Property | Description | Required | Default
54  n | (nx ny nz) | yes |
55  delta | delta for rotation matrix | no | 0.001
56  order | order of operation | no | xyz
57  \endtable
58 
59 SourceFiles
60  hierarchGeomDecomp.C
61 
62 \*---------------------------------------------------------------------------*/
63 
64 #ifndef hierarchGeomDecomp_H
65 #define hierarchGeomDecomp_H
66 
67 #include "geomDecomp.H"
68 #include "FixedList.H"
69 #include "direction.H"
70 
71 namespace Foam
72 {
73 
74 /*---------------------------------------------------------------------------*\
75  Class hierarchGeomDecomp Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 class hierarchGeomDecomp
79 :
80  public geomDecomp
81 {
82  // Private Data
83 
84  //- Decomposition order in terms of components.
85  FixedList<direction, 3> order_;
86 
87 
88  // Private Member Functions
89 
90  //- Convert ordering string ("xyz") into list of components.
91  // Checks for bad entries, but no check for duplicate entries.
92  void setOrder();
93 
94  //- Find index of value in list between
95  //- first (inclusive) and last (exclusive)
96  static label findLower
97  (
98  const UList<scalar>& list,
99  const scalar val,
100  const label first,
101  const label last
102  );
103 
104  //- Evaluates the weighted sizes for each sorted point.
105  static void calculateSortedWeightedSizes
106  (
107  const labelList& current,
108  const labelList& indices,
109  const scalarField& weights,
110  const label globalCurrentSize,
111 
112  scalarField& sortedWeightedSizes
113  );
114 
115  //- Find midValue (at local index mid) such that the number of
116  // elements between mid and leftIndex are (globally summed) the
117  // wantedSize. Binary search.
118  //
119  // \Return False if the binary search completed
120  static bool findBinary
121  (
122  const label sizeTol, // size difference considered acceptable
123  const List<scalar>&,
124  const label leftIndex, // index of previous value
125  const scalar leftValue, // value at leftIndex
126  const scalar maxValue, // global max of values
127  const scalar wantedSize, // wanted size
128  label& mid, // index where size of bin is wantedSize
129  scalar& midValue // value at mid
130  );
131 
132  //- Find midValue (at local index mid) such that the number of
133  // elements between mid and leftIndex are (globally summed) the
134  // wantedSize. Binary search.
135  static bool findBinary
136  (
137  const label sizeTol, // size difference considered acceptable
138  const List<scalar>& sortedWeightedSizes,
139  const List<scalar>&,
140  const label leftIndex, // index of previous value
141  const scalar leftValue, // value at leftIndex
142  const scalar maxValue, // global max of values
143  const scalar wantedSize, // wanted size
144  label& mid, // index where size of bin is wantedSize
145  scalar& midValue // value at mid
146  );
147 
148  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
149  // \return the number of warnings from findBinary
150  label sortComponent
151  (
152  const label sizeTol,
153  const pointField&,
154  const labelList& slice, // slice of points to decompose
155  const direction componentIndex, // index in decompOrder_
156  const label prevMult, // multiplication factor
157  labelList& finalDecomp // overall decomposition
158  ) const;
159 
160  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
161  //- Using weighted points.
162  // \return the number of warnings from findBinary
163  label sortComponent
164  (
165  const label sizeTol,
166  const scalarField& weights,
167  const pointField&,
168  const labelList& slice, // slice of points to decompose
169  const direction componentIndex, // index in decompOrder_
170  const label prevMult, // multiplication factor
171  labelList& finalDecomp // overall decomposition
172  ) const;
173 
174 
175  //- No copy construct
176  hierarchGeomDecomp(const hierarchGeomDecomp&) = delete;
177 
178  //- No copy assignment
179  void operator=(const hierarchGeomDecomp&) = delete;
180 
181 
182 public:
183 
184  //- Runtime type information
185  TypeName("hierarchical");
186 
187 
188  // Constructors
189 
190  //- Construct given the decomposition dictionary
191  hierarchGeomDecomp(const dictionary& decompDict);
192 
193  //- Construct for decomposition dictionary and region name
195  (
196  const dictionary& decompDict,
197  const word& regionName
198  );
199 
200 
201  //- Destructor
202  virtual ~hierarchGeomDecomp() = default;
203 
204 
205  // Member Functions
206 
207  //- Hierarchical is aware of processor boundaries
208  virtual bool parallelAware() const
209  {
210  return true;
211  }
212 
213  //- Return for every coordinate the wanted processor number.
214  virtual labelList decompose
215  (
216  const pointField&,
217  const scalarField& weights
218  ) const;
219 
220  //- Decompose with uniform weights.
221  // Code for weighted decomposition is a bit complex,
222  // so kept separate for now.
223  virtual labelList decompose(const pointField&) const;
224 
225 
226  //- Return for every coordinate the wanted processor number.
227  // Use the mesh connectivity (if needed).
228  virtual labelList decompose
229  (
230  const polyMesh& mesh,
231  const pointField& cc,
232  const scalarField& cWeights
233  ) const
234  {
235  checkDecompositionDirections(mesh.geometricD());
236  return decompose(cc, cWeights);
237  }
238 
239  //- Decompose with uniform weights.
240  // Code for weighted decomposition is a bit complex,
241  // so kept separate for now.
242  virtual labelList decompose
243  (
244  const polyMesh& mesh,
245  const pointField& cc
246  ) const
247  {
249  return decompose(cc);
250  }
251 
252  //- Return for every coordinate the wanted processor number.
253  // Explicitly provided connectivity - does not use mesh_.
254  // The connectivity is equal to mesh.cellCells() except for
255  // - in parallel the cell numbers are global cell numbers (starting
256  // from 0 at processor0 and then incrementing all through the
257  // processors)
258  // - the connections are across coupled patches
259  virtual labelList decompose
260  (
261  const labelListList& globalCellCells,
262  const pointField& cc,
263  const scalarField& cWeights
264  ) const
265  {
266  return decompose(cc, cWeights);
267  }
268 
269  virtual labelList decompose
270  (
271  const labelListList& globalCellCells,
272  const pointField& cc
273  ) const
274  {
275  return decompose(cc);
276  }
277 };
278 
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
geomDecomp.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::geomDecomp
Base for geometrical domain decomposition methods.
Definition: geomDecomp.H:71
Foam::Field< scalar >
Foam::findLower
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Foam::geomDecomp::checkDecompositionDirections
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:64
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
Foam::hierarchGeomDecomp::parallelAware
virtual bool parallelAware() const
Hierarchical is aware of processor boundaries.
Definition: hierarchGeomDecomp.H:227
Foam::hierarchGeomDecomp::TypeName
TypeName("hierarchical")
Runtime type information.
Foam::List< label >
Foam::hierarchGeomDecomp::decompose
virtual labelList decompose(const pointField &, const scalarField &weights) const
Return for every coordinate the wanted processor number.
Definition: hierarchGeomDecomp.C:790
Foam::FixedList< direction, 3 >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::hierarchGeomDecomp
Does hierarchical decomposition of points, selectable as hierarchical.
Definition: hierarchGeomDecomp.H:97
FixedList.H
Foam::hierarchGeomDecomp::~hierarchGeomDecomp
virtual ~hierarchGeomDecomp()=default
Destructor.
maxValue
scalar maxValue
Definition: LISASMDCalcMethod1.H:5