diff --git a/applications/solvers/combustion/XiFoam/XiDyMFoam/XiDyMFoam.C b/applications/solvers/combustion/XiFoam/XiDyMFoam/XiDyMFoam.C index 1386fd5cb8e4dd53f25368e338ef174539341def..aa21c87867d171f485628abd73c6b817c48aad5a 100644 --- a/applications/solvers/combustion/XiFoam/XiDyMFoam/XiDyMFoam.C +++ b/applications/solvers/combustion/XiFoam/XiDyMFoam/XiDyMFoam.C @@ -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()) diff --git a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C index 4ecab1373c493cf9d0b270f1ab272652d39206c5..b2169cbf3537750de5a72049b5e4cb867b4d6cc0 100644 --- a/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C +++ b/applications/solvers/compressible/sonicFoam/sonicDyMFoam/sonicDyMFoam.C @@ -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()) diff --git a/applications/solvers/heatTransfer/buoyantSimpleFoam/pEqn.H b/applications/solvers/heatTransfer/buoyantSimpleFoam/pEqn.H index aa3aca24242bbf4326e58328e910539cfb5ca7fd..3a38713a640645eeec34ef0b045e312c00d75609 100644 --- a/applications/solvers/heatTransfer/buoyantSimpleFoam/pEqn.H +++ b/applications/solvers/heatTransfer/buoyantSimpleFoam/pEqn.H @@ -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; } diff --git a/applications/solvers/lagrangian/sprayFoam/pEqn.H b/applications/solvers/lagrangian/sprayFoam/pEqn.H index 10c49d18117a0a31d4d149b61f4aa16446111897..838044ba73313746825cb37c3aa96d8886ba560f 100644 --- a/applications/solvers/lagrangian/sprayFoam/pEqn.H +++ b/applications/solvers/lagrangian/sprayFoam/pEqn.H @@ -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(); diff --git a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/pEqn.H b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/pEqn.H index a08bcf9fd10f3bb3e927bbccac2a9927b771270b..54a8ae0322b02b2d2798da6399375c605e486058 100644 --- a/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/pEqn.H +++ b/applications/solvers/lagrangian/sprayFoam/sprayDyMFoam/pEqn.H @@ -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(); diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C index 95b301284c7520b73eedd410c80ac112cf0a0d9b..be6d03ea8863eac9524c720564312461f2d36474 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C +++ b/applications/solvers/multiphase/reactingEulerFoam/reactingMultiphaseEulerFoam/multiphaseSystem/multiphaseSystem.C @@ -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(); diff --git a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C index 07c640f89587d489130ef6280d5767ffbf34c748..60b7adf9e2f235be66e8bd6ae5eeec7a3bb2e54c 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C +++ b/applications/solvers/multiphase/reactingEulerFoam/reactingTwoPhaseEulerFoam/twoPhaseSystem/twoPhaseSystem.C @@ -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; diff --git a/applications/test/minMax1/Test-minMax1.C b/applications/test/minMax1/Test-minMax1.C index cb5f94725e6893540ffc1f2f9f9dfbe21b3695e6..26d242a8041a6fc1ae8029d200a5cff485d39850 100644 --- a/applications/test/minMax1/Test-minMax1.C +++ b/applications/test/minMax1/Test-minMax1.C @@ -138,7 +138,23 @@ int main(int argc, char *argv[]) minmax1 += values1; Pout<<"range: " << minmax1 << endl; + Info<< "Reduced: "<< returnReduce(minmax1, plusOp()) << nl; + Info<< "Reduced: "<< returnReduce(minmax1, minMaxOp()) << nl; + + // Info<< "gMinMax: "<< gMinMax(values1v) << nl; + + vectorField values1v + ( + ListOps::create + ( + values1, + [](const scalar s) { return vector(s, 2*s, -2*s); } + ) + ); + + Info<< "gMinMax: " << gMinMax(values1v) << nl; + Info<< "gMinMaxMag: " << gMinMaxMag(values1v) << nl; { MinMax 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; } diff --git a/applications/test/minMax2/Make/files b/applications/test/minMax2/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..08cdfd97514bd555731dd9e5766c232048513a33 --- /dev/null +++ b/applications/test/minMax2/Make/files @@ -0,0 +1,3 @@ +Test-minMax2.C + +EXE = $(FOAM_USER_APPBIN)/Test-minMax2 diff --git a/applications/test/minMax2/Make/options b/applications/test/minMax2/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..d27c95d033dd5d7b1995c8ff8dc406e35ca1f586 --- /dev/null +++ b/applications/test/minMax2/Make/options @@ -0,0 +1,7 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -lmeshTools diff --git a/applications/test/minMax2/Test-minMax2.C b/applications/test/minMax2/Test-minMax2.C new file mode 100644 index 0000000000000000000000000000000000000000..810f879e22a3a11124d27772fddc5996f1cfe57a --- /dev/null +++ b/applications/test/minMax2/Test-minMax2.C @@ -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 . + +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 +Ostream& printInfo(const MinMax& range) +{ + Info<< range << " valid=" << range.valid(); + + return Info; +} + + +dimensionedScalarMinMax rhoLimit(const dictionary& dict) +{ + Info<< "From " << dict; + + dimensionedScalarMinMax range = + makeDimensionedMinMax + ( + "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) <("velrange", dimVelocity, {1, 20}) + << nl; + + dimensioned range1("a", dimVelocity, {10, 20}); + dimensioned range2("b", dimVelocity, {40, 50}); + + Info<< "Dimensioned range : " << (range1 + range2) << endl; + } + + { + Info<< nl << "makeDimensionedMinMax:" << nl << nl; + + Info + << makeDimensionedMinMax("rhoa", dimDensity, 1, 20) + << nl; + + { + dimensionedScalar minval("min", dimDensity, 0.3); + dimensionedScalar maxval("max", dimDensity, 0.5); + + Info + << makeDimensionedMinMax(minval, maxval) + << nl; + + Info + << makeDimensionedMinMax("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; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMax.H b/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMax.H new file mode 100644 index 0000000000000000000000000000000000000000..d4c079b8a11876e2d7012e080be4ec2d32270671 --- /dev/null +++ b/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMax.H @@ -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 . + +Typedef + Foam::dimensionedScalarMinMax + +Description + A dimensioned scalarMinMix (MinMax for scalar quantities). + +Typedef + Foam::dimensionedMinMax\ + +Description + A templated type alias for dimensioned\\> + +SourceFiles + dimensionedMinMaxTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef dimensionedMinMax_H +#define dimensionedMinMax_H + +#include "dimensionedType.H" +#include "MinMax.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// General alias +template +using dimensionedMinMax = dimensioned>; + +// Common typedefs +typedef dimensioned dimensionedScalarMinMax; + + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +//- Make a dimensionedMinMax from all components +template +inline dimensioned> makeDimensionedMinMax +( + const word& name, + const dimensionSet& dims, + const T& minVal, + const T& maxVal +) +{ + return dimensioned>(name, dims, MinMax(minVal, maxVal)); +} + + +//- Create a dimensionless "minmax" +template +inline dimensioned> makeDimensionedMinMax +( + const T& minVal, + const T& maxVal +) +{ + return + dimensioned> + ( + "minmax", dimensionSet(), MinMax(minVal, maxVal) + ); +} + + +//- Combine two dimensioned types into a dimensionedMinMax with specified name +template +inline dimensioned> makeDimensionedMinMax +( + const word& name, + const dimensioned& minVal, + const dimensioned& maxVal +) +{ + // Dimension check when (dimensionSet::debug) + return dimensioned> + ( + name, + (minVal.dimensions() + maxVal.dimensions()), + MinMax(minVal.value(), maxVal.value()) + ); +} + + +//- Combine two dimensioned types into a dimensionedMinMax "minmax" +template +inline dimensioned> makeDimensionedMinMax +( + const dimensioned& minVal, + const dimensioned& 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 +// ( +// "rhoMinMax", dimDensity, {Zero, GREAT}, dict, "rhoMin", "rhoMax" +// ); +// \endverbatim +template +dimensioned> makeDimensionedMinMax +( + const word& name, + const dimensionSet& dims, + const MinMax& values, + const dictionary& dict, + const word& minName, + const word& maxName +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "dimensionedMinMaxTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMaxTemplates.C b/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMaxTemplates.C new file mode 100644 index 0000000000000000000000000000000000000000..bf1ed89f21415550e8657d2d42eaec7a86893595 --- /dev/null +++ b/src/OpenFOAM/dimensionedTypes/dimensionedMinMax/dimensionedMinMaxTemplates.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "dimensionedMinMax.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + + +template +Foam::dimensioned> Foam::makeDimensionedMinMax +( + const word& name, + const dimensionSet& dims, + const MinMax& values, + const dictionary& dict, + const word& minName, + const word& maxName +) +{ + // Normal construction with optional entry + + dimensioned> range(name, dims, values, dict); + + // Optional min specification + if (!minName.empty()) + { + dimensioned minVal(minName, dims, values.min(), dict); + range.dimensions() += minVal.dimensions(); + range.value().min() = minVal.value(); + } + + // Optional max specification + if (!maxName.empty()) + { + dimensioned maxVal(maxName, dims, values.max(), dict); + range.dimensions() += maxVal.dimensions(); + range.value().max() = maxVal.value(); + } + + return range; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedTypes.H b/src/OpenFOAM/dimensionedTypes/dimensionedTypes.H index 32f3f0e6b84b7e0e941de92ee37f078b04028e6f..cc776d957b9cd5c9466fbbd23164028cffc0dae7 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedTypes.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedTypes.H @@ -33,6 +33,7 @@ License #include "dimensionedSphericalTensor.H" #include "dimensionedSymmTensor.H" #include "dimensionedTensor.H" +#include "dimensionedMinMax.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C index f8435e19a3730be9aefa48ec998761531b7b66cc..afba61d648dff00518b31b8be3462eb4e3e0bfd6 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C @@ -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, 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, clip) + // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H index f39dff925d931aab88686e928c7e2941803beea6..6e65702b48aa985801119546ea9f10e257f33fc4 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H @@ -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, 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, clip) + // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C index a4e4b927362c31edc75f6d8242839acf9df6183a..8977275f8bbb299531d1aecb5fac74167a52fd52 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.C @@ -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& f) TMP_UNARY_FUNCTION(Type, average) +template class Field, class Type> +MinMax minMax(const FieldField& f) +{ + MinMax result; + + forAll(f, i) + { + result += minMax(f[i]); + } + + return result; +} + +TMP_UNARY_FUNCTION(MinMax, minMax) + +template class Field, class Type> +scalarMinMax minMaxMag(const FieldField& 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 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, 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, clip) + /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H index 26bd7540fe61916f082a75039dea45430da9fa1c..8124dbf0ce563a0762ab208ba5a6250590724a8f 100644 --- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H +++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldFieldFunctions.H @@ -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& f); TMP_UNARY_FUNCTION(Type, average) +//- Return min/max for a field of fields +template class Field, class Type> +MinMax minMax(const FieldField& f); + +TMP_UNARY_FUNCTION(MinMax, minMax) + +//- Return mag min/max for a field of fields +template class Field, class Type> +scalarMinMax minMaxMag(const FieldField& f); + +TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag) + + #define G_UNARY_FUNCTION(returnType, gFunc, func, rFunc) \ \ template 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, 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, clip) + /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index d36a76d488258206032d2711e76e27df440a37aa..f2e7bb6f262f24e8a8a2e66ea7c3c99123d0ca0b 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -357,6 +357,15 @@ Type sum(const UList& f) TMP_UNARY_FUNCTION(Type, sum) + +// From MinMaxOps.H: +// - Foam::minMax(const UList&) +// - Foam::minMaxMag(const UList&) + +TMP_UNARY_FUNCTION(MinMax, minMax) +TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag) + + template Type maxMagSqr(const UList& f) { @@ -414,25 +423,21 @@ TMP_UNARY_FUNCTION(Type, minMagSqr) template scalar sumProd(const UList& f1, const UList& 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 Type sumCmptProd(const UList& f1, const UList& 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& f1, const UList& f2) Type, f2 ) - return SumProd; - } - else - { - return Zero; } + return SumProd; } template scalar sumSqr(const UList& 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 scalar sumMag(const UList& 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 Type sumCmptMag(const UList& 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, gMinMax, minMax, minMax) +G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag) + #undef G_UNARY_FUNCTION + template 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, clip) + /* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */ diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H index 29f52c49e0450bf5e35d6a9f82b7bca9d68ebb72..5ebb762e88a7c5d8c41776c0cb71a347581d74bd 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H @@ -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 #include "FieldFunctionsM.H" #include "UPstream.H" +#include "MinMax.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -151,8 +152,10 @@ tmp> cmptMag(const UList& f); template tmp> cmptMag(const tmp>& tf); + #define TMP_UNARY_FUNCTION(ReturnType, Func) \ \ +/** \brief Apply the \c Func() function on the tmp field */ \ template \ ReturnType Func(const tmp>& tf1); @@ -171,6 +174,15 @@ Type sum(const UList& f); TMP_UNARY_FUNCTION(Type, sum) + +// From MinMaxOps.H: +// - Foam::minMax(const UList&) +// - Foam::minMaxMag(const UList&) + +TMP_UNARY_FUNCTION(MinMax, minMax) +TMP_UNARY_FUNCTION(scalarMinMax, minMaxMag) + + template Type maxMagSqr(const UList& 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, gMinMax, minMax, minMax) +G_UNARY_FUNCTION(scalarMinMax, gMinMaxMag, minMaxMag, minMaxMag) + #undef G_UNARY_FUNCTION template @@ -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, clip) + // * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index f01bfec5445931d7d01fc2e36aaea7fbb39bb329..28049136c7d8776f505b294e91208c324b16e41d 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -991,10 +991,10 @@ void Foam::GeometricField::writeMinMax Ostream& os ) const { + MinMax 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,6 +1095,17 @@ void Foam::GeometricField::replace } +template class PatchField, class GeoMesh> +void Foam::GeometricField::min +( + const dimensioned& dt +) +{ + Foam::min(primitiveFieldRef(), primitiveField(), dt.value()); + Foam::min(boundaryFieldRef(), boundaryField(), dt.value()); +} + + template class PatchField, class GeoMesh> void Foam::GeometricField::max ( @@ -1107,27 +1118,38 @@ void Foam::GeometricField::max template class PatchField, class GeoMesh> -void Foam::GeometricField::min +void Foam::GeometricField::clip ( - const dimensioned& dt + const dimensioned>& range ) { - Foam::min(primitiveFieldRef(), primitiveField(), dt.value()); - Foam::min(boundaryFieldRef(), boundaryField(), dt.value()); + Foam::clip(primitiveFieldRef(), primitiveField(), range.value()); + Foam::clip(boundaryFieldRef(), boundaryField(), range.value()); +} + + +template class PatchField, class GeoMesh> +void Foam::GeometricField::clip +( + const dimensioned& minVal, + const dimensioned& maxVal +) +{ + MinMax range(minVal.value(), maxVal.value()); + + Foam::clip(primitiveFieldRef(), primitiveField(), range); + Foam::clip(boundaryFieldRef(), boundaryField(), range); } template class PatchField, class GeoMesh> void Foam::GeometricField::maxMin ( - const dimensioned& minDt, - const dimensioned& maxDt + const dimensioned& minVal, + const dimensioned& maxVal ) { - Foam::max(primitiveFieldRef(), primitiveField(), minDt.value()); - Foam::max(boundaryFieldRef(), boundaryField(), minDt.value()); - Foam::min(primitiveFieldRef(), primitiveField(), maxDt.value()); - Foam::min(boundaryFieldRef(), boundaryField(), maxDt.value()); + this->clip(minVal, maxVal); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 5226c1c4f95a36071b0ba190f2d9a92b16a6ba73..039b7e41a42e47d6260c9874b3a6a147ee4fed4b 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -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,12 +598,24 @@ public: // This sets the \em floor on the field values void max(const dimensioned& dt); - void maxMin + //- Clip the field to be bounded within the specified range + void clip(const dimensioned>& range); + + //- Clip the field to be bounded within the specified range + void clip ( - const dimensioned& minDt, - const dimensioned& maxDt + const dimensioned& minVal, + const dimensioned& maxVal ); + //- Deprecated(2019-01) identical to clip() + // \deprecated(2019-01) identical to clip() + void maxMin + ( + const dimensioned& minVal, + const dimensioned& maxVal + ) FOAM_DEPRECATED_FOR(2019-01, "clip() method"); + // Member Operators diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C index 967da818851b0e9fe7929827a8fc02bb2f873bd9..c4fe474f47d0b07ddfdca33bffd580c4f422d149 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C @@ -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 func \ UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, max, maxOp) UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(Type, min, minOp) +UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(MinMax, minMax, minMaxOp) +UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, minMaxMagOp) #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H index 63cdbdd8a9591929184a537ab2bd400252eeae29..af34bc755ba9504d3d000943fd123b8a31151c00 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H @@ -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 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, minMax, unused) +UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY(scalarMinMax, minMaxMag, unused) + #undef UNARY_REDUCTION_FUNCTION_WITH_BOUNDARY diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H index f9dbf5b9d40b208980c7d297559f070bfe7a2fae..2400289f6b26202f1728a9056eae2ed409cf03fc 100644 --- a/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H +++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMax.H @@ -99,7 +99,7 @@ Description #include "scalar.H" #include "Pair.H" #include "Tuple2.H" -#include "ListListOps.H" +#include "VectorSpace.H" #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -109,6 +109,7 @@ namespace Foam // Forward declarations template class MinMax; +class zero; // Common min/max types typedef MinMax