"""
Simple unit conversion module.
Some basic conversions for length and temperature.
"""
ft_to_m = 0.3048
m_to_ft = 3.28084
ft_to_in = 12.0
in_to_ft = 1.0/12.0
mi_to_ft = 5280.0
ft_to_mi = 1.0/5280.0
in_to_mi = 1.0/12.0/5280.0
mi_to_in = 5280.0*12.0
m_to_km = 0.001
m_to_dm = 10.0
m_to_cm = 100.0
m_to_mm = 1000.0
m_to_um = 1.0E6 # m to micrometers
def K_to_C(T_K) :
return T_K - 278.15
def C_to_K(T_C) :
return T_C + 278.15
def F_to_C(T_F) :
return (T_F - 32.0)/1.8
def C_to_F(T_C) :
return T_C*1.8 + 32.0
__init__
function, and then include an appropriate __init__
function.
The heat capacity and enthalpy for ideal gas species are given as $$ \frac{c_p}{R_g} = a_0 + a_1T+a_2T^2 + a_3T^3+a_4T^4 $$ $$\frac{h}{R_gT} = a_0 + \frac{a_1}{2}T + \frac{a_2}{3}T^2 + \frac{a_3}{4}T^3 + \frac{a_4}{5}T^4 + \frac{a_5}{T}$$
We want to make a class that can give us $c_p$ and $h$ for a given species.
thermo
.spName
, Rgas
, Tlo
, Tmid
, and Thi
.cp
and h
that compute and return the heat capacity (J/kmol*K) and enthalpy (J/kmol), respectively, according to the above equations.self.Rgas
and you can access the $a$ coefficients as self.a_lo[0]
.__init__
function below, I set s=self
. If you do this in your functions, then you can use s.Rgas
and s.a_lo
or s.a_lo[0]
, etc.import yaml
class thermo():
def __init__(self, species_name):
s = self # typing self. is annoying, now we can type s. instead
s.spName = species_name # store the species name
s.Rgas = 8314.46 # J/kmol*K
yfile = yaml.safe_load(open("thermoData.yaml"))
s.a_lo = yfile[species_name]["a_lo"] # get low T a coeffs for given species
s.a_hi = yfile[species_name]["a_hi"] # get high T a coeffs for given species
s.Tlo = 300
s.Tmid = 1000
s.Thi = 3000
#--------------------------------------
#--------------------------------------
co2 = thermo("CO2")
h2o = thermo("H2O")
co2.cp(700)
co2 = thermo("CO2")