Submodules

Fluid

class pythermophy.fluid.Fluid(name, M, Tc, pc, acentric, cp_coeffs)

Bases: object

Class for representing the fluid you want to study.

Parameters:
  • name (str) – name of the fluid
  • M (float) – molar mass of the fluid (kg/mol)
  • Tc (float) – critical temperature of the fluid (K)
  • pc (float) – critical pressure of the fluid (Pa)
  • acentric (float) – acentric factor of the fluid (dimensionless)
  • cp_coeffs (list(float)) – coefficients of the ideal gas isobaric heat capacity polynomial [a,b,c,d] c_p = a + bT + cT^2 + dT^3 (c_p in J/mol/K)
classmethod init_from_file(filename)

Creates a new Fluid instance by reading parameters from an input file.

The input file must be a yaml file in the following format:

name: CO2   # Name of the fluid
molar_mass: 44.01e-3    # Molar mass [kg/mol]
T_crit: 304.25  # Critical temperature [K]
p_crit: 7.38e+6 # Critical pressure [Pa]
acentric: 0.228 # Acentric factor [dimensionless]
ideal_cp_coeffs: [22.26, 5.981e-2, -3.501e-5, 7.469e-9] # Cp = a + b*T + c*T^2 + d*T^3 [J/mol/K]
Parameters:filename (str) – input file
is_valid()

Checks if the Fluid instance is valid by ensuring that all the parameters of the object are of the correct type.

Returns:True if valid. False otherwise.
Return type:bool
save_to_file(filename)

Saves the Fluid instance to a yaml file which can later be fed to init_from_file().

Parameters:filename (str) – output file

Parent EOS

class pythermophy.parent_class.EOS(fluid)

Bases: object

The parent equation of state (EOS) class. All the other EOS classes are derived from this.

Parameters:fluid – a Fluid instance
Returns:a EOS instance
R = 8.3144598
get_Z(T, p)

Returns the compressibility factor of the fluid.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

compressibility factor

Return type:

float

get_adiabatic_index(T, p, **kwargs)

Returns the adiabatic index (ratio between isobaric and isochoric heat capacities) for a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

adiabatic index (dimensionless)

Return type:

float

get_cp(T, p, **kwargs)

Returns the real gas isobaric specific heat capacity (c_p) in J/mol/K.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

isobaric specific heat capacity (J/mol/K)

Return type:

float

get_cv(T, p, **kwargs)

Returns the real gas isochoric specific heat capacity (c_v) in J/mol/K.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

isochoric specific heat capacity (J/mol/K)

Return type:

float

get_departure_cp(T, p)

Returns the departure (difference between real gas and ideal gas) of isobaric specific heat capacity (c_p) in J/mol/K.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

departure for isobaric specific heat capacity (J/mol/K)

Return type:

float

get_departure_cv(T, p)

Returns the departure (difference between real gas and ideal gas) of isochoric specific heat capacity (c_v) in J/mol/K.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

departure for isochoric specific heat capacity (J/mol/K)

Return type:

float

get_ideal_cp(T)

Returns the ideal gas isobaric specific heat capacity (c_p^0) in J/mol/K. See http://www.wiley.com/college/moran/CL_0471465704_S/user/tables/TABLE3S/table3sframe.html

Parameters:T (float) – temperature (K)
Returns:ideal gas isobaric specific heat capacity (J/mol/K)
Return type:float
get_ideal_cv(T)

Returns the ideal gas isochoric specific heat capacity (c_v^0) in J/mol/K.

Parameters:T (float) – temperature (K)
Returns:ideal gas isochoric specific heat capacity (J/mol/K)
Return type:float
get_rho(T, p, **kwargs)

Returns the density of the fluid.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
get_speed_of_sound(T, p, **kwargs)

Returns the speed of sound in a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

speed of sound (m/s)

Return type:

float

Ideal Gas EOS

class pythermophy.ideal_gas.IdealGas(fluid)

Bases: pythermophy.parent_class.EOS

Ideal gas equation of state.

Parameters:fluid – a Fluid instance
Returns:an equation of state (EOS) instance
get_isothermal_compressibility(T, p, **kwargs)

Returns the isothermal compressibility of an ideal gas

Parameters:
  • T (float) – temperature (K) [only required for consistency with the same function for other classes; not used in computation]
  • p (float) – pressure (Pa)
Returns:

isothermal compressibility (1/Pa)

Return type:

float

Parent Cubic EOS

class pythermophy.cubic_parent.CubicEOS(b, c, d, e, fluid)

Bases: pythermophy.parent_class.EOS

Parent class from which other cubic equations of state are derived.

The equation of state is expressed as:

p = \frac{RT}{v - b + c} - \frac{a(T)}{v^2 + dv + e}

where (p, v, T) are the pressure, specific volume, and temperature respectively. R is the specific gas constant, and (a(T), b,
c, d, e) are the coefficients of the cubic equation of state.

Parameters:
  • b (float) – coefficient b
  • c (float) – coefficient c
  • d (float) – coefficient d
  • e (float) – coefficient e
  • fluid – a Fluid instance
Returns:

a EOS instance

get_A(T, p)

Returns the coefficient A of the cubic polynomial of compressiblity factor given by Z^3 + A Z^2 + B Z + C = 0.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

A

Return type:

float

get_B(T, p)

Returns the coefficient B of the cubic polynomial of compressiblity factor given by Z^3 + A Z^2 + B Z + C = 0.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

B

Return type:

float

get_C(T, p)

Returns the coefficient C of the cubic polynomial of compressiblity factor given by Z^3 + A Z^2 + B Z + C = 0.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

C

Return type:

float

get_Z(T, p)

Returns the compressibility factor of a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

compressibility factor

Return type:

float

get_a(T)

Returns the temperature dependent coefficient a(T).

Function should be redefined in the child class.

get_departure_cp(T, p, **kwargs)

Returns the departure (difference between real gas and ideal gas) of isobaric specific heat capacity c_p (J/mol/K)

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
  • Z (float) – (optional kwarg) compressibility factor at (T, p). Computed by get_Z() if not provided.
Returns:

departure of isobaric specific heat capacity (J/mol/K)

Return type:

float

get_departure_cv(T, p, **kwargs)

Returns the departure (difference between real gas and ideal gas) for isochoric specific heat capacity (c_v) in J/mol/K.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
  • Z (float) – (optional kwarg) compressibility factor at (T, p). Computed by get_Z() if not provided.
Returns:

departure of isochoric specific heat capacity (J/mol/K)

Return type:

float

get_diff_a_T(T)

Returns the derivative of coefficient a(T) wrt. temperature T.

Function should be redefined in the child class.

get_double_diff_a_T(T)

Returns the second derivative of coefficient a(T) wrt. temperature T.

Function should be redefined in the child class.

get_isothermal_compressibility(T, p, **kwargs)

Returns the isothermal compressibility of a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

isothermal compressibility (1/Pa)

Return type:

float

get_pdiff_A_T_p(T, p)

Returns the partial derivative of coefficient A wrt. T at constant p.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_A_p_T(T, p)

Returns the partial derivative of coefficient A wrt. p at constant T.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_B_T_p(T, p)

Returns the partial derivative of coefficient B wrt. T at constant p.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_B_p_T(T, p)

Returns the partial derivative of coefficient B wrt. p at constant T.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_C_T_p(T, p)

Returns the partial derivative of coefficient C wrt. T at constant p.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_C_p_T(T, p)

Returns the partial derivative of coefficient C wrt. p at constant T.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Return type:

float

get_pdiff_Z_T_p(T, p, **kwargs)

Returns the partial derivative of Z wrt. T at constant p.

Parameters:
  • T (float) – temperature (K)
  • p – pressure (Pa)
  • Z (float) – (optional kwarg) compressibility factor at (T, p). Computed by get_Z() if not provided.
Return type:

float

get_pdiff_Z_p_T(T, p, **kwargs)

Returns the partial derivative of Z wrt. p at constant T.

Parameters:
  • T (float) – temperature (K)
  • p – pressure (Pa)
  • Z (float) – (optional kwarg) compressibility factor at (T, p). Computed by get_Z() if not provided.
Return type:

float

Cubic EOS

class pythermophy.cubic_eos.PengRobinson(fluid)

Bases: pythermophy.cubic_parent.CubicEOS

Peng-Robinson equation of state. For details see: https://www.e-education.psu.edu/png520/m11_p2.html

Parameters:fluid – a Fluid instance
Returns:an EOS instance
get_a(T)

Returns the temperature dependent coefficient a(T).

get_diff_a_T(T)

Returns the derivative of coefficient a(T) wrt. temperature T.

get_double_diff_a_T(T)

Returns the second derivative of coefficient a(T) wrt. temperature T.

class pythermophy.cubic_eos.RedlichKwong(fluid)

Bases: pythermophy.cubic_parent.CubicEOS

Redlich-Kwong equation of state. For details see https://www.e-education.psu.edu/png520/m10_p4.html

Parameters:fluid – a Fluid instance
Returns:an EOS instance
get_a(T)

Returns the temperature dependent coefficient a(T).

get_diff_a_T(T)

Returns the derivative of coefficient a(T) wrt. temperature T.

get_double_diff_a_T(T)

Returns the second derivative of coefficient a(T) wrt. temperature T.

class pythermophy.cubic_eos.SoaveRedlichKwong(fluid)

Bases: pythermophy.cubic_parent.CubicEOS

Soave-Redlich-Kwong equation of state. For details see: https://www.e-education.psu.edu/png520/m10_p5.html

Parameters:fluid – a Fluid instance
Returns:an EOS instance
get_a(T)

Returns the temperature dependent coefficient a(T).

get_diff_a_T(T)

Returns the derivative of coefficient a(T) wrt. temperature T.

get_double_diff_a_T(T)

Returns the second derivative of coefficient a(T) wrt. temperature T.

Lee-Kesler EOS

class pythermophy.lee_kesler.LeeKesler(fluid)

Bases: pythermophy.parent_class.EOS

Lee-Kesler equation of state.

Parameters:fluid – a Fluid instance
Returns:a EOS instance
acentric_r = 0.3978
b1 = [0.1181193, 0.2026579]
b2 = [0.265728, 0.331511]
b3 = [0.15479, 0.027655]
b4 = [0.030323, 0.203488]
beta = [0.65392, 1.226]
c1 = [0.0236744, 0.0313385]
c2 = [0.0186984, 0.0503618]
c3 = [0.0, 0.016901]
c4 = [0.042724, 0.041577]
d1 = [1.55488e-05, 4.8736e-05]
d2 = [6.23689e-05, 7.40336e-06]
gamma = [0.060167, 0.03754]
get_B(Tr, fluid)

Returns B(T_r) = b_1 - b_2/T_r - b_3/T_r^2 - b_4/T_r^3.

Parameters:
  • Tr (float) – reduced temperature (T_r = T/T_c)
  • fluid (str) – specifies if the fluid is simple or reference
Returns:

B(T_r)

Return type:

float

get_C(Tr, fluid)

Returns C(T_r) = c_1 - c_2/T_r + c_3/T_r^3.

Parameters:
  • Tr (float) – reduced temperature (T_r = T/T_c)
  • fluid (str) – specifies if the fluid is simple or reference
Returns:

C(T_r)

Return type:

float

get_D(Tr, fluid)

Returns D(T_r) = d_1 + c_2/T_r.

Parameters:
  • Tr (float) – reduced temperature (T_r = T/T_c)
  • fluid (str) – specifies if the fluid is simple or reference
Returns:

D(T_r)

Return type:

float

get_Z(T, p, **kwargs)

Returns the compressibility factor of a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
  • init_vol (list(float)) – (optional kwarg) initial guess for reduced volumes of ideal and reference fluids to be used in the nonlinear equation solver in get_reduced_volume(). Should be a list [v0, vr], where v0 is the inital guess for the simple fluid, and vr is the initial guess for the reference fluid.
Returns:

compressibility factor

Return type:

float

get_departure_cp(T, p)

Returns the departure (difference between real gas and ideal gas) of isobaric specific heat capacity c_p (J/mol/K)

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

departure of isobaric specific heat capacity (J/mol/K)

Return type:

float

get_departure_cp_aux(Tr, pr, fluid)

Auxiliary function used by get_departure_cp().

Computes the departure in isobaric specific heat capacity for simple and reference fluids.

Parameters:
  • Tr (float) – reduced temperature
  • pr (float) – reduced pressure
  • fluid (str) – specifices if the fluid is simple or reference
get_departure_cv(T, p)

Returns the departure (difference between real gas and ideal gas) of isochoric specific heat capacity c_v (J/mol/K)

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

departure of isochoric specific heat capacity (J/mol/K)

Return type:

float

get_departure_cv_aux(Tr, pr, fluid, **kwargs)

Auxiliary function used by get_departure_cv().

Computes the departure in isochoric specific heat capacity for simple and reference fluids.

Parameters:
  • Tr (float) – reduced temperature
  • pr (float) – reduced pressure
  • fluid (str) – specifices if the fluid is simple or reference
  • Vr (float) – (optional kwarg) reduced volume at (Tr, pr). If not provided, get_reduced_volume() is used to compute it.
get_isothermal_compressibility(T, p)

Returns the isothermal compressibility of a real gas.

Parameters:
  • T (float) – temperature (K)
  • p (float) – pressure (Pa)
Returns:

isothermal compressibility (1/Pa)

Return type:

float

get_pdiff_pr_Tr_Vr(Tr, Vr, fluid)

Returns the partial derivative of p_r wrt. T_r at constant v_r.

Parameters:
  • Tr (float) – reduced temperature
  • Vr (float) – reduced volume
  • fluid (str) – specifices if the fluid is simple or reference
Return type:

float

get_pdiff_pr_Vr_Tr(Tr, Vr, fluid)

Returns the partial derivative of p_r wrt. V_r at constant T_r.

Parameters:
  • Tr (float) – reduced temperature
  • Vr (float) – reduced volume
  • fluid (str) – specifices if the fluid is simple or reference
Return type:

float

get_reduced_volume(Tr, pr, fluid, **kwargs)

Returns the reduced volume v_r.

This is done by solving the following nonlinear equation:

\frac{p_r v_r}{T_r} = 1 + \frac{B(T_r)}{v_r} + \frac{C(T_r)}{v_r^2}
+ \frac{D(T_r)}{v_r^5} + \frac{c_4}{T_r^3 v_r^2}
(\beta + \frac{\gamma}{v_r^2}) \exp(-\frac{\gamma}{v_r^2})

Parameters:
  • Tr (float) – reduced temperature (T_r = T/T_c)
  • pr (float) – reduced pressure (p_r = p/p_c)
  • fluid (str) – specifies if the fluid is simple or reference
  • init_vol (float) – (optional kwarg) initial guess for reduced volume to be used in the nonlinear solver
Returns:

reduced volume

Return type:

float