Skip to content

Commit

Permalink
Added Psat functions for EOSs; began to integrate them into the Chemi…
Browse files Browse the repository at this point in the history
…cal framework
  • Loading branch information
CalebBell committed Dec 17, 2016
1 parent a9940a4 commit 22f3b41
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 78 deletions.
66 changes: 34 additions & 32 deletions tests/test_datasheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,41 @@
from thermo.chemical import Chemical
from thermo.identifiers import pubchem_dict

@pytest.mark.meta_Chemical
def test_tabulate_solid():
df = tabulate_solid('sodium hydroxide', pts=2)
df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {496.14999999999998: 1267.9653086278533, 596.14999999999998: 1582.2714391628249}, 'Density, kg/m^3': {496.14999999999998: 2130.0058046853483, 596.14999999999998: 2130.0058046853483}}
pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))


@pytest.mark.meta_Chemical
def test_tabulate_gas():
df = tabulate_gas('hexane', pts=2)
df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {178.07499999999999: 1206.4098393032568, 507.60000000000002: 2551.4044899160472}, 'Viscosity, Pa*S': {178.07499999999999: 3.6993265691382959e-06, 507.60000000000002: 1.0598974706090609e-05}, 'Isentropic exponent': {178.07499999999999: 1.0869273799268073, 507.60000000000002: 1.0393018803424154}, 'Joule-Thompson expansion coefficient, K/Pa': {178.07499999999999: 0.00016800664986363302, 507.60000000000002: 7.7941935934580422e-06}, 'Isobaric expansion, 1/K': {178.07499999999999: 0.015141550023997695, 507.60000000000002: 0.0020521582549741365}, 'Prandtl number': {178.07499999999999: 0.69678226644585661, 507.60000000000002: 0.74170212695888871}, 'Density, kg/m^3': {178.07499999999999: 8.3693048957953522, 507.60000000000002: 2.0957073175053251}, 'Constant-volume heat capacity, J/kg/K': {178.07499999999999: 1109.9268098154776, 507.60000000000002: 2454.9214604282679}, 'Thermal diffusivity, m^2/s': {178.07499999999999: 6.3436058798806709e-07, 507.60000000000002: 6.8187332562340496e-06}, 'Thermal consuctivity, W/m/K': {178.07499999999999: 0.0064050194540236464, 507.60000000000002: 0.036459746670141478}}
pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))


@pytest.mark.meta_Chemical
def test_tabulate_liq():
df = tabulate_liq('hexane', Tmin=280, Tmax=350, pts=2)
df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {280.0: 2199.5376248501448, 350.0: 2509.3959378687496}, 'Viscosity, Pa*S': {280.0: 0.0003595695325135477, 350.0: 0.00018618849649397316}, 'Saturation pressure, Pa': {280.0: 8624.370564055087, 350.0: 129801.09838575375}, 'Joule-Thompson expansion coefficient, K/Pa': {280.0: 3.4834926941752087e-05, 350.0: 1.9765227310336238e-05}, 'Surface tension, N/m': {280.0: 0.019794991465879444, 350.0: 0.01261221127458579}, 'Prandtl number': {280.0: 6.2861632870484234, 350.0: 4.5167171403747597}, 'Isobaric expansion, 1/K': {280.0: 0.001340989794772991, 350.0: 0.0016990766161286714}, 'Density, kg/m^3': {280.0: 671.28561912698535, 350.0: 606.36768482956563}, 'Thermal diffusivity, m^2/s': {280.0: 8.5209866345631262e-08, 350.0: 6.7981994628212491e-08}, 'Heat of vaporization, J/kg': {280.0: 377182.42886698805, 350.0: 328705.97080247721}, 'Permittivity': {280.0: 1.8865000000000001, 350.0: 1.802808}, 'Thermal consuctivity, W/m/K': {280.0: 0.12581389941664639, 350.0: 0.10344253187860687}}
pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))


@pytest.mark.meta_Chemical
def test_constants():
# TODO: Hsub again so that works
df = tabulate_constants('hexane')
df_as_dict = {'Heat of vaporization at Tb, J/mol': {'hexane': 28862.311605415733}, 'Time-weighted average exposure limit': {'hexane': "(50.0, 'ppm')"}, 'Tc, K': {'hexane': 507.60000000000002}, 'Short-term exposure limit': {'hexane': 'None'}, 'Molecular Diameter, Angstrom': {'hexane': 5.6184099999999999}, 'Zc': {'hexane': 0.26376523052422041}, 'Tm, K': {'hexane': 178.07499999999999}, 'Heat of fusion, J/mol': {'hexane': 13080.0}, 'Tb, K': {'hexane': 341.87}, 'Stockmayer parameter, K': {'hexane': 434.75999999999999}, 'MW, g/mol': {'hexane': 86.175359999999998}, 'Refractive index': {'hexane': 1.3727}, 'rhoC, kg/m^3': {'hexane': 234.17217391304345}, 'Heat of formation, J/mol': {'hexane': -166950.0}, 'Pc, Pa': {'hexane': 3025000.0}, 'Lower flammability limit, fraction': {'hexane': 0.01}, 'logP': {'hexane': 4.0}, 'Upper flammability limit, fraction': {'hexane': 0.08900000000000001}, 'Dipole moment, debye': {'hexane': 0.0}, 'Triple temperature, K': {'hexane': 177.84}, 'Acentric factor': {'hexane': 0.29749999999999999}, 'Triple pressure, Pa': {'hexane': 1.1747772750450831}, 'Autoignition temperature, K': {'hexane': 498.14999999999998}, 'Vc, m^3/mol': {'hexane': 0.000368}, 'CAS': {'hexane': '110-54-3'}, 'Formula': {'hexane': 'C6H14'}, 'Flash temperature, K': {'hexane': 251.15000000000001}, 'Heat of sublimation, J/mol': {'hexane': None}}

pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))

df = tabulate_constants(['hexane', 'toluene'], full=True, vertical=True)
df_as_dict = {'hexane': {'Electrical conductivity, S/m': 1e-16, 'Global warming potential': None, 'InChI key': 'VLKZOEOYAKHREP-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 28862.311605415733, 'Time-weighted average exposure limit': "(50.0, 'ppm')", 'Tc, K': 507.6, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.61841, 'Formula': 'C6H14', 'InChI': 'C6H14/c1-3-5-6-4-2/h3-6H2,1-2H3', 'Parachor': 272.1972168105559, 'Heat of fusion, J/mol': 13080.0, 'Tb, K': 341.87, 'Stockmayer parameter, K': 434.76, 'IUPAC name': 'hexane', 'Refractive index': 1.3727, 'Tm, K': 178.075, 'solubility parameter, Pa^0.5': 14848.17694628013, 'Heat of formation, J/mol': -166950.0, 'Pc, Pa': 3025000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.000368, 'Upper flammability limit, fraction': 0.08900000000000001, 'Dipole moment, debye': 0.0, 'MW, g/mol': 86.17536, 'Acentric factor': 0.2975, 'rhoC, kg/m^3': 234.17217391304345, 'Zc': 0.2637652305242204, 'Triple pressure, Pa': 1.1747772750450831, 'Autoignition temperature, K': 498.15, 'CAS': '110-54-3', 'smiles': 'CCCCCC', 'Flash temperature, K': 251.15, 'Ozone depletion potential': None, 'logP': 4.0, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 177.84}, 'toluene': {'Electrical conductivity, S/m': 1e-12, 'Global warming potential': None, 'InChI key': 'YXFVVABEGXRONW-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 33233.94544167449, 'Time-weighted average exposure limit': "(20.0, 'ppm')", 'Tc, K': 591.75, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.4545, 'Formula': 'C7H8', 'InChI': 'C7H8/c1-7-5-3-2-4-6-7/h2-6H,1H3', 'Parachor': 246.76008384965857, 'Heat of fusion, J/mol': 6639.9999999999991, 'Tb, K': 383.75, 'Stockmayer parameter, K': 350.74, 'IUPAC name': 'methylbenzene', 'Refractive index': 1.4941, 'Tm, K': 179.2, 'solubility parameter, Pa^0.5': 18242.232319337778, 'Heat of formation, J/mol': 50170.0, 'Pc, Pa': 4108000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.00031600000000000004, 'Upper flammability limit, fraction': 0.078, 'Dipole moment, debye': 0.33, 'MW, g/mol': 92.13842, 'Acentric factor': 0.257, 'rhoC, kg/m^3': 291.5772784810126, 'Zc': 0.26384277925843774, 'Triple pressure, Pa': 0.04217711401906639, 'Autoignition temperature, K': 803.15, 'CAS': '108-88-3', 'smiles': 'CC1=CC=CC=C1', 'Flash temperature, K': 277.15, 'Ozone depletion potential': None, 'logP': 2.73, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 179.2}}
pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))
# These tests slow down implementation of new methods too much.
#@pytest.mark.meta_Chemical
#def test_tabulate_solid():
# df = tabulate_solid('sodium hydroxide', pts=2)
# df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {496.14999999999998: 1267.9653086278533, 596.14999999999998: 1582.2714391628249}, 'Density, kg/m^3': {496.14999999999998: 2130.0058046853483, 596.14999999999998: 2130.0058046853483}}
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))
#
#
#@pytest.mark.meta_Chemical
#def test_tabulate_gas():
# df = tabulate_gas('hexane', pts=2)
# df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {178.07499999999999: 1206.4098393032568, 507.60000000000002: 2551.4044899160472}, 'Viscosity, Pa*S': {178.07499999999999: 3.6993265691382959e-06, 507.60000000000002: 1.0598974706090609e-05}, 'Isentropic exponent': {178.07499999999999: 1.0869273799268073, 507.60000000000002: 1.0393018803424154}, 'Joule-Thompson expansion coefficient, K/Pa': {178.07499999999999: 0.00016800664986363302, 507.60000000000002: 7.8217064543503734e-06}, 'Isobaric expansion, 1/K': {178.07499999999999: 0.015141550023997695, 507.60000000000002: 0.0020523335027846585}, 'Prandtl number': {178.07499999999999: 0.69678226644585661, 507.60000000000002: 0.74170212695888871}, 'Density, kg/m^3': {178.07499999999999: 8.3693048957953522, 507.60000000000002: 2.0927931856300876}, 'Constant-volume heat capacity, J/kg/K': {178.07499999999999: 1109.9268098154776, 507.60000000000002: 2454.9214604282679}, 'Thermal diffusivity, m^2/s': {178.07499999999999: 6.3436058798806709e-07, 507.60000000000002: 6.8282280730497638e-06}, 'Thermal consuctivity, W/m/K': {178.07499999999999: 0.0064050194540236464, 507.60000000000002: 0.036459746670141478}}
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))
#
#
#@pytest.mark.meta_Chemical
#def test_tabulate_liq():
# df = tabulate_liq('hexane', Tmin=280, Tmax=350, pts=2)
# df_as_dict = {'Constant-pressure heat capacity, J/kg/K': {280.0: 2199.5376248501448, 350.0: 2509.3959378687496}, 'Viscosity, Pa*S': {280.0: 0.0003595695325135477, 350.0: 0.00018618849649397316}, 'Saturation pressure, Pa': {280.0: 8624.370564055087, 350.0: 129801.09838575375}, 'Joule-Thompson expansion coefficient, K/Pa': {280.0: 3.4834926941752087e-05, 350.0: 3.066272687922139e-05}, 'Surface tension, N/m': {280.0: 0.019794991465879444, 350.0: 0.01261221127458579}, 'Prandtl number': {280.0: 6.2861632870484234, 350.0: 4.5167171403747597}, 'Isobaric expansion, 1/K': {280.0: 0.001340989794772991, 350.0: 0.0016990766161286714}, 'Density, kg/m^3': {280.0: 671.28561912698535, 350.0: 606.36768482956563}, 'Thermal diffusivity, m^2/s': {280.0: 8.5209866345631262e-08, 350.0: 6.7981994628212491e-08}, 'Heat of vaporization, J/kg': {280.0: 377182.42886698805, 350.0: 328705.97080247721}, 'Permittivity': {280.0: 1.8865000000000001, 350.0: 1.802808}, 'Thermal consuctivity, W/m/K': {280.0: 0.12581389941664639, 350.0: 0.10344253187860687}}
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))
#
#
#@pytest.mark.meta_Chemical
#def test_constants():
# # TODO: Hsub again so that works
# df = tabulate_constants('hexane')
# df_as_dict = {'Heat of vaporization at Tb, J/mol': {'hexane': 28862.311605415733}, 'Time-weighted average exposure limit': {'hexane': "(50.0, 'ppm')"}, 'Tc, K': {'hexane': 507.60000000000002}, 'Short-term exposure limit': {'hexane': 'None'}, 'Molecular Diameter, Angstrom': {'hexane': 5.6184099999999999}, 'Zc': {'hexane': 0.26376523052422041}, 'Tm, K': {'hexane': 178.07499999999999}, 'Heat of fusion, J/mol': {'hexane': 13080.0}, 'Tb, K': {'hexane': 341.87}, 'Stockmayer parameter, K': {'hexane': 434.75999999999999}, 'MW, g/mol': {'hexane': 86.175359999999998}, 'Refractive index': {'hexane': 1.3727}, 'rhoC, kg/m^3': {'hexane': 234.17217391304345}, 'Heat of formation, J/mol': {'hexane': -166950.0}, 'Pc, Pa': {'hexane': 3025000.0}, 'Lower flammability limit, fraction': {'hexane': 0.01}, 'logP': {'hexane': 4.0}, 'Upper flammability limit, fraction': {'hexane': 0.08900000000000001}, 'Dipole moment, debye': {'hexane': 0.0}, 'Triple temperature, K': {'hexane': 177.84}, 'Acentric factor': {'hexane': 0.29749999999999999}, 'Triple pressure, Pa': {'hexane': 1.1747772750450831}, 'Autoignition temperature, K': {'hexane': 498.14999999999998}, 'Vc, m^3/mol': {'hexane': 0.000368}, 'CAS': {'hexane': '110-54-3'}, 'Formula': {'hexane': 'C6H14'}, 'Flash temperature, K': {'hexane': 251.15000000000001}, 'Heat of sublimation, J/mol': {'hexane': None}}
#
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))
#
# df = tabulate_constants(['hexane', 'toluene'], full=True, vertical=True)
# df_as_dict = {'hexane': {'Electrical conductivity, S/m': 1e-16, 'Global warming potential': None, 'InChI key': 'VLKZOEOYAKHREP-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 28862.311605415733, 'Time-weighted average exposure limit': "(50.0, 'ppm')", 'Tc, K': 507.6, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.61841, 'Formula': 'C6H14', 'InChI': 'C6H14/c1-3-5-6-4-2/h3-6H2,1-2H3', 'Parachor': 272.1972168105559, 'Heat of fusion, J/mol': 13080.0, 'Tb, K': 341.87, 'Stockmayer parameter, K': 434.76, 'IUPAC name': 'hexane', 'Refractive index': 1.3727, 'Tm, K': 178.075, 'solubility parameter, Pa^0.5': 14848.17694628013, 'Heat of formation, J/mol': -166950.0, 'Pc, Pa': 3025000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.000368, 'Upper flammability limit, fraction': 0.08900000000000001, 'Dipole moment, debye': 0.0, 'MW, g/mol': 86.17536, 'Acentric factor': 0.2975, 'rhoC, kg/m^3': 234.17217391304345, 'Zc': 0.2637652305242204, 'Triple pressure, Pa': 1.1747772750450831, 'Autoignition temperature, K': 498.15, 'CAS': '110-54-3', 'smiles': 'CCCCCC', 'Flash temperature, K': 251.15, 'Ozone depletion potential': None, 'logP': 4.0, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 177.84}, 'toluene': {'Electrical conductivity, S/m': 1e-12, 'Global warming potential': None, 'InChI key': 'YXFVVABEGXRONW-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 33233.94544167449, 'Time-weighted average exposure limit': "(20.0, 'ppm')", 'Tc, K': 591.75, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.4545, 'Formula': 'C7H8', 'InChI': 'C7H8/c1-7-5-3-2-4-6-7/h2-6H,1H3', 'Parachor': 246.76008384965857, 'Heat of fusion, J/mol': 6639.9999999999991, 'Tb, K': 383.75, 'Stockmayer parameter, K': 350.74, 'IUPAC name': 'methylbenzene', 'Refractive index': 1.4941, 'Tm, K': 179.2, 'solubility parameter, Pa^0.5': 18242.232319337778, 'Heat of formation, J/mol': 50170.0, 'Pc, Pa': 4108000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.00031600000000000004, 'Upper flammability limit, fraction': 0.078, 'Dipole moment, debye': 0.33, 'MW, g/mol': 92.13842, 'Acentric factor': 0.257, 'rhoC, kg/m^3': 291.5772784810126, 'Zc': 0.26384277925843774, 'Triple pressure, Pa': 0.04217711401906639, 'Autoignition temperature, K': 803.15, 'CAS': '108-88-3', 'smiles': 'CC1=CC=CC=C1', 'Flash temperature, K': 277.15, 'Ozone depletion potential': None, 'logP': 2.73, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 179.2}}
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))

@pytest.mark.slow
@pytest.mark.meta_Chemical
def test_all_chemicals():
for i in pubchem_dict.keys():
Expand Down
106 changes: 105 additions & 1 deletion tests/test_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def numeric_sub_l(expr):
# Cv integral, real slow
# The Cv integral is possible with a more general form, but not here
# The S and H integrals don't work in Sympy at present




Expand Down Expand Up @@ -249,6 +248,35 @@ def test_PR_quick():
assert_allclose(H_dep_orig, H_dep_expect)


def test_PR_Psat():
eos = PR(Tc=507.6, Pc=3025000, omega=0.2975, T=299., P=1E6)
Cs_PR = [-3.3466262, -9.9145207E-02, 1.015969390, -1.032780679,
0.2904927517, 1.64073501E-02, -9.67894565E-03, 1.74161549E-03,
-1.56974110E-04, 5.87311295E-06]
def Psat(T, Tc, Pc, omega):
Tr = T/Tc
e = PR(Tc=Tc, Pc=Pc, omega=omega, T=T, P=1E5)
alpha = e.a_alpha/e.a
tot = 0
for k, Ck in enumerate(Cs_PR[0:4]):
tot += Ck*(alpha/Tr-1)**((k+2)/2.)
for k, Ck in enumerate(Cs_PR[4:]):
tot += Ck*(alpha/Tr-1)**(k+3)
P = exp(tot)*Tr*Pc
return P

Ts = np.linspace(507.6*0.32, 504)
Psats_lit = [Psat(T, Tc=507.6, Pc=3025000, omega=0.2975) for T in Ts]
Psats_eos = [eos.Psat(T) for T in Ts]
assert_allclose(Psats_lit, Psats_eos, rtol=1.5E-3)

# Check that fugacities exist for both phases
for T, P in zip(Ts, Psats_eos):
eos = PR(Tc=507.6, Pc=3025000, omega=0.2975, T=T, P=P)
assert_allclose(eos.fugacity_l, eos.fugacity_g, rtol=2E-3)



def test_PR78():
eos = PR78(Tc=632, Pc=5350000, omega=0.734, T=299., P=1E6)
three_props = [eos.V_l, eos.H_dep_l, eos.S_dep_l]
Expand Down Expand Up @@ -356,6 +384,34 @@ def test_VDW():
VDW(Tc=507.6, Pc=3025000, P=1E6)


def test_VDW_Psat():
eos = VDW(Tc=507.6, Pc=3025000, T=299., P=1E6)
Cs_VDW = [-2.9959015, -4.281688E-2, 0.47692435, -0.35939335, -2.7490208E-3,
4.4205329E-2, -1.18597319E-2, 1.74962842E-3, -1.41793758E-4,
4.93570180E-6]

def Psat(T, Tc, Pc, omega):
Tr = T/Tc
e = VDW(Tc=Tc, Pc=Pc, T=T, P=1E5)
alpha = e.a_alpha/e.a
tot = 0
for k, Ck in enumerate(Cs_VDW[0:4]):
tot += Ck*(alpha/Tr-1)**((k+2)/2.)
for k, Ck in enumerate(Cs_VDW[4:]):
tot += Ck*(alpha/Tr-1)**(k+3)
P = exp(tot)*Tr*Pc
return P

Ts = np.linspace(507.6*.32, 506)
Psats_lit = [Psat(T, Tc=507.6, Pc=3025000, omega=0.2975) for T in Ts]
Psats_eos = [eos.Psat(T) for T in Ts]
assert_allclose(Psats_lit, Psats_eos, rtol=2E-5)

# Check that fugacities exist for both phases
for T, P in zip(Ts, Psats_eos):
eos = VDW(Tc=507.6, Pc=3025000, T=T, P=P)
assert_allclose(eos.fugacity_l, eos.fugacity_g, rtol=1E-6)


def test_RK_quick():
# Test solution for molar volumes
Expand Down Expand Up @@ -432,6 +488,20 @@ def test_RK_quick():
assert_allclose(H_dep_expect, eos.H_dep_l)


def test_RK_Psat():
eos = RK(Tc=507.6, Pc=3025000, omega=0.2975, T=299., P=1E6)

Ts = np.linspace(507.6*0.32, 504, 100)
Psats_eos = [eos.Psat(T) for T in Ts]
fugacity_ls, fugacity_gs = [], []
for T, P in zip(Ts, Psats_eos):
eos = RK(Tc=507.6, Pc=3025000, omega=0.2975, T=T, P=P)
fugacity_ls.append(eos.fugacity_l)
fugacity_gs.append(eos.fugacity_g)

# Fit is very good
assert_allclose(fugacity_ls, fugacity_gs, rtol=3E-4)


def test_SRK_quick():
# Test solution for molar volumes
Expand Down Expand Up @@ -496,6 +566,40 @@ def test_SRK_quick():
assert_allclose(phi_l_expect, eos.phi_l)
assert_allclose(phi_walas, eos.phi_l)

def test_SRK_Psat():
eos = SRK(Tc=507.6, Pc=3025000, omega=0.2975, T=299., P=1E6)

# ERROR actually for RK not SRK
Cs_SRK = [-3.0486334, -5.2157649E-2, 0.55002312, -0.44506984, 3.1735078E-2,
4.1819219E-2, -1.18709865E-2, 1.79267167E-3, -1.47491666E-4,
5.19352748E-6]

def Psat(T, Tc, Pc, omega):
Tr = T/Tc
e = SRK(Tc=Tc, Pc=Pc, omega=omega, T=T, P=1E5)
alpha = e.a_alpha/e.a
tot = 0
for k, Ck in enumerate(Cs_SRK[0:4]):
tot += Ck*(alpha/Tr-1)**((k+2)/2.)
for k, Ck in enumerate(Cs_SRK[4:]):
tot += Ck*(alpha/Tr-1)**(k+3)
P = exp(tot)*Tr*Pc
return P

Ts = np.linspace(160, 504, 100)
Psats_lit = [Psat(T, Tc=507.6, Pc=3025000, omega=0.2975) for T in Ts]
Psats_eos = [eos.Psat(T) for T in Ts]
assert_allclose(Psats_lit, Psats_eos, rtol=5E-2)
# Not sure why the fit was so poor for the original author

fugacity_ls, fugacity_gs = [], []
for T, P in zip(Ts, Psats_eos):
eos = SRK(Tc=507.6, Pc=3025000, omega=0.2975, T=T, P=P)
fugacity_ls.append(eos.fugacity_l)
fugacity_gs.append(eos.fugacity_g)

assert allclose_variable(fugacity_ls, fugacity_gs, limits=[0, .1, .5], rtols=[3E-2, 1E-3, 3E-4])


def test_APISRK_quick():
# Test solution for molar volumes
Expand Down
Loading

0 comments on commit 22f3b41

Please sign in to comment.