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:
Mark Olesen
2023-01-13 20:45:53 +01:00
parent 3888bfa17f
commit ba153df8db
25 changed files with 501 additions and 164 deletions

View File

@ -1279,7 +1279,7 @@ void write_scalarField
continue;
}
os << limits.clip(fld(cellIdx)) << nl;
os << limits.clamp(fld(cellIdx)) << nl;
}
os << token::END_LIST << token::END_STATEMENT << nl;

View File

@ -58,12 +58,11 @@ namespace Foam
{
// Read porosity, change to blockage. Clamp values [0-1] silently
static const scalarMinMax limits01(scalarMinMax::zero_one());
// Volume porosity -> blockage
inline scalar getPorosity(const dictionary& dict)
{
return 1 - limits01.clip(dict.getOrDefault<scalar>("porosity", 0));
return 1 - clamp(dict.getOrDefault<scalar>("porosity", 0), 0, 1);
}
// Direction porosities -> blockage
@ -75,7 +74,7 @@ inline vector getPorosities(const dictionary& dict)
{
for (scalar& val : blockage)
{
val = 1 - limits01.clip(val);
val = 1 - clamp(val, 0, 1);
}
}