00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::hierarchGeomDecomp 00026 00027 Description 00028 Does hierarchical decomposition of points. Works by first sorting the 00029 points in x direction into equal sized bins, then in y direction and 00030 finally in z direction. 00031 00032 Uses single array to hold decomposition which is indexed as if it is a 00033 3 dimensional array: 00034 00035 finalDecomp[i,j,k] is indexed as 00036 00037 i*n[0]*n[1] + j*n[1] + k 00038 00039 E.g. if we're sorting 'xyz': the first sort (over the x-component) 00040 determines in which x-domain the point goes. Then for each of the x-domains 00041 the points are sorted in y direction and each individual x-domain gets 00042 split into three y-domains. And similar for the z-direction. 00043 00044 Since the domains are of equal size the maximum difference in size is 00045 n[0]*n[1] (or n[1]*n[2]?) (small anyway) 00046 00047 00048 SourceFiles 00049 hierarchGeomDecomp.C 00050 00051 \*---------------------------------------------------------------------------*/ 00052 00053 #ifndef hierarchGeomDecomp_H 00054 #define hierarchGeomDecomp_H 00055 00056 #include <decompositionMethods/geomDecomp.H> 00057 #include <OpenFOAM/FixedList.H> 00058 #include <OpenFOAM/direction.H> 00059 00060 namespace Foam 00061 { 00062 00063 /*---------------------------------------------------------------------------*\ 00064 Class hierarchGeomDecomp Declaration 00065 \*---------------------------------------------------------------------------*/ 00066 00067 class hierarchGeomDecomp 00068 : 00069 public geomDecomp 00070 { 00071 // Private data 00072 00073 //- Decomposition order in terms of components. 00074 FixedList<direction, 3> decompOrder_; 00075 00076 00077 // Private Member Functions 00078 00079 //- Convert ordering string ("xyz") into list of components. 00080 void setDecompOrder(); 00081 00082 //- Evaluates the weighted sizes for each sorted point. 00083 static void calculateSortedWeightedSizes 00084 ( 00085 const labelList& current, 00086 const labelList& indices, 00087 const scalarField& weights, 00088 const label globalCurrentSize, 00089 00090 scalarField& sortedWeightedSizes 00091 ); 00092 00093 //- Find index of t in list inbetween indices left and right 00094 static label findLower 00095 ( 00096 const List<scalar>&, 00097 const scalar t, 00098 const label left, 00099 const label right 00100 ); 00101 00102 //- Find midValue (at local index mid) such that the number of 00103 // elements between mid and leftIndex are (globally summed) the 00104 // wantedSize. Binary search. 00105 static void findBinary 00106 ( 00107 const label sizeTol, // size difference considered acceptible 00108 const List<scalar>&, 00109 const label leftIndex, // index of previous value 00110 const scalar leftValue, // value at leftIndex 00111 const scalar maxValue, // global max of values 00112 const scalar wantedSize, // wanted size 00113 label& mid, // index where size of bin is wantedSize 00114 scalar& midValue // value at mid 00115 ); 00116 00117 //- Find midValue (at local index mid) such that the number of 00118 // elements between mid and leftIndex are (globally summed) the 00119 // wantedSize. Binary search. 00120 static void findBinary 00121 ( 00122 const label sizeTol, // size difference considered acceptible 00123 const List<scalar>& sortedWeightedSizes, 00124 const List<scalar>&, 00125 const label leftIndex, // index of previous value 00126 const scalar leftValue, // value at leftIndex 00127 const scalar maxValue, // global max of values 00128 const scalar wantedSize, // wanted size 00129 label& mid, // index where size of bin is wantedSize 00130 scalar& midValue // value at mid 00131 ); 00132 00133 //- Recursively sort in x,y,z (or rather acc. to decompOrder_) 00134 void sortComponent 00135 ( 00136 const label sizeTol, 00137 const pointField&, 00138 const labelList& slice, // slice of points to decompose 00139 const direction componentIndex, // index in decompOrder_ 00140 const label prevMult, // multiplication factor 00141 labelList& finalDecomp // overall decomposition 00142 ); 00143 00144 //- Recursively sort in x,y,z (or rather acc. to decompOrder_) 00145 //- using weighted points. 00146 void sortComponent 00147 ( 00148 const label sizeTol, 00149 const scalarField& weights, 00150 const pointField&, 00151 const labelList& slice, // slice of points to decompose 00152 const direction componentIndex, // index in decompOrder_ 00153 const label prevMult, // multiplication factor 00154 labelList& finalDecomp // overall decomposition 00155 ); 00156 00157 00158 //- Disallow default bitwise copy construct and assignment 00159 void operator=(const hierarchGeomDecomp&); 00160 hierarchGeomDecomp(const hierarchGeomDecomp&); 00161 00162 00163 public: 00164 00165 //- Runtime type information 00166 TypeName("hierarchical"); 00167 00168 00169 // Constructors 00170 00171 //- Construct given the decomposition dictionary 00172 hierarchGeomDecomp(const dictionary& decompositionDict); 00173 00174 //- Construct given the decomposition dictionary and mesh 00175 hierarchGeomDecomp 00176 ( 00177 const dictionary& decompositionDict, 00178 const polyMesh& mesh 00179 ); 00180 00181 00182 // Destructor 00183 00184 virtual ~hierarchGeomDecomp() 00185 {} 00186 00187 00188 // Member Functions 00189 00190 //- hierarchgeom is aware of processor boundaries 00191 virtual bool parallelAware() const 00192 { 00193 return true; 00194 } 00195 00196 //- Return for every coordinate the wanted processor number. Use the 00197 // mesh connectivity (if needed) 00198 virtual labelList decompose 00199 ( 00200 const pointField&, 00201 const scalarField& weights 00202 ); 00203 00204 //- Without weights. Code for weighted decomposition is a bit complex 00205 // so kept separate for now. 00206 virtual labelList decompose(const pointField&); 00207 00208 //- Return for every coordinate the wanted processor number. Explicitly 00209 // provided connectivity - does not use mesh_. 00210 // The connectivity is equal to mesh.cellCells() except for 00211 // - in parallel the cell numbers are global cell numbers (starting 00212 // from 0 at processor0 and then incrementing all through the 00213 // processors) 00214 // - the connections are across coupled patches 00215 virtual labelList decompose 00216 ( 00217 const labelListList& globalCellCells, 00218 const pointField& cc, 00219 const scalarField& cWeights 00220 ) 00221 { 00222 return decompose(cc, cWeights); 00223 } 00224 00225 virtual labelList decompose 00226 ( 00227 const labelListList& globalCellCells, 00228 const pointField& cc 00229 ) 00230 { 00231 return decompose(cc); 00232 } 00233 }; 00234 00235 00236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00237 00238 } // End namespace Foam 00239 00240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00241 00242 #endif 00243 00244 // ************************ vim: set sw=4 sts=4 et: ************************ //