Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
OpenFOAM-plus
Commits
3c050d96
Commit
3c050d96
authored
Jun 19, 2019
by
Andrew Heather
Browse files
ENH: Refactored pressure function object
parent
de3091fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/functionObjects/field/pressure/pressure.C
View file @
3c050d96
...
...
@@ -27,7 +27,7 @@ License
#include
"pressure.H"
#include
"volFields.H"
#include
"
fluid
Thermo.H"
#include
"
basic
Thermo.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_
)
if
(
mode_
&
STATIC
)
{
rName
=
"static("
+
fieldName_
+
")"
;
}
else
if
(
mode_
&
TOTAL
)
{
rName
=
"total("
+
fieldName_
+
")"
;
}
else
if
(
calcIsen_
)
else
if
(
mode_
&
ISENTROPIC
)
{
rName
=
"
totalIsen
("
+
fieldName_
+
")"
;
rName
=
"
isentropic
("
+
fieldName_
+
")"
;
}
else
{
rName
=
"static("
+
fieldName_
+
")"
;
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
);
if
(
dict
.
found
(
"calcTotal"
))
{
// Backwards compatibility - check for the presence of 'calcTotal'
if
(
dict
.
getCompat
<
bool
>
(
"mode"
,
{{
"calcTotal"
,
1812
}}))
{
mode_
=
TOTAL
;
}
else
{
mode_
=
STATIC
;
}
dict
.
readEntry
(
"calcTotal"
,
calcTotal_
);
if
(
calcTotal_
)
if
(
dict
.
getCompat
<
bool
>
(
"mode"
,
{{
"calcCoeff"
,
1812
}}))
{
mode_
=
static_cast
<
mode
>
(
COEFF
|
mode_
);
}
}
else
{
pRef_
=
dict
.
lookupOrDefault
<
scalar
>
(
"pRef"
,
0
);
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_
);
...
...
src/functionObjects/field/pressure/pressure.H
View file @
3c050d96
...
...
@@ -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_i
so
= 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
|
P
ressure [Pa]
p
_s
|
Statoc p
ressure [Pa]
p_0 | Total pressure [Pa]
p_{ref} | Reference pressure level [Pa]
p_i
so
| 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
...
...
tutorials/compressible/rhoSimpleFoam/squareBend/system/isentropicTotalPressure
View file @
3c050d96
...
...
@@ -4,8 +4,6 @@ isentropicPressure
libs ("libfieldFunctionObjects.so");
enabled yes;
writeControl writeTime;
calcIsen yes;
calcTotal no;
calcCoeff no;
result isenTropicP;
mode isentropic;
result isentropicP;
}
tutorials/incompressible/simpleFoam/backwardFacingStep2D/system/pressureCoefficient
View file @
3c050d96
...
...
@@ -3,8 +3,7 @@ libs ("libfieldFunctionObjects.so");
writeControl writeTime;
calcCoeff yes;
calcTotal no;
mode staticCoeff;
result cp;
...
...
tutorials/incompressible/simpleFoam/bump2D/system/controlDict
View file @
3c050d96
...
...
@@ -53,8 +53,7 @@ functions
libs ("libfieldFunctionObjects.so");
writeControl writeTime;
result Cp;
calcTotal no;
calcCoeff yes;
mode staticCoeff;
rho rhoInf;
rhoInf 1;
U UInf;
...
...
Mattijs Janssens
@Mattijs
mentioned in issue
#1344 (closed)
·
Jun 19, 2019
mentioned in issue
#1344 (closed)
mentioned in issue #1344
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment