OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

hierarchGeomDecomp.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::hierarchGeomDecomp
00027 
00028 Description
00029     Does hierarchical decomposition of points. Works by first sorting the
00030     points in x direction into equal sized bins, then in y direction and
00031     finally in z direction.
00032 
00033     Uses single array to hold decomposition which is indexed as if it is a
00034     3 dimensional array:
00035 
00036         finalDecomp[i,j,k] is indexed as
00037 
00038         i*n[0]*n[1] + j*n[1] + k
00039 
00040     E.g. if we're sorting 'xyz': the first sort (over the x-component)
00041     determines in which x-domain the point goes. Then for each of the x-domains
00042     the points are sorted in y direction and each individual x-domain gets
00043     split into three y-domains. And similar for the z-direction.
00044 
00045     Since the domains are of equal size the maximum difference in size is
00046     n[0]*n[1] (or n[1]*n[2]?) (small anyway)
00047 
00048 
00049 SourceFiles
00050     hierarchGeomDecomp.C
00051 
00052 \*---------------------------------------------------------------------------*/
00053 
00054 #ifndef hierarchGeomDecomp_H
00055 #define hierarchGeomDecomp_H
00056 
00057 #include "geomDecomp.H"
00058 #include "FixedList.H"
00059 #include "direction.H"
00060 
00061 namespace Foam
00062 {
00063 
00064 /*---------------------------------------------------------------------------*\
00065                            Class hierarchGeomDecomp Declaration
00066 \*---------------------------------------------------------------------------*/
00067 
00068 class hierarchGeomDecomp
00069 :
00070     public geomDecomp
00071 {
00072     // Private data
00073 
00074         //- Decomposition order in terms of components.
00075         FixedList<direction, 3> decompOrder_;
00076 
00077 
00078     // Private Member Functions
00079 
00080         //- Convert ordering string ("xyz") into list of components.
00081         void setDecompOrder();
00082 
00083         //- Find index of t in list inbetween indices left and right
00084         static label findLower
00085         (
00086             const List<scalar>&,
00087             const scalar t,
00088             const label left,
00089             const label right
00090         );
00091 
00092         //- Find midValue (at local index mid) such that the number of
00093         //  elements between mid and leftIndex are (globally summed) the
00094         //  wantedSize. Binary search.
00095         static void findBinary
00096         (
00097             const label sizeTol,        // size difference considered acceptible
00098             const List<scalar>&,
00099             const label leftIndex,      // index of previous value
00100             const scalar leftValue,     // value at leftIndex
00101             const scalar maxValue,      // global max of values
00102             const scalar wantedSize,    // wanted size
00103             label& mid,                 // index where size of bin is wantedSize
00104             scalar& midValue            // value at mid
00105         );
00106 
00107         //- Recursively sort in x,y,z (or rather acc. to decompOrder_)
00108         void sortComponent
00109         (
00110             const label sizeTol,
00111             const pointField&,
00112             const labelList& slice,         // slice of points to decompose
00113             const direction componentIndex, // index in decompOrder_
00114             const label prevMult,           // multiplication factor
00115             labelList& finalDecomp          // overall decomposition
00116         );
00117 
00118 
00119         //- Disallow default bitwise copy construct and assignment
00120         void operator=(const hierarchGeomDecomp&);
00121         hierarchGeomDecomp(const hierarchGeomDecomp&);
00122 
00123 
00124 public:
00125 
00126     //- Runtime type information
00127     TypeName("hierarchical");
00128 
00129 
00130     // Constructors
00131 
00132         //- Construct given the decomposition dictionary
00133         hierarchGeomDecomp(const dictionary& decompositionDict);
00134 
00135         //- Construct given the decomposition dictionary and mesh
00136         hierarchGeomDecomp
00137         (
00138             const dictionary& decompositionDict,
00139             const polyMesh& mesh
00140         );
00141 
00142 
00143     // Destructor
00144 
00145         virtual ~hierarchGeomDecomp()
00146         {}
00147 
00148 
00149     // Member Functions
00150 
00151         //- hierarchgeom is aware of processor boundaries
00152         virtual bool parallelAware() const
00153         {
00154             return true;
00155         }
00156 
00157         //- Return for every coordinate the wanted processor number. Use the
00158         //  mesh connectivity (if needed)
00159         virtual labelList decompose(const pointField&);
00160 
00161         //- Return for every coordinate the wanted processor number. Explicitly
00162         //  provided connectivity - does not use mesh_.
00163         //  The connectivity is equal to mesh.cellCells() except for
00164         //  - in parallel the cell numbers are global cell numbers (starting
00165         //    from 0 at processor0 and then incrementing all through the
00166         //    processors)
00167         //  - the connections are across coupled patches
00168         virtual labelList decompose
00169         (
00170             const labelListList& globalCellCells,
00171             const pointField& cc
00172         )
00173         {
00174             return decompose(cc);
00175         }
00176 };
00177 
00178 
00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00180 
00181 } // End namespace Foam
00182 
00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00184 
00185 #endif
00186 
00187 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd