functionObjects::log: Added optional switch to disable dimension checking:

Description
    Calculates the natural logarithm of the specified scalar field.

    Performs \f$ln(max(x, a))\f$ where \f$x\f$ is the field and \f$a\f$ an
    optional clip to handle 0 or negative \f$x\f$.  Dimension checking can
    optionally be suspended for this operation if \f$x\f$ is dimensioned.

    Example of function object specification:
    \verbatim
    log1
    {
        type            log;
        libs            ("libfieldFunctionObjects.so");
        field           p;
        clip            1e-3;
        checkDimensions no;
    }
    \endverbatim

    or using \c postProcess
    \verbatim
    postProcess -func 'log(p, clip=1e-3, checkDimensions=no)'
    \endverbatim

Usage
    \table
        Property        | Description               | Required | Default value
        type            | Type name: log            | yes      |
        clip            | Clip value                | no       |
        checkDimensions | Dimension checking switch | no       |
    \endtable
This commit is contained in:
Henry Weller
2019-09-24 11:37:38 +01:00
parent 474962ffcc
commit 4feee735a3
2 changed files with 66 additions and 8 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,11 +53,28 @@ bool Foam::functionObjects::log::calc()
{
const volScalarField& x = lookupObject<volScalarField>(fieldName_);
return store
// Cache the current debug setting for dimensionSet
const bool dimensionSetDebug = dimensionSet::debug;
// Switch-off dimension checking if requested
if (!checkDimensions_)
{
dimensionSet::debug = 0;
}
bool stored = store
(
resultName_,
Foam::log(max(x, clip_))
clip_ ? Foam::log(max(x, clipValue_)) : Foam::log(x)
);
// Reinstate dimension checking
if (!checkDimensions_)
{
dimensionSet::debug = dimensionSetDebug;
}
return stored;
}
else
{
@ -77,7 +94,10 @@ Foam::functionObjects::log::log
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
fieldExpression(name, runTime, dict),
clip_(false),
clipValue_(0),
checkDimensions_(true)
{
read(dict);
}
@ -100,7 +120,13 @@ bool Foam::functionObjects::log::read(const dictionary& dict)
resultName_ = "log(" + fieldName_ + ")";
}
clip_ = dict.lookupOrDefault<scalar>("clip", 0);
if (dict.found("clip"))
{
clip_ = true;
dict.lookup("clip") >> clipValue_;
}
checkDimensions_ = dict.lookupOrDefault<Switch>("checkDimensions", true);
return true;
}

View File

@ -28,7 +28,33 @@ Description
Calculates the natural logarithm of the specified scalar field.
Performs \f$ln(max(x, a))\f$ where \f$x\f$ is the field and \f$a\f$ an
optional clip to handle 0 or negative \f$x\f$.
optional clip to handle 0 or negative \f$x\f$. Dimension checking can
optionally be suspended for this operation if \f$x\f$ is dimensioned.
Example of function object specification:
\verbatim
log1
{
type log;
libs ("libfieldFunctionObjects.so");
field p;
clip 1e-3;
checkDimensions no;
}
\endverbatim
or using \c postProcess
\verbatim
postProcess -func 'log(p, clip=1e-3, checkDimensions=no)'
\endverbatim
Usage
\table
Property | Description | Required | Default value
type | Type name: log | yes |
clip | Clip value | no |
checkDimensions | Dimension checking switch | no |
\endtable
See also
Foam::functionObjects::fieldExpression
@ -61,8 +87,14 @@ class log
{
// Private Data
//- Optional clip (default is 0)
scalar clip_;
//- Optional clip, default = false
bool clip_;
//- Optional clip value
scalar clipValue_;
//- Optional dimension checking override
Switch checkDimensions_;
// Private Member Functions