mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use GeometricField clamp_min, clamp_max, clamp_range
- newer naming allows for less confusing code.
Eg,
max(lower) -> clamp_min(lower)
min(upper) -> clamp_max(upper)
- prefer combined method, for few operations.
Eg,
max(lower) + min(upper) -> clamp_range(lower, upper)
The updated naming also helps avoid some obvious coding errors.
Eg,
Re.min(1200.0);
Re.max(18800.0);
instead of
Re.clamp_range(1200.0, 18800.0);
- can also use implicit conversion of zero_one to MinMax<Type> for
this type of code:
lambda_.clamp_range(zero_one{});
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -41,6 +41,11 @@ namespace functionObjects
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Temperature bounds based on EN ISO 7730 (10 - 40 degC)
|
||||
static const Foam::scalarMinMax Tbounds(283.15, 313.15);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::comfort::magU() const
|
||||
@ -93,7 +98,7 @@ Foam::dimensionedScalar Foam::functionObjects::comfort::Trad() const
|
||||
}
|
||||
|
||||
// Bounds based on EN ISO 7730
|
||||
if ((Trad.value() < 283.15) || (Trad.value() > 313.15))
|
||||
if (!Tbounds.contains(Trad.value()))
|
||||
{
|
||||
WarningInFunction
|
||||
<< "The calculated mean wall radiation temperature is out of the\n"
|
||||
@ -177,9 +182,6 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::comfort::Tcloth
|
||||
|
||||
Tcl.storePrevIter();
|
||||
|
||||
// Same temperatures as for the radiation
|
||||
const dimensionedScalar Tmin(dimTemperature, 283.15);
|
||||
const dimensionedScalar Tmax(dimTemperature, 313.15);
|
||||
|
||||
// Iterative solving of equation (2)
|
||||
do
|
||||
@ -208,7 +210,7 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::comfort::Tcloth
|
||||
|
||||
// Make sure that Tcl is in some physical limit (same range as we used
|
||||
// for the radiative estimation - based on ISO EN 7730:2005)
|
||||
Tcl.clip(Tmin, Tmax);
|
||||
Tcl.clamp_range(Tbounds);
|
||||
|
||||
} while (!converged(Tcl) && i++ < maxClothIter_);
|
||||
|
||||
@ -422,7 +424,7 @@ bool Foam::functionObjects::comfort::execute()
|
||||
|
||||
// Limit the velocity field to the values given in EN ISO 7733
|
||||
volScalarField Umag(mag(lookupObject<volVectorField>("U")));
|
||||
Umag.clip(Umin, Umax);
|
||||
Umag.clamp_range(Umin, Umax);
|
||||
|
||||
// Calculate the turbulent intensity if turbulent kinetic energy field k
|
||||
// exists
|
||||
|
||||
@ -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.
|
||||
@ -46,9 +46,10 @@ const Foam::Enum
|
||||
>
|
||||
Foam::functionObjects::limitFields::limitTypeNames_
|
||||
({
|
||||
{ limitType::MIN, "min" },
|
||||
{ limitType::MAX, "max" },
|
||||
{ limitType::BOTH, "both" },
|
||||
{ limitType::CLAMP_MIN, "min" },
|
||||
{ limitType::CLAMP_MAX, "max" },
|
||||
{ limitType::CLAMP_RANGE, "range" },
|
||||
{ limitType::CLAMP_RANGE, "both" },
|
||||
});
|
||||
|
||||
|
||||
@ -67,16 +68,31 @@ bool Foam::functionObjects::limitFields::limitScalarField
|
||||
|
||||
auto& field = *fieldPtr;
|
||||
|
||||
if (limit_ & MIN)
|
||||
if (limitType::CLAMP_NONE != withBounds_)
|
||||
{
|
||||
Log << ": min(" << gMin(field) << ")";
|
||||
field.max(dimensionedScalar("", field.dimensions(), min_));
|
||||
MinMax<scalar> currentRange = gMinMax(field);
|
||||
|
||||
if (withBounds_ & limitType::CLAMP_MIN)
|
||||
{
|
||||
Log << ": min(" << currentRange.min() << ')';
|
||||
}
|
||||
if (withBounds_ & limitType::CLAMP_MAX)
|
||||
{
|
||||
Log << ": max(" << currentRange.max() << ')';
|
||||
}
|
||||
}
|
||||
|
||||
if (limit_ & MAX)
|
||||
if (limitType::CLAMP_MIN == withBounds_)
|
||||
{
|
||||
Log << ": max(" << gMax(field) << ")";
|
||||
field.min(dimensionedScalar("", field.dimensions(), max_));
|
||||
field.clamp_min(min_);
|
||||
}
|
||||
else if (limitType::CLAMP_MAX == withBounds_)
|
||||
{
|
||||
field.clamp_max(max_);
|
||||
}
|
||||
else if (limitType::CLAMP_RANGE == withBounds_)
|
||||
{
|
||||
field.clamp_range(min_, max_);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -93,8 +109,8 @@ Foam::functionObjects::limitFields::limitFields
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
limit_(MIN),
|
||||
fieldSet_(mesh_),
|
||||
withBounds_(limitType::CLAMP_NONE),
|
||||
min_(-VGREAT),
|
||||
max_(VGREAT)
|
||||
{
|
||||
@ -106,19 +122,21 @@ Foam::functionObjects::limitFields::limitFields
|
||||
|
||||
bool Foam::functionObjects::limitFields::read(const dictionary& dict)
|
||||
{
|
||||
withBounds_ = limitType::CLAMP_NONE;
|
||||
|
||||
if (fvMeshFunctionObject::read(dict))
|
||||
{
|
||||
Info<< type() << " " << name() << ":" << nl;
|
||||
|
||||
limit_ = limitTypeNames_.get("limit", dict);
|
||||
withBounds_ = limitTypeNames_.get("limit", dict);
|
||||
|
||||
if (limit_ & MIN)
|
||||
if (withBounds_ & limitType::CLAMP_MIN)
|
||||
{
|
||||
min_ = dict.get<scalar>("min");
|
||||
Info<< " Imposing lower limit " << min_ << nl;
|
||||
}
|
||||
|
||||
if (limit_ & MAX)
|
||||
if (withBounds_ & limitType::CLAMP_MAX)
|
||||
{
|
||||
max_ = dict.get<scalar>("max");
|
||||
Info<< " Imposing upper limit " << max_ << nl;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -127,9 +127,10 @@ public:
|
||||
|
||||
enum limitType : unsigned
|
||||
{
|
||||
MIN = 0x1, //!< limit by minimum value
|
||||
MAX = 0x2, //!< limit by maximum value
|
||||
BOTH = (MIN | MAX) //!< limit by both minimum and maximum values
|
||||
CLAMP_NONE = 0, //!< No limit
|
||||
CLAMP_MIN = 0x1, //!< Clamp minimum value
|
||||
CLAMP_MAX = 0x2, //!< Clamp maximum value
|
||||
CLAMP_RANGE = (CLAMP_MIN | CLAMP_MAX) //!< Clamp min/max
|
||||
};
|
||||
|
||||
|
||||
@ -140,12 +141,12 @@ protected:
|
||||
//- Limit type names
|
||||
static const Enum<limitType> limitTypeNames_;
|
||||
|
||||
//- Limiting type
|
||||
limitType limit_;
|
||||
|
||||
//- Fields to limit
|
||||
volFieldSelection fieldSet_;
|
||||
|
||||
//- Limiting type
|
||||
limitType withBounds_;
|
||||
|
||||
//- Minimum limit
|
||||
scalar min_;
|
||||
|
||||
|
||||
@ -47,23 +47,23 @@ bool Foam::functionObjects::limitFields::limitField(const word& fieldName)
|
||||
|
||||
const dimensionedScalar eps("eps", field.dimensions(), ROOTVSMALL);
|
||||
|
||||
if (limit_ & MIN)
|
||||
if (withBounds_ & limitType::CLAMP_MIN)
|
||||
{
|
||||
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
|
||||
Log << " min(|" << gMin(mField) << "|)";
|
||||
//field.normalise();
|
||||
field /= mag(field) + eps;
|
||||
mField.max(dimensionedScalar("min", field.dimensions(), min_));
|
||||
mField.clamp_min(min_);
|
||||
field *= mField;
|
||||
}
|
||||
|
||||
if (limit_ & MAX)
|
||||
if (withBounds_ & limitType::CLAMP_MAX)
|
||||
{
|
||||
volScalarField mField(typeName + ":mag" + field.name(), mag(field));
|
||||
Log << " max(|" << gMax(mField) << "|)";
|
||||
//field.normalise();
|
||||
field /= mag(field) + eps;
|
||||
mField.min(dimensionedScalar("max", field.dimensions(), max_));
|
||||
mField.clamp_max(max_);
|
||||
field *= mField;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -448,8 +448,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
||||
}
|
||||
|
||||
indicator.correctBoundaryConditions();
|
||||
indicator.min(1.0);
|
||||
indicator.max(0.0);
|
||||
indicator.clamp_range(zero_one{});
|
||||
|
||||
// Update the blended surface field
|
||||
auto& surBlended = mesh_.lookupObjectRef<surfaceScalarField>(resultName_);
|
||||
|
||||
Reference in New Issue
Block a user