COMP: remove 'special purpose' minMaxOp (#3326)

- replace with plusOp for reductions. The old use didn't necessarily work
  well with compiler resolution in all cases.
  Simplify to use plusOp (and removed the old version).
  [Does not affect very much code...]

COMP: incorrect include ordering for GeometricFieldFunctions

- header was included after the template code

REGRESSION: combineAllGather mapped to incorrect method (81fa7d08ee)

STYLE: use UPstream::commWarn(...) setter method
This commit is contained in:
Mark Olesen
2025-02-20 13:54:40 +01:00
parent d655c2d343
commit 14b2302b38
15 changed files with 141 additions and 148 deletions

View File

@ -1,3 +1,3 @@
Test-minMax1.C
Test-minMax1.cxx
EXE = $(FOAM_USER_APPBIN)/Test-minMax1

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -182,10 +182,7 @@ int main(int argc, char *argv[])
minmax1 += values1;
Pout<<"range: " << minmax1 << endl;
Info<< "Reduced: "<< returnReduce(minmax1, plusOp<scalarMinMax>()) << nl;
Info<< "Reduced: "<< returnReduce(minmax1, minMaxOp<scalar>()) << nl;
// Info<< "gMinMax: "<< gMinMax(values1v) << nl;

View File

@ -123,7 +123,7 @@ void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology)
{
// Number of global patches and min-max range of total patches
Info<< mesh.boundaryMesh().nNonProcessor() << ' '
<< returnReduce(labelMinMax(nPatches), minMaxOp<label>()) << nl;
<< returnReduce(labelMinMax(nPatches), sumOp<labelMinMax>{}) << nl;
}
else
{

View File

@ -124,8 +124,8 @@ void Foam::PDRutils::one_d_overlap
}
// Ensure search is within the (point) bounds
xmin = grid.clip(xmin);
xmax = grid.clip(xmax);
xmin = grid.clamp(xmin);
xmax = grid.clamp(xmax);
// The begin/end of the obstacle
*cmin = grid.findCell(xmin);

View File

@ -208,7 +208,7 @@ public:
const label comm = UPstream::worldComm
)
{
Pstream::listCombineReduce(value, cop, tag, comm);
Pstream::combineReduce(value, cop, tag, comm);
}

View File

@ -1037,6 +1037,7 @@ public:
//- Clamp field values (in-place) to the specified range.
// \deprecated(2023-01) prefer clamp_range() naming
FOAM_DEPRECATED_FOR(2023-01, "clamp_range() method")
void clip(const dimensioned<MinMax<Type>>& range)
{
this->clamp_range(range);
@ -1044,6 +1045,7 @@ public:
//- Clamp field values (in-place) to the specified range.
// \deprecated(2023-01) prefer clamp_range() naming
FOAM_DEPRECATED_FOR(2023-01, "clamp_range() method")
void clip(const dimensioned<Type>& lo, const dimensioned<Type>& hi)
{
this->clamp_range(lo.value(), hi.value());
@ -1076,13 +1078,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "GeometricFieldI.H"
#include "GeometricFieldFunctions.H"
#ifdef NoRepository
#include "GeometricField.C"
#endif
#include "GeometricFieldFunctions.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -461,13 +461,14 @@ dimensioned<ReturnType> Func \
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, minMaxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, plusOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, plusOp)
#undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \
// Forward to DimensionedField directly (same name)
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func) \
\
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
@ -475,12 +476,7 @@ dimensioned<ReturnType> Func \
const GeometricField<Type, PatchField, GeoMesh>& f1 \
) \
{ \
return dimensioned<ReturnType> \
( \
#Func "(" + f1.name() + ')', \
f1.dimensions(), \
gFunc(f1.primitiveField()) \
); \
return Func(f1.internalField()); \
} \
\
template<class Type, template<class> class PatchField, class GeoMesh> \
@ -489,14 +485,14 @@ dimensioned<ReturnType> Func \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
) \
{ \
dimensioned<ReturnType> res = Func(tf1()); \
auto result = Func(tf1()); \
tf1.clear(); \
return res; \
return result; \
}
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(Type, sum)
UNARY_REDUCTION_FUNCTION(Type, average)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag)
#undef UNARY_REDUCTION_FUNCTION

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -236,14 +236,15 @@ dimensioned<ReturnType> Func \
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, minMaxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, plusOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, plusOp)
#undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func, gFunc) \
#define UNARY_REDUCTION_FUNCTION(ReturnType, Func) \
\
/*! \brief Forwards to Func on internalField */ \
template<class Type, template<class> class PatchField, class GeoMesh> \
dimensioned<ReturnType> Func \
( \
@ -256,9 +257,9 @@ dimensioned<ReturnType> Func \
const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1 \
);
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(Type, sum)
UNARY_REDUCTION_FUNCTION(Type, average)
UNARY_REDUCTION_FUNCTION(typename typeOfMag<Type>::type, sumMag)
#undef UNARY_REDUCTION_FUNCTION

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2023 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -280,7 +280,17 @@ public:
};
// Global Functions
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
//- Declare MinMax as non-contiguous (similar to Tuple2).
// Output remains separate (even in binary) and, since the defined
// \c operator+ is somewhat non-standard, also avoid false matching with
// any MPI intrinsic operation.
template<class T>
struct is_contiguous<MinMax<T>> : std::false_type {};
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Min/max range as a string
template<class T>

View File

@ -134,53 +134,6 @@ inline MinMax<T> minMax(const MinMax<T>& x, const MinMax<T>& y)
}
//- Combine values and/or MinMax ranges
template<class T>
struct minMaxOp
{
MinMax<T> operator()(const T& x, const T& y) const
{
return MinMax<T>(x).add(y);
}
MinMax<T> operator()(const MinMax<T>& x, const T& y) const
{
return MinMax<T>(x).add(y);
}
MinMax<T> operator()(const T& x, const MinMax<T>& y) const
{
return MinMax<T>(y).add(x);
}
MinMax<T> operator()(const MinMax<T>& x, const MinMax<T>& y) const
{
return MinMax<T>(x).add(y); // Same as (x + y)
}
};
//- Combine assignment for MinMax range
template<class T>
struct minMaxEqOp
{
MinMax<T>& operator()(MinMax<T>& x, const T& y) const
{
return x.add(y);
}
MinMax<T>& operator()(MinMax<T>& x, const UList<T>& y) const
{
return x.add(y);
}
MinMax<T>& operator()(MinMax<T>& x, const MinMax<T>& y) const
{
return x.add(y);
}
};
//- The magnitude of a single value.
inline scalarMinMax minMaxMag(const scalar val)
{
@ -256,57 +209,92 @@ inline scalarMinMax minMaxMag(const MinMax<T1>& x, const MinMax<T2>& y)
}
//- Scalar combine the magitude of a value.
template<class T>
struct minMaxMagOp
{
scalarMinMax operator()(const scalarMinMax& x, const T& y) const
{
return minMaxMag(x).add(Foam::mag(y));
}
template<class T1, class T2>
scalarMinMax operator()(const MinMax<T1>& x, const MinMax<T2>& y) const
{
return minMaxMag(x, y);
}
};
//- Combine assignment for MinMax range
template<class T>
struct minMaxMagEqOp
{
scalarMinMax& operator()(scalarMinMax& x, const T& y) const
{
x = minMaxMag(x);
return x.add(Foam::mag(y));
}
scalarMinMax& operator()(scalarMinMax& x, const MinMax<T>& y) const
{
x = minMaxMag(x);
return
(
x
.add(Foam::mag(y.min()))
.add(Foam::mag(y.max()))
);
}
scalarMinMax& operator()(scalarMinMax& x, const UList<T>& y) const
{
x = minMaxMag(x);
for (const T& val : y)
{
x.add(Foam::mag(val));
}
return x;
}
};
// Mark as unused (2025-02)
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// //- Combine values and/or MinMax ranges
// template<class T>
// struct minMaxOp
// {
// MinMax<T> operator()(const T& x, const T& y) const
// {
// return MinMax<T>(x).add(y);
// }
//
// MinMax<T> operator()(const MinMax<T>& x, const T& y) const
// {
// return MinMax<T>(x).add(y);
// }
//
// MinMax<T> operator()(const T& x, const MinMax<T>& y) const
// {
// return MinMax<T>(y).add(x);
// }
// };
//
//
// //- Combine assignment for MinMax range
// template<class T>
// struct minMaxEqOp
// {
// MinMax<T>& operator()(MinMax<T>& x, const T& y) const
// {
// return x.add(y);
// }
//
// MinMax<T>& operator()(MinMax<T>& x, const UList<T>& y) const
// {
// return x.add(y);
// }
// };
//
//
// //- Scalar combine the magitude of a value.
// template<class T>
// struct minMaxMagOp
// {
// scalarMinMax operator()(const scalarMinMax& x, const T& y) const
// {
// return minMaxMag(x).add(Foam::mag(y));
// }
//
// template<class T1, class T2>
// scalarMinMax operator()(const MinMax<T1>& x, const MinMax<T2>& y) const
// {
// return minMaxMag(x).add(Foam::mag(y.min()), Foam::mag(y.max()));
// }
// };
//
//
// //- Combine assignment for MinMax range
// template<class T>
// struct minMaxMagEqOp
// {
// scalarMinMax& operator()(scalarMinMax& x, const T& y) const
// {
// x = minMaxMag(x);
// return x.add(Foam::mag(y));
// }
//
// scalarMinMax& operator()(scalarMinMax& x, const MinMax<T>& y) const
// {
// x = minMaxMag(x);
//
// return x.add(Foam::mag(y.min()), Foam::mag(y.max()));
// }
//
// scalarMinMax& operator()(scalarMinMax& x, const UList<T>& y) const
// {
// x = minMaxMag(x);
//
// for (const T& val : y)
// {
// x.add(Foam::mag(val));
// }
//
// return x;
// }
// };
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //

View File

@ -161,14 +161,14 @@ void Foam::faMeshTools::printMeshChecks
scalarMinMax limit(minMax(mesh.magLe().primitiveField()));
// Include processor boundaries into 'internal' edges
if (Pstream::parRun())
if (UPstream::parRun())
{
for (label patchi = nNonProcessor; patchi < nPatches; ++patchi)
{
limit.add(minMax(mesh.magLe().boundaryField()[patchi]));
}
reduce(limit, minMaxOp<scalar>());
reduce(limit, plusOp<scalarMinMax>{});
}
Info<< "Edge length (internal):" << nl
@ -181,9 +181,9 @@ void Foam::faMeshTools::printMeshChecks
limit.add(minMax(mesh.magLe().boundaryField()[patchi]));
}
if (Pstream::parRun())
if (UPstream::parRun())
{
reduce(limit, minMaxOp<scalar>());
reduce(limit, plusOp<scalarMinMax>{});
}
Info<< "Edge length:" << nl

View File

@ -75,7 +75,7 @@ void Foam::binModels::singleDirectionUniformBin::initialise()
}
// Globally consistent
reduce(geomLimits, minMaxOp<scalar>());
reduce(geomLimits, sumOp<scalarMinMax>());
if (!geomLimits.good())
{

View File

@ -175,10 +175,12 @@ public:
// within bounds, but not aligned with a grid point.
label findIndex(const scalar p, const scalar tol) const;
//- If out of range, return the respective min/max limits,
//- otherwise return the value itself.
//- Return value clamped to min/max limits.
// If the range is invalid, always return the value.
inline const scalar& clip(const scalar& val) const;
inline const scalar& clamp(const scalar& val) const;
//- Return value clamped to min/max limits.
const scalar& clip(const scalar& val) const { return clamp(val); }
};

View File

@ -124,7 +124,7 @@ inline Foam::scalar Foam::PDRblock::location::C(const label i) const
inline const Foam::scalar&
Foam::PDRblock::location::clip(const scalar& val) const
Foam::PDRblock::location::clamp(const scalar& val) const
{
if (scalarList::size())
{

View File

@ -180,8 +180,7 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
const auto& AMI = amiPtr_();
if (debug & 2)
{
const auto oldWarnComm = UPstream::warnComm;
UPstream::warnComm = AMI.comm();
const auto oldWarnComm = UPstream::commWarn(AMI.comm());
const label myRank = UPstream::myProcNo(AMI.comm());
Pout<< "At level:" << fineLevelIndex
@ -297,7 +296,7 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
}
Pout<< "DONE agglomerating at level:" << fineLevelIndex << endl;
UPstream::warnComm = oldWarnComm;
UPstream::commWarn(oldWarnComm);
}
}
}
@ -820,8 +819,7 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
{
const auto& AMI = amiPtr_();
const auto oldWarnComm = UPstream::warnComm;
UPstream::warnComm = AMI.comm();
const auto oldWarnComm = UPstream::commWarn(AMI.comm());
const label myRank = UPstream::myProcNo(AMI.comm());
Pout<< "PROCAGGLOMERATED :"
@ -930,7 +928,7 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
}
}
Pout<< "DONE PROCAGGLOMERATED" << endl;
UPstream::warnComm = oldWarnComm;
UPstream::commWarn(oldWarnComm);
}
}
}