From 12afb3d34a7968d80a8a9d51c3ad0ee4b916bba5 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Wed, 19 Jun 2019 09:00:14 +0100 Subject: [PATCH] ENH: Refactored pressure function object --- src/functionObjects/field/pressure/pressure.C | 155 ++++++++++-------- src/functionObjects/field/pressure/pressure.H | 70 ++++---- .../squareBend/system/isentropicTotalPressure | 6 +- .../system/pressureCoefficient | 3 +- .../simpleFoam/bump2D/system/controlDict | 3 +- 5 files changed, 133 insertions(+), 104 deletions(-) diff --git a/src/functionObjects/field/pressure/pressure.C b/src/functionObjects/field/pressure/pressure.C index a14664e096..0f9e78536d 100644 --- a/src/functionObjects/field/pressure/pressure.C +++ b/src/functionObjects/field/pressure/pressure.C @@ -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::functionObjects::pressure::rhoScale } -Foam::tmp Foam::functionObjects::pressure::pRef -( - const tmp& tp -) const -{ - if (calcTotal_) - { - return tp + dimensionedScalar("pRef", dimPressure, pRef_); - } - else - { - return std::move(tp); - } -} - - -Foam::tmp Foam::functionObjects::pressure::pDyn +Foam::tmp Foam::functionObjects::pressure::calcPressure ( const volScalarField& p, const tmp& tp ) const { - if (calcTotal_) + switch (mode_) { - return - tp - + rhoScale(p, 0.5*magSqr(lookupObject(UName_))); - } - else if (calcIsen_) - { - const fluidThermo* thermoPtr = - p.mesh().lookupObjectPtr(basicThermo::dictName); + case TOTAL: + { + return + tp + + dimensionedScalar("pRef", dimPressure, pRef_) + + rhoScale(p, 0.5*magSqr(lookupObject(UName_))); + } + case ISENTROPIC: + { + const basicThermo* thermoPtr = + p.mesh().lookupObjectPtr(basicThermo::dictName); - const volScalarField gamma(thermoPtr->gamma()); + if (!thermoPtr) + { + FatalErrorInFunction + << "Isentropic pressure calculation requires a " + << "thermodynamics package" + << exit(FatalError); + } - const volScalarField Mb - ( - mag(lookupObject(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(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::functionObjects::pressure::coeff const tmp& tp ) const { - if (calcCoeff_) + if (mode_ & COEFF) { tmp 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("calcIsen", false); - - dict.readEntry("calcTotal", calcTotal_); - if (calcTotal_) + if (dict.found("calcTotal")) { - pRef_ = dict.lookupOrDefault("pRef", 0); + // Backwards compatibility - check for the presence of 'calcTotal' + if (dict.getCompat("mode", {{"calcTotal", 1812}})) + { + mode_ = TOTAL; + } + else + { + mode_ = STATIC; + } + + if (dict.getCompat("mode", {{"calcCoeff", 1812}})) + { + mode_ = static_cast(COEFF | mode_); + } + } + else + { + mode_ = modeNames.get("mode", dict); } - dict.readEntry("calcCoeff", calcCoeff_); - if (calcCoeff_) + pRef_ = dict.lookupOrDefault("pRef", 0); + + if (mode_ & COEFF) { dict.readEntry("pInf", pInf_); dict.readEntry("UInf", UInf_); diff --git a/src/functionObjects/field/pressure/pressure.H b/src/functionObjects/field/pressure/pressure.H index 38b112279b..63f3694712 100644 --- a/src/functionObjects/field/pressure/pressure.H +++ b/src/functionObjects/field/pressure/pressure.H @@ -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 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 pRef(const tmp& tp) const; - //- Calculate and return the dynamic pressure - tmp pDyn + //- Calculate and return the pressure + tmp calcPressure ( const volScalarField& p, const tmp& tp @@ -234,7 +244,7 @@ public: //- Destructor - virtual ~pressure(); + virtual ~pressure() = default; // Member Functions diff --git a/tutorials/compressible/rhoSimpleFoam/squareBend/system/isentropicTotalPressure b/tutorials/compressible/rhoSimpleFoam/squareBend/system/isentropicTotalPressure index 0d62dabe8f..7add37ce96 100644 --- a/tutorials/compressible/rhoSimpleFoam/squareBend/system/isentropicTotalPressure +++ b/tutorials/compressible/rhoSimpleFoam/squareBend/system/isentropicTotalPressure @@ -4,8 +4,6 @@ isentropicPressure libs ("libfieldFunctionObjects.so"); enabled yes; writeControl writeTime; - calcIsen yes; - calcTotal no; - calcCoeff no; - result isenTropicP; + mode isentropic; + result isentropicP; } diff --git a/tutorials/incompressible/simpleFoam/backwardFacingStep2D/system/pressureCoefficient b/tutorials/incompressible/simpleFoam/backwardFacingStep2D/system/pressureCoefficient index 5a24f95419..4790eb96ed 100644 --- a/tutorials/incompressible/simpleFoam/backwardFacingStep2D/system/pressureCoefficient +++ b/tutorials/incompressible/simpleFoam/backwardFacingStep2D/system/pressureCoefficient @@ -3,8 +3,7 @@ libs ("libfieldFunctionObjects.so"); writeControl writeTime; -calcCoeff yes; -calcTotal no; +mode staticCoeff; result cp; diff --git a/tutorials/incompressible/simpleFoam/bump2D/system/controlDict b/tutorials/incompressible/simpleFoam/bump2D/system/controlDict index a555221eb0..043bd2f12d 100644 --- a/tutorials/incompressible/simpleFoam/bump2D/system/controlDict +++ b/tutorials/incompressible/simpleFoam/bump2D/system/controlDict @@ -53,8 +53,7 @@ functions libs ("libfieldFunctionObjects.so"); writeControl writeTime; result Cp; - calcTotal no; - calcCoeff yes; + mode staticCoeff; rho rhoInf; rhoInf 1; U UInf;