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:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -53,11 +53,28 @@ bool Foam::functionObjects::log::calc()
|
|||||||
{
|
{
|
||||||
const volScalarField& x = lookupObject<volScalarField>(fieldName_);
|
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_,
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -77,7 +94,10 @@ Foam::functionObjects::log::log
|
|||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
fieldExpression(name, runTime, dict)
|
fieldExpression(name, runTime, dict),
|
||||||
|
clip_(false),
|
||||||
|
clipValue_(0),
|
||||||
|
checkDimensions_(true)
|
||||||
{
|
{
|
||||||
read(dict);
|
read(dict);
|
||||||
}
|
}
|
||||||
@ -100,7 +120,13 @@ bool Foam::functionObjects::log::read(const dictionary& dict)
|
|||||||
resultName_ = "log(" + fieldName_ + ")";
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,33 @@ Description
|
|||||||
Calculates the natural logarithm of the specified scalar field.
|
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
|
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
|
See also
|
||||||
Foam::functionObjects::fieldExpression
|
Foam::functionObjects::fieldExpression
|
||||||
@ -61,8 +87,14 @@ class log
|
|||||||
{
|
{
|
||||||
// Private Data
|
// Private Data
|
||||||
|
|
||||||
//- Optional clip (default is 0)
|
//- Optional clip, default = false
|
||||||
scalar clip_;
|
bool clip_;
|
||||||
|
|
||||||
|
//- Optional clip value
|
||||||
|
scalar clipValue_;
|
||||||
|
|
||||||
|
//- Optional dimension checking override
|
||||||
|
Switch checkDimensions_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user