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] ( 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 toinit_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
instanceReturns: 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 () 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 () 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 () 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 () 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 () 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 () 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
instanceReturns: 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:
where are the pressure, specific volume, and temperature respectively. is the specific gas constant, and are the coefficients of the cubic equation of state.
Parameters: - b (float) – coefficient
- c (float) – coefficient
- d (float) – coefficient
- e (float) – coefficient
- fluid – a
Fluid
instance
Returns: a
EOS
instance-
get_A
(T, p)¶ Returns the coefficient of the cubic polynomial of compressiblity factor given by .
Parameters: - T (float) – temperature (K)
- p (float) – pressure (Pa)
Returns: Return type: float
-
get_B
(T, p)¶ Returns the coefficient of the cubic polynomial of compressiblity factor given by .
Parameters: - T (float) – temperature (K)
- p (float) – pressure (Pa)
Returns: Return type: float
-
get_C
(T, p)¶ Returns the coefficient of the cubic polynomial of compressiblity factor given by .
Parameters: - T (float) – temperature (K)
- p (float) – pressure (Pa)
Returns: 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 .
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 (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 () 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 wrt. temperature .
Function should be redefined in the child class.
-
get_double_diff_a_T
(T)¶ Returns the second derivative of coefficient wrt. temperature .
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 wrt. at constant .
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 wrt. at constant .
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 wrt. at constant .
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 wrt. at constant .
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 wrt. at constant .
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 wrt. at constant .
Parameters: - T (float) – temperature (K)
- p (float) – pressure (Pa)
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
instanceReturns: an EOS
instance-
get_a
(T)¶ Returns the temperature dependent coefficient .
-
get_diff_a_T
(T)¶ Returns the derivative of coefficient wrt. temperature .
-
get_double_diff_a_T
(T)¶ Returns the second derivative of coefficient wrt. temperature .
-
-
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
instanceReturns: an EOS
instance-
get_a
(T)¶ Returns the temperature dependent coefficient .
-
get_diff_a_T
(T)¶ Returns the derivative of coefficient wrt. temperature .
-
get_double_diff_a_T
(T)¶ Returns the second derivative of coefficient wrt. temperature .
-
-
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
instanceReturns: an EOS
instance-
get_a
(T)¶ Returns the temperature dependent coefficient .
-
get_diff_a_T
(T)¶ Returns the derivative of coefficient wrt. temperature .
-
get_double_diff_a_T
(T)¶ Returns the second derivative of coefficient wrt. temperature .
-
Lee-Kesler EOS¶
-
class
pythermophy.lee_kesler.
LeeKesler
(fluid)¶ Bases:
pythermophy.parent_class.EOS
Lee-Kesler equation of state.
Parameters: fluid – a Fluid
instanceReturns: 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 .
Parameters: - Tr (float) – reduced temperature ()
- fluid (str) – specifies if the fluid is simple or reference
Returns: Return type: float
-
get_C
(Tr, fluid)¶ Returns .
Parameters: - Tr (float) – reduced temperature ()
- fluid (str) – specifies if the fluid is simple or reference
Returns: Return type: float
-
get_D
(Tr, fluid)¶ Returns .
Parameters: - Tr (float) – reduced temperature ()
- fluid (str) – specifies if the fluid is simple or reference
Returns: 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 (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 (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 wrt. at constant .
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 wrt. at constant .
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 .
This is done by solving the following nonlinear equation:
Parameters: - Tr (float) – reduced temperature ()
- pr (float) – reduced pressure ()
- 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
-