diff --git a/applications/test/minMax1/Make/files b/applications/test/minMax1/Make/files index 3b5fddb9fcf5eea27ab938e708a9cd79929fd3de..eb933b6ea46055ad86002e0bb33770d86535cbf9 100644 --- a/applications/test/minMax1/Make/files +++ b/applications/test/minMax1/Make/files @@ -1,3 +1,3 @@ -Test-minMax1.C +Test-minMax1.cxx EXE = $(FOAM_USER_APPBIN)/Test-minMax1 diff --git a/applications/test/minMax1/Test-minMax1.C b/applications/test/minMax1/Test-minMax1.cxx similarity index 98% rename from applications/test/minMax1/Test-minMax1.C rename to applications/test/minMax1/Test-minMax1.cxx index 86ff65d720a9eb996c8b1eefd7fab8cd9b1df10f..327ca27dc6d6c51185865334b35de93d4a6a3041 100644 --- a/applications/test/minMax1/Test-minMax1.C +++ b/applications/test/minMax1/Test-minMax1.cxx @@ -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; diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C index e13ef311335bb73138839d1c738b109f76beb8d0..8b6b0d3195db0367d053a012062de1a328355240 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -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 { diff --git a/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C b/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C index e2874cdc9e4ad61182ca45b39e02daefb28d0ed4..1c27f536cfe2538b17e4f9ec83527679a6962581 100644 --- a/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C +++ b/applications/utilities/preProcessing/PDR/pdrFields/PDRutilsOverlap.C @@ -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); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index 0f7a17e3a3397808256cc427f76bcdf956da9810..a43808ed462f843a9b72288ffed7ae420276945d 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -208,7 +208,7 @@ public: const label comm = UPstream::worldComm ) { - Pstream::listCombineReduce(value, cop, tag, comm); + Pstream::combineReduce(value, cop, tag, comm); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 8cb500f580c66c083ae5201e21e4cb0f533f9a21..077c34149d6ec2ab126b0f7d8a222655297f311a 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -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 diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index 40ab6e76461d52de79295cd90207546a3569a65b..8048be9d6d71df12958607c74ea6a8ea32ebe938 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C @@ -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 diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H index 65863a90c0280f81e0ed8bfb7c80c35105a0122d..93339f2688c2a249df859e6f0b1bd2d9472462dc 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H @@ -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 diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H index 377cb6d3e6bb4b32722efd243d97867ef6b25d79..abe625765df3f5ad4ea5a711384507682e16d061 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H @@ -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> diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H index 5bad8452ec13ea97f6649347f4a9827afee6e6ff..70ea46674b801fbd628f5249a327d2f5bfc4cc35 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H @@ -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 * * * * * * * * * * * * * // diff --git a/src/finiteArea/faMesh/faMeshTools/faMeshToolsChecks.C b/src/finiteArea/faMesh/faMeshTools/faMeshToolsChecks.C index 7664356be9330945c1042d35d85c21238b48ff79..e166a0bdd25256b438c669867ea08abb597cd3fc 100644 --- a/src/finiteArea/faMesh/faMeshTools/faMeshToolsChecks.C +++ b/src/finiteArea/faMesh/faMeshTools/faMeshToolsChecks.C @@ -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 diff --git a/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C b/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C index 4d66960b97fa465e2bf69cfdf41b9d7fc884ee86..6b39e51995b38b6669212e39af342199b748cbf5 100644 --- a/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C +++ b/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C @@ -75,7 +75,7 @@ void Foam::binModels::singleDirectionUniformBin::initialise() } // Globally consistent - reduce(geomLimits, minMaxOp<scalar>()); + reduce(geomLimits, sumOp<scalarMinMax>()); if (!geomLimits.good()) { diff --git a/src/mesh/blockMesh/PDRblockMesh/PDRblock.H b/src/mesh/blockMesh/PDRblockMesh/PDRblock.H index d0302b075b5515156a05cd3ebfe27a6f346486dd..22bc331633933fdd01b9b0da2bd72e7da7a1ec1e 100644 --- a/src/mesh/blockMesh/PDRblockMesh/PDRblock.H +++ b/src/mesh/blockMesh/PDRblockMesh/PDRblock.H @@ -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); } }; diff --git a/src/mesh/blockMesh/PDRblockMesh/PDRblockI.H b/src/mesh/blockMesh/PDRblockMesh/PDRblockI.H index 8e34c6ddd4db0ab0df6a5779774a11a37afaf6a6..7999f86d29bab6d819d9ed9f0a3f48ecf4783264 100644 --- a/src/mesh/blockMesh/PDRblockMesh/PDRblockI.H +++ b/src/mesh/blockMesh/PDRblockMesh/PDRblockI.H @@ -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()) { diff --git a/src/meshTools/AMIInterpolation/GAMG/interfaces/cyclicAMIGAMGInterface/cyclicAMIGAMGInterface.C b/src/meshTools/AMIInterpolation/GAMG/interfaces/cyclicAMIGAMGInterface/cyclicAMIGAMGInterface.C index 69dd64b6380598167798e0f864d9c65f84646aed..f2a2d0ebe4dc5a98961697ccc93d5e73351e84e9 100644 --- a/src/meshTools/AMIInterpolation/GAMG/interfaces/cyclicAMIGAMGInterface/cyclicAMIGAMGInterface.C +++ b/src/meshTools/AMIInterpolation/GAMG/interfaces/cyclicAMIGAMGInterface/cyclicAMIGAMGInterface.C @@ -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); } } }