initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / decompositionMethods / decompositionMethods / hierarchGeomDecomp / hierarchGeomDecomp.H
blobc2ed56521136a9157b1e0536703930c7345fe218
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::hierarchGeomDecomp
28 Description
29     Does hierarchical decomposition of points. Works by first sorting the
30     points in x direction into equal sized bins, then in y direction and
31     finally in z direction.
33     Uses single array to hold decomposition which is indexed as if it is a
34     3 dimensional array:
36         finalDecomp[i,j,k] is indexed as
38         i*n[0]*n[1] + j*n[1] + k
40     E.g. if we're sorting 'xyz': the first sort (over the x-component)
41     determines in which x-domain the point goes. Then for each of the x-domains
42     the points are sorted in y direction and each individual x-domain gets
43     split into three y-domains. And similar for the z-direction.
45     Since the domains are of equal size the maximum difference in size is
46     n[0]*n[1] (or n[1]*n[2]?) (small anyway)
49 SourceFiles
50     hierarchGeomDecomp.C
52 \*---------------------------------------------------------------------------*/
54 #ifndef hierarchGeomDecomp_H
55 #define hierarchGeomDecomp_H
57 #include "geomDecomp.H"
58 #include "FixedList.H"
59 #include "direction.H"
61 namespace Foam
64 /*---------------------------------------------------------------------------*\
65                            Class hierarchGeomDecomp Declaration
66 \*---------------------------------------------------------------------------*/
68 class hierarchGeomDecomp
70     public geomDecomp
72     // Private data
74         //- Decomposition order in terms of components.
75         FixedList<direction, 3> decompOrder_;
78     // Private Member Functions
80         //- Convert ordering string ("xyz") into list of components.
81         void setDecompOrder();
83         //- Find index of t in list inbetween indices left and right
84         static label findLower
85         (
86             const List<scalar>&,
87             const scalar t,
88             const label left,
89             const label right
90         );
92         //- Find midValue (at local index mid) such that the number of
93         //  elements between mid and leftIndex are (globally summed) the
94         //  wantedSize. Binary search.
95         static void findBinary
96         (
97             const label sizeTol,        // size difference considered acceptible
98             const List<scalar>&,
99             const label leftIndex,      // index of previous value
100             const scalar leftValue,     // value at leftIndex
101             const scalar maxValue,      // global max of values
102             const scalar wantedSize,    // wanted size
103             label& mid,                 // index where size of bin is wantedSize
104             scalar& midValue            // value at mid
105         );
107         //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
108         void sortComponent
109         (
110             const label sizeTol,
111             const pointField&,
112             const labelList& slice,         // slice of points to decompose
113             const direction componentIndex, // index in decompOrder_
114             const label prevMult,           // multiplication factor
115             labelList& finalDecomp          // overall decomposition
116         );
119         //- Disallow default bitwise copy construct and assignment
120         void operator=(const hierarchGeomDecomp&);
121         hierarchGeomDecomp(const hierarchGeomDecomp&);
124 public:
126     //- Runtime type information
127     TypeName("hierarchical");
130     // Constructors
132         //- Construct given the decomposition dictionary
133         hierarchGeomDecomp(const dictionary& decompositionDict);
135         //- Construct given the decomposition dictionary and mesh
136         hierarchGeomDecomp
137         (
138             const dictionary& decompositionDict,
139             const polyMesh& mesh
140         );
143     // Destructor
145         virtual ~hierarchGeomDecomp()
146         {}
149     // Member Functions
151         //- hierarchgeom is aware of processor boundaries
152         virtual bool parallelAware() const
153         {
154             return true;
155         }
157         //- Return for every coordinate the wanted processor number. Use the
158         //  mesh connectivity (if needed)
159         virtual labelList decompose(const pointField&);
161         //- Return for every coordinate the wanted processor number. Explicitly
162         //  provided connectivity - does not use mesh_.
163         //  The connectivity is equal to mesh.cellCells() except for
164         //  - in parallel the cell numbers are global cell numbers (starting
165         //    from 0 at processor0 and then incrementing all through the
166         //    processors)
167         //  - the connections are across coupled patches
168         virtual labelList decompose
169         (
170             const labelListList& globalCellCells,
171             const pointField& cc
172         )
173         {
174             return decompose(cc);
175         }
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 } // End namespace Foam
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 #endif
187 // ************************************************************************* //