ENH: FieldFunctions reduce on returnType, not input type (#1327)
- for most functions the input type and return type are identical, but MinMax, sumMag are not.
This commit is contained in:
parent
7945ca739c
commit
26a6533053
@ -324,12 +324,13 @@ dimensioned<returnType> func \
|
||||
UNARY_REDUCTION_FUNCTION(Type, max, gMax)
|
||||
UNARY_REDUCTION_FUNCTION(Type, min, gMin)
|
||||
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
|
||||
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
|
||||
#undef UNARY_REDUCTION_FUNCTION
|
||||
|
||||
|
||||
|
@ -102,6 +102,7 @@ tmp
|
||||
cmptAv(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
|
||||
|
||||
|
||||
// Forward to FieldFunction via dfunc()
|
||||
#define UNARY_REDUCTION_FUNCTION(returnType, func, dfunc) \
|
||||
\
|
||||
template<class Type, class GeoMesh> \
|
||||
@ -118,12 +119,12 @@ dimensioned<returnType> func \
|
||||
UNARY_REDUCTION_FUNCTION(Type, max, gMax)
|
||||
UNARY_REDUCTION_FUNCTION(Type, min, gMin)
|
||||
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
|
||||
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
|
||||
#undef UNARY_REDUCTION_FUNCTION
|
||||
|
||||
|
||||
|
@ -554,13 +554,14 @@ scalarMinMax minMaxMag(const FieldField<Field, Type>& f)
|
||||
TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
|
||||
|
||||
|
||||
// With reduction on ReturnType
|
||||
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
|
||||
\
|
||||
template<template<class> class Field, class Type> \
|
||||
returnType gFunc(const FieldField<Field, Type>& f) \
|
||||
{ \
|
||||
returnType res = func(f); \
|
||||
reduce(res, rFunc##Op<Type>()); \
|
||||
reduce(res, rFunc##Op<returnType>()); \
|
||||
return res; \
|
||||
} \
|
||||
TMP_UNARY_FUNCTION(returnType, gFunc)
|
||||
@ -568,10 +569,11 @@ 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(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
#undef G_UNARY_FUNCTION
|
||||
|
||||
|
@ -238,6 +238,7 @@ scalarMinMax minMaxMag(const FieldField<Field, Type>& f);
|
||||
TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
|
||||
|
||||
|
||||
// With reduction on ReturnType
|
||||
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
|
||||
\
|
||||
template<template<class> class Field, class Type> \
|
||||
@ -247,10 +248,11 @@ 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(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
#undef G_UNARY_FUNCTION
|
||||
|
||||
|
@ -317,10 +317,8 @@ Type max(const UList<Type>& f)
|
||||
TFOR_ALL_S_OP_FUNC_F_S(Type, Max, =, max, Type, f, Type, Max)
|
||||
return Max;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pTraits<Type>::min;
|
||||
}
|
||||
|
||||
return pTraits<Type>::min;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, max)
|
||||
@ -334,10 +332,8 @@ Type min(const UList<Type>& f)
|
||||
TFOR_ALL_S_OP_FUNC_F_S(Type, Min, =, min, Type, f, Type, Min)
|
||||
return Min;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pTraits<Type>::max;
|
||||
}
|
||||
|
||||
return pTraits<Type>::max;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, min)
|
||||
@ -351,10 +347,8 @@ Type sum(const UList<Type>& f)
|
||||
TFOR_ALL_S_OP_F(Type, Sum, +=, Type, f)
|
||||
return Sum;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Zero;
|
||||
}
|
||||
|
||||
return Zero;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, sum)
|
||||
@ -387,10 +381,8 @@ Type maxMagSqr(const UList<Type>& f)
|
||||
)
|
||||
return Max;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Zero;
|
||||
}
|
||||
|
||||
return Zero;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, maxMagSqr)
|
||||
@ -414,10 +406,8 @@ Type minMagSqr(const UList<Type>& f)
|
||||
)
|
||||
return Min;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pTraits<Type>::rootMax;
|
||||
}
|
||||
|
||||
return pTraits<Type>::rootMax;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, minMagSqr)
|
||||
@ -508,25 +498,24 @@ Type average(const UList<Type>& f)
|
||||
|
||||
return avrg;
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "empty field, returning zero" << endl;
|
||||
|
||||
return Zero;
|
||||
}
|
||||
WarningInFunction
|
||||
<< "empty field, returning zero" << endl;
|
||||
|
||||
return Zero;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, average)
|
||||
|
||||
|
||||
// With reduction on ReturnType
|
||||
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
|
||||
\
|
||||
template<class Type> \
|
||||
ReturnType gFunc(const UList<Type>& f, const label comm) \
|
||||
{ \
|
||||
ReturnType res = Func(f); \
|
||||
reduce(res, rFunc##Op<Type>(), Pstream::msgType(), comm); \
|
||||
reduce(res, rFunc##Op<ReturnType>(), Pstream::msgType(), comm); \
|
||||
return res; \
|
||||
} \
|
||||
TMP_UNARY_FUNCTION(ReturnType, gFunc)
|
||||
@ -536,12 +525,13 @@ 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)
|
||||
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
|
||||
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
#undef G_UNARY_FUNCTION
|
||||
|
||||
@ -591,13 +581,11 @@ Type gAverage
|
||||
|
||||
return avrg;
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "empty field, returning zero." << endl;
|
||||
|
||||
return Zero;
|
||||
}
|
||||
WarningInFunction
|
||||
<< "empty field, returning zero." << endl;
|
||||
|
||||
return Zero;
|
||||
}
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, gAverage)
|
||||
|
@ -227,6 +227,7 @@ Type average(const UList<Type>& f);
|
||||
TMP_UNARY_FUNCTION(Type, average)
|
||||
|
||||
|
||||
// With reduction on ReturnType
|
||||
#define G_UNARY_FUNCTION(ReturnType, gFunc, Func, rFunc) \
|
||||
\
|
||||
template<class Type> \
|
||||
@ -238,12 +239,13 @@ 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)
|
||||
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
|
||||
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, sum)
|
||||
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, sum)
|
||||
|
||||
G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
|
||||
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
|
||||
|
||||
#undef G_UNARY_FUNCTION
|
||||
|
||||
|
@ -506,7 +506,7 @@ dimensioned<returnType> func \
|
||||
Foam::func(gf.primitiveField()), \
|
||||
Foam::func(gf.boundaryField()) \
|
||||
), \
|
||||
binaryOp<Type>() \
|
||||
binaryOp<returnType>() \
|
||||
) \
|
||||
); \
|
||||
} \
|
||||
@ -558,8 +558,8 @@ dimensioned<returnType> func \
|
||||
}
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
|
||||
#undef UNARY_REDUCTION_FUNCTION
|
||||
|
||||
|
@ -230,10 +230,8 @@ dimensioned<returnType> func \
|
||||
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp)
|
||||
|
||||
// Same signature, but different implementation
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, unused)
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, unused)
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax<Type>, minMax, minMaxOp)
|
||||
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp)
|
||||
|
||||
#undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY
|
||||
|
||||
@ -253,8 +251,8 @@ dimensioned<returnType> func \
|
||||
);
|
||||
|
||||
UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
|
||||
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
|
||||
|
||||
#undef UNARY_REDUCTION_FUNCTION
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user