Commit 0a43d605 authored by Henry Weller's avatar Henry Weller
Browse files

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

parent e134af2a
......@@ -42,5 +42,6 @@ Lambda2/Lambda2.C
CourantNo/CourantNo.C
PecletNo/PecletNo.C
blendingFactor/blendingFactor.C
pressure/pressure.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects
......@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "pressureTools.H"
#include "pressure.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
......@@ -33,172 +33,150 @@ namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(pressureTools, 0);
addToRunTimeSelectionTable(functionObject, pressureTools, dictionary);
defineTypeNameAndDebug(pressure, 0);
addToRunTimeSelectionTable(functionObject, pressure, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::functionObjects::pressureTools::pName() const
Foam::word Foam::functionObjects::pressure::resultName() const
{
word fieldName = pName_;
word rName;
if (calcTotal_)
{
fieldName = "total(" + fieldName + ")";
rName = "total(" + fieldName_ + ")";
}
else
{
fieldName = "static(" + fieldName + ")";
rName = "static(" + fieldName_ + ")";
}
if (calcCoeff_)
{
fieldName = fieldName + "_coeff";
rName += "_coeff";
}
return fieldName;
return rName;
}
Foam::dimensionedScalar Foam::functionObjects::pressureTools::rhoScale
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return dimensionedScalar("1", dimless, 1.0);
return p;
}
else
{
return dimensionedScalar("rhoRef", dimDensity, rhoInf_);
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*p;
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressureTools::rho
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p
const volScalarField& p,
const tmp<volScalarField>& tsf
) const
{
if (p.dimensions() == dimPressure)
{
return p.mesh().lookupObject<volScalarField>(rhoName_);
return lookupField<volScalarField>(rhoName_)*tsf;
}
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_)
)
);
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*tsf;
}
}
Foam::dimensionedScalar Foam::functionObjects::pressureTools::pRef() const
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
(
const tmp<volScalarField>& tp
) const
{
dimensionedScalar value("pRef", dimPressure, 0.0);
if (calcTotal_)
{
value.value() += pRef_;
return tp + dimensionedScalar("pRef", dimPressure, pRef_);
}
else
{
return tmp<volScalarField>(tp.ptr());
}
return value;
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressureTools::pDyn
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pDyn
(
const volScalarField& p
const volScalarField& p,
const tmp<volScalarField>& tp
) 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
tp
+ rhoScale(p, 0.5*magSqr(lookupField<volVectorField>(UName_)));
}
else
{
return tmp<volScalarField>(tp.ptr());
}
return tpDyn;
}
Foam::tmp<Foam::volScalarField>
Foam::functionObjects::pressureTools::convertToCoeff
Foam::functionObjects::pressure::coeff
(
const volScalarField& p
const tmp<volScalarField>& tp
) const
{
tmp<volScalarField> tCoeff(p);
if (calcCoeff_)
{
tCoeff.ref() -= dimensionedScalar("pInf", dimPressure, pInf_);
tmp<volScalarField> tpCoeff(tp.ptr());
volScalarField& pCoeff = tpCoeff.ref();
const dimensionedScalar p0("p0", dimPressure, SMALL);
pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
const dimensionedScalar pSmall("pSmall", dimPressure, SMALL);
const dimensionedVector U("U", dimVelocity, UInf_);
const dimensionedScalar rho("rho", dimDensity, rhoInf_);
tCoeff.ref() /= 0.5*rho*magSqr(U) + p0;
}
pCoeff /= 0.5*rho*magSqr(U) + pSmall;
return tCoeff;
return tpCoeff;
}
else
{
return tmp<volScalarField>(tp.ptr());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::pressureTools::pressureTools
Foam::functionObjects::pressure::pressure
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
pName_("p"),
fieldExpression(name, runTime, dict, "p"),
UName_("U"),
rhoName_("rho"),
calcTotal_(false),
pRef_(0.0),
pRef_(0),
calcCoeff_(false),
pInf_(0.0),
pInf_(0),
UInf_(Zero),
rhoInf_(0.0)
rhoInf_(1)
{
read(dict);
......@@ -208,39 +186,19 @@ Foam::functionObjects::pressureTools::pressureTools
{
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()
Foam::functionObjects::pressure::~pressure()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::pressureTools::read(const dictionary& dict)
bool Foam::functionObjects::pressure::read(const dictionary& dict)
{
dict.readIfPresent("p", pName_);
dict.readIfPresent("U", UName_);
dict.readIfPresent("rho", rhoName_);
......@@ -274,37 +232,28 @@ bool Foam::functionObjects::pressureTools::read(const dictionary& dict)
}
}
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());
resultName_ = dict.lookupOrDefault<word>("result", resultName());
return true;
}
bool Foam::functionObjects::pressureTools::write(const bool postProcess)
bool Foam::functionObjects::pressure::execute(const bool postProcess)
{
const volScalarField& pResult =
obr_.lookupObject<volScalarField>(pName());
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << pResult.name() << nl
<< endl;
pResult.write();
if (foundField<volScalarField>(fieldName_))
{
const volScalarField& p = lookupField<volScalarField>(fieldName_);
return true;
return store
(
resultName_,
coeff(pRef(pDyn(p, rhoScale(p))))
);
}
else
{
return false;
}
}
......
......@@ -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);
};
......
pressureTools/pressureTools.C
wallShearStress/wallShearStress.C
forces/forces.C
forceCoeffs/forceCoeffs.C
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment