From 8f2e21952bf9e46de4e3487e7ceff05671963239 Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 14 Oct 2013 14:50:44 +0100 Subject: [PATCH] ENH: Field: add maxMagSqr op --- .../fields/Fields/Field/FieldFunctions.C | 55 +++++++++++++++++++ .../fields/Fields/Field/FieldFunctions.H | 12 ++++ 2 files changed, 67 insertions(+) diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index b33a9bc0918..ff38ae0917f 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -358,6 +358,59 @@ Type sum(const UList<Type>& f) TMP_UNARY_FUNCTION(Type, sum) +template<class Type> +Type maxMagSqr(const UList<Type>& f) +{ + if (f.size()) + { + Type Max(f[0]); + TFOR_ALL_S_OP_FUNC_F_S + ( + Type, + Max, + =, + maxMagSqrOp<Type>(), + Type, + f, + Type, + Max + ) + return Max; + } + else + { + return pTraits<Type>::min; + } +} + +TMP_UNARY_FUNCTION(Type, maxMagSqr) + +template<class Type> +Type minMagSqr(const UList<Type>& f) +{ + if (f.size()) + { + Type Min(f[0]); + TFOR_ALL_S_OP_FUNC_F_S + ( + Type, + Min, + =, + minMagSqrOp<Type>(), + Type, + f, + Type, + Min + ) + return Min; + } + else + { + return pTraits<Type>::max; + } +} + +TMP_UNARY_FUNCTION(Type, minMagSqr) template<class Type> scalar sumProd(const UList<Type>& f1, const UList<Type>& f2) @@ -488,6 +541,8 @@ TMP_UNARY_FUNCTION(ReturnType, gFunc) G_UNARY_FUNCTION(Type, gMax, max, max) G_UNARY_FUNCTION(Type, gMin, min, min) G_UNARY_FUNCTION(Type, gSum, sum, sum) +G_UNARY_FUNCTION(Type, gMaxMagSqr, maxMagSqr, maxMagSqr) +G_UNARY_FUNCTION(Type, gMinMagSqr, minMagSqr, minMagSqr) G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum) diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H index f1fa2fdd968..4c51262f9e3 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H @@ -171,6 +171,16 @@ Type sum(const UList<Type>& f); TMP_UNARY_FUNCTION(Type, sum) +template<class Type> +Type maxMagSqr(const UList<Type>& f); + +TMP_UNARY_FUNCTION(Type, maxMagSqr) + +template<class Type> +Type minMagSqr(const UList<Type>& f); + +TMP_UNARY_FUNCTION(Type, minMagSqr) + template<class Type> scalar sumProd(const UList<Type>& f1, const UList<Type>& f2); @@ -208,6 +218,8 @@ TMP_UNARY_FUNCTION(ReturnType, gFunc) G_UNARY_FUNCTION(Type, gMax, max, max) G_UNARY_FUNCTION(Type, gMin, min, min) G_UNARY_FUNCTION(Type, gSum, sum, sum) +G_UNARY_FUNCTION(Type, gMaxMagSqr, maxMagSqr, maxMagSqr) +G_UNARY_FUNCTION(Type, gMinMagSqr, minMagSqr, minMagSqr) G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, sum) -- GitLab