Redlich Kwong
In [17]:
Copied!
## Redlich_Kwong Equation - for Mixtures
import pandas as pd
import numpy as np
from pvtpy.compositional import Chromatography, Component, properties_df
from pvtpy.units import Pressure, Temperature
## Redlich_Kwong Equation - for Mixtures
import pandas as pd
import numpy as np
from pvtpy.compositional import Chromatography, Component, properties_df
from pvtpy.units import Pressure, Temperature
Liquid Hydrocarbon Mixture¶
In [18]:
Copied!
d1 = {
'comp': ['methane','ethane','propane','butane','pentane','n-hexane'],
'mole_fraction':[0.45,0.05,0.05,0.03,0.01,0.01]
}
c7_plus = Component(
name = 'C7+',
molecular_weight=215,
mole_fraction=0.4,
critical_pressure=285,
critical_pressure_unit='psi',
critical_temperature=1287,
critical_temperature_unit='rankine',
)
ch1 = Chromatography()
ch1.from_df(pd.DataFrame(d1),name='comp')
ch1.plus_fraction = c7_plus
ch1.df()['mole_fraction']
d1 = {
'comp': ['methane','ethane','propane','butane','pentane','n-hexane'],
'mole_fraction':[0.45,0.05,0.05,0.03,0.01,0.01]
}
c7_plus = Component(
name = 'C7+',
molecular_weight=215,
mole_fraction=0.4,
critical_pressure=285,
critical_pressure_unit='psi',
critical_temperature=1287,
critical_temperature_unit='rankine',
)
ch1 = Chromatography()
ch1.from_df(pd.DataFrame(d1),name='comp')
ch1.plus_fraction = c7_plus
ch1.df()['mole_fraction']
Out[18]:
methane 0.45 ethane 0.05 propane 0.05 butane 0.03 pentane 0.01 n-hexane 0.01 C7+ 0.40 Name: mole_fraction, dtype: float64
In [19]:
Copied!
ch1.redlich_kwong_components_coef()
ch1.df(columns=['mole_fraction','rk_a','rk_b'])
ch1.redlich_kwong_components_coef()
ch1.df(columns=['mole_fraction','rk_a','rk_b'])
Out[19]:
mole_fraction | rk_a | rk_b | |
---|---|---|---|
methane | 0.45 | 1.609183e+05 | 0.478495 |
ethane | 0.05 | 4.932760e+05 | 0.723177 |
propane | 0.05 | 9.136286e+05 | 1.004698 |
butane | 0.03 | 1.448218e+06 | 1.292135 |
pentane | 0.01 | 2.093616e+06 | 1.608655 |
n-hexane | 0.01 | 2.839364e+06 | 1.943280 |
C7+ | 0.40 | 1.026140e+07 | 4.198091 |
In [20]:
Copied!
ch1.redlich_kwong_mix_coef()
ch1.redlich_kwong_mix_coef()
Out[20]:
(2599136.1341489274, 2.0552362922703455)
In [21]:
Copied!
p1 = Pressure(value = 4000, unit='psi')
t1 = Temperature(value = 160, unit='farenheit')
ma = ch1.apparent_molecular_weight()
ma
p1 = Pressure(value = 4000, unit='psi')
t1 = Temperature(value = 160, unit='farenheit')
ma = ch1.apparent_molecular_weight()
ma
Out[21]:
100.264435
In [22]:
Copied!
df1 = ch1.df(columns=['mole_fraction','molecular_weight'])
print(df1)
df1 = ch1.df(columns=['mole_fraction','molecular_weight'])
print(df1)
mole_fraction molecular_weight methane 0.45 16.0425 ethane 0.05 30.0700 propane 0.05 44.0970 butane 0.03 58.1230 pentane 0.01 73.1500 n-hexane 0.01 86.1770 C7+ 0.40 215.0000
In [23]:
Copied!
A,B = ch1.redlich_kwong.coef_AB(p1,t1)
print(A,B)
A,B = ch1.redlich_kwong.coef_AB(p1,t1)
print(A,B)
9.446879948552613 1.2364072939404886
In [24]:
Copied!
poly = ch1.redlich_kwong.cubic_poly(p1,t1)
print(type(poly))
print(poly)
poly = ch1.redlich_kwong.cubic_poly(p1,t1)
print(type(poly))
print(poly)
<class 'numpy.polynomial.polynomial.Polynomial'> -11.6801912733706 + 6.681769658102883·x¹ - 1.0·x² + 1.0·x³
In [25]:
Copied!
roots = poly.roots()
roots[np.isreal(roots)].real
roots = poly.roots()
roots[np.isreal(roots)].real
Out[25]:
array([1.55019215])
In [26]:
Copied!
ch1.redlich_kwong.estimate_densities(p1,t1, ma)
ch1.redlich_kwong.estimate_densities(p1,t1, ma)
Out[26]:
{'rho': array([38.90999504])}
Gas Hydrocarbon Mixture¶
In [27]:
Copied!
d2 = {
'comp': ['methane','ethane','propane','butane','pentane','n-hexane'],
'mole_fraction':[0.86,0.05,0.05,0.02,0.01,0.005]
}
c7_plus2 = Component(
name = 'C7+',
molecular_weight=215,
mole_fraction=0.005,
critical_pressure=285,
critical_pressure_unit='psi',
critical_temperature=1287,
critical_temperature_unit='rankine'
)
ch2 = Chromatography()
ch2.from_df(pd.DataFrame(d2),name='comp')
ch2.plus_fraction = c7_plus2
ch2.df(columns=['mole_fraction'], normalize=False)
d2 = {
'comp': ['methane','ethane','propane','butane','pentane','n-hexane'],
'mole_fraction':[0.86,0.05,0.05,0.02,0.01,0.005]
}
c7_plus2 = Component(
name = 'C7+',
molecular_weight=215,
mole_fraction=0.005,
critical_pressure=285,
critical_pressure_unit='psi',
critical_temperature=1287,
critical_temperature_unit='rankine'
)
ch2 = Chromatography()
ch2.from_df(pd.DataFrame(d2),name='comp')
ch2.plus_fraction = c7_plus2
ch2.df(columns=['mole_fraction'], normalize=False)
Out[27]:
mole_fraction | |
---|---|
methane | 0.860 |
ethane | 0.050 |
propane | 0.050 |
butane | 0.020 |
pentane | 0.010 |
n-hexane | 0.005 |
C7+ | 0.005 |
In [28]:
Copied!
ch2.redlich_kwong_components_coef()
ch2.df(columns=['mole_fraction','rk_a','rk_b'])
ch2.redlich_kwong_components_coef()
ch2.df(columns=['mole_fraction','rk_a','rk_b'])
Out[28]:
mole_fraction | rk_a | rk_b | |
---|---|---|---|
methane | 0.860 | 1.609183e+05 | 0.478495 |
ethane | 0.050 | 4.932760e+05 | 0.723177 |
propane | 0.050 | 9.136286e+05 | 1.004698 |
butane | 0.020 | 1.448218e+06 | 1.292135 |
pentane | 0.010 | 2.093616e+06 | 1.608655 |
n-hexane | 0.005 | 2.839364e+06 | 1.943280 |
C7+ | 0.005 | 1.026140e+07 | 4.198091 |
In [29]:
Copied!
ma2 = ch2.apparent_molecular_weight()
ma2
ma2 = ch2.apparent_molecular_weight()
ma2
Out[29]:
20.904745
In [30]:
Copied!
ch2.redlich_kwong_mix_coef()
ch2.redlich_kwong_mix_coef()
Out[30]:
(240957.42827545686, 0.570535481591962)
In [ ]:
Copied!
In [31]:
Copied!
p2 = Pressure(value = 4000, unit='psi')
t2 = Temperature(value = 160, unit='farenheit')
ch2.redlich_kwong.estimate_densities(p2,t2, ma2)
p2 = Pressure(value = 4000, unit='psi')
t2 = Temperature(value = 160, unit='farenheit')
ch2.redlich_kwong.estimate_densities(p2,t2, ma2)
Out[31]:
{'rho': array([13.85246264])}
In [32]:
Copied!
ch2.redlich_kwong.cubic_poly(p2,t2)
ch2.redlich_kwong.cubic_poly(p2,t2)
Out[32]:
$x \mapsto \text{-0.3005952718766425} + \text{0.4147562859938712}\,x - \text{1.0}\,x^{2} + \text{1.0}\,x^{3}$
In [ ]:
Copied!