diff --git a/etc/caseDicts/postProcessing/fields/log b/etc/caseDicts/postProcessing/fields/log new file mode 100644 index 0000000000..6931f6b482 --- /dev/null +++ b/etc/caseDicts/postProcessing/fields/log @@ -0,0 +1,22 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +------------------------------------------------------------------------------- +Description + Calculates the natural logarithm of the specified scalar field + +\*---------------------------------------------------------------------------*/ + +type log; +libs ("libfieldFunctionObjects.so"); + +field ; + +executeControl writeTime; +writeControl writeTime; + + +// ************************************************************************* // diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 081f8bc484..a439e3bab6 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -36,6 +36,7 @@ ddt/ddt.C mag/mag.C magSqr/magSqr.C scale/scale.C +log/log.C vorticity/vorticity.C enstrophy/enstrophy.C Q/Q.C diff --git a/src/functionObjects/field/log/log.C b/src/functionObjects/field/log/log.C new file mode 100644 index 0000000000..2735c402ed --- /dev/null +++ b/src/functionObjects/field/log/log.C @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "log.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + defineTypeNameAndDebug(log, 0); + + addToRunTimeSelectionTable + ( + functionObject, + log, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::functionObjects::log::calc() +{ + if (foundObject(fieldName_)) + { + const volScalarField& x = lookupObject(fieldName_); + + return store + ( + resultName_, + Foam::log(max(x, clip_)) + ); + } + else + { + return false; + } + + return true; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::log::log +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + fieldExpression(name, runTime, dict) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::log::~log() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::log::read(const dictionary& dict) +{ + fieldExpression::read(dict); + + if (resultName_.empty()) + { + resultName_ = "log(" + fieldName_ + ")"; + } + + clip_ = dict.lookupOrDefault("clip", 0); + + return true; +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/log/log.H b/src/functionObjects/field/log/log.H new file mode 100644 index 0000000000..efcfce21b8 --- /dev/null +++ b/src/functionObjects/field/log/log.H @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::functionObjects::log + +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$. + +See also + Foam::functionObjects::fieldExpression + Foam::functionObjects::fvMeshFunctionObject + +SourceFiles + log.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_log_H +#define functionObjects_log_H + +#include "fieldExpression.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class log Declaration +\*---------------------------------------------------------------------------*/ + +class log +: + public fieldExpression +{ + // Private data + + //- Optional clip (default is 0) + scalar clip_; + + + // Private Member Functions + + //- Calculate the log field and return true if successful + virtual bool calc(); + + +public: + + //- Runtime type information + TypeName("log"); + + + // Constructors + + //- Construct from Time and dictionary + log + ( + const word& name, + const Time& runTime, + const dictionary& dict + ); + + + //- Destructor + virtual ~log(); + + + // Member Functions + + //- Read the randomise data + virtual bool read(const dictionary&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //