Merge branch 'feature-fieldLimits' into 'develop'

Add minMax and clip field functions

See merge request Development/OpenFOAM-plus!230
This commit is contained in:
Andrew Heather 2019-02-01 16:54:36 +00:00
commit 4435819a7a
27 changed files with 1008 additions and 228 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -692,7 +692,7 @@ void Foam::multiphaseSystem::solve()
phase.alphaRhoPhi() = fvc::interpolate(phase.rho())*phase.alphaPhi();
// Ensure the phase-fractions are bounded
phase.maxMin(0, 1);
phase.clip(0, 1);
}
calcAlphas();

View File

@ -403,7 +403,7 @@ void Foam::twoPhaseSystem::solve()
<< endl;
// Ensure the phase-fractions are bounded
alpha1.maxMin(0, 1);
alpha1.clip(0, 1);
// Update the phase-fraction of the other phase
alpha2 = scalar(1) - alpha1;

View File

@ -138,7 +138,23 @@ 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;
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);
@ -159,13 +175,14 @@ int main(int argc, char *argv[])
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);
Info<< "before: " << flatOutput(values2) << nl;
Info<< nl << "inplace clip" << nl;
Info<< "before: " << flatOutput(values2) << nl;
Info<< "before " << flatOutput(values2) << nl;
for (scalar& val : values2)
{
@ -176,7 +193,9 @@ int main(int argc, char *argv[])
Info<< nl << "For list: " << flatOutput(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 "dimensionedSymmTensor.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(Type, average, gAverage)
UNARY_REDUCTION_FUNCTION(MinMax<Type>, minMax, gMinMax)
UNARY_REDUCTION_FUNCTION(scalarMinMax, minMaxMag, gMinMaxMag)
#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, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //

View File

@ -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.
@ -119,6 +119,9 @@ 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)
#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, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
// * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * //

View File

@ -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.
@ -521,6 +521,37 @@ Type average(const FieldField<Field, Type>& f)
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) \
\
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(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
#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, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */

View File

@ -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.
@ -223,6 +223,19 @@ Type average(const FieldField<Field, Type>& f);
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) \
\
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(scalar, gSumMag, sumMag, sum)
G_UNARY_FUNCTION(MinMax<Type>, gMinMax, minMax, minMax)
G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag)
#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, cmptDivide)
BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clip)
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */

View File

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

View File

@ -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 * * * * * * * * * * * * * //

View File

@ -991,10 +991,10 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::writeMinMax
Ostream& os
) const
{
MinMax<Type> range = Foam::minMax(*this).value();
os << "min/max(" << this->name() << ") = "
<< Foam::min(*this).value() << ", "
<< Foam::max(*this).value()
<< endl;
<< range.min() << ", " << range.max() << endl;
}
@ -1095,17 +1095,6 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::replace
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::max
(
const dimensioned<Type>& dt
)
{
Foam::max(primitiveFieldRef(), primitiveField(), dt.value());
Foam::max(boundaryFieldRef(), boundaryField(), dt.value());
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::min
(
@ -1118,16 +1107,49 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::min
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::maxMin
void Foam::GeometricField<Type, PatchField, GeoMesh>::max
(
const dimensioned<Type>& minDt,
const dimensioned<Type>& maxDt
const dimensioned<Type>& dt
)
{
Foam::max(primitiveFieldRef(), primitiveField(), minDt.value());
Foam::max(boundaryFieldRef(), boundaryField(), minDt.value());
Foam::min(primitiveFieldRef(), primitiveField(), maxDt.value());
Foam::min(boundaryFieldRef(), boundaryField(), maxDt.value());
Foam::max(primitiveFieldRef(), primitiveField(), dt.value());
Foam::max(boundaryFieldRef(), boundaryField(), dt.value());
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::clip
(
const dimensioned<MinMax<Type>>& range
)
{
Foam::clip(primitiveFieldRef(), primitiveField(), range.value());
Foam::clip(boundaryFieldRef(), boundaryField(), range.value());
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::clip
(
const dimensioned<Type>& minVal,
const dimensioned<Type>& maxVal
)
{
MinMax<Type> range(minVal.value(), maxVal.value());
Foam::clip(primitiveFieldRef(), primitiveField(), range);
Foam::clip(boundaryFieldRef(), boundaryField(), range);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::maxMin
(
const dimensioned<Type>& minVal,
const dimensioned<Type>& maxVal
)
{
this->clip(minVal, maxVal);
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -598,11 +598,23 @@ public:
// This sets the \em floor on the field values
void max(const dimensioned<Type>& dt);
//- Clip the field to be bounded within the specified range
void clip(const dimensioned<MinMax<Type>>& range);
//- Clip the field to be bounded within the specified range
void clip
(
const dimensioned<Type>& minVal,
const dimensioned<Type>& maxVal
);
//- Deprecated(2019-01) identical to clip()
// \deprecated(2019-01) identical to clip()
void maxMin
(
const dimensioned<Type>& minDt,
const dimensioned<Type>& maxDt
);
const dimensioned<Type>& minVal,
const dimensioned<Type>& maxVal
) FOAM_DEPRECATED_FOR(2019-01, "clip() method");
// Member Operators

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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, 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

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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, 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

View File

@ -99,7 +99,7 @@ Description
#include "scalar.H"
#include "Pair.H"
#include "Tuple2.H"
#include "ListListOps.H"
#include "VectorSpace.H"
#include <type_traits>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -109,6 +109,7 @@ namespace Foam
// Forward declarations
template<class T> class MinMax;
class zero;
// Common min/max types
typedef MinMax<label> labelMinMax;
@ -148,11 +149,14 @@ public:
//- Copy construct from components
inline MinMax(const Pair<T>& range);
//- Construct with a single zero value
inline explicit MinMax(const zero);
//- Construct with a single initial value
inline explicit MinMax(const T& val);
//- Construct from list
inline explicit MinMax(const UList<T>& list);
//- Construct from list of values
inline explicit MinMax(const UList<T>& vals);
// Member Functions
@ -174,6 +178,8 @@ public:
//- The min/max average value
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
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
@ -410,4 +277,8 @@ operator>=(const U& val, const MinMax<T>& range)
#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>
inline Foam::MinMax<T>::MinMax(const T& val)
:
@ -61,11 +68,11 @@ inline Foam::MinMax<T>::MinMax(const T& val)
template<class T>
inline Foam::MinMax<T>::MinMax(const UList<T>& list)
inline Foam::MinMax<T>::MinMax(const UList<T>& vals)
:
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>
inline bool Foam::MinMax<T>::empty() const
{
@ -214,10 +228,7 @@ inline bool Foam::MinMax<T>::inplaceClip(T& val) const
template<class T>
inline Foam::MinMax<T>& Foam::MinMax<T>::add
(
const MinMax& other
)
inline Foam::MinMax<T>& Foam::MinMax<T>::add(const MinMax& other)
{
min() = Foam::min(min(), other.min());
max() = Foam::max(max(), other.max());
@ -286,10 +297,7 @@ inline bool Foam::MinMax<T>::operator()(const T& val) const
template<class T>
inline Foam::MinMax<T>& Foam::MinMax<T>::operator+=
(
const MinMax<T>& b
)
inline Foam::MinMax<T>& Foam::MinMax<T>::operator+=(const MinMax<T>& 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
// ************************************************************************* //