ENH: reduce number of warnings emitted by hierarchGeomDecomp

- it is sufficient to provide the total number of times that findBinary()
  failed instead of flooding the screen with messages

  Full verbose warnings still emitted when debugging is on.
This commit is contained in:
Mark Olesen 2018-12-13 18:26:30 +01:00
parent d64a738d0f
commit e761570986
2 changed files with 81 additions and 42 deletions

View File

@ -28,7 +28,7 @@ License
#include "PstreamReduceOps.H"
#include "SortableList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
@ -49,7 +49,8 @@ namespace Foam
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::hierarchGeomDecomp::setDecompOrder()
{
@ -167,7 +168,7 @@ void Foam::hierarchGeomDecomp::calculateSortedWeightedSizes
// Find position in values so between minIndex and this position there
// are wantedSize elements.
void Foam::hierarchGeomDecomp::findBinary
bool Foam::hierarchGeomDecomp::findBinary
(
const label sizeTol,
const List<scalar>& values,
@ -228,20 +229,26 @@ void Foam::hierarchGeomDecomp::findBinary
if (returnReduce(hasNotChanged, andOp<bool>()))
{
WarningInFunction
<< "unable to find desired decomposition split, making do!"
<< endl;
break;
if (debug)
{
WarningInFunction
<< "unable to find desired decomposition split, making do!"
<< endl;
}
return false;
}
midValuePrev = midValue;
}
return true;
}
// Find position in values so between minIndex and this position there
// are wantedSize elements.
void Foam::hierarchGeomDecomp::findBinary
bool Foam::hierarchGeomDecomp::findBinary
(
const label sizeTol,
const List<scalar>& sortedWeightedSizes,
@ -308,19 +315,25 @@ void Foam::hierarchGeomDecomp::findBinary
if (returnReduce(hasNotChanged, andOp<bool>()))
{
WarningInFunction
<< "unable to find desired deomposition split, making do!"
<< endl;
break;
if (debug)
{
WarningInFunction
<< "Unable to find desired decomposition split, making do!"
<< endl;
}
return false;
}
midValuePrev = midValue;
}
return true;
}
// Sort points into bins according to one component. Recurses to next component.
void Foam::hierarchGeomDecomp::sortComponent
Foam::label Foam::hierarchGeomDecomp::sortComponent
(
const label sizeTol,
const pointField& points,
@ -331,7 +344,10 @@ void Foam::hierarchGeomDecomp::sortComponent
) const
{
// Current component
label compI = decompOrder_[componentIndex];
const label compI = decompOrder_[componentIndex];
// Track the number of times that findBinary() did not converge
label nWarnings = 0;
if (debug)
{
@ -426,7 +442,7 @@ void Foam::hierarchGeomDecomp::sortComponent
rightCoord = maxCoord;
// Calculate rightIndex/rightCoord to have wanted size
findBinary
bool ok = findBinary
(
sizeTol,
sortedCoord,
@ -439,6 +455,11 @@ void Foam::hierarchGeomDecomp::sortComponent
rightCoord
);
localSize = rightIndex - leftIndex;
if (!ok)
{
++nWarnings;
}
}
if (debug)
@ -477,7 +498,7 @@ void Foam::hierarchGeomDecomp::sortComponent
Pout.prefix() = " " + oldPrefix;
}
sortComponent
nWarnings += sortComponent
(
sizeTol,
points,
@ -497,11 +518,13 @@ void Foam::hierarchGeomDecomp::sortComponent
leftIndex += localSize;
leftCoord = rightCoord;
}
return nWarnings;
}
// Sort points into bins according to one component. Recurses to next component.
void Foam::hierarchGeomDecomp::sortComponent
Foam::label Foam::hierarchGeomDecomp::sortComponent
(
const label sizeTol,
const scalarField& weights,
@ -513,7 +536,10 @@ void Foam::hierarchGeomDecomp::sortComponent
) const
{
// Current component
label compI = decompOrder_[componentIndex];
const label compI = decompOrder_[componentIndex];
// Track the number of times that findBinary() did not converge
label nWarnings = 0;
if (debug)
{
@ -608,7 +634,7 @@ void Foam::hierarchGeomDecomp::sortComponent
rightCoord = maxCoord;
// Calculate rightIndex/rightCoord to have wanted size
findBinary
bool ok = findBinary
(
sizeTol,
sortedWeightedSizes,
@ -622,6 +648,11 @@ void Foam::hierarchGeomDecomp::sortComponent
rightCoord
);
localSize = rightIndex - leftIndex;
if (!ok)
{
++nWarnings;
}
}
if (debug)
@ -660,7 +691,7 @@ void Foam::hierarchGeomDecomp::sortComponent
Pout.prefix() = " " + oldPrefix;
}
sortComponent
nWarnings += sortComponent
(
sizeTol,
weights,
@ -681,6 +712,8 @@ void Foam::hierarchGeomDecomp::sortComponent
leftIndex += localSize;
leftCoord = rightCoord;
}
return nWarnings;
}
@ -722,24 +755,18 @@ Foam::labelList Foam::hierarchGeomDecomp::decompose
labelList finalDecomp(points.size(), Zero);
// Start off with every point sorted onto itself.
labelList slice(points.size());
forAll(slice, i)
{
slice[i] = i;
}
labelList slice(identity(points.size()));
pointField rotatedPoints(rotDelta_ & points);
// Calculate tolerance of cell distribution. For large cases finding
// distribution to the cell exact would cause too many iterations so allow
// some slack.
label allSize = points.size();
reduce(allSize, sumOp<label>());
const label allSize = returnReduce(points.size(), sumOp<label>());
const label sizeTol = max(1, label(1e-3*allSize/nDomains_));
// Sort recursive
sortComponent
const label nWarnings = sortComponent
(
sizeTol,
rotatedPoints,
@ -749,6 +776,13 @@ Foam::labelList Foam::hierarchGeomDecomp::decompose
finalDecomp
);
if (nWarnings)
{
WarningInFunction
<< "\nEncountered " << nWarnings << " occurrences where the desired"
" decomposition split could not be properly satisfied" << endl;
}
return finalDecomp;
}
@ -763,24 +797,18 @@ Foam::labelList Foam::hierarchGeomDecomp::decompose
labelList finalDecomp(points.size(), Zero);
// Start off with every point sorted onto itself.
labelList slice(points.size());
forAll(slice, i)
{
slice[i] = i;
}
labelList slice(identity(points.size()));
pointField rotatedPoints(rotDelta_ & points);
// Calculate tolerance of cell distribution. For large cases finding
// distribution to the cell exact would cause too many iterations so allow
// some slack.
label allSize = points.size();
reduce(allSize, sumOp<label>());
const label allSize = returnReduce(points.size(), sumOp<label>());
const label sizeTol = max(1, label(1e-3*allSize/nDomains_));
// Sort recursive
sortComponent
const label nWarnings = sortComponent
(
sizeTol,
weights,
@ -791,6 +819,13 @@ Foam::labelList Foam::hierarchGeomDecomp::decompose
finalDecomp
);
if (nWarnings)
{
WarningInFunction
<< "\nEncountered " << nWarnings << " occurrences where the desired"
" decomposition split could not be properly satisfied" << endl;
}
return finalDecomp;
}

View File

@ -111,7 +111,9 @@ class hierarchGeomDecomp
//- Find midValue (at local index mid) such that the number of
// elements between mid and leftIndex are (globally summed) the
// wantedSize. Binary search.
static void findBinary
//
// \Return False if the binary search completed
static bool findBinary
(
const label sizeTol, // size difference considered acceptable
const List<scalar>&,
@ -126,7 +128,7 @@ class hierarchGeomDecomp
//- Find midValue (at local index mid) such that the number of
// elements between mid and leftIndex are (globally summed) the
// wantedSize. Binary search.
static void findBinary
static bool findBinary
(
const label sizeTol, // size difference considered acceptable
const List<scalar>& sortedWeightedSizes,
@ -140,7 +142,8 @@ class hierarchGeomDecomp
);
//- Recursively sort in x,y,z (or rather acc. to decompOrder_)
void sortComponent
// \return the number of warnings from findBinary
label sortComponent
(
const label sizeTol,
const pointField&,
@ -152,7 +155,8 @@ class hierarchGeomDecomp
//- Recursively sort in x,y,z (or rather acc. to decompOrder_)
//- Using weighted points.
void sortComponent
// \return the number of warnings from findBinary
label sortComponent
(
const label sizeTol,
const scalarField& weights,