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_IdealPPThermodynamic_enthalpy_Cpl_Cpg_Hvap_binary_Tb_ref():
w = Chemical('water')
MeOH = Chemical('methanol')
m = Mixture(['water', 'methanol'], zs=[0.3, 0.7], 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)
pkg.set_T_transitions('Tb')
# Full vapor flash, high T
pkg.flash(T=1200, P=1E7, zs=m.zs)
dH = pkg.enthalpy_Cpl_Cpg_Hvap()
liq_w_dH = 0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, w.Tb)
liq_MeOH_dH = 0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, MeOH.Tb)
dH_w_vapor = 0.3*w.HeatCapacityGas.T_dependent_property_integral(w.Tb, 1200)
dH_MeOH_vapor = 0.7*MeOH.HeatCapacityGas.T_dependent_property_integral(MeOH.Tb, 1200)
def test_IdealPPThermodynamic_single_component_H():
w = Chemical('water')
EnthalpyVaporization = w.EnthalpyVaporization
HeatCapacityGas = w.HeatCapacityGas
VaporPressure = w.VaporPressure
m = Mixture(['water'], zs=[1], 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)
# Check the enthalpy of vaporization matches at the reference temperature
pkg.flash(T=298.15, P=1E5, zs=m.zs)
H_pp = pkg.enthalpy_Cpg_Hvap()
assert_allclose(H_pp, -EnthalpyVaporization(298.15))
# Check it's pressure independent for the gas (at ref T)
kw_options = [{'P': w.Psat}, {'P': 100}, {'P': 1E-10}, {'VF': 1}]
def test_IdealPPThermodynamic_enthalpy_Cpl_Cpg_Hvap_binary_Tc_ref():
w = Chemical('water')
MeOH = Chemical('methanol')
m = Mixture(['water', 'methanol'], zs=[0.3, 0.7], 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)
pkg.set_T_transitions('Tc')
# Liquid change only, but to the phase change barrier
pkg.flash(T=298.15+200, VF=0, zs=m.zs)
dH = pkg.enthalpy_Cpl_Cpg_Hvap()
dH_hand = (0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, 298.15+200)
+0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, 298.15+200))
assert_allclose(dH, dH_hand)
# Flash a minute amount - check the calc still works and the value is the same
pkg.flash(T=298.15+200, VF=1E-7, zs=m.zs)
def test_IdealPPThermodynamic_enthalpy_Cpl_Cpg_Hvap_binary_Tb_ref():
w = Chemical('water')
MeOH = Chemical('methanol')
m = Mixture(['water', 'methanol'], zs=[0.3, 0.7], 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)
pkg.set_T_transitions('Tb')
# Full vapor flash, high T
pkg.flash(T=1200, P=1E7, zs=m.zs)
dH = pkg.enthalpy_Cpl_Cpg_Hvap()
liq_w_dH = 0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, w.Tb)
liq_MeOH_dH = 0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, MeOH.Tb)
dH_w_vapor = 0.3*w.HeatCapacityGas.T_dependent_property_integral(w.Tb, 1200)
dH_MeOH_vapor = 0.7*MeOH.HeatCapacityGas.T_dependent_property_integral(MeOH.Tb, 1200)
Vfgs = list(Vfgs.values())
length_matching = len(Vfgs) == len(IDs)
else:
raise Exception("One of 'zs', 'ws', 'Vfls', or 'Vfgs' is required to define the mixture")
# Do not to a test on multiple composition inputs in case the user specified
# a composition, plus one was set (it will be zero anyway)
if len(IDs) > 1 and ((zs is not None) + (ws is not None) + (Vfgs is not None) + (Vfls is not None)) > 1:
raise Exception('Multiple different composition arguments were '
"specified; specify only one of the arguments "
"'zs', 'ws', 'Vfls', or 'Vfgs'.")
if not length_matching:
raise Exception('Composition is not the same length as the component identifiers')
self.components = tuple(IDs)
self.Chemicals = [Chemical(component, P=P, T=T) for component in self.components]
self.names = [i.name for i in self.Chemicals]
self.MWs = [i.MW for i in self.Chemicals]
self.CASs = [i.CAS for i in self.Chemicals]
# Required for densities for volume fractions before setting fractions
self.set_chemical_constants()
self.set_chemical_TP()
self.set_Chemical_property_objects()
if zs:
self.zs = zs if sum(zs) == 1 else [zi/sum(zs) for zi in zs]
self.ws = zs_to_ws(zs, self.MWs)
elif ws:
self.ws = ws if sum(ws) == 1 else [wi/sum(ws) for wi in ws]
self.zs = ws_to_zs(ws, self.MWs)
elif Vfls or Vfgs:
(rhos, Cps) = [[] for i in range(2)]
if not Tmin: # pragma: no cover
if chem.Tm:
Tmin = chem.Tm-100
else:
Tmin = 150.
if not Tmax: # pragma: no cover
if chem.Tm:
Tmax = chem.Tm
else:
Tmax = 350
Ts = np.linspace(Tmin, Tmax, pts)
for T in Ts:
chem = Chemical(chemical, T=T)
rhos.append(chem.rhos)
Cps.append(chem.Cps)
data = OrderedDict()
data['Density, kg/m^3'] = rhos
data['Constant-pressure heat capacity, J/kg/K'] = Cps
df = pd.DataFrame(data, index=Ts)
df.index.name = 'T, K'
return df
def tabulate_gas(chemical, Tmin=None, Tmax=None, pts=10):
chem = Chemical(chemical)
(rhos, Cps, Cvs, mugs, kgs, Prs, alphas, isobarics, isentropics, JTs) = [[] for i in range(10)]
if not Tmin: # pragma: no cover
if chem.Tm:
Tmin = chem.Tm
else:
Tmin = 273.15
if not Tmax: # pragma: no cover
if chem.Tc:
Tmax = chem.Tc
else:
Tmax = 450
Ts = np.linspace(Tmin, Tmax, pts)
for T in Ts:
chem = Chemical(chemical, T=T)
def tabulate_constants(chemical, full=False, vertical=False):
pd.set_option('display.max_rows', 100000)
pd.set_option('display.max_columns', 100000)
all_chemicals = OrderedDict()
if isinstance(chemical, str):
cs = [chemical]
else:
cs = chemical
for chemical in cs:
chem = Chemical(chemical)
data = OrderedDict()
data['CAS'] = chem.CAS
data['Formula'] = chem.formula
data['MW, g/mol'] = chem.MW
data['Tm, K'] = chem.Tm
data['Tb, K'] = chem.Tb
data['Tc, K'] = chem.Tc
data['Pc, Pa'] = chem.Pc
data['Vc, m^3/mol'] = chem.Vc
data['Zc'] = chem.Zc
data['rhoc, kg/m^3'] = chem.rhoc
data['Acentric factor'] = chem.omega
data['Triple temperature, K'] = chem.Tt
data['Triple pressure, Pa'] = chem.Pt
data['Heat of vaporization at Tb, J/mol'] = chem.Hvap_Tbm
data['Heat of fusion, J/mol'] = chem.Hfusm
def tabulate_liq(chemical, Tmin=None, Tmax=None, pts=10):
chem = Chemical(chemical)
(rhos, Cps, mugs, kgs, Prs, alphas, isobarics, JTs, Psats, sigmas, Hvaps,
permittivities) = [[] for i in range(12)]
if not Tmin: # pragma: no cover
if chem.Tm:
Tmin = chem.Tm
else:
Tmin = 273.15
if not Tmax: # pragma: no cover
if chem.Tc:
Tmax = chem.Tc
else:
Tmax = 450
Ts = np.linspace(Tmin, Tmax, pts)
for T in Ts:
(rhos, Cps, mugs, kgs, Prs, alphas, isobarics, JTs, Psats, sigmas, Hvaps,
permittivities) = [[] for i in range(12)]
if not Tmin: # pragma: no cover
if chem.Tm:
Tmin = chem.Tm
else:
Tmin = 273.15
if not Tmax: # pragma: no cover
if chem.Tc:
Tmax = chem.Tc
else:
Tmax = 450
Ts = np.linspace(Tmin, Tmax, pts)
for T in Ts:
chem = Chemical(chemical, T=T)
rhos.append(chem.rhol)
Cps.append(chem.Cpl)
mugs.append(chem.mul)
kgs.append(chem.kl)
Prs.append(chem.Prl)
alphas.append(chem.alphal)
isobarics.append(chem.isobaric_expansion_l)
JTs.append(chem.JTg)
Psats.append(chem.Psat)
Hvaps.append(chem.Hvap)
sigmas.append(chem.sigma)
permittivities.append(chem.permittivity)
data = OrderedDict()
data['Saturation pressure, Pa'] = Psats