diff --git a/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.C b/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.C index e4f727871d..18a27a54a6 100644 --- a/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.C +++ b/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -249,14 +249,14 @@ Foam::labelList Foam::decompositionMethod::decompose const pointField& coarsePoints ) { - scalarField cWeights(coarsePoints.size(), 1.0); + scalarField cellWeights(coarsePoints.size(), 1.0); return decompose ( mesh, fineToCoarse, coarsePoints, - cWeights + cellWeights ); } @@ -264,12 +264,43 @@ Foam::labelList Foam::decompositionMethod::decompose Foam::labelList Foam::decompositionMethod::decompose ( const labelListList& globalCellCells, - const pointField& cc + const pointField& cellCentres ) { - scalarField cWeights(cc.size(), 1.0); + scalarField cellWeights(cellCentres.size(), 1.0); - return decompose(globalCellCells, cc, cWeights); + return decompose(globalCellCells, cellCentres, cellWeights); +} + + +Foam::labelList Foam::decompositionMethod::scaleWeights +( + const scalarField& weights, + const label nWeights, + const bool distributed +) +{ + labelList intWeights; + + if (weights.size() > 0) + { + const scalar sumWeights + ( + distributed + ? gSum(weights) + : sum(weights) + ); + const scalar scale = labelMax/(2*sumWeights); + + // Convert to integers. + intWeights.setSize(weights.size()); + forAll(intWeights, i) + { + intWeights[i] = ceil(scale*weights[i]); + } + } + + return intWeights; } diff --git a/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.H b/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.H index b5fbc8806b..38e9ae227f 100644 --- a/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.H +++ b/src/parallel/decompose/decompositionMethods/decompositionMethod/decompositionMethod.H @@ -53,6 +53,7 @@ protected: // Protected data dictionary decompositionDict_; + label nProcessors_; //- Optional constraints @@ -214,6 +215,15 @@ public: // Other + //- Convert the given scalar weights to labels + // in the range 0-labelMax/2 + static labelList scaleWeights + ( + const scalarField& weights, + const label nWeights, + const bool distributed = true + ); + //- Helper: determine (local or global) cellCells from mesh // agglomeration. Agglomeration is local to the processor. // local : connections are in local indices. Coupled across @@ -301,7 +311,7 @@ public: labelList decompose ( const polyMesh& mesh, - const scalarField& cWeights + const scalarField& cellWeights ); diff --git a/src/parallel/decompose/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.H b/src/parallel/decompose/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.H index c92376a022..9f0aecc166 100644 --- a/src/parallel/decompose/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.H +++ b/src/parallel/decompose/decompositionMethods/hierarchGeomDecomp/hierarchGeomDecomp.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -194,18 +194,22 @@ public: virtual labelList decompose ( const polyMesh& mesh, - const pointField& cc, - const scalarField& cWeights + const pointField& cellCentres, + const scalarField& cellWeights ) { - return decompose(cc, cWeights); + return decompose(cellCentres, cellWeights); } //- Without weights. Code for weighted decomposition is a bit complex // so kept separate for now. - virtual labelList decompose(const polyMesh& mesh, const pointField& cc) + virtual labelList decompose + ( + const polyMesh& mesh, + const pointField& cellCentres + ) { - return decompose(cc); + return decompose(cellCentres); } //- Return for every coordinate the wanted processor number. Explicitly @@ -218,11 +222,11 @@ public: virtual labelList decompose ( const labelListList& globalCellCells, - const pointField& cc, - const scalarField& cWeights + const pointField& cellCentres, + const scalarField& cellWeights ) { - return decompose(cc, cWeights); + return decompose(cellCentres, cellWeights); } virtual labelList decompose diff --git a/src/parallel/decompose/decompositionMethods/manualDecomp/manualDecomp.H b/src/parallel/decompose/decompositionMethods/manualDecomp/manualDecomp.H index d92623fc7d..37c00275b4 100644 --- a/src/parallel/decompose/decompositionMethods/manualDecomp/manualDecomp.H +++ b/src/parallel/decompose/decompositionMethods/manualDecomp/manualDecomp.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -80,8 +80,8 @@ public: virtual labelList decompose ( const polyMesh& mesh, - const pointField& cc, - const scalarField& cWeights + const pointField& cellCentres, + const scalarField& cellWeights ); //- Return for every coordinate the wanted processor number. Explicitly @@ -94,8 +94,8 @@ public: virtual labelList decompose ( const labelListList& globalCellCells, - const pointField& cc, - const scalarField& cWeights + const pointField& cellCentres, + const scalarField& cellWeights ) { NotImplemented; diff --git a/src/parallel/decompose/decompositionMethods/multiLevelDecomp/multiLevelDecomp.C b/src/parallel/decompose/decompositionMethods/multiLevelDecomp/multiLevelDecomp.C index 0530a28121..35c8943e87 100644 --- a/src/parallel/decompose/decompositionMethods/multiLevelDecomp/multiLevelDecomp.C +++ b/src/parallel/decompose/decompositionMethods/multiLevelDecomp/multiLevelDecomp.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -136,8 +136,7 @@ void Foam::multiLevelDecomp::decompose const scalarField& pointWeights, const labelList& pointMap, // map back to original points const label levelI, - - labelField& finalDecomp + labelField& decomp ) { labelList dist @@ -153,7 +152,7 @@ void Foam::multiLevelDecomp::decompose forAll(pointMap, i) { label orig = pointMap[i]; - finalDecomp[orig] += dist[i]; + decomp[orig] += dist[i]; } if (levelI != methods_.size()-1) @@ -165,7 +164,7 @@ void Foam::multiLevelDecomp::decompose labelListList domainToPoints(invertOneToMany(n, dist)); // 'Make space' for new levels of decomposition - finalDecomp *= methods_[levelI+1].nDomains(); + decomp *= methods_[levelI+1].nDomains(); // Extract processor+local index from point-point addressing if (debug && Pstream::master()) @@ -233,7 +232,7 @@ void Foam::multiLevelDecomp::decompose subPointMap, levelI+1, - finalDecomp + decomp ); if (debug && Pstream::master()) { @@ -374,28 +373,35 @@ Foam::multiLevelDecomp::multiLevelDecomp(const dictionary& decompositionDict) Foam::labelList Foam::multiLevelDecomp::decompose ( const polyMesh& mesh, - const pointField& cc, - const scalarField& cWeights + const pointField& cellCentres, + const scalarField& cellWeights ) { CompactListList