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 "volFields.H"
|
||||
#include "fluidThermo.H"
|
||||
#include "basicThermo.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * 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 * * * * * * * * * * * //
|
||||
|
||||
@ -48,20 +60,26 @@ Foam::word Foam::functionObjects::pressure::resultName() const
|
||||
{
|
||||
word rName;
|
||||
|
||||
if (calcTotal_)
|
||||
{
|
||||
rName = "total(" + fieldName_ + ")";
|
||||
}
|
||||
else if (calcIsen_)
|
||||
{
|
||||
rName = "totalIsen(" + fieldName_ + ")";
|
||||
}
|
||||
else
|
||||
if (mode_ & STATIC)
|
||||
{
|
||||
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";
|
||||
}
|
||||
@ -122,52 +140,50 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
|
||||
(
|
||||
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
|
||||
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::calcPressure
|
||||
(
|
||||
const volScalarField& p,
|
||||
const tmp<volScalarField>& tp
|
||||
) const
|
||||
{
|
||||
if (calcTotal_)
|
||||
switch (mode_)
|
||||
{
|
||||
return
|
||||
tp
|
||||
+ rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
|
||||
}
|
||||
else if (calcIsen_)
|
||||
{
|
||||
const fluidThermo* thermoPtr =
|
||||
p.mesh().lookupObjectPtr<fluidThermo>(basicThermo::dictName);
|
||||
case TOTAL:
|
||||
{
|
||||
return
|
||||
tp
|
||||
+ dimensionedScalar("pRef", dimPressure, pRef_)
|
||||
+ rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
|
||||
}
|
||||
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
|
||||
(
|
||||
mag(lookupObject<volVectorField>(UName_))
|
||||
/sqrt(gamma*tp.ref()/thermoPtr->rho())
|
||||
);
|
||||
const volScalarField gamma(thermoPtr->gamma());
|
||||
|
||||
return tp.ref()*(pow(1 + (gamma-1)/2*sqr(Mb), gamma/(gamma-1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::move(tp);
|
||||
const volScalarField Mb
|
||||
(
|
||||
mag(lookupObject<volVectorField>(UName_))
|
||||
/sqrt(gamma*tp.ref()/thermoPtr->rho())
|
||||
);
|
||||
|
||||
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
|
||||
{
|
||||
if (calcCoeff_)
|
||||
if (mode_ & COEFF)
|
||||
{
|
||||
tmp<volScalarField> tpCoeff(tp.ptr());
|
||||
volScalarField& pCoeff = tpCoeff.ref();
|
||||
@ -217,7 +233,7 @@ bool Foam::functionObjects::pressure::calc()
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
coeff(pRef(pDyn(p, rhoScale(p))))
|
||||
coeff(calcPressure(p, rhoScale(p)))
|
||||
);
|
||||
|
||||
return store(resultName_, tp);
|
||||
@ -237,12 +253,10 @@ Foam::functionObjects::pressure::pressure
|
||||
)
|
||||
:
|
||||
fieldExpression(name, runTime, dict, "p"),
|
||||
mode_(STATIC),
|
||||
UName_("U"),
|
||||
rhoName_("rho"),
|
||||
calcTotal_(false),
|
||||
calcIsen_(false),
|
||||
pRef_(0),
|
||||
calcCoeff_(false),
|
||||
pInf_(0),
|
||||
UInf_(Zero),
|
||||
rhoInf_(1),
|
||||
@ -252,12 +266,6 @@ Foam::functionObjects::pressure::pressure
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::pressure::~pressure()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::pressure::read(const dictionary& dict)
|
||||
@ -273,16 +281,31 @@ bool Foam::functionObjects::pressure::read(const dictionary& dict)
|
||||
rhoInfInitialised_ = true;
|
||||
}
|
||||
|
||||
calcIsen_ = dict.lookupOrDefault<bool>("calcIsen", false);
|
||||
|
||||
dict.readEntry("calcTotal", calcTotal_);
|
||||
if (calcTotal_)
|
||||
if (dict.found("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_);
|
||||
if (calcCoeff_)
|
||||
pRef_ = dict.lookupOrDefault<scalar>("pRef", 0);
|
||||
|
||||
if (mode_ & COEFF)
|
||||
{
|
||||
dict.readEntry("pInf", pInf_);
|
||||
dict.readEntry("UInf", UInf_);
|
||||
|
||||
@ -35,7 +35,7 @@ Description
|
||||
These currently include:
|
||||
- static pressure
|
||||
\f[
|
||||
p = \rho p_k
|
||||
p_s = p_{ref} + \rho p_k
|
||||
\f]
|
||||
- total pressure
|
||||
\f[
|
||||
@ -43,11 +43,11 @@ Description
|
||||
\f]
|
||||
- isentropic pressure
|
||||
\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]
|
||||
- static pressure coefficient
|
||||
\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]
|
||||
- total pressure coefficient
|
||||
\f[
|
||||
@ -62,10 +62,10 @@ Description
|
||||
p_{\inf} | Freestream pressure [Pa]
|
||||
U_{\inf} | Freestream velocity [m/s]
|
||||
p_k | Kinematic pressure (p/rho)[m2/s2]
|
||||
p | Pressure [Pa]
|
||||
p_s | Statoc pressure [Pa]
|
||||
p_0 | Total pressure [Pa]
|
||||
p_{ref} | Reference pressure level [Pa]
|
||||
p_iso | Total isentropic pressure
|
||||
p_i | Total isentropic pressure
|
||||
Cp | Pressure coefficient
|
||||
Cp_0 | Total pressure coefficient
|
||||
\endvartable
|
||||
@ -74,16 +74,6 @@ Description
|
||||
pressure (\f$ p \f$) fields, and the result is written as a
|
||||
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
|
||||
Example of function object specification to calculate pressure coefficient:
|
||||
\verbatim
|
||||
@ -105,15 +95,21 @@ Usage
|
||||
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 |
|
||||
calcIsen | Calculate total isentropic | no | no
|
||||
mode | Calculation mode (see below) | 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 |
|
||||
\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
|
||||
Foam::functionObjects::fieldExpression
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
@ -145,8 +141,31 @@ class pressure
|
||||
:
|
||||
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
|
||||
|
||||
//- Calculation mode
|
||||
mode mode_;
|
||||
|
||||
//- Name of velocity field, default is "U"
|
||||
word UName_;
|
||||
|
||||
@ -156,21 +175,12 @@ class pressure
|
||||
|
||||
// Total pressure calculation
|
||||
|
||||
//- Flag to calculate total pressure
|
||||
bool calcTotal_;
|
||||
|
||||
//- Flag to calculate identropic total pressure
|
||||
bool calcIsen_;
|
||||
|
||||
//- Reference pressure level
|
||||
scalar pRef_;
|
||||
|
||||
|
||||
// Pressure coefficient calculation
|
||||
|
||||
//- Flag to calculate pressure coefficient
|
||||
bool calcCoeff_;
|
||||
|
||||
//- Freestream pressure
|
||||
scalar pInf_;
|
||||
|
||||
@ -202,8 +212,8 @@ class pressure
|
||||
//- Return the reference pressure
|
||||
tmp<volScalarField> pRef(const tmp<volScalarField>& tp) const;
|
||||
|
||||
//- Calculate and return the dynamic pressure
|
||||
tmp<volScalarField> pDyn
|
||||
//- Calculate and return the pressure
|
||||
tmp<volScalarField> calcPressure
|
||||
(
|
||||
const volScalarField& p,
|
||||
const tmp<volScalarField>& tp
|
||||
@ -234,7 +244,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pressure();
|
||||
virtual ~pressure() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -4,8 +4,6 @@ isentropicPressure
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
enabled yes;
|
||||
writeControl writeTime;
|
||||
calcIsen yes;
|
||||
calcTotal no;
|
||||
calcCoeff no;
|
||||
result isenTropicP;
|
||||
mode isentropic;
|
||||
result isentropicP;
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@ libs ("libfieldFunctionObjects.so");
|
||||
|
||||
writeControl writeTime;
|
||||
|
||||
calcCoeff yes;
|
||||
calcTotal no;
|
||||
mode staticCoeff;
|
||||
|
||||
result cp;
|
||||
|
||||
|
||||
@ -53,8 +53,7 @@ functions
|
||||
libs ("libfieldFunctionObjects.so");
|
||||
writeControl writeTime;
|
||||
result Cp;
|
||||
calcTotal no;
|
||||
calcCoeff yes;
|
||||
mode staticCoeff;
|
||||
rho rhoInf;
|
||||
rhoInf 1;
|
||||
U UInf;
|
||||
|
||||
Reference in New Issue
Block a user