From 4feee735a342d412462d094a3a8ee67ca7a4e36c Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 24 Sep 2019 11:37:38 +0100 Subject: [PATCH] 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 --- src/functionObjects/field/log/log.C | 36 +++++++++++++++++++++++---- src/functionObjects/field/log/log.H | 38 ++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/functionObjects/field/log/log.C b/src/functionObjects/field/log/log.C index 2735c402ed..14c95b04a5 100644 --- a/src/functionObjects/field/log/log.C +++ b/src/functionObjects/field/log/log.C @@ -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(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("clip", 0); + if (dict.found("clip")) + { + clip_ = true; + dict.lookup("clip") >> clipValue_; + } + + checkDimensions_ = dict.lookupOrDefault("checkDimensions", true); return true; } diff --git a/src/functionObjects/field/log/log.H b/src/functionObjects/field/log/log.H index 50c1aa4768..dd10e01b2b 100644 --- a/src/functionObjects/field/log/log.H +++ b/src/functionObjects/field/log/log.H @@ -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