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-2023 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  order | order of operation | no | xyz
56  delta | delta (jitter) for rotation matrix | no | 0.001
57  transform | cartesian coordinate transformation | no |
58  \endtable
59 
60 SourceFiles
61  hierarchGeomDecomp.C
62 
63 \*---------------------------------------------------------------------------*/
64 
65 #ifndef Foam_hierarchGeomDecomp_H
66 #define Foam_hierarchGeomDecomp_H
67 
68 #include "geomDecomp.H"
69 
70 namespace Foam
71 {
72 
73 /*---------------------------------------------------------------------------*\
74  Class hierarchGeomDecomp Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class hierarchGeomDecomp
78 :
79  public geomDecomp
80 {
81  // Private Member Functions
82 
83  //- Find index of value in list between
84  //- first (inclusive) and last (exclusive)
85  static label findLower
86  (
87  const UList<scalar>& list,
88  const scalar val,
89  const label first,
90  const label last
91  );
92 
93  //- Evaluates the weighted sizes for each sorted point.
94  static void calculateSortedWeightedSizes
95  (
96  const labelList& current,
97  const labelList& indices,
98  const scalarField& weights,
99  const label globalCurrentSize,
100 
101  scalarField& sortedWeightedSizes
102  );
103 
104  //- Find midValue (at local index mid) such that the number of
105  // elements between mid and leftIndex are (globally summed) the
106  // wantedSize. Binary search.
107  //
108  // \Return False if the binary search completed
109  static bool findBinary
110  (
111  const label sizeTol, // size difference considered acceptable
112  const List<scalar>&,
113  const label leftIndex, // index of previous value
114  const scalar leftValue, // value at leftIndex
115  const scalar maxValue, // global max of values
116  const scalar wantedSize, // wanted size
117  label& mid, // index where size of bin is wantedSize
118  scalar& midValue // value at mid
119  );
120 
121  //- Find midValue (at local index mid) such that the number of
122  // elements between mid and leftIndex are (globally summed) the
123  // wantedSize. Binary search.
124  static bool findBinary
125  (
126  const label sizeTol, // size difference considered acceptable
127  const List<scalar>& sortedWeightedSizes,
128  const List<scalar>&,
129  const label leftIndex, // index of previous value
130  const scalar leftValue, // value at leftIndex
131  const scalar maxValue, // global max of values
132  const scalar wantedSize, // wanted size
133  label& mid, // index where size of bin is wantedSize
134  scalar& midValue // value at mid
135  );
136 
137  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
138  // \return the number of warnings from findBinary
139  label sortComponent
140  (
141  const label sizeTol,
142  const pointField&,
143  const labelList& slice, // slice of points to decompose
144  const direction componentIndex, // index in decompOrder_
145  const label prevMult, // multiplication factor
146  labelList& finalDecomp // overall decomposition
147  ) const;
148 
149  //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
150  //- Using weighted points.
151  // \return the number of warnings from findBinary
152  label sortComponent
153  (
154  const label sizeTol,
155  const scalarField& weights,
156  const pointField&,
157  const labelList& slice, // slice of points to decompose
158  const direction componentIndex, // index in decompOrder_
159  const label prevMult, // multiplication factor
160  labelList& finalDecomp // overall decomposition
161  ) const;
162 
163 
164 public:
165 
166  //- No copy construct
167  hierarchGeomDecomp(const hierarchGeomDecomp&) = delete;
168 
169  //- No copy assignment
170  void operator=(const hierarchGeomDecomp&) = delete;
171 
172 
173  //- Runtime type information
174  TypeName("hierarchical");
175 
176 
177  // Constructors
178 
179  //- Construct with number of x/y/z division
180  //- (no coefficients or constraints)
181  explicit hierarchGeomDecomp(const Vector<label>& divisions);
182 
183  //- Construct given decomposition dictionary and optional region name
184  explicit hierarchGeomDecomp
185  (
186  const dictionary& decompDict,
187  const word& regionName = ""
188  );
189 
190 
191  //- Destructor
192  virtual ~hierarchGeomDecomp() = default;
193 
194 
195  // Member Functions
196 
197  //- Hierarchical is aware of processor boundaries
198  virtual bool parallelAware() const
199  {
200  return true;
201  }
202 
203  //- Return for every coordinate the wanted processor number.
204  //- using uniform or specified point weights.
205  virtual labelList decompose
206  (
207  const pointField& points,
208  const scalarField& weights = scalarField::null()
209  ) const;
210 
211  //- Return for every coordinate the wanted processor number.
212  // Use the mesh connectivity (if needed).
213  // With uniform or specified point weights.
214  virtual labelList decompose
215  (
216  const polyMesh& mesh,
217  const pointField& cc,
218  const scalarField& cWeights = scalarField::null()
219  ) const
220  {
221  checkDecompositionDirections(mesh.geometricD());
222  return decompose(cc, cWeights);
223  }
224 
225  //- Explicitly provided connectivity
226  virtual labelList decompose
227  (
228  const CompactListList<label>& globalCellCells,
229  const pointField& cc,
230  const scalarField& cWeights = scalarField::null()
231  ) const
232  {
233  return decompose(cc, cWeights);
234  }
235 
236  //- Return for every coordinate the wanted processor number.
237  // Explicitly provided connectivity - does not use mesh_.
238  // The connectivity is equal to mesh.cellCells() except for
239  // - in parallel the cell numbers are global cell numbers (starting
240  // from 0 at processor0 and then incrementing all through the
241  // processors)
242  // - the connections are across coupled patches
243  virtual labelList decompose
244  (
245  const labelListList& globalCellCells,
246  const pointField& cc,
247  const scalarField& cWeights = scalarField::null()
248  ) const
249  {
250  return decompose(cc, cWeights);
251  }
252 };
253 
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
uint8_t direction
Definition: direction.H:46
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual labelList decompose(const pointField &points, const scalarField &weights=scalarField::null()) const
Return for every coordinate the wanted processor number. using uniform or specified point weights...
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
Does hierarchical decomposition of points, selectable as hierarchical.
TypeName("hierarchical")
Runtime type information.
scalar maxValue
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:124
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
hierarchGeomDecomp(const hierarchGeomDecomp &)=delete
No copy construct.
virtual ~hierarchGeomDecomp()=default
Destructor.
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
static const Field< scalar > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
void operator=(const hierarchGeomDecomp &)=delete
No copy assignment.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
virtual bool parallelAware() const
Hierarchical is aware of processor boundaries.
Namespace for OpenFOAM.