Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_Mixture_calculated_Vfs():
# Liquid standard fractions
S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75])
Vfls = S.Vfls(298.16, 101326)
assert_allclose(Vfls, [0.18301434895886864, 0.8169856510411313])
assert_allclose(S.Vfls(), [0.18301384717011993, 0.8169861528298801])
assert_allclose(S.Vfls(P=1E6), [0.18292777184777048, 0.8170722281522296])
assert_allclose(S.Vfls(T=299.15), [0.1830642468206885, 0.8169357531793114])
# gas fractions
S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75], T=699)
assert_allclose(S.Vfgs(700, 101326), [0.251236709756207, 0.748763290243793])
assert_allclose(S.Vfgs(), [0.25124363058052673, 0.7487563694194732])
assert_allclose(S.Vfgs(P=101326), [0.2512436429605387, 0.7487563570394613])
assert_allclose(S.Vfgs(T=699), [0.25124363058052673, 0.7487563694194732])
def test_bubble_at_P_with_ideal_mixing():
'''Check to see if the bubble pressure calculated from the temperature
matches the temperature calculated by the test function'''
test_mix = Mixture(['ethylene oxide',
'tetrahydrofuran',
'beta-propiolactone'],
ws=[6021, 111569.76, 30711.21, ],
T=273.15 + 80,
P=101325 + 1.5e5)
bubble_temp = bubble_at_P(test_mix.Pbubble,
test_mix.zs,
test_mix.VaporPressures)
assert_allclose(test_mix.T, bubble_temp)
def test_constant_properties():
R_specific = Mixture(['N2', 'O2'], zs=[0.79, .21]).R_specific
assert_allclose(R_specific, 288.1928437986195, rtol=1E-5)
def test_UNIFAC_Dortmund_PP():
m = Mixture(['ethanol', 'water'], zs=[0.5, 0.5], P=6500, T=298.15)
vodka = UNIFAC_Dortmund_PP(UNIFAC_groups=m.UNIFAC_Dortmund_groups, VaporPressures=m.VaporPressures,
Tms=m.Tms, Tcs=m.Tcs, Pcs=m.Pcs)
# Low pressure ethanol-water ideal TP flash
phase, xs, ys, V_over_F = vodka.flash_TP_zs(m.T, m.P, m.zs)
V_over_F_expect = 0.721802969194136
xs_expect = [0.26331608196660095, 0.736683918033399]
ys_expect = [0.5912226272910779, 0.408777372708922]
assert phase == 'l/g'
assert_allclose(xs, xs_expect)
assert_allclose(ys, ys_expect)
assert_allclose(V_over_F, V_over_F_expect)
# Same flash with T-VF spec
phase, xs, ys, V_over_F, P = vodka.flash_TVF_zs(m.T, V_over_F_expect, m.zs)
assert phase == 'l/g'
assert_allclose(xs, xs_expect, rtol=1E-5)
assert_allclose(ys, ys_expect, rtol=1E-5)
m = Mixture(**{key:d})
assert_allclose(m.zs, kwargs['zs'], rtol=1E-6)
assert_allclose(m.zs, m.xs)
assert_allclose(m.Vfls(), kwargs['Vfls'], rtol=1E-5)
assert_allclose(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)
# numpy array inputs
IDs = ['pentane', 'hexane', 'heptane']
kwargs = {'ws': np.array([0.4401066297270966, 0.31540115235588945, 0.24449221791701395]),
'zs': np.array([.5, .3, .2]),
'Vfls': np.array([0.45725229530669054, 0.3106973688150756, 0.2320503358782339]),
'Vfgs': np.array([0.5127892380094016, 0.2979448661739439, 0.18926589581665448])}
for key, val in kwargs.items():
m = Mixture(IDs, **{key:val})
assert_allclose(m.zs, kwargs['zs'], rtol=1E-6)
assert_allclose(m.zs, m.xs)
assert_allclose(m.Vfls(), kwargs['Vfls'], rtol=1E-5)
assert_allclose(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)
with pytest.raises(Exception):
Mixture(['water', 'ethanol'])
Mixture(['water'], ws=[1], T=300, P=1E5)
Mixture('water', ws=[1], T=365).SGl
# DIPPR 1983 manual example
m = Mixture(['carbon tetrachloride', 'isopropanol'], zs=[0.5, 0.5], T=313.2)
ViscosityLiquids = [i.ViscosityLiquid for i in m.Chemicals]
obj = ViscosityLiquidMixture(ViscosityLiquids=ViscosityLiquids, CASs=m.CASs)
mu = obj.mixture_property(m.T, m.P, m.zs, m.ws)
assert_allclose(mu, 0.0009956952502281852)
mu = obj.calculate(m.T, m.P, m.zs, m.ws, MIXING_LOG_MOLAR)
assert_allclose(mu, 0.0009956952502281852)
mu = obj.calculate(m.T, m.P, m.zs, m.ws, MIXING_LOG_MASS)
assert_allclose(mu, 0.0008741268796817256)
# Test Laliberte
m = Mixture(['water', 'sulfuric acid'], zs=[0.5, 0.5], T=298.15)
ViscosityLiquids = [i.ViscosityLiquid for i in m.Chemicals]
obj = ViscosityLiquidMixture(ViscosityLiquids=ViscosityLiquids, CASs=m.CASs)
mu = obj.mixture_property(m.T, m.P, m.zs, m.ws)
assert_allclose(mu, 0.024955325569420893)
assert obj.sorted_valid_methods == [LALIBERTE_MU]
# Unhappy paths
with pytest.raises(Exception):
obj.calculate(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
with pytest.raises(Exception):
obj.test_method_validity(m.T, m.P, m.zs, m.ws, 'BADMETHOD')
def test_IdealPPThermodynamic_TS():
m = Mixture(['pentane', 'hexane', 'octane'], zs=[.1, .4, .5], T=298.15)
pkg = IdealPPThermodynamic(VaporPressures=m.VaporPressures, Tms=m.Tms, Tbs=m.Tbs, Tcs=m.Tcs, Pcs=m.Pcs,
HeatCapacityLiquids=m.HeatCapacityLiquids, HeatCapacityGases=m.HeatCapacityGases,
EnthalpyVaporizations=m.EnthalpyVaporizations)
Ts = np.linspace(300, 400, 10)
VFs = [1E-5, .1, .5, .99, 1]
for T in Ts:
for VF in VFs:
T = float(T)
pkg.flash(T=T, VF=VF, zs=m.zs)
pkg._post_flash()
P = pkg.P
P_calc = pkg.flash_TS_zs_bounded(T=T, Sm=pkg.Sm, zs=m.zs)
assert_allclose(P_calc, P, rtol=1E-3)
def test_Mixture():
Mixture(['water', 'ethanol'], ws=[.5, .5], T=320, P=1E5)
Mixture(['water', 'phosphoric acid'], ws=[.5, .5], T=320, P=1E5)
Mixture('air', T=320, P=1E5)
Mixture(['ethanol', 'water'], ws=[0.5, 0.5], T=500)
Mixture('water')
s = Mixture(['water', 'ethanol'], P=5200, zs=[0.5, 0.5])
assert_allclose(s.V_over_F, 0.3061646720256255, rtol=1E-3)
s = Mixture(['water', 'ethanol'], P=5200, zs=[0.5, 0.5])
assert_allclose(s.quality, 0.34745483870024646, rtol=1E-3)
with pytest.raises(Exception):
Mixture(['2,2-Dichloro-1,1,1-trifluoroethane'], T=276.15, P=37000, zs=[0.5, 0.5])
m = Mixture(['Na+', 'Cl-', 'water'], ws=[.01, .02, .97]).charge_balance
assert_allclose(m, -0.0023550338411239182)
def test_Perrys2_313_data():
# All values calculated at Tmin and Tmax check out to at least 5E-3 precision
# The rounding has some effect, but it is not worrying.
assert all([checkCAS(i) for i in Perrys2_313.index])
tots_calc = [Perrys2_313[i].abs().sum() for i in [u'C1', u'C2', u'C3', u'C4', u'C5', u'Tmin', u'Tmax']]
tots = [9166.6971369999992, 615425.94497999991, 1125.5317557875198, 9.054869390623603e+34, 402.21244000000002, 72467.140000000014, 136954.85999999999]
assert_allclose(tots_calc, tots)
assert Perrys2_313.index.is_unique
assert Perrys2_313.shape == (337, 8)
def test_VDI_PPDS_2_data():
'''Plenty of interesting errors here.
The chemicals 463-58-1, 75-44-5, 75-15-0, 7446-11-9, 2551-62-4
do not match the tabulated data. They are all in the same section, so a
mixup was probably made there. The errors versus the tabulated data are
very large.
Note this table needed to have Tc and MW added to it as well, from the
same source.
'''
assert all([checkCAS(i) for i in VDI_PPDS_2.index])
tots_calc = [VDI_PPDS_2[i].abs().sum() for i in [u'A', u'B', u'C', u'D', u'Tc', u'rhoc', u'MW']]
tots = [208878.27130000002, 117504.59450000001, 202008.99950000001, 85280.333600000013, 150142.28, 97269, 27786.919999999998]
assert_allclose(tots_calc, tots)
assert VDI_PPDS_2.index.is_unique
assert VDI_PPDS_2.shape == (272, 8)