Fluids¶
Calculation of thermodynamic properties for working fluids.
Turbomachinery design and analysis requires knowledge of thermodynamic properties of the working fluid. This module contains classes that abstract real or perfect gases, so that calculations of thermodynamic properties can be performed using a common interface independent of the fluid equation of state.
The general pattern of usage of these classes is as follows. First initialise a
state using turbigen.fluid.PerfectState.from_properties()
or
turbigen.fluid.RealState.from_fluid_name()
constructors. If the type
of working fluid is not known at runtime, the copy() method of an existing
state can be used. Second, specify a pair of two thermodynamic properties
using, for example, turbigen.fluid.PerfectState.set_P_T()
. Finally,
other derived properties can be read off as
attributes of the state, such as turbigen.fluid.PerfectState.rho
.
The examples below illustrate functionality of the
classes; practical usages are found in the turbigen.meanline
functions.
Example code¶
Create a state for real Air, print some properties, then if this is a stagnation state, find static pressure given a Mach number:
>>> import turbigen.fluid
>>> So1 = turbigen.fluid.RealState.from_fluid_name('Air')
>>> So1.set_P_T(16e5, 1600.)
RealState(Air, P=16.000 bar, T=1600.0 K)
>>> print('cp = %.1f kJ/kg' % So1.cp)
cp = 1220.9 kJ/kg
>>> print('ga = %.3f' % So1.gamma)
ga = 1.308
>>> S1 = So1.to_static(Ma=0.6)
>>> print('P1 = %.3e' % S1.P)
P1 = 1.271e+06
Initialise states for both perfect air and steam, then calculate the work required for an isentropic compression:
>>> S_water = turbigen.fluid.RealState.from_fluid_name('water')
>>> S_air = turbigen.fluid.PerfectState.from_properties(
... cp=1005.,gamma=1.4, mu=1.8e-4
... )
>>> PR = 3.
>>> for S1 in (S_water, S_air):
... S1.set_P_T(1e5, 300.)
... S2 = S1.copy().set_P_s(S1.P * PR, S1.s)
... print(f'wx12 = {(S2.h-S1.h)/1e3:.2f} kJ/kg')
RealState(water, P=1.000 bar, T=300.0 K)
wx12 = 0.20 kJ/kg
PerfectState(P=1.000 bar, T=300.0 K)
wx12 = 111.17 kJ/kg
Array states are also supported, by passing a shape tuple on initialisation. Broadcasting input values, and read-only iterating and slicing work:
>>> import turbigen.fluid
>>> S = turbigen.fluid.RealState.from_fluid_name('water', shape=(3,))
>>> S.set_P_T(1e5, [400., 500., 800])
RealState(water, P=[1. 1. 1.] bar, T=[400. 500. 800.] K)
>>> print(S.rho)
[0.54760542 0.43514008 0.27102399]
>>> for Si in S[1:]:
... print(Si)
RealState(water, P=1.000 bar, T=500.0 K)
RealState(water, P=1.000 bar, T=800.0 K)
Property attributes¶
The state classes expose the following thermodynamic and fluid properties as attributes:
Attribute |
Property |
Units |
---|---|---|
a |
Acoustic Speed |
m/s |
cp |
Specific heat capacity at constant pressure |
J/kg/K |
cv |
Specific heat capacity at constant volume |
J/kg/K |
gamma |
Ratio of specific heats |
|
h |
Specific enthalpy |
J/kg |
mu |
Dynamic viscosity |
kg/m/s |
P |
Pressure |
Pa |
Pr |
Prandtl number |
|
rgas |
Specific gas constant |
J/kg/K |
rho |
Mass density |
kg/m^3 |
s |
Specific entropy |
J/kg/K |
T |
Temperature |
K |
u |
Specific internal energy |
J/kg |
Setting methods¶
The state classes expose the following methods to specify the thermodynamic state, each taking two properties as arguments:
Method |
Properties specified |
---|---|
set_P_T(P,T) |
Pressure, temperature |
set_P_s(P,s) |
Pressure, entropy |
set_h_s(h,s) |
Enthalpy, entropy |
set_T_s(T,s) |
Temperature, entropy |
set_P_h(P,h) |
Enthalpy, entropy |
set_rho_u(rho,u) |
Density, internal energy |
set_rho_s(rho,s) |
Density, entropy |
Static/stagnation methods¶
Consider the problem of converting between static and stagnation conditions at a given Mach number \(\Ma=V/a\). If static conditions are known, it is straightforward to use Mach number and acoustic speed to evaluate velocity and hence enthalpy of the stagnation state; an ideal stagnation is an isentropic process, so static and stagnation states have the same entropy. The reverse problem, where static conditions must be found for known stagnation conditions, in general requires iteration because acoustic speed is unknown a-priori.
The state classes have two methods to streamline these conversions:
to_stagnation(Ma) returns a State object for stagnation conditions
to_static(Ma) returns a State object for static conditions
Constructor methods¶
- class PerfectState(shape=(), order='C', typ=<class 'numpy.float64'>)[source]¶
Thermodynamic properties from perfect gas equations of state.
- classmethod from_properties(cp, gamma, mu, shape=(), Pr=0.72)[source]¶
Create a state for a perfect gas with specified properties.
- Parameters:
cp (float) – Specific heat capacity at constant pressure [J/kg/K]
gamma (float) – Ratio of specific heats [–].
mu (float) – Kinematic viscosity [kg/m/s].
shape (tuple) – Specify a tuple to allocate an array of states; defaults to scalar.
Pr (float) – Prandtl number [–], default to room-temperature air.
- class RealState(shape=(), order='C', typ=<class 'numpy.float64'>)[source]¶
Thermodynamic properties for a real fluid using table lookups.
- classmethod from_fluid_name(fluid_name, shape=())[source]¶
Create a state for a particular real working fluid.
- Parameters:
fluid_name (str) – Name of the fluid in the CoolProp nomenclature.
shape (tuple) – Specify a tuple to allocate an array of states; defaults to scalar.