Skip to content
Permalink
Browse files

functionObjects::log: New functionObject to calculate the natural log…

…arithm of a scalar field

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$.

The etc/caseDicts/postProcessing/fields/log configuration file is provided so
that the simple #includeFunc can be used to execute this functionObject during
the run, e.g. for some dimensionless field x

functions
{
    #includeFunc log(x)
}

or if x might be 0 or negative in some regions the optional clip may be applied:

functions
{
    #includeFunc log(p,clip=1e-6)
}
  • Loading branch information...
Henry Weller
Henry Weller committed Sep 5, 2018
1 parent 53ee32d commit e757d5210e0bab2b0e14c7a90e172e955b35313e
@@ -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 <fieldName>;

executeControl writeTime;
writeControl writeTime;


// ************************************************************************* //
@@ -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
@@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/

#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<volScalarField>(fieldName_))
{
const volScalarField& x = lookupObject<volScalarField>(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<scalar>("clip", 0);

return true;
}


// ************************************************************************* //
@@ -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 <http://www.gnu.org/licenses/>.
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

// ************************************************************************* //

0 comments on commit e757d52

Please sign in to comment.
You can’t perform that action at this time.