def Excess_Enthalpy_vector(rho,T,tau,delta,Tc,rho_c,parameter_set1,parameter_set2,parameter_set12,x_1,x_2): from thermodynamic_functions.enthalpy_vector import enthalpy_vector from thermodynamic_functions.pressure_vector import pressure_vector from residual_pressure_pure_substance import residual_pressure_pure_substance from scipy.optimize import leastsq Enthalpy_of_mixture=enthalpy_vector(rho,T,tau,delta,Tc,rho_c,'mix',parameter_set1,parameter_set2,parameter_set12,x_1,x_2) Pressure_of_mixture=pressure_vector(rho,T,tau,delta,'mix',parameter_set1,parameter_set2,parameter_set12,x_1,x_2,Tc,rho_c) density_guess_component_1=Pressure_of_mixture/((parameter_set1['R']/parameter_set1['M_amu'])*T) density_guess_component_2=Pressure_of_mixture/((parameter_set2['R']/parameter_set2['M_amu'])*T) [density_component_1,message_1]=leastsq(residual_pressure_pure_substance,density_guess_component_1,args=(Pressure_of_mixture,T,parameter_set1)) [density_component_2,message_2]=leastsq(residual_pressure_pure_substance,density_guess_component_2,args=(Pressure_of_mixture,T,parameter_set2)) Tc1=parameter_set1['Tc'] Tc2=parameter_set2['Tc'] rho_c1=parameter_set1['rho_c'] rho_c2=parameter_set2['rho_c'] tau_1=Tc1/T tau_2=Tc2/T delta_1=density_component_1/parameter_set1['rho_c'] delta_2=density_component_2/parameter_set2['rho_c'] Enthalpy_component_1=enthalpy_vector(density_component_1,T,tau_1,delta_1,Tc1,rho_c1,'pure_substance',parameter_set1,parameter_set1,parameter_set1,1,1) Enthalpy_component_2=enthalpy_vector(density_component_2,T,tau_2,delta_2,Tc2,rho_c2,'pure_substance',parameter_set2,parameter_set2,parameter_set2,1,1) Excess_Enthalpy=Enthalpy_of_mixture-x_1*Enthalpy_component_1-x_2*Enthalpy_component_2 return Excess_Enthalpy
def residual_pressure_pure_substance(density, Pin, T, params): from thermodynamic_functions.pressure_vector import pressure_vector from pylab import shape tau = params["Tc"] / T delta = density / params["rho_c"] Pcalc = pressure_vector(tau, delta, "pure_substance", params, 0, params, 0, 0, params["rho_c"], params["Tc"]) err = Pin - Pcalc return err
def residual_pressure(density,Pin,T,h2_params,h2o_params,mix_params,x_h2,x_h2o): from thermodynamic_functions.pressure_vector import pressure_vector from thermodynamic_functions.enthalpy import enthalpy from scale_tau_and_delta_kw import scale_tau_and_delta_kw from pylab import shape [tau,delta,Tc,rho_c]=scale_tau_and_delta_kw(T,density/mix_params['M_amu'],x_h2,x_h2o,h2_params['Tc'],h2o_params['Tc'],h2_params['rho_c']/h2_params['M_amu'],h2o_params['rho_c']/h2o_params['M_amu'],mix_params['BetaT'],mix_params['BetaV'],mix_params['GammaT'],mix_params['GammaV']) Pcalc=pressure_vector(density,T,tau,delta,'mix',h2_params,h2o_params,mix_params,x_h2,x_h2o,rho_c,Tc) err=Pin-Pcalc return err
def residual_pressure_pure_substance(density,Pin,T,params): from thermodynamic_functions.pressure_vector import pressure_vector from numpy import shape tau=params['Tc']/T delta=density/params['rho_c'] Pcalc=pressure_vector(density,T,tau,delta,'pure_substance',params,params,params,0,0,0,0) err=Pin-Pcalc return err
[tau, delta, Tc, rho_c] = scale_tau_and_delta_kw( T, density / h2_ch4_mix_params["M_amu"], x_h2, x_ch4, h2_params["Tc"], ch4_params["Tc"], h2_params["rho_c"] / h2_params["M_amu"], ch4_params["rho_c"] / ch4_params["M_amu"], h2_ch4_mix_params["BetaT"], h2_ch4_mix_params["BetaV"], h2_ch4_mix_params["GammaT"], h2_ch4_mix_params["GammaV"], ) P = pressure_vector(density, T, tau, delta, "mix", h2_params, ch4_params, h2_ch4_mix_params, x_h2, x_ch4, rho_c, Tc) h = enthalpy_vector(density, T, tau, delta, Tc, rho_c, "mix", h2_params, ch4_params, h2_ch4_mix_params, x_h2, x_ch4) Excess_h = Excess_Enthalpy_vector( density, T, tau, delta, Tc, rho_c, h2_params, ch4_params, h2_ch4_mix_params, x_h2, x_ch4 ) B = Virial_B_vector(tau, h2_params, ch4_params, h2_ch4_mix_params, x_h2, x_ch4, rho_c, Tc, "mix") C = Virial_C_vector(tau, h2_params, ch4_params, h2_ch4_mix_params, x_h2, x_ch4, rho_c, Tc, "mix") print Excess_h # Excess Enthalpy in J/mol print P - 1000 * P_refprop # Pressure in kPa print h - M_amu * enthalpy_refprop # Enthalpy in J/mol M_amu used to convert from kJ/kg print B print C print tau, delta print P # ...and BEHOLD! IT WORKS!