from gas_library import get_h2_h2o_mix from thermodynamic_functions.C_p_vector_mix import C_p_vector_mix from scale_tau_and_delta_kw_4comp import scale_tau_and_delta_kw_4comp from thermodynamic_functions.pressure_vector4 import pressure_vector4 from thermodynamic_functions.C_p_vector_mix4 import C_p_vector_mix4 from scipy.optimize import fsolve from numpy import asarray,zeros f=open('python_compressibility/calc_Cp/output_T_P.txt','r') data=f.readline() f.close() T_i,P_h2_i,P_he_i,P_ch4_i,P_h2o_i=data.split("\t") parameters_H2=get_h2_params() parameters_h2o=get_h2o_params() parameters_ch4=get_ch4_params() parameters_he=get_he_params() Bars_to_kPa=100 T=asarray([float(T_i),float(T_i)]) P_h2=asarray([float(P_h2_i),float(P_h2_i)])*Bars_to_kPa P_he=asarray([float(P_he_i),float(P_he_i)])*Bars_to_kPa P_ch4=asarray([float(P_ch4_i),float(P_ch4_i)])*Bars_to_kPa P_h2o=asarray([float(P_h2o_i),float(P_h2o_i)])*Bars_to_kPa #here we are using the ideal gas law as a proxy for density. The final pressure will be defined by the equation of state. #In other words this is a kludge to keep density fixed, then calculate the real pressure.
def get_h2_h2o_mix(x_h2, x_h2o): from numpy import asarray from gas_library import get_h2_params from gas_library import get_h2o_params h2o_params = get_h2o_params() h2_params = get_h2_params() p = asarray( [ -6.84724158e01, 2.76510561e00, -1.72902015e02, 3.36805346e00, 8.43730166e-02, 1.20304163e-02, 4.85353759e00, -9.45732780e00, 2.96892622e01, 5.66963126e00, -4.72763978e-01, 5.68600592e00, 1.01325950e00, 8.75427966e-01, 2.25904893e00, 1.73721803e00, 1.57106640e-01, -1.23114242e-01, 1.07298418e00, 7.51254725e-01, ] ) BetaT = p[0] BetaV = p[1] GammaT = p[2] GammaV = p[3] N_i = asarray([p[4], p[5], p[6], p[7]]) t_i = asarray([p[8], p[9], p[10], p[11]]) d_i = asarray([p[12], p[13], p[14], p[15]]) p_i = asarray([p[16], p[17], p[18], p[19]]) Rmix = x_h2o * h2o_params["R"] + x_h2 * h2_params["R"] M_amu = x_h2o * h2o_params["M_amu"] + x_h2 * h2_params["M_amu"] n_power_terms_wo_exp = 0 n_power_terms_w_exp = 4 mix_params = { "N_i": N_i, "BetaT": BetaT, "BetaV": BetaV, "GammaT": GammaT, "GammaV": GammaV, "t_i": t_i, "d_i": d_i, "p_i": p_i, "n_power_terms_wo_exp": n_power_terms_wo_exp, "n_power_terms_w_exp": n_power_terms_w_exp, "phi_i": 0, "Beta_i": 0, "gamma_i": 0, "D_i": 0, "R": Rmix, "M_amu": M_amu, "ideal_n": 0, "ideal_gamma": 0, "n_gaussian_terms": 0, "n_critical_terms": 0, "RES_a": 0, "RES_b": 0, "RES_B": 0, "RES_C": 0, "RES_D": 0, "RES_A": 0, "ni": 0, "ti": 0, "vi": 0, "ui": 0, "ho": 0, "so": 0, "n_ideal_gas_terms_pow": 0, "n_ideal_gas_terms_exp": 0, "To": 0, "Po": 0, "rho_o": 0, } return mix_params
def PressureCAPI(T_i,P_h2_i,P_he_i,P_ch4_i,P_h2o_i): from gas_library import get_h2_params from gas_library import get_ch4_params from gas_library import get_he_params from gas_library import get_h2o_params from gas_library import get_h2_ch4_mix from gas_library import get_h2_h2o_mix from thermodynamic_functions.C_p_vector_mix import C_p_vector_mix from scale_tau_and_delta_kw_4comp import scale_tau_and_delta_kw_4comp from thermodynamic_functions.pressure_vector4 import pressure_vector4 from thermodynamic_functions.C_p_vector_mix4 import C_p_vector_mix4 from scipy.optimize import fsolve from numpy import asarray,zeros #f=open('python_compressibility/calc_Cp/output_T_P.txt','r') #data=f.readline() #f.close() #data=input_string_from_C #T_i,P_h2_i,P_he_i,P_ch4_i,P_h2o_i=data.split("\t") parameters_H2=get_h2_params() parameters_h2o=get_h2o_params() parameters_ch4=get_ch4_params() parameters_he=get_he_params() Bars_to_kPa=100 T=asarray([float(T_i),float(T_i)]) P_h2=asarray([float(P_h2_i),float(P_h2_i)])*Bars_to_kPa P_he=asarray([float(P_he_i),float(P_he_i)])*Bars_to_kPa P_ch4=asarray([float(P_ch4_i),float(P_ch4_i)])*Bars_to_kPa P_h2o=asarray([float(P_h2o_i),float(P_h2o_i)])*Bars_to_kPa #here we are using the ideal gas law as a proxy for density. The final pressure will be defined by the equation of state. #In other words this is a kludge to keep density fixed, then calculate the real pressure. density_h2=P_h2/((parameters_H2['R']/parameters_H2['M_amu'])*T) #density_h2=fsolve(residual_pressure_pure_substance,density_guess_h2,args=(P_h2,T,parameters_H2)) delta_h2=density_h2/parameters_H2['rho_c'] density_h2o=P_h2o/((parameters_h2o['R']/parameters_h2o['M_amu'])*T) #density_h2o=fsolve(residual_pressure_pure_substance,density_guess_h2o,args=(P_h2o,T,parameters_h2o)) delta_h2o=density_h2o/parameters_h2o['rho_c'] density_he=P_he/((parameters_he['R']/parameters_he['M_amu'])*T) #density_he=fsolve(residual_pressure_pure_substance,density_guess_he,args=(P_he,T,parameters_he)) delta_he=density_he/parameters_he['rho_c'] density_ch4=P_ch4/((parameters_ch4['R']/parameters_ch4['M_amu'])*T) #density_ch4=fsolve(residual_pressure_pure_substance,density_guess_ch4,args=(P_ch4,T,parameters_ch4)) delta_ch4=density_ch4/parameters_ch4['rho_c'] density=density_h2+density_h2o+density_ch4+density_he #note we're calculating x_h2 and x_ch4 according to the mixture of just H2+CH4, not the whole thing He+h2o+etc... molar_density_h2=density_h2/parameters_H2['M_amu'] molar_density_he=density_he/parameters_he['M_amu'] molar_density_ch4=density_ch4/parameters_ch4['M_amu'] molar_density_h2o=density_h2o/parameters_h2o['M_amu'] x_h2=molar_density_h2/(molar_density_h2+molar_density_ch4+molar_density_he+molar_density_h2o) x_ch4=molar_density_ch4/(molar_density_h2+molar_density_ch4+molar_density_he+molar_density_h2o) x_he=molar_density_he/(molar_density_h2+molar_density_ch4+molar_density_he+molar_density_h2o) x_h2o=molar_density_h2o/(molar_density_h2+molar_density_ch4+molar_density_he+molar_density_h2o) h2_ch4_mix_params=get_h2_ch4_mix(x_h2,x_ch4) h2_h2o_mix_params=get_h2_h2o_mix(x_h2,x_h2o) M_amu_mix=x_h2*parameters_H2['M_amu']+x_he*parameters_he['M_amu']+x_ch4*parameters_ch4['M_amu']+x_h2o*parameters_h2o['M_amu'] [tau,delta,Tc_mix,rho_c_mix]=scale_tau_and_delta_kw_4comp(T,density/M_amu_mix,x_h2,x_ch4,x_h2o,x_he,parameters_H2['Tc'],parameters_ch4['Tc'],parameters_h2o['Tc'],parameters_he['Tc'],parameters_H2['rho_c']/parameters_H2['M_amu'],parameters_ch4['rho_c']/parameters_ch4['M_amu'],parameters_h2o['rho_c']/parameters_h2o['M_amu'],parameters_he['rho_c']/parameters_he['M_amu'],h2_ch4_mix_params['BetaT'],h2_ch4_mix_params['BetaV'],h2_ch4_mix_params['GammaT'],h2_ch4_mix_params['GammaV'],h2_h2o_mix_params['BetaT'],h2_h2o_mix_params['BetaV'],h2_h2o_mix_params['GammaT'],h2_h2o_mix_params['GammaV'],1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) Pcalc=pressure_vector4(density,T,tau,delta,parameters_H2,parameters_ch4,parameters_h2o,parameters_he,h2_ch4_mix_params,h2_h2o_mix_params,x_h2,x_ch4,x_h2o,x_he,rho_c_mix,Tc_mix) CP_mix=C_p_vector_mix4(density,T,delta,tau,parameters_H2,parameters_ch4,parameters_he,parameters_h2o,h2_ch4_mix_params,h2_h2o_mix_params,x_h2,x_ch4,x_he,x_h2o) Pcalc=Pcalc/Bars_to_kPa #print Pcalc[0],CP_mix[0]#,T_i,P_h2_i,P_he_i,P_ch4_i,P_h2o_i return (float(Pcalc[0]),float(CP_mix[0]))
from gas_library import get_h2_params from gas_library import get_ch4_params from gas_library import get_he_params from gas_library import get_h2o_params from gas_library import get_h2_ch4_mix from gas_library import get_h2_h2o_mix from scale_tau_and_delta_kw_4comp import scale_tau_and_delta_kw_4comp from thermodynamic_functions.pressure_vector4 import pressure_vector4 from numpy import asarray,zeros h2_params=get_h2_params() ch4_params=get_ch4_params() he_params=get_he_params() h2o_params=get_h2o_params() h2_ch4_mix_params=get_h2_ch4_mix(0.5,0.5) h2_h2o_mix_params=get_h2_h2o_mix(0.5,0.5) density=asarray([0.1,0.1]) x_h2=asarray([0.99,0.99]) x_ch4=asarray([0.01,0.01]) x_h2o=asarray([0.00,0.00]) x_he=asarray([0.0,0.0]) T=asarray([500.0,500.0]) M_amu_mix=x_h2*h2_params['M_amu']+x_ch4*ch4_params['M_amu']+x_h2o*h2o_params['M_amu']+x_he*he_params['M_amu'] [tau,delta,Tc_mix,rho_c_mix]=scale_tau_and_delta_kw_4comp(T,density/M_amu_mix,x_h2,x_ch4,x_h2o,x_he,h2_params['Tc'],ch4_params['Tc'],h2o_params['Tc'],he_params['Tc'],h2_params['rho_c']/h2_params['M_amu'],ch4_params['rho_c']/ch4_params['M_amu'],h2o_params['rho_c']/h2o_params['M_amu'],he_params['rho_c']/he_params['M_amu'],h2_ch4_mix_params['BetaT'],h2_ch4_mix_params['BetaV'],h2_ch4_mix_params['GammaT'],h2_ch4_mix_params['GammaV'],h2_h2o_mix_params['BetaT'],h2_h2o_mix_params['BetaV'],h2_h2o_mix_params['GammaT'],h2_h2o_mix_params['GammaV'],1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) print 'tau,delta',tau,delta P=pressure_vector4(density,T,tau,delta,h2_params,ch4_params,h2o_params,he_params,h2_ch4_mix_params,h2_h2o_mix_params,x_h2,x_ch4,x_h2o,x_he,rho_c_mix,Tc_mix) print P