functionObjects::pressureTools: simplified, standardized, rationalized and renamed 'pressure'

This commit is contained in:
Henry Weller
2016-05-22 21:29:46 +01:00
parent 593df27f58
commit f58a48c675
5 changed files with 322 additions and 372 deletions

View File

@ -42,5 +42,6 @@ Lambda2/Lambda2.C
CourantNo/CourantNo.C
PecletNo/PecletNo.C
blendingFactor/blendingFactor.C
pressure/pressure.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -0,0 +1,260 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 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 "pressure.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(pressure, 0);
addToRunTimeSelectionTable(functionObject, pressure, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::functionObjects::pressure::resultName() const
{
word rName;
if (calcTotal_)
{
rName = "total(" + fieldName_ + ")";
}
else
{
rName = "static(" + fieldName_ + ")";
}
if (calcCoeff_)
{
rName += "_coeff";
}
return rName;
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return p;
}
else
{
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*p;
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p,
const tmp<volScalarField>& tsf
) const
{
if (p.dimensions() == dimPressure)
{
return lookupField<volScalarField>(rhoName_)*tsf;
}
else
{
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*tsf;
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
(
const tmp<volScalarField>& tp
) const
{
if (calcTotal_)
{
return tp + dimensionedScalar("pRef", dimPressure, pRef_);
}
else
{
return tmp<volScalarField>(tp.ptr());
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pDyn
(
const volScalarField& p,
const tmp<volScalarField>& tp
) const
{
if (calcTotal_)
{
return
tp
+ rhoScale(p, 0.5*magSqr(lookupField<volVectorField>(UName_)));
}
else
{
return tmp<volScalarField>(tp.ptr());
}
}
Foam::tmp<Foam::volScalarField>
Foam::functionObjects::pressure::coeff
(
const tmp<volScalarField>& tp
) const
{
if (calcCoeff_)
{
tmp<volScalarField> tpCoeff(tp.ptr());
volScalarField& pCoeff = tpCoeff.ref();
pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
const dimensionedScalar pSmall("pSmall", dimPressure, SMALL);
const dimensionedVector U("U", dimVelocity, UInf_);
const dimensionedScalar rho("rho", dimDensity, rhoInf_);
pCoeff /= 0.5*rho*magSqr(U) + pSmall;
return tpCoeff;
}
else
{
return tmp<volScalarField>(tp.ptr());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::pressure::pressure
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "p"),
UName_("U"),
rhoName_("rho"),
calcTotal_(false),
pRef_(0),
calcCoeff_(false),
pInf_(0),
UInf_(Zero),
rhoInf_(1)
{
read(dict);
dimensionSet pDims(dimPressure);
if (calcCoeff_)
{
pDims /= dimPressure;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::pressure::~pressure()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::pressure::read(const dictionary& dict)
{
dict.readIfPresent("U", UName_);
dict.readIfPresent("rho", rhoName_);
if (rhoName_ == "rhoInf")
{
dict.lookup("rhoInf") >> rhoInf_;
}
dict.lookup("calcTotal") >> calcTotal_;
if (calcTotal_)
{
dict.lookup("pRef") >> pRef_;
}
dict.lookup("calcCoeff") >> calcCoeff_;
if (calcCoeff_)
{
dict.lookup("pInf") >> pInf_;
dict.lookup("UInf") >> UInf_;
dict.lookup("rhoInf") >> rhoInf_;
scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
if (mag(zeroCheck) < ROOTVSMALL)
{
WarningInFunction
<< type() << " " << name() << ": "
<< "Coefficient calculation requested, but reference "
<< "pressure level is zero. Please check the supplied "
<< "values of pInf, UInf and rhoInf" << endl;
}
}
resultName_ = dict.lookupOrDefault<word>("result", resultName());
return true;
}
bool Foam::functionObjects::pressure::execute(const bool postProcess)
{
if (foundField<volScalarField>(fieldName_))
{
const volScalarField& p = lookupField<volScalarField>(fieldName_);
return store
(
resultName_,
coeff(pRef(pDyn(p, rhoScale(p))))
);
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -22,7 +22,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::pressureTools
Foam::functionObjects::pressure
Group
grpForcesFunctionObjects
@ -33,54 +33,54 @@ Description
- static pressure
\f[
p_s = \rho p_k
p = \rho p_k
\f]
- total pressure
\f[
p_T = p_{ref} + p_s + 0.5 \rho |U|^2
p_0 = p_{ref} + p + 0.5 \rho |U|^2
\f]
- static pressure coefficient
\f[
Cp_s = \frac{p_s - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
Cp = \frac{p - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
\f]
- total pressure coefficient
\f[
Cp_T = \frac{p_T - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
Cp_0 = \frac{p_0 - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
\f]
where
\vartable
\rho | density [kg/m3]
U | velocity [m/s]
\rho_{\inf} | freestream density [kg/m3]
p_{\inf} | freestream pressure [Pa]
U_{\inf} | freestream velocity [m/s]
p_k | kinematic pressure (p/rho)[m2/s2]
p_s | pressure [Pa]
p_T | total pressure [Pa]
p_{ref} | reference pressure level [Pa]
Cp_{s} | pressure coefficient
Cp_{T} | total pressure coefficient
\rho | Density [kg/m3]
U | Velocity [m/s]
\rho_{\inf} | Freestream density [kg/m3]
p_{\inf} | Freestream pressure [Pa]
U_{\inf} | Freestream velocity [m/s]
p_k | Kinematic pressure (p/rho)[m2/s2]
p | Pressure [Pa]
p_0 | Total pressure [Pa]
p_{ref} | Reference pressure level [Pa]
Cp | Pressure coefficient
Cp_0 | Total pressure coefficient
\endvartable
The function object will operate on both kinematic (\f$ p_k \f$) and static
pressure (\f$ p_s \f$) fields, and the result is written as a
pressure (\f$ p \f$) fields, and the result is written as a
volScalarField.
The modes of operation are:
\table
Mode | calcTotal | calcCoeff
static pressure | no | no
total pressure | yes | no
pressure coefficient | no | yes
total pressure coefficient | yes | yes
Static pressure | no | no
Total pressure | yes | no
Pressure coefficient | no | yes
Total pressure coefficient | yes | yes
\endtable
Example of function object specification to calculate pressure coefficient:
\verbatim
pressureTools1
pressure1
{
type pressureTools;
type pressure;
libs ("libutilityFunctionObjects.so");
...
calcTotal no;
@ -90,28 +90,33 @@ Description
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: pressureTools| yes |
calcTotal | Calculate total coefficient | yes |
pRef | Reference pressure for total pressure | no | 0.0
Property | Description | Required | Default value
type | type name: pressure | yes |
field | Name of the pressure field | no | p
U | Name of the velocity field | no | U
rho | Name of the density field | no | rho
result | Name of the resulting field | no | derived from p
calcTotal | Calculate total coefficient | yes |
pRef | Reference pressure for total pressure | no | 0
calcCoeff | Calculate pressure coefficient | yes |
pInf | Freestream pressure for coefficient calculation | no |
UInf | Freestream velocity for coefficient calculation | no |
rhoInf | Freestream density for coefficient calculation | no |
rhoInf | Freestream density for coefficient calculation | no |
\endtable
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
pressureTools.C
pressure.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_pressureTools_H
#define functionObjects_pressureTools_H
#ifndef functionObjects_pressure_H
#define functionObjects_pressure_H
#include "fvMeshFunctionObject.H"
#include "fieldExpression.H"
#include "volFieldsFwd.H"
#include "dimensionedScalar.H"
@ -123,18 +128,15 @@ namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class pressureTools Declaration
Class pressure Declaration
\*---------------------------------------------------------------------------*/
class pressureTools
class pressure
:
public fvMeshFunctionObject
public fieldExpression
{
// Private data
//- Name of pressure field, default is "p"
word pName_;
//- Name of velocity field, default is "U"
word UName_;
@ -169,40 +171,42 @@ class pressureTools
// Private Member Functions
//- Return the name of the derived pressure field
word pName() const;
word resultName() const;
//- Return the density scaling if supplied with kinematic pressure
dimensionedScalar rhoScale(const volScalarField& p) const;
//- Multiply the static pressure p by rhoInf if necessary and return
tmp<volScalarField> rhoScale(const volScalarField& p) const;
//- Return the density field
tmp<volScalarField> rho(const volScalarField& p) const;
//- Multiply the given field by rho or rhoInf as appropriate and return
tmp<volScalarField> rhoScale
(
const volScalarField& p,
const tmp<volScalarField>& tsf
) const;
//- Return the reference pressure
dimensionedScalar pRef() const;
tmp<volScalarField> pRef(const tmp<volScalarField>& tp) const;
//- Calculate and return the dynamic pressure
tmp<volScalarField> pDyn(const volScalarField& p) const;
tmp<volScalarField> pDyn
(
const volScalarField& p,
const tmp<volScalarField>& tp
) const;
//- Convert to coeff by applying the freestream dynamic pressure scaling
tmp<volScalarField> convertToCoeff(const volScalarField& p) const;
//- Disallow default bitwise copy construct
pressureTools(const pressureTools&);
//- Disallow default bitwise assignment
void operator=(const pressureTools&);
tmp<volScalarField> coeff(const tmp<volScalarField>& tp) const;
public:
//- Runtime type information
TypeName("pressureTools");
TypeName("pressure");
// Constructors
//- Construct from Time and dictionary
pressureTools
pressure
(
const word& name,
const Time& runTime,
@ -211,19 +215,16 @@ public:
//- Destructor
virtual ~pressureTools();
virtual ~pressure();
// Member Functions
//- Read the pressureTools data
//- Read the pressure data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
//- Calculate the selected pressure form
virtual bool execute(const bool postProcess = false);
//- Calculate the pressureTools and write
virtual bool write(const bool postProcess = false);
};

View File

@ -1,4 +1,3 @@
pressureTools/pressureTools.C
wallShearStress/wallShearStress.C
forces/forces.C
forceCoeffs/forceCoeffs.C

View File

@ -1,311 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 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 "pressureTools.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(pressureTools, 0);
addToRunTimeSelectionTable(functionObject, pressureTools, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::functionObjects::pressureTools::pName() const
{
word fieldName = pName_;
if (calcTotal_)
{
fieldName = "total(" + fieldName + ")";
}
else
{
fieldName = "static(" + fieldName + ")";
}
if (calcCoeff_)
{
fieldName = fieldName + "_coeff";
}
return fieldName;
}
Foam::dimensionedScalar Foam::functionObjects::pressureTools::rhoScale
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return dimensionedScalar("1", dimless, 1.0);
}
else
{
return dimensionedScalar("rhoRef", dimDensity, rhoInf_);
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressureTools::rho
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return p.mesh().lookupObject<volScalarField>(rhoName_);
}
else
{
return
tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"rho",
p.mesh().time().timeName(),
p.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
p.mesh(),
dimensionedScalar("zero", dimDensity, rhoInf_)
)
);
}
}
Foam::dimensionedScalar Foam::functionObjects::pressureTools::pRef() const
{
dimensionedScalar value("pRef", dimPressure, 0.0);
if (calcTotal_)
{
value.value() += pRef_;
}
return value;
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressureTools::pDyn
(
const volScalarField& p
) const
{
tmp<volScalarField> tpDyn
(
new volScalarField
(
IOobject
(
"pDyn",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", dimPressure, 0.0)
)
);
if (calcTotal_)
{
const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
tpDyn.ref() == rho(p)*0.5*magSqr(U);
}
return tpDyn;
}
Foam::tmp<Foam::volScalarField>
Foam::functionObjects::pressureTools::convertToCoeff
(
const volScalarField& p
) const
{
tmp<volScalarField> tCoeff(p);
if (calcCoeff_)
{
tCoeff.ref() -= dimensionedScalar("pInf", dimPressure, pInf_);
const dimensionedScalar p0("p0", dimPressure, SMALL);
const dimensionedVector U("U", dimVelocity, UInf_);
const dimensionedScalar rho("rho", dimDensity, rhoInf_);
tCoeff.ref() /= 0.5*rho*magSqr(U) + p0;
}
return tCoeff;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::pressureTools::pressureTools
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
pName_("p"),
UName_("U"),
rhoName_("rho"),
calcTotal_(false),
pRef_(0.0),
calcCoeff_(false),
pInf_(0.0),
UInf_(Zero),
rhoInf_(0.0)
{
read(dict);
dimensionSet pDims(dimPressure);
if (calcCoeff_)
{
pDims /= dimPressure;
}
volScalarField* pPtr
(
new volScalarField
(
IOobject
(
pName(),
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", pDims, 0.0)
)
);
mesh_.objectRegistry::store(pPtr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::pressureTools::~pressureTools()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::pressureTools::read(const dictionary& dict)
{
dict.readIfPresent("p", pName_);
dict.readIfPresent("U", UName_);
dict.readIfPresent("rho", rhoName_);
if (rhoName_ == "rhoInf")
{
dict.lookup("rhoInf") >> rhoInf_;
}
dict.lookup("calcTotal") >> calcTotal_;
if (calcTotal_)
{
dict.lookup("pRef") >> pRef_;
}
dict.lookup("calcCoeff") >> calcCoeff_;
if (calcCoeff_)
{
dict.lookup("pInf") >> pInf_;
dict.lookup("UInf") >> UInf_;
dict.lookup("rhoInf") >> rhoInf_;
scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
if (mag(zeroCheck) < ROOTVSMALL)
{
WarningInFunction
<< type() << " " << name() << ": "
<< "Coefficient calculation requested, but reference "
<< "pressure level is zero. Please check the supplied "
<< "values of pInf, UInf and rhoInf" << endl;
}
}
return true;
}
bool Foam::functionObjects::pressureTools::execute(const bool postProcess)
{
const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
volScalarField& pResult = const_cast<volScalarField&>
(
obr_.lookupObject<volScalarField>(pName())
);
pResult == convertToCoeff(rhoScale(p)*p + pDyn(p) + pRef());
return true;
}
bool Foam::functionObjects::pressureTools::write(const bool postProcess)
{
const volScalarField& pResult =
obr_.lookupObject<volScalarField>(pName());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << pResult.name() << nl
<< endl;
pResult.write();
return true;
}
// ************************************************************************* //