mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Refactored pressure function object
This commit is contained in:
@ -27,7 +27,7 @@ License
|
|||||||
|
|
||||||
#include "pressure.H"
|
#include "pressure.H"
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "fluidThermo.H"
|
#include "basicThermo.H"
|
||||||
#include "addToRunTimeSelectionTable.H"
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -41,6 +41,18 @@ namespace functionObjects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Foam::Enum
|
||||||
|
<
|
||||||
|
Foam::functionObjects::pressure::mode
|
||||||
|
>
|
||||||
|
Foam::functionObjects::pressure::modeNames
|
||||||
|
({
|
||||||
|
{ STATIC, "static" },
|
||||||
|
{ TOTAL, "total" },
|
||||||
|
{ ISENTROPIC, "isentropic" },
|
||||||
|
{ STATIC_COEFF, "staticCoeff" },
|
||||||
|
{ TOTAL_COEFF, "totalCoeff" },
|
||||||
|
});
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -48,20 +60,26 @@ Foam::word Foam::functionObjects::pressure::resultName() const
|
|||||||
{
|
{
|
||||||
word rName;
|
word rName;
|
||||||
|
|
||||||
if (calcTotal_)
|
if (mode_ & STATIC)
|
||||||
{
|
|
||||||
rName = "total(" + fieldName_ + ")";
|
|
||||||
}
|
|
||||||
else if (calcIsen_)
|
|
||||||
{
|
|
||||||
rName = "totalIsen(" + fieldName_ + ")";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
rName = "static(" + fieldName_ + ")";
|
rName = "static(" + fieldName_ + ")";
|
||||||
}
|
}
|
||||||
|
else if (mode_ & TOTAL)
|
||||||
|
{
|
||||||
|
rName = "total(" + fieldName_ + ")";
|
||||||
|
}
|
||||||
|
else if (mode_ & ISENTROPIC)
|
||||||
|
{
|
||||||
|
rName = "isentropic(" + fieldName_ + ")";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Unhandled calculation mode " << modeNames[mode_]
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
if (calcCoeff_)
|
if (mode_ & COEFF)
|
||||||
{
|
{
|
||||||
rName += "_coeff";
|
rName += "_coeff";
|
||||||
}
|
}
|
||||||
@ -122,52 +140,50 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
|
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::calcPressure
|
||||||
(
|
|
||||||
const tmp<volScalarField>& tp
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
if (calcTotal_)
|
|
||||||
{
|
|
||||||
return tp + dimensionedScalar("pRef", dimPressure, pRef_);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return std::move(tp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pDyn
|
|
||||||
(
|
(
|
||||||
const volScalarField& p,
|
const volScalarField& p,
|
||||||
const tmp<volScalarField>& tp
|
const tmp<volScalarField>& tp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (calcTotal_)
|
switch (mode_)
|
||||||
{
|
{
|
||||||
return
|
case TOTAL:
|
||||||
tp
|
{
|
||||||
+ rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
|
return
|
||||||
}
|
tp
|
||||||
else if (calcIsen_)
|
+ dimensionedScalar("pRef", dimPressure, pRef_)
|
||||||
{
|
+ rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
|
||||||
const fluidThermo* thermoPtr =
|
}
|
||||||
p.mesh().lookupObjectPtr<fluidThermo>(basicThermo::dictName);
|
case ISENTROPIC:
|
||||||
|
{
|
||||||
|
const basicThermo* thermoPtr =
|
||||||
|
p.mesh().lookupObjectPtr<basicThermo>(basicThermo::dictName);
|
||||||
|
|
||||||
const volScalarField gamma(thermoPtr->gamma());
|
if (!thermoPtr)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Isentropic pressure calculation requires a "
|
||||||
|
<< "thermodynamics package"
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
const volScalarField Mb
|
const volScalarField gamma(thermoPtr->gamma());
|
||||||
(
|
|
||||||
mag(lookupObject<volVectorField>(UName_))
|
|
||||||
/sqrt(gamma*tp.ref()/thermoPtr->rho())
|
|
||||||
);
|
|
||||||
|
|
||||||
return tp.ref()*(pow(1 + (gamma-1)/2*sqr(Mb), gamma/(gamma-1)));
|
const volScalarField Mb
|
||||||
}
|
(
|
||||||
else
|
mag(lookupObject<volVectorField>(UName_))
|
||||||
{
|
/sqrt(gamma*tp.ref()/thermoPtr->rho())
|
||||||
return std::move(tp);
|
);
|
||||||
|
|
||||||
|
return tp()*(pow(1 + (gamma - 1)/2*sqr(Mb), gamma/(gamma - 1)));
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return
|
||||||
|
tp
|
||||||
|
+ dimensionedScalar("pRef", dimPressure, pRef_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +193,7 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::coeff
|
|||||||
const tmp<volScalarField>& tp
|
const tmp<volScalarField>& tp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (calcCoeff_)
|
if (mode_ & COEFF)
|
||||||
{
|
{
|
||||||
tmp<volScalarField> tpCoeff(tp.ptr());
|
tmp<volScalarField> tpCoeff(tp.ptr());
|
||||||
volScalarField& pCoeff = tpCoeff.ref();
|
volScalarField& pCoeff = tpCoeff.ref();
|
||||||
@ -217,7 +233,7 @@ bool Foam::functionObjects::pressure::calc()
|
|||||||
IOobject::NO_READ,
|
IOobject::NO_READ,
|
||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
),
|
),
|
||||||
coeff(pRef(pDyn(p, rhoScale(p))))
|
coeff(calcPressure(p, rhoScale(p)))
|
||||||
);
|
);
|
||||||
|
|
||||||
return store(resultName_, tp);
|
return store(resultName_, tp);
|
||||||
@ -237,12 +253,10 @@ Foam::functionObjects::pressure::pressure
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
fieldExpression(name, runTime, dict, "p"),
|
fieldExpression(name, runTime, dict, "p"),
|
||||||
|
mode_(STATIC),
|
||||||
UName_("U"),
|
UName_("U"),
|
||||||
rhoName_("rho"),
|
rhoName_("rho"),
|
||||||
calcTotal_(false),
|
|
||||||
calcIsen_(false),
|
|
||||||
pRef_(0),
|
pRef_(0),
|
||||||
calcCoeff_(false),
|
|
||||||
pInf_(0),
|
pInf_(0),
|
||||||
UInf_(Zero),
|
UInf_(Zero),
|
||||||
rhoInf_(1),
|
rhoInf_(1),
|
||||||
@ -252,12 +266,6 @@ Foam::functionObjects::pressure::pressure
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::functionObjects::pressure::~pressure()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::functionObjects::pressure::read(const dictionary& dict)
|
bool Foam::functionObjects::pressure::read(const dictionary& dict)
|
||||||
@ -273,16 +281,31 @@ bool Foam::functionObjects::pressure::read(const dictionary& dict)
|
|||||||
rhoInfInitialised_ = true;
|
rhoInfInitialised_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
calcIsen_ = dict.lookupOrDefault<bool>("calcIsen", false);
|
if (dict.found("calcTotal"))
|
||||||
|
|
||||||
dict.readEntry("calcTotal", calcTotal_);
|
|
||||||
if (calcTotal_)
|
|
||||||
{
|
{
|
||||||
pRef_ = dict.lookupOrDefault<scalar>("pRef", 0);
|
// Backwards compatibility - check for the presence of 'calcTotal'
|
||||||
|
if (dict.getCompat<bool>("mode", {{"calcTotal", 1812}}))
|
||||||
|
{
|
||||||
|
mode_ = TOTAL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mode_ = STATIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dict.getCompat<bool>("mode", {{"calcCoeff", 1812}}))
|
||||||
|
{
|
||||||
|
mode_ = static_cast<mode>(COEFF | mode_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mode_ = modeNames.get("mode", dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
dict.readEntry("calcCoeff", calcCoeff_);
|
pRef_ = dict.lookupOrDefault<scalar>("pRef", 0);
|
||||||
if (calcCoeff_)
|
|
||||||
|
if (mode_ & COEFF)
|
||||||
{
|
{
|
||||||
dict.readEntry("pInf", pInf_);
|
dict.readEntry("pInf", pInf_);
|
||||||
dict.readEntry("UInf", UInf_);
|
dict.readEntry("UInf", UInf_);
|
||||||
|
|||||||
@ -35,7 +35,7 @@ Description
|
|||||||
These currently include:
|
These currently include:
|
||||||
- static pressure
|
- static pressure
|
||||||
\f[
|
\f[
|
||||||
p = \rho p_k
|
p_s = p_{ref} + \rho p_k
|
||||||
\f]
|
\f]
|
||||||
- total pressure
|
- total pressure
|
||||||
\f[
|
\f[
|
||||||
@ -43,11 +43,11 @@ Description
|
|||||||
\f]
|
\f]
|
||||||
- isentropic pressure
|
- isentropic pressure
|
||||||
\f[
|
\f[
|
||||||
p_iso = p*(1 + ((gamma-1)*M^2)/2)^(gamma/(gamma - 1))
|
p_i = p*(1 + ((gamma-1)*M^2)/2)^(gamma/(gamma - 1))
|
||||||
\f]
|
\f]
|
||||||
- static pressure coefficient
|
- static pressure coefficient
|
||||||
\f[
|
\f[
|
||||||
Cp = \frac{p - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
|
Cp = \frac{p_s - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
|
||||||
\f]
|
\f]
|
||||||
- total pressure coefficient
|
- total pressure coefficient
|
||||||
\f[
|
\f[
|
||||||
@ -62,10 +62,10 @@ Description
|
|||||||
p_{\inf} | Freestream pressure [Pa]
|
p_{\inf} | Freestream pressure [Pa]
|
||||||
U_{\inf} | Freestream velocity [m/s]
|
U_{\inf} | Freestream velocity [m/s]
|
||||||
p_k | Kinematic pressure (p/rho)[m2/s2]
|
p_k | Kinematic pressure (p/rho)[m2/s2]
|
||||||
p | Pressure [Pa]
|
p_s | Statoc pressure [Pa]
|
||||||
p_0 | Total pressure [Pa]
|
p_0 | Total pressure [Pa]
|
||||||
p_{ref} | Reference pressure level [Pa]
|
p_{ref} | Reference pressure level [Pa]
|
||||||
p_iso | Total isentropic pressure
|
p_i | Total isentropic pressure
|
||||||
Cp | Pressure coefficient
|
Cp | Pressure coefficient
|
||||||
Cp_0 | Total pressure coefficient
|
Cp_0 | Total pressure coefficient
|
||||||
\endvartable
|
\endvartable
|
||||||
@ -74,16 +74,6 @@ Description
|
|||||||
pressure (\f$ p \f$) fields, and the result is written as a
|
pressure (\f$ p \f$) fields, and the result is written as a
|
||||||
volScalarField.
|
volScalarField.
|
||||||
|
|
||||||
The modes of operation are:
|
|
||||||
\table
|
|
||||||
Mode | calcTotal | calcCoeff | calcIsen
|
|
||||||
Static pressure | no | no | no
|
|
||||||
Total pressure | yes | no | no
|
|
||||||
Pressure coefficient | no | yes | no
|
|
||||||
Total pressure coefficient | yes | yes | no
|
|
||||||
Total isentropic pressure | no | no | yes
|
|
||||||
\endtable
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
Example of function object specification to calculate pressure coefficient:
|
Example of function object specification to calculate pressure coefficient:
|
||||||
\verbatim
|
\verbatim
|
||||||
@ -105,15 +95,21 @@ Usage
|
|||||||
U | Name of the velocity field | no | U
|
U | Name of the velocity field | no | U
|
||||||
rho | Name of the density field | no | rho
|
rho | Name of the density field | no | rho
|
||||||
result | Name of the resulting field | no | derived from p
|
result | Name of the resulting field | no | derived from p
|
||||||
calcTotal | Calculate total coefficient | yes |
|
mode | Calculation mode (see below) | yes |
|
||||||
calcIsen | Calculate total isentropic | no | no
|
|
||||||
pRef | Reference pressure for total pressure | no | 0
|
pRef | Reference pressure for total pressure | no | 0
|
||||||
calcCoeff | Calculate pressure coefficient | yes |
|
|
||||||
pInf | Freestream pressure for coefficient calculation | no |
|
pInf | Freestream pressure for coefficient calculation | no |
|
||||||
UInf | Freestream velocity 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
|
\endtable
|
||||||
|
|
||||||
|
The \c mode entry is used to select the type of pressure that is calculated.
|
||||||
|
Selections include:
|
||||||
|
- static
|
||||||
|
- total
|
||||||
|
- isentropic
|
||||||
|
- staticCoeff
|
||||||
|
- totalCoeff
|
||||||
|
|
||||||
See also
|
See also
|
||||||
Foam::functionObjects::fieldExpression
|
Foam::functionObjects::fieldExpression
|
||||||
Foam::functionObjects::fvMeshFunctionObject
|
Foam::functionObjects::fvMeshFunctionObject
|
||||||
@ -145,8 +141,31 @@ class pressure
|
|||||||
:
|
:
|
||||||
public fieldExpression
|
public fieldExpression
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Public Data Types
|
||||||
|
|
||||||
|
//- Enumeration for pressure calculation mode
|
||||||
|
enum mode : unsigned
|
||||||
|
{
|
||||||
|
STATIC = 0x1, //!< Static pressure
|
||||||
|
TOTAL = 0x2, //!< Total pressure
|
||||||
|
ISENTROPIC = 0x4, //!< Isentropic pressure
|
||||||
|
COEFF = 0x8, //!< Coefficient manipulator
|
||||||
|
STATIC_COEFF = (STATIC | COEFF),
|
||||||
|
TOTAL_COEFF = (TOTAL | COEFF)
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Enum<mode> modeNames;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
|
//- Calculation mode
|
||||||
|
mode mode_;
|
||||||
|
|
||||||
//- Name of velocity field, default is "U"
|
//- Name of velocity field, default is "U"
|
||||||
word UName_;
|
word UName_;
|
||||||
|
|
||||||
@ -156,21 +175,12 @@ class pressure
|
|||||||
|
|
||||||
// Total pressure calculation
|
// Total pressure calculation
|
||||||
|
|
||||||
//- Flag to calculate total pressure
|
|
||||||
bool calcTotal_;
|
|
||||||
|
|
||||||
//- Flag to calculate identropic total pressure
|
|
||||||
bool calcIsen_;
|
|
||||||
|
|
||||||
//- Reference pressure level
|
//- Reference pressure level
|
||||||
scalar pRef_;
|
scalar pRef_;
|
||||||
|
|
||||||
|
|
||||||
// Pressure coefficient calculation
|
// Pressure coefficient calculation
|
||||||
|
|
||||||
//- Flag to calculate pressure coefficient
|
|
||||||
bool calcCoeff_;
|
|
||||||
|
|
||||||
//- Freestream pressure
|
//- Freestream pressure
|
||||||
scalar pInf_;
|
scalar pInf_;
|
||||||
|
|
||||||
@ -202,8 +212,8 @@ class pressure
|
|||||||
//- Return the reference pressure
|
//- Return the reference pressure
|
||||||
tmp<volScalarField> pRef(const tmp<volScalarField>& tp) const;
|
tmp<volScalarField> pRef(const tmp<volScalarField>& tp) const;
|
||||||
|
|
||||||
//- Calculate and return the dynamic pressure
|
//- Calculate and return the pressure
|
||||||
tmp<volScalarField> pDyn
|
tmp<volScalarField> calcPressure
|
||||||
(
|
(
|
||||||
const volScalarField& p,
|
const volScalarField& p,
|
||||||
const tmp<volScalarField>& tp
|
const tmp<volScalarField>& tp
|
||||||
@ -234,7 +244,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~pressure();
|
virtual ~pressure() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -4,8 +4,6 @@ isentropicPressure
|
|||||||
libs ("libfieldFunctionObjects.so");
|
libs ("libfieldFunctionObjects.so");
|
||||||
enabled yes;
|
enabled yes;
|
||||||
writeControl writeTime;
|
writeControl writeTime;
|
||||||
calcIsen yes;
|
mode isentropic;
|
||||||
calcTotal no;
|
result isentropicP;
|
||||||
calcCoeff no;
|
|
||||||
result isenTropicP;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,7 @@ libs ("libfieldFunctionObjects.so");
|
|||||||
|
|
||||||
writeControl writeTime;
|
writeControl writeTime;
|
||||||
|
|
||||||
calcCoeff yes;
|
mode staticCoeff;
|
||||||
calcTotal no;
|
|
||||||
|
|
||||||
result cp;
|
result cp;
|
||||||
|
|
||||||
|
|||||||
@ -53,8 +53,7 @@ functions
|
|||||||
libs ("libfieldFunctionObjects.so");
|
libs ("libfieldFunctionObjects.so");
|
||||||
writeControl writeTime;
|
writeControl writeTime;
|
||||||
result Cp;
|
result Cp;
|
||||||
calcTotal no;
|
mode staticCoeff;
|
||||||
calcCoeff yes;
|
|
||||||
rho rhoInf;
|
rho rhoInf;
|
||||||
rhoInf 1;
|
rhoInf 1;
|
||||||
U UInf;
|
U UInf;
|
||||||
|
|||||||
Reference in New Issue
Block a user