FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 
57 #include <OpenFOAM/FixedList.H>
58 #include <OpenFOAM/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 
158  //- Disallow default bitwise copy construct and assignment
159  void operator=(const hierarchGeomDecomp&);
161 
162 
163 public:
164 
165  //- Runtime type information
166  TypeName("hierarchical");
167 
168 
169  // Constructors
170 
171  //- Construct given the decomposition dictionary
172  hierarchGeomDecomp(const dictionary& decompositionDict);
173 
174  //- Construct given the decomposition dictionary and mesh
176  (
177  const dictionary& decompositionDict,
178  const polyMesh& mesh
179  );
180 
181 
182  // Destructor
183 
185  {}
186 
187 
188  // Member Functions
189 
190  //- hierarchgeom is aware of processor boundaries
191  virtual bool parallelAware() const
192  {
193  return true;
194  }
195 
196  //- Return for every coordinate the wanted processor number. Use the
197  // mesh connectivity (if needed)
198  virtual labelList decompose
199  (
200  const pointField&,
201  const scalarField& weights
202  );
203 
204  //- Without weights. Code for weighted decomposition is a bit complex
205  // so kept separate for now.
206  virtual labelList decompose(const pointField&);
207 
208  //- Return for every coordinate the wanted processor number. Explicitly
209  // provided connectivity - does not use mesh_.
210  // The connectivity is equal to mesh.cellCells() except for
211  // - in parallel the cell numbers are global cell numbers (starting
212  // from 0 at processor0 and then incrementing all through the
213  // processors)
214  // - the connections are across coupled patches
215  virtual labelList decompose
216  (
217  const labelListList& globalCellCells,
218  const pointField& cc,
219  const scalarField& cWeights
220  )
221  {
222  return decompose(cc, cWeights);
223  }
224 
225  virtual labelList decompose
226  (
227  const labelListList& globalCellCells,
228  const pointField& cc
229  )
230  {
231  return decompose(cc);
232  }
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #endif
243 
244 // ************************ vim: set sw=4 sts=4 et: ************************ //