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:
Mark Olesen
2019-01-10 09:43:23 +01:00
parent 1370060da2
commit 9a7029004c
24 changed files with 950 additions and 204 deletions

View File

@ -141,8 +141,8 @@ int main(int argc, char *argv[])
} }
#include "rhoEqn.H" #include "rhoEqn.H"
Info<< "rhoEqn max/min : " << max(rho).value() Info<< "rho min/max : " << min(rho).value() << " " << max(rho).value()
<< " " << min(rho).value() << endl; << endl;
// --- Pressure-velocity PIMPLE corrector loop // --- Pressure-velocity PIMPLE corrector loop
while (pimple.loop()) while (pimple.loop())

View File

@ -121,8 +121,8 @@ int main(int argc, char *argv[])
} }
#include "rhoEqn.H" #include "rhoEqn.H"
Info<< "rhoEqn max/min : " << max(rho).value() Info<< "rho min/max : " << min(rho).value() << " " << max(rho).value()
<< " " << min(rho).value() << endl; << endl;
// --- Pressure-velocity PIMPLE corrector loop // --- Pressure-velocity PIMPLE corrector loop
while (pimple.loop()) while (pimple.loop())

View File

@ -79,6 +79,6 @@
rho = thermo.rho(); rho = thermo.rho();
rho.relax(); rho.relax();
Info<< "rho max/min : " << max(rho).value() << " " << min(rho).value() Info<< "rho min/max : " << min(rho).value() << " " << max(rho).value()
<< endl; << endl;
} }

View File

@ -97,8 +97,7 @@ rho = thermo.rho();
rho = max(rho, rhoMin); rho = max(rho, rhoMin);
rho = min(rho, rhoMax); rho = min(rho, rhoMax);
rho.relax(); rho.relax();
Info<< "rho max/min : " << max(rho).value() Info<< "rho min/max : " << min(rho).value() << " " << max(rho).value() << endl;
<< " " << min(rho).value() << endl;
U = HbyA - rAU*fvc::grad(p); U = HbyA - rAU*fvc::grad(p);
U.correctBoundaryConditions(); U.correctBoundaryConditions();

View File

@ -97,8 +97,7 @@ rho = thermo.rho();
rho = max(rho, rhoMin); rho = max(rho, rhoMin);
rho = min(rho, rhoMax); rho = min(rho, rhoMax);
rho.relax(); rho.relax();
Info<< "rho max/min : " << max(rho).value() Info<< "rho min/max : " << min(rho).value() << " " << max(rho).value() << endl;
<< " " << min(rho).value() << endl;
U = HbyA - rAU*fvc::grad(p); U = HbyA - rAU*fvc::grad(p);
U.correctBoundaryConditions(); U.correctBoundaryConditions();

View File

@ -138,7 +138,23 @@ int main(int argc, char *argv[])
minmax1 += values1; minmax1 += values1;
Pout<<"range: " << minmax1 << endl; Pout<<"range: " << minmax1 << endl;
Info<< "Reduced: "<< returnReduce(minmax1, plusOp<scalarMinMax>()) << nl; Info<< "Reduced: "<< returnReduce(minmax1, plusOp<scalarMinMax>()) << nl;
Info<< "Reduced: "<< returnReduce(minmax1, minMaxOp<scalar>()) << nl;
// Info<< "gMinMax: "<< gMinMax(values1v) << nl;
vectorField values1v
(
ListOps::create<vector>
(
values1,
[](const scalar s) { return vector(s, 2*s, -2*s); }
)
);
Info<< "gMinMax: " << gMinMax(values1v) << nl;
Info<< "gMinMaxMag: " << gMinMaxMag(values1v) << nl;
{ {
MinMax<scalar> limiter(10, 200); MinMax<scalar> limiter(10, 200);
@ -159,13 +175,14 @@ int main(int argc, char *argv[])
Info<< "clipped : " << val << " = " << clip(val, limiter) << nl; Info<< "clipped : " << val << " = " << clip(val, limiter) << nl;
} }
Info<< nl << "inplace clip" << nl; Info<< nl << "test clip(Field) with limiter: " << limiter << nl;
Info<< "clipped : " << clip(values1, limiter) << nl;
scalarField values2(values1); scalarField values2(values1);
Info<< "before: " << flatOutput(values2) << nl; Info<< nl << "inplace clip" << nl;
Info<< "before: " << flatOutput(values2) << nl; Info<< "before " << flatOutput(values2) << nl;
for (scalar& val : values2) for (scalar& val : values2)
{ {
@ -176,7 +193,9 @@ int main(int argc, char *argv[])
Info<< nl << "For list: " << flatOutput(values1) << nl Info<< nl << "For list: " << flatOutput(values1) << nl
<< " minMax : " << minMax(values1) << nl << " minMax : " << minMax(values1) << nl
<< " minMaxMag : " << minMaxMag(values1) << nl; << " minMaxMag : " << minMaxMag(values1)
<< " = " << mag(minMaxMag(vector(1, 2, 3)))
<< nl;
} }

View File

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

View File

@ -0,0 +1,7 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools

View File

@ -0,0 +1,146 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Test minMax
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "Time.H"
#include "BitOps.H"
#include "HashOps.H"
#include "ListOps.H"
#include "scalarField.H"
#include "MinMax.H"
#include "dimensionedScalar.H"
#include "dimensionedMinMax.H"
using namespace Foam;
template<class T>
Ostream& printInfo(const MinMax<T>& range)
{
Info<< range << " valid=" << range.valid();
return Info;
}
dimensionedScalarMinMax rhoLimit(const dictionary& dict)
{
Info<< "From " << dict;
dimensionedScalarMinMax range =
makeDimensionedMinMax<scalar>
(
"rhoLimit", dimDensity, scalarMinMax{Zero, GREAT}, dict,
"rhoMin", "rhoMax"
);
Info<< "=> " << range << nl;
return range;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noCheckProcessorDirectories();
#include "setRootCase.H"
Info<< "Test min/max " << nl;
{
scalarMinMax range1(10, 20);
scalarMinMax range2(40, 50);
Info<< range1 << " + " << range2 << " = " << (range1 + range2) <<nl;
}
{
Info<< "Dimensioned range : "
<< dimensioned<scalarMinMax>("velrange", dimVelocity, {1, 20})
<< nl;
dimensioned<scalarMinMax> range1("a", dimVelocity, {10, 20});
dimensioned<scalarMinMax> range2("b", dimVelocity, {40, 50});
Info<< "Dimensioned range : " << (range1 + range2) << endl;
}
{
Info<< nl << "makeDimensionedMinMax:" << nl << nl;
Info
<< makeDimensionedMinMax<scalar>("rhoa", dimDensity, 1, 20)
<< nl;
{
dimensionedScalar minval("min", dimDensity, 0.3);
dimensionedScalar maxval("max", dimDensity, 0.5);
Info
<< makeDimensionedMinMax<scalar>(minval, maxval)
<< nl;
Info
<< makeDimensionedMinMax<scalar>("rhob", minval, maxval)
<< nl;
}
{
dictionary dict1, dict2, dict3, dict4;
dict1.add("rhoMin", dimensionedScalar("", dimDensity, 0.1));
dict2.add("rhoMax", dimensionedScalar("", dimDensity, 20));
dict3.add("rhoMin", dimensionedScalar("", dimDensity, 0.3));
dict3.add("rhoMax", dimensionedScalar("", dimDensity, 30));
dict4.add
(
"rhoLimit",
dimensionedScalarMinMax("", dimDensity, scalarMinMax(0.4, 40))
);
rhoLimit(dict1);
rhoLimit(dict2);
rhoLimit(dict3);
rhoLimit(dict4);
}
}
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,167 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::dimensionedScalarMinMax
Description
A dimensioned scalarMinMix (MinMax for scalar quantities).
Typedef
Foam::dimensionedMinMax\<T\>
Description
A templated type alias for dimensioned\<MinMax\<T\>\>
SourceFiles
dimensionedMinMaxTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef dimensionedMinMax_H
#define dimensionedMinMax_H
#include "dimensionedType.H"
#include "MinMax.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// General alias
template<class T>
using dimensionedMinMax = dimensioned<MinMax<T>>;
// Common typedefs
typedef dimensioned<scalarMinMax> dimensionedScalarMinMax;
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Make a dimensionedMinMax from all components
template<class T>
inline dimensioned<MinMax<T>> makeDimensionedMinMax
(
const word& name,
const dimensionSet& dims,
const T& minVal,
const T& maxVal
)
{
return dimensioned<MinMax<T>>(name, dims, MinMax<T>(minVal, maxVal));
}
//- Create a dimensionless "minmax"
template<class T>
inline dimensioned<MinMax<T>> makeDimensionedMinMax
(
const T& minVal,
const T& maxVal
)
{
return
dimensioned<MinMax<T>>
(
"minmax", dimensionSet(), MinMax<T>(minVal, maxVal)
);
}
//- Combine two dimensioned types into a dimensionedMinMax with specified name
template<class T>
inline dimensioned<MinMax<T>> makeDimensionedMinMax
(
const word& name,
const dimensioned<T>& minVal,
const dimensioned<T>& maxVal
)
{
// Dimension check when (dimensionSet::debug)
return dimensioned<MinMax<T>>
(
name,
(minVal.dimensions() + maxVal.dimensions()),
MinMax<T>(minVal.value(), maxVal.value())
);
}
//- Combine two dimensioned types into a dimensionedMinMax "minmax"
template<class T>
inline dimensioned<MinMax<T>> makeDimensionedMinMax
(
const dimensioned<T>& minVal,
const dimensioned<T>& maxVal
)
{
return makeDimensionedMinMax("minmax", minVal, maxVal);
}
//- Construct from components (name, dimensions, value) with an optional
//- dictionary override that can also \e zip together different sub-entries.
//
// The dictionary override can specify separate min/max dictionary entries.
// For example,
// \verbatim
// rhoMin 0.3;
// rhoMax 2.0;
// \endverbatim
//
// Construct as following:
//
// \verbatim
// makeDimensionedMinMax<scalar>
// (
// "rhoMinMax", dimDensity, {Zero, GREAT}, dict, "rhoMin", "rhoMax"
// );
// \endverbatim
template<class T>
dimensioned<MinMax<T>> makeDimensionedMinMax
(
const word& name,
const dimensionSet& dims,
const MinMax<T>& values,
const dictionary& dict,
const word& minName,
const word& maxName
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "dimensionedMinMaxTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "dimensionedMinMax.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class T>
Foam::dimensioned<Foam::MinMax<T>> Foam::makeDimensionedMinMax
(
const word& name,
const dimensionSet& dims,
const MinMax<T>& values,
const dictionary& dict,
const word& minName,
const word& maxName
)
{
// Normal construction with optional entry
dimensioned<MinMax<T>> range(name, dims, values, dict);
// Optional min specification
if (!minName.empty())
{
dimensioned<T> minVal(minName, dims, values.min(), dict);
range.dimensions() += minVal.dimensions();
range.value().min() = minVal.value();
}
// Optional max specification
if (!maxName.empty())
{
dimensioned<T> maxVal(maxName, dims, values.max(), dict);
range.dimensions() += maxVal.dimensions();
range.value().max() = maxVal.value();
}
return range;
}
// ************************************************************************* //

View File

@ -33,6 +33,7 @@ License
#include "dimensionedSphericalTensor.H" #include "dimensionedSphericalTensor.H"
#include "dimensionedSymmTensor.H" #include "dimensionedSymmTensor.H"
#include "dimensionedTensor.H" #include "dimensionedTensor.H"
#include "dimensionedMinMax.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -325,6 +325,9 @@ UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag) UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(Type, average, gAverage) UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
#undef UNARY_REDUCTION_FUNCTION #undef UNARY_REDUCTION_FUNCTION
@ -338,6 +341,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -119,6 +119,9 @@ UNARY_REDUCTION_FUNCTION(Type, sum, gSum)
UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag) UNARY_REDUCTION_FUNCTION(scalar, sumMag, gSumMag)
UNARY_REDUCTION_FUNCTION(Type, average, gAverage) UNARY_REDUCTION_FUNCTION(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
#undef UNARY_REDUCTION_FUNCTION #undef UNARY_REDUCTION_FUNCTION
@ -132,6 +135,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -521,6 +521,37 @@ Type average(const FieldField<Field, Type>& f)
TMP_UNARY_FUNCTION(Type, average) TMP_UNARY_FUNCTION(Type, average)
template<template<class> class Field, class Type>
MinMax<Type> minMax(const FieldField<Field, Type>& f)
{
MinMax<Type> result;
forAll(f, i)
{
result += minMax(f[i]);
}
return result;
}
TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
template<template<class> class Field, class Type>
scalarMinMax minMaxMag(const FieldField<Field, Type>& f)
{
scalarMinMax result;
forAll(f, i)
{
result += minMaxMag(f[i]);
}
return result;
}
TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \ #define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
\ \
template<template<class> class Field, class Type> \ template<template<class> class Field, class Type> \
@ -537,6 +568,9 @@ G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum) G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
#undef G_UNARY_FUNCTION #undef G_UNARY_FUNCTION
@ -580,6 +614,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -223,6 +223,19 @@ Type average(const FieldField<Field, Type>& f);
TMP_UNARY_FUNCTION(Type, average) TMP_UNARY_FUNCTION(Type, average)
//- Return min/max for a field of fields
template<template<class> class Field, class Type>
MinMax<Type> minMax(const FieldField<Field, Type>& f);
TMP_UNARY_FUNCTION(MinMax<Type>, minMax)
//- Return mag min/max for a field of fields
template<template<class> class Field, class Type>
scalarMinMax minMaxMag(const FieldField<Field, Type>& f);
TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag)
#define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \ #define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \
\ \
template<template<class> class Field, class Type> \ template<template<class> class Field, class Type> \
@ -234,6 +247,9 @@ G_UNARY_FUNCTION(Type, gMin, min, min)
G_UNARY_FUNCTION(Type, gSum, sum, sum) G_UNARY_FUNCTION(Type, gSum, sum, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
#undef G_UNARY_FUNCTION #undef G_UNARY_FUNCTION
@ -255,6 +271,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */

View File

@ -357,6 +357,15 @@ Type sum(const UList<Type>& f)
TMP_UNARY_FUNCTION(Type, sum) 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> template<class Type>
Type maxMagSqr(const UList<Type>& f) Type maxMagSqr(const UList<Type>& f)
{ {
@ -414,25 +423,21 @@ TMP_UNARY_FUNCTION(Type, minMagSqr)
template<class Type> template<class Type>
scalar sumProd(const UList<Type>& f1, const UList<Type>& f2) scalar sumProd(const UList<Type>& f1, const UList<Type>& f2)
{ {
scalar SumProd = 0;
if (f1.size() && (f1.size() == f2.size())) if (f1.size() && (f1.size() == f2.size()))
{ {
scalar SumProd = 0;
TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, &&, Type, f2) TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, &&, Type, f2)
return SumProd;
}
else
{
return 0;
} }
return SumProd;
} }
template<class Type> template<class Type>
Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2) Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
{ {
Type SumProd = Zero;
if (f1.size() && (f1.size() == f2.size())) if (f1.size() && (f1.size() == f2.size()))
{ {
Type SumProd = Zero;
TFOR_ALL_S_OP_FUNC_F_F TFOR_ALL_S_OP_FUNC_F_F
( (
Type, Type,
@ -444,28 +449,20 @@ Type sumCmptProd(const UList<Type>& f1, const UList<Type>& f2)
Type, Type,
f2 f2
) )
return SumProd;
}
else
{
return Zero;
} }
return SumProd;
} }
template<class Type> template<class Type>
scalar sumSqr(const UList<Type>& f) scalar sumSqr(const UList<Type>& f)
{ {
scalar SumSqr = 0;
if (f.size()) if (f.size())
{ {
scalar SumSqr = 0;
TFOR_ALL_S_OP_FUNC_F(scalar, SumSqr, +=, sqr, Type, f) TFOR_ALL_S_OP_FUNC_F(scalar, SumSqr, +=, sqr, Type, f)
return SumSqr;
}
else
{
return 0;
} }
return SumSqr;
} }
TMP_UNARY_FUNCTION(scalar, sumSqr) TMP_UNARY_FUNCTION(scalar, sumSqr)
@ -473,16 +470,12 @@ TMP_UNARY_FUNCTION(scalar, sumSqr)
template<class Type> template<class Type>
scalar sumMag(const UList<Type>& f) scalar sumMag(const UList<Type>& f)
{ {
scalar SumMag = 0;
if (f.size()) if (f.size())
{ {
scalar SumMag = 0;
TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, mag, Type, f) TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, mag, Type, f)
return SumMag;
}
else
{
return 0;
} }
return SumMag;
} }
TMP_UNARY_FUNCTION(scalar, sumMag) TMP_UNARY_FUNCTION(scalar, sumMag)
@ -491,16 +484,12 @@ TMP_UNARY_FUNCTION(scalar, sumMag)
template<class Type> template<class Type>
Type sumCmptMag(const UList<Type>& f) Type sumCmptMag(const UList<Type>& f)
{ {
Type SumMag = Zero;
if (f.size()) if (f.size())
{ {
Type SumMag = Zero;
TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, cmptMag, Type, f) TFOR_ALL_S_OP_FUNC_F(scalar, SumMag, +=, cmptMag, Type, f)
return SumMag;
}
else
{
return Zero;
} }
return SumMag;
} }
TMP_UNARY_FUNCTION(Type, sumCmptMag) TMP_UNARY_FUNCTION(Type, sumCmptMag)
@ -546,8 +535,12 @@ G_UNARY_FUNCTION(scalar, gSumSqr, sumSqr, sum)
G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum) G_UNARY_FUNCTION(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, 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 #undef G_UNARY_FUNCTION
template<class Type> template<class Type>
scalar gSumProd scalar gSumProd
( (
@ -615,6 +608,8 @@ BINARY_TYPE_FUNCTION(Type, Type, Type, min)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
#define TEMPLATE template<class Type> #define TEMPLATE template<class Type>
#include "FieldFunctionsM.H" #include "FieldFunctionsM.H"
#include "UPstream.H" #include "UPstream.H"
#include "MinMax.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -151,8 +152,10 @@ tmp<Field<Type>> cmptMag(const UList<Type>& f);
template<class Type> template<class Type>
tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf); tmp<Field<Type>> cmptMag(const tmp<Field<Type>>& tf);
#define TMP_UNARY_FUNCTION(ReturnType, Func) \ #define TMP_UNARY_FUNCTION(ReturnType, Func) \
\ \
/** \brief Apply the \c Func() function on the tmp field */ \
template<class Type> \ template<class Type> \
ReturnType Func(const tmp<Field<Type>>& tf1); ReturnType Func(const tmp<Field<Type>>& tf1);
@ -171,6 +174,15 @@ Type sum(const UList<Type>& f);
TMP_UNARY_FUNCTION(Type, sum) 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> template<class Type>
Type maxMagSqr(const UList<Type>& f); 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(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(Type, gSumCmptMag, sumCmptMag, 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 #undef G_UNARY_FUNCTION
template<class Type> 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, cmptMultiply)
BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide) BINARY_TYPE_FUNCTION(Type, Type, Type, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //

View File

@ -991,10 +991,10 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::writeMinMax
Ostream& os Ostream& os
) const ) const
{ {
MinMax<Type> range = Foam::minMax(*this).value();
os << "min/max(" << this->name() << ") = " os << "min/max(" << this->name() << ") = "
<< Foam::min(*this).value() << ", " << range.min() << ", " << range.max() << endl;
<< Foam::max(*this).value()
<< endl;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -522,6 +522,8 @@ dimensioned<returnType> func \
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp) UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp) 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)
#undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -229,6 +229,10 @@ dimensioned<returnType> func \
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp) UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp)
UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp) 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)
#undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY

View File

@ -99,7 +99,7 @@ Description
#include "scalar.H" #include "scalar.H"
#include "Pair.H" #include "Pair.H"
#include "Tuple2.H" #include "Tuple2.H"
#include "ListListOps.H" #include "VectorSpace.H"
#include <type_traits> #include <type_traits>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -109,6 +109,7 @@ namespace Foam
// Forward declarations // Forward declarations
template<class T> class MinMax; template<class T> class MinMax;
class zero;
// Common min/max types // Common min/max types
typedef MinMax<label> labelMinMax; typedef MinMax<label> labelMinMax;
@ -148,11 +149,14 @@ public:
//- Copy construct from components //- Copy construct from components
inline MinMax(const Pair<T>& range); inline MinMax(const Pair<T>& range);
//- Construct with a single zero value
inline explicit MinMax(const zero);
//- Construct with a single initial value //- Construct with a single initial value
inline explicit MinMax(const T& val); inline explicit MinMax(const T& val);
//- Construct from list //- Construct from list of values
inline explicit MinMax(const UList<T>& list); inline explicit MinMax(const UList<T>& vals);
// Member Functions // Member Functions
@ -174,6 +178,8 @@ public:
//- The min/max average value //- The min/max average value
inline T centre() const; inline T centre() const;
//- The magnitude of the min to max span. Zero if the range is invalid.
inline scalar mag() const;
//- Range is empty if it is inverted //- Range is empty if it is inverted
inline bool empty() const; inline bool empty() const;
@ -259,145 +265,6 @@ word name(const MinMax<T>& range)
} }
//- Return the value after clipping by the min/max limiter
template<class T>
T clip(const T& val, const MinMax<T>& range)
{
return range.clip(val);
}
//- Return the value after clipping by the min/max limiter
template<class T>
struct clipOp
{
T operator()(T& val, const MinMax<T>& range) const
{
return range.clip(val);
}
};
//- Clip value and assign inplace
template<class T>
struct clipEqOp
{
bool operator()(T& val, const MinMax<T>& range) const
{
return range.inplaceClip(val);
}
};
//- Extract the min/max range from a list of values
template<class T>
MinMax<T> minMax(const UList<T>& list)
{
return MinMax<T>(list);
}
//- Extract the min/max magnitudes from a list of values
template<class T>
MinMax<scalar> minMaxMag(const UList<T>& list)
{
MinMax<scalar> result;
for (const T& val : list)
{
result += Foam::mag(val);
}
return result;
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Combine two ranges
template<class T>
inline MinMax<T> operator+(const MinMax<T>& x, const MinMax<T>& y)
{
return MinMax<T>(x).add(y);
}
//- Multiply range by scalar factor
template<class T>
inline MinMax<T> operator*(const MinMax<T>& x, const scalar& s)
{
return MinMax<T>(x.min()*s, x.max()*s);
}
//- Divide range by scalar factor
template<class T>
inline MinMax<T> operator/(const MinMax<T>& x, const scalar& s)
{
return MinMax<T>(x.min()/s, x.max()/s);
}
// Comparison
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<(const MinMax<T>& range, const U& val)
{
return (range.compare(val) < 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<=(const MinMax<T>& range, const U& val)
{
return (range.compare(val) <= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>(const MinMax<T>& range, const U& val)
{
return (range.compare(val) > 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>=(const MinMax<T>& range, const U& val)
{
return (range.compare(val) >= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<(const U& val, const MinMax<T>& range)
{
return (range.compare(val) > 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<=(const U& val, const MinMax<T>& range)
{
return (range.compare(val) >= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>(const U& val, const MinMax<T>& range)
{
return (range.compare(val) < 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>=(const U& val, const MinMax<T>& range)
{
return (range.compare(val) <= 0);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam
@ -410,4 +277,8 @@ operator>=(const U& val, const MinMax<T>& range)
#endif #endif
// Global Functions and Operators
#include "MinMaxOps.H"
// ************************************************************************* // // ************************************************************************* //

View File

@ -53,6 +53,13 @@ inline Foam::MinMax<T>::MinMax(const Pair<T>& range)
{} {}
template<class T>
inline Foam::MinMax<T>::MinMax(const zero)
:
Tuple2<T,T>(pTraits<T>::zero, pTraits<T>::zero)
{}
template<class T> template<class T>
inline Foam::MinMax<T>::MinMax(const T& val) inline Foam::MinMax<T>::MinMax(const T& val)
: :
@ -61,11 +68,11 @@ inline Foam::MinMax<T>::MinMax(const T& val)
template<class T> template<class T>
inline Foam::MinMax<T>::MinMax(const UList<T>& list) inline Foam::MinMax<T>::MinMax(const UList<T>& vals)
: :
MinMax<T>() MinMax<T>()
{ {
add(list); add(vals);
} }
@ -107,6 +114,13 @@ inline T Foam::MinMax<T>::centre() const
} }
template<class T>
inline Foam::scalar Foam::MinMax<T>::mag() const
{
return (empty() ? Zero : ::Foam::mag(max() - min()));
}
template<class T> template<class T>
inline bool Foam::MinMax<T>::empty() const inline bool Foam::MinMax<T>::empty() const
{ {
@ -214,10 +228,7 @@ inline bool Foam::MinMax<T>::inplaceClip(T& val) const
template<class T> template<class T>
inline Foam::MinMax<T>& Foam::MinMax<T>::add inline Foam::MinMax<T>& Foam::MinMax<T>::add(const MinMax& other)
(
const MinMax& other
)
{ {
min() = Foam::min(min(), other.min()); min() = Foam::min(min(), other.min());
max() = Foam::max(max(), other.max()); max() = Foam::max(max(), other.max());
@ -286,10 +297,7 @@ inline bool Foam::MinMax<T>::operator()(const T& val) const
template<class T> template<class T>
inline Foam::MinMax<T>& Foam::MinMax<T>::operator+= inline Foam::MinMax<T>& Foam::MinMax<T>::operator+=(const MinMax<T>& b)
(
const MinMax<T>& b
)
{ {
return add(b); return add(b);
} }

View File

@ -0,0 +1,377 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
InNamespace
Foam
Description
Global functions and operators related to the MinMax class.
Included by MinMax.H
\*---------------------------------------------------------------------------*/
#ifndef MinMaxOps_H
#define MinMaxOps_H
#include "MinMax.H"
#include "VectorSpace.H"
#include <type_traits>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Global Functions
//- The mag() function for min/max range
template<class T>
inline scalar mag(const MinMax<T>& range)
{
return range.mag();
}
//- Return the value after clipping by the min/max limiter
template<class T>
inline T clip(const T& val, const MinMax<T>& range)
{
return range.clip(val);
}
//- Return the value after clipping by the min/max limiter
template<class T>
struct clipOp
{
T operator()(T& val, const MinMax<T>& range) const
{
return range.clip(val);
}
};
//- Clip value and assign inplace
template<class T>
struct clipEqOp
{
bool operator()(T& val, const MinMax<T>& range) const
{
return range.inplaceClip(val);
}
};
//- Extract the min/max range from a list of values.
template<class T>
inline MinMax<T> minMax(const UList<T>& vals)
{
return MinMax<T>(vals);
}
//- Combine two values to create a min/max range. Order is unimportant.
template<class T>
inline MinMax<T> minMax(const T& x, const T& y)
{
return MinMax<T>(x).add(y);
}
//- Combine two MinMax ranges (same as x + y)
template<class T>
inline MinMax<T> minMax(const MinMax<T>& x, const MinMax<T>& y)
{
return MinMax<T>(x).add(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 an initial single value.
inline scalarMinMax minMaxMag(const scalar val)
{
return scalarMinMax(Foam::mag(val));
}
//- The magnitude of from an initial VectorSpace.
template<class Form, class Cmpt, direction nCmpt>
inline scalarMinMax minMaxMag(const VectorSpace<Form,Cmpt,nCmpt>& vs)
{
return scalarMinMax(Foam::mag(vs));
}
//- The min/max magnitudes from a list of values
template<class T>
inline scalarMinMax minMaxMag(const UList<T>& vals)
{
scalarMinMax result;
for (const T& val : vals)
{
result += Foam::mag(val);
}
return result;
}
//- The min/max magnitudes from a min/max range
template<class T>
inline scalarMinMax minMaxMag(const MinMax<T>& range)
{
return
(
scalarMinMax(Foam::mag(range.min())).add(Foam::mag(range.max()))
);
}
//- Combine the magitude of two values to create a min/max range.
//- Order is unimportant.
template<class T>
inline scalarMinMax minMaxMag(const T& x, const T& y)
{
return minMaxMag(x).add(Foam::mag(y));
}
//- Scalar combine two MinMax ranges of same type
template<class T>
inline scalarMinMax minMaxMag(const MinMax<T>& x, const MinMax<T>& y)
{
return
(
minMaxMag(x)
.add(Foam::mag(y.min()))
.add(Foam::mag(y.max()))
);
}
//- Scalar combine two MinMax ranges of dissimilar types
template<class T1, class T2>
inline scalarMinMax minMaxMag(const MinMax<T1>& x, const MinMax<T2>& y)
{
return
(
minMaxMag(x)
.add(Foam::mag(y.min()))
.add(Foam::mag(y.max()))
);
}
//- 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;
}
};
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
//- Combine two ranges
template<class T>
inline MinMax<T> operator+(const MinMax<T>& x, const MinMax<T>& y)
{
return MinMax<T>(x).add(y);
}
//- Multiply range by scalar factor
template<class T>
inline MinMax<T> operator*(const MinMax<T>& x, const scalar& s)
{
return MinMax<T>(x.min()*s, x.max()*s);
}
//- Divide range by scalar factor
template<class T>
inline MinMax<T> operator/(const MinMax<T>& x, const scalar& s)
{
return MinMax<T>(x.min()/s, x.max()/s);
}
// Comparison
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<(const MinMax<T>& range, const U& val)
{
return (range.compare(val) < 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<=(const MinMax<T>& range, const U& val)
{
return (range.compare(val) <= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>(const MinMax<T>& range, const U& val)
{
return (range.compare(val) > 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>=(const MinMax<T>& range, const U& val)
{
return (range.compare(val) >= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<(const U& val, const MinMax<T>& range)
{
return (range.compare(val) > 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator<=(const U& val, const MinMax<T>& range)
{
return (range.compare(val) >= 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>(const U& val, const MinMax<T>& range)
{
return (range.compare(val) < 0);
}
template<class T, class U>
inline typename std::enable_if<std::is_convertible<U, T>::value, bool>::type
operator>=(const U& val, const MinMax<T>& range)
{
return (range.compare(val) <= 0);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
#endif
// ************************************************************************* //