mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: minMax, minMaxMag as functions and field functions
- Global functions are unary or combining binary functions, which are
defined in MinMax.H (MinMaxOps.H).
There are also global reduction functions (gMinMax, gMinMaxMag)
as well as supporting 'Op' classes:
- minMaxOp, minMaxEqOp, minMaxMagOp, minMaxMagEqOp
Since the result of the functions represents a content reduction
into a single MinMax<T> value (a min/max pair), field operations
returning a field simply do not make sense.
- Implemented for lists, fields, field-fields, DimensionedField,
GeometricField (parallel reducing, with boundaries).
- Since the minMax evaluates during its operation, this makes it more
efficient for cases where both min/max values are required since it
avoids looping twice through the data.
* Changed GeometricField writeMinMax accordingly.
ENH: clip as field function
- clipping provides a more efficient, single-pass operation to apply
lower/upper limits on single or multiple values.
Examples,
scalarMinMax limiter(0, 1);
limiter.clip(value)
-> returns a const-ref to the value if within the range, or else
returns the appropriate lower/upper limit
limiter.inplaceClip(value)
-> Modifies the value if necessary to be within lower/upper limit
Function calls
clip(value, limiter)
-> returns a copy after applying lower/upper limit
clip(values, limiter)
-> returns a tmp<Field> of clipped values
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
\\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,6 +26,7 @@ License
|
||||
#define TEMPLATE template<class Type>
|
||||
#include "FieldFunctionsM.H"
|
||||
#include "UPstream.H"
|
||||
#include "MinMax.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -151,8 +152,10 @@ tmp<Field<Type>> cmptMag(const UList<Type>& f);
|
||||
template<class Type>
|
||||
tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
|
||||
|
||||
|
||||
#define TMP_UNARY_FUNCTION(ReturnType, Func) \
|
||||
\
|
||||
/** \brief Apply the \c Func() function on the tmp field */ \
|
||||
template<class Type> \
|
||||
ReturnType Func(const tmp<Field<Type>>& tf1);
|
||||
|
||||
@ -171,6 +174,15 @@ Type sum(const UList<Type>& f);
|
||||
|
||||
TMP_UNARY_FUNCTION(Type, sum)
|
||||
|
||||
|
||||
// From MinMaxOps.H:
|
||||
// - Foam::minMax(const UList<Type>&)
|
||||
// - Foam::minMaxMag(const UList<Type>&)
|
||||
|
||||
TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
|
||||
TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type maxMagSqr(const UList<Type>& f);
|
||||
|
||||
@ -224,6 +236,9 @@ 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)
|
||||
|
||||
#undef G_UNARY_FUNCTION
|
||||
|
||||
template<class Type>
|
||||
@ -264,6 +279,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
|
||||
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
|
||||
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
|
||||
|
||||
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user