From 6428c60abf017dc17ade5210446754c7dff786c1 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 29 Jan 2010 16:53:56 +0000 Subject: [PATCH] ENH: Have weighted decomposition. All decomposition methods now take an additional scalarField which is the weight per cell. For some of the decomposition methods (scotch,metis) this gets converted to an integer so can have only limited values. --- .../decompositionMethod/decompositionMethod.C | 47 +- .../decompositionMethod/decompositionMethod.H | 31 +- .../decompositionMethods/geomDecomp/geomDecomp.C | 2 - .../decompositionMethods/geomDecomp/geomDecomp.H | 2 +- .../hierarchGeomDecomp/hierarchGeomDecomp.C | 340 ++++++++++++- .../hierarchGeomDecomp/hierarchGeomDecomp.H | 58 +++ .../manualDecomp/manualDecomp.C | 20 +- .../manualDecomp/manualDecomp.H | 11 +- .../decompositionMethods/metisDecomp/metisDecomp.C | 175 ++++--- .../decompositionMethods/metisDecomp/metisDecomp.H | 30 +- .../scotchDecomp/scotchDecomp.C | 217 +++------ .../scotchDecomp/scotchDecomp.H | 26 +- .../simpleGeomDecomp/simpleGeomDecomp.C | 144 +++++- .../simpleGeomDecomp/simpleGeomDecomp.H | 27 +- .../parMetisDecomp/parMetisDecomp.C | 541 +++++++++++---------- .../parMetisDecomp/parMetisDecomp.H | 27 +- 16 files changed, 1169 insertions(+), 529 deletions(-) diff --git a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C index b526f391..26f6949d 100644 --- a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C +++ b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.C @@ -25,8 +25,6 @@ License InClass decompositionMethod -Description - \*---------------------------------------------------------------------------*/ #include "decompositionMethod.H" @@ -106,6 +104,39 @@ Foam::autoPtr Foam::decompositionMethod::New Foam::labelList Foam::decompositionMethod::decompose ( + const pointField& points +) +{ + scalarField weights(0); + + return decompose(points, weights); +} + + +Foam::labelList Foam::decompositionMethod::decompose +( + const labelList& fineToCoarse, + const pointField& coarsePoints, + const scalarField& coarseWeights +) +{ + // Decompose based on agglomerated points + labelList coarseDistribution(decompose(coarsePoints, coarseWeights)); + + // Rework back into decomposition for original mesh_ + labelList fineDistribution(fineToCoarse.size()); + + forAll(fineDistribution, i) + { + fineDistribution[i] = coarseDistribution[fineToCoarse[i]]; + } + + return fineDistribution; +} + + +Foam::labelList Foam::decompositionMethod::decompose +( const labelList& fineToCoarse, const pointField& coarsePoints ) @@ -170,4 +201,16 @@ void Foam::decompositionMethod::calcCellCells } +Foam::labelList Foam::decompositionMethod::decompose +( + const labelListList& globalCellCells, + const pointField& cc +) +{ + scalarField cWeights(0); + + return decompose(globalCellCells, cc, cWeights); +} + + // ************************************************************************* // diff --git a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H index 7055f24d..7f66e9f5 100644 --- a/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H +++ b/src/decompositionMethods/decompositionMethods/decompositionMethod/decompositionMethod.H @@ -150,20 +150,37 @@ public: //- Return for every coordinate the wanted processor number. Use the // mesh connectivity (if needed) - virtual labelList decompose(const pointField&) = 0; + virtual labelList decompose + ( + const pointField& points, + const scalarField& pointWeights + ) = 0; + + //- Like decompose but with uniform weights on the points + virtual labelList decompose(const pointField&); + //- Return for every coordinate the wanted processor number. Gets // passed agglomeration map (from fine to coarse cells) and coarse cell // location. Can be overridden by decomposers that provide this // functionality natively. Coarse cells are local to the processor // (if in parallel). If you want to have coarse cells spanning - // processors use the next function below instead. + // processors use the globalCellCells instead. + virtual labelList decompose + ( + const labelList& cellToRegion, + const pointField& regionPoints, + const scalarField& regionWeights + ); + + //- Like decompose but with uniform weights on the regions virtual labelList decompose ( const labelList& cellToRegion, const pointField& regionPoints ); + //- Return for every coordinate the wanted processor number. Explicitly // provided connectivity - does not use mesh_. // The connectivity is equal to mesh.cellCells() except for @@ -174,9 +191,17 @@ public: virtual labelList decompose ( const labelListList& globalCellCells, - const pointField& cc + const pointField& cc, + const scalarField& cWeights ) = 0; + //- Like decompose but with uniform weights on the cells + virtual labelList decompose + ( + const labelListList& globalCellCells, + const pointField& cc + ); + }; diff --git a/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.C b/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.C index 3c5a783a..b3cfa8ff 100644 --- a/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.C +++ b/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.C @@ -22,8 +22,6 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ #include "geomDecomp.H" diff --git a/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.H b/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.H index df4e88ee..82765cdc 100644 --- a/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.H +++ b/src/decompositionMethods/decompositionMethods/geomDecomp/geomDecomp.H @@ -65,7 +65,7 @@ public: // Constructors - //- Construct given the decomposition dictionary + //- Construct given the decomposition dictionary // and the derived type name geomDecomp ( diff --git a/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C b/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C index 5750cd33..ff6c84f8 100644 --- a/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C +++ b/src/decompositionMethods/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.C @@ -142,6 +142,38 @@ Foam::label Foam::hierarchGeomDecomp::findLower } +// Create a mapping between the index and the weighted size. +// For convenience, sortedWeightedSize is one size bigger than current. This +// avoids extra tests. +void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes +( + const labelList& current, + const labelList& indices, + const scalarField& weights, + const label globalCurrentSize, + + scalarField& sortedWeightedSizes +) +{ + // Evaluate cumulative weights. + sortedWeightedSizes[0] = 0; + forAll(current, i) + { + label pointI = current[indices[i]]; + sortedWeightedSizes[i + 1] = sortedWeightedSizes[i] + weights[pointI]; + } + // Non-dimensionalise and multiply by size. + scalar globalCurrentLength = returnReduce + ( + sortedWeightedSizes[current.size()], + sumOp() + ); + // Normalise weights by global sum of weights and multiply through + // by global size. + sortedWeightedSizes *= (globalCurrentSize/globalCurrentLength); +} + + // Find position in values so between minIndex and this position there // are wantedSize elements. void Foam::hierarchGeomDecomp::findBinary @@ -206,7 +238,87 @@ void Foam::hierarchGeomDecomp::findBinary if (returnReduce(hasNotChanged, andOp())) { WarningIn("hierarchGeomDecomp::findBinary(..)") - << "unable to find desired deomposition split, making do!" + << "unable to find desired deomposition split, making do!" + << endl; + break; + } + + midValuePrev = midValue; + } +} + + +// Find position in values so between minIndex and this position there +// are wantedSize elements. +void Foam::hierarchGeomDecomp::findBinary +( + const label sizeTol, + const List& sortedWeightedSizes, + const List& values, + const label minIndex, // index of previous value + const scalar minValue, // value at minIndex + const scalar maxValue, // global max of values + const scalar wantedSize, // wanted size + + label& mid, // index where size of bin is + // wantedSize (to within sizeTol) + scalar& midValue // value at mid +) +{ + label low = minIndex; + scalar lowValue = minValue; + + scalar highValue = maxValue; + // (one beyond) index of highValue + label high = values.size(); + + // Safeguards to avoid infinite loop. + scalar midValuePrev = VGREAT; + + while (true) + { + label weightedSize = returnReduce + ( + sortedWeightedSizes[mid] - sortedWeightedSizes[minIndex], + sumOp