def test_Mixture_calculated_Vfs(): # Liquid standard fractions S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75]) Vfls = S.Vfls(298.16, 101326) assert_close1d(Vfls, [0.18301434895886864, 0.8169856510411313], rtol=1e-3) assert_close1d(S.Vfls(), [0.18301384717011993, 0.8169861528298801], rtol=1e-3) assert_close1d(S.Vfls(P=1E6), [0.18292777184777048, 0.8170722281522296], rtol=1e-3) assert_close1d(S.Vfls(T=299.15), [0.1830642468206885, 0.8169357531793114], rtol=1e-3) # gas fractions S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75], T=699) assert_close1d(S.Vfgs(700, 101326), [0.25, 0.75], rtol=1e-3) assert_close1d(S.Vfgs(), [0.25, 0.75], rtol=1e-3) assert_close1d(S.Vfgs(P=101326), [0.25, 0.75], rtol=1e-3) assert_close1d(S.Vfgs(T=699), [0.25, 0.75], rtol=1e-3)
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_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.18299723912903532, 0.8170027608709647]) assert_allclose(S.Vfls(), [0.18299676086285419, 0.8170032391371459]) assert_allclose(S.Vfls(P=1E6), [0.18291966593930253, 0.8170803340606975]) assert_allclose(S.Vfls(T=299.15), [0.18304482422114987, 0.8169551757788501]) # 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_Mixture_input_basics(): # Run a test initializing a mixture from mole fractions, mass fractions, # liquid fractions, gas fractions (liq/gas are with volumes of pure components at T and P) kwargs = {'ws': [0.5, 0.5], 'zs': [0.7188789914193495, 0.2811210085806504], 'Vfls': [0.44054617180108374, 0.5594538281989162], 'Vfgs': [0.7188789914193495, 0.2811210085806504]} for key, val in kwargs.items(): m = Mixture(['water', 'ethanol'], **{key:val}) assert_close1d(m.zs, kwargs['zs'], rtol=1E-6) assert_close1d(m.zs, m.xs) assert_close1d(m.Vfls(), kwargs['Vfls'], rtol=1E-5) assert_close1d(m.Vfgs(), kwargs['Vfgs'])
def test_Mixture_input_np_array(): # 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.45711574619871703, 0.31076035223551646, 0.23212390156576654]), 'Vfgs': np.array([.5, .3, .2])} for key, val in kwargs.items(): m = Mixture(IDs, **{key:val}) assert_close1d(m.zs, kwargs['zs'], rtol=1E-6) assert_close1d(m.zs, m.xs) assert_close1d(m.Vfls(), kwargs['Vfls'], rtol=1E-5) assert_close1d(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)
def test_Mixture_input_ordered_dict(): # Ordered dict inputs IDs = ['pentane', 'hexane', 'heptane'] kwargs = {'ws': [0.4401066297270966, 0.31540115235588945, 0.24449221791701395], 'zs': [.5, .3, .2], 'Vfls': [0.45711574619871703, 0.31076035223551646, 0.23212390156576654], 'Vfgs': [.5, .3, .2]} for key, val in kwargs.items(): d = OrderedDict() for i, j in zip(IDs, val): d.update({i: j}) m = Mixture(**{key:d}) assert_close1d(m.zs, kwargs['zs'], rtol=1E-6) assert_close1d(m.zs, m.xs) assert_close1d(m.Vfls(), kwargs['Vfls'], rtol=1E-5) assert_close1d(m.Vfgs(), kwargs['Vfgs'], rtol=2E-5)
def test_Mixture_input_forms(): # Run a test initializing a mixture from mole fractions, mass fractions, # liquid fractions, gas fractions (liq/gas are with volumes of pure components at T and P) kwargs = { 'ws': [0.5, 0.5], 'zs': [0.7188789914193495, 0.2811210085806504], 'Vfls': [0.44054617180108374, 0.5594538281989162], 'Vfgs': [0.7229421485513368, 0.2770578514486633] } for key, val in kwargs.items(): m = Mixture(['water', 'ethanol'], **{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']) with pytest.raises(Exception): Mixture(['water', 'ethanol']) Mixture(['water'], ws=[1], T=300, P=1E5)
def test_Mixture_input_forms(): # Run a test initializing a mixture from mole fractions, mass fractions, # liquid fractions, gas fractions (liq/gas are with volumes of pure components at T and P) kwargs = { 'ws': [0.5, 0.5], 'zs': [0.7188789914193495, 0.2811210085806504], 'Vfls': [0.44054617180108374, 0.5594538281989162], 'Vfgs': [0.7229421485513368, 0.2770578514486633] } for key, val in kwargs.items(): m = Mixture(['water', 'ethanol'], **{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']) # Ordered dict inputs IDs = ['pentane', 'hexane', 'heptane'] kwargs = { 'ws': [0.4401066297270966, 0.31540115235588945, 0.24449221791701395], 'zs': [.5, .3, .2], 'Vfls': [0.45711574619871703, 0.31076035223551646, 0.23212390156576654], 'Vfgs': [0.5127892380094016, 0.2979448661739439, 0.18926589581665448] } for key, val in kwargs.items(): d = OrderedDict() for i, j in zip(IDs, val): d.update({i: j}) 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.45711574619871703, 0.31076035223551646, 0.23212390156576654]), '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