mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
ENH: improved handling for clamping
- proper component-wise clamping for MinMax clamp(). - construct clampOp from components - propagate clamp() method from GeometricField to FieldField and Field - clamp_min() and clamp_max() for one-sided clamping, as explicit alternative to min/max free functions which can be less intuitive and often involve additional field copies. - top-level checks to skip applying invalid min/max ranges and bypass the internal checks of MinMax::clamp() etc.
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -24,7 +24,7 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
Test minMax
|
||||
Test-minMax2
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -37,6 +37,7 @@ Description
|
||||
#include "MinMax.H"
|
||||
#include "dimensionedScalar.H"
|
||||
#include "dimensionedMinMax.H"
|
||||
#include "Random.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -78,7 +79,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< "Test min/max " << nl;
|
||||
|
||||
|
||||
{
|
||||
scalarMinMax range1(10, 20);
|
||||
scalarMinMax range2(40, 50);
|
||||
@ -140,7 +140,34 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
scalarField someField(25);
|
||||
|
||||
Random rnd(4567);
|
||||
for (scalar& val : someField)
|
||||
{
|
||||
val = rnd.position(-0.2, 1.2);
|
||||
}
|
||||
|
||||
Info<< nl
|
||||
<< "field: " << flatOutput(someField) << nl;
|
||||
Info<< "clamp01: "
|
||||
<< flatOutput(clamp(someField, scalarMinMax(zero_one{}))()) << nl;
|
||||
|
||||
Info<< "clamp01: "
|
||||
<< clamp(tmp<scalarField>(someField), scalarMinMax(zero_one{}))<< nl;
|
||||
|
||||
scalarField result(10);
|
||||
clamp(result, someField, scalarMinMax(zero_one{}));
|
||||
|
||||
Info<< "result: " << result << nl;
|
||||
|
||||
someField.clamp(zero_one{});
|
||||
|
||||
Info<< "inplace: " << someField << nl;
|
||||
}
|
||||
|
||||
Info<< nl << "\nDone\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user