def input_properties_case_REFPROP___ButaneOctane(comp1, comp2, kij): this_function_name = sys._getframe().f_code.co_name print('\n---\n THE DATA USED IN THIS SIMULATION WAS OBTAINED FROM: ', this_function_name) print('\n---\n') ''' SOURCE: REFPROP -- BUTANE AND OCTANE. ''' critical_pressure = np.array([comp1.pC, comp2.pC]) critical_temperature = np.array([comp1.TC, comp2.TC]) acentric_factor = np.array([comp1.AcF, comp2.AcF]) molar_mass = np.array([comp1.MM, comp2.MM]) omega_a = 0.45724 * np.ones_like(molar_mass) omega_b = 0.07780 * np.ones_like(molar_mass) binary_interaction = np.array( [[0.0000, kij], [kij, 0.0000]] ) specific_heat_mass_base = np.array([comp1.Cp, comp2.Cp]) specific_heat = Tools_Convert.convert_specific_heat_massbase_TO_molarbase(specific_heat_mass_base, molar_mass) return (critical_pressure, critical_temperature, acentric_factor, molar_mass, omega_a, omega_b, binary_interaction, specific_heat)
def solution_concentration_set_function(lightComponent, molar_weight, base): ''' This function is useful to obtain mass fraction and molar fraction VECTOR of a BINARY mixture \n lightComponent: the subcooled liquid solution concentration is set up ... ... based on R134a concentration (e.g.: 5./100, 0.05/100, etc...) \n MM: vector with molar weight of each component "i" [kg/kmol], i.e., (MM = ([MMrefrig, MMpoe])) \n base: 'molar' or 'mass' [-]; you need inform one of them \n z: vector concentration [-], i.e., (z = ([zR, zO])) \n z_mass: vector mass concentration [-] (z_mass = ([zR_mass, zO_mass])) \n Return: z, z_mass ''' MM = molar_weight nome_desta_funcao = sys._getframe().f_code.co_name if lightComponent > 1. or lightComponent < 0.0: raise Exception('You entered with a concentration out of expected range whe you calls the function ' + str(nome_desta_funcao)) elif MM.shape[0] != 2: raise Exception('You must entered a vector like MM = ([MM1,MM2]) when you calls the function ' + str(nome_desta_funcao)) elif base != 'mass' and 'molar': raise Exception('You need type \'mass\' or \'molar\' when calls the function: ' + str(nome_desta_funcao)) zin = np.array([lightComponent, (1. - lightComponent)]) z, z_mass = Tools_Convert.frac_input(MM, zin, base) return z, z_mass
def specificVolumeLiquid_Wrap(self, pressure, temperature, molar_weight, molar_composition, density_model): ''' This function chooses density from EXperimental CORrelation ('jpDias') or from THErmodynamics ('ELV') \n T: temperature [K] \n p: pressure [Pa] \n MM: vector with molar weight of each component "i" [kg/kmol], i.e., (MM = ([MMrefrig, MMpoe])) \n x: vector molar concentration [-], i.e., (x = ([xR, xO])) \n x_mass: vector mass concentration [-] (x_mass = ([xR_mass, xO_mass])) \n spvolL: specific volume from correlation 'jpDias' or from 'ELV' [m3/kg] \n Return: spvolL''' p, T, MM, x = pressure, temperature, molar_weight, molar_composition nome_desta_funcao = sys._getframe().f_code.co_name x_mass = Tools_Convert.convert_molarfrac_TO_massfrac(MM, x) density_models = ['ELV', 'jpDias'] if density_model not in density_models: msg = 'Invalid density model in --> %s' % nome_desta_funcao msg += '\t Choose one of the models: %s' % density_models raise Exception(msg) if density_model == 'ELV': densL = super().calculate_density_phase(p, T, MM, x, fluid_type='liquid') elif density_model == 'jpDias': densL = self.densityLiquid_jpDias_SEC(T, p, x_mass) spvolL = np.power(densL, -1) return spvolL
def main(): #[1] - INPUT DATA p = 15e5 T = 300. LC, base = 99. / 100, 'mass' # <=============================== change here if necessary #[2] - CHANGING BASE zin = np.array([LC, (1. - LC)]) z, _z_mass = Tools_Convert.frac_input(MM, zin, base) #[3] - STANDARD VALUES hR = hR_mass * prop_obj.calculate_weight_molar_mixture( MM, z, 'saturated_liquid') sR = sR_mass * prop_obj.calculate_weight_molar_mixture( MM, z, 'saturated_liquid') #[4] - CREATING THE OBJECT hsfv_obj = HSFv(pC, TR, Tc, AcF, Cp, MM, hR, sR) #[5] - GETTING THE RESULTS F_V, h, s = hsfv_obj(p, T, z)
LEGEND: name: compost name MM: molar mass of each component [kg/kmol] Tc: critical temperature [K] pC: critical pressure [Pa] AcF: acentric factor [-] Cp: specific heat [J / kg K] !<=== HERE IT IS IN MASS BASE, BUT IT IS CONVERTED TO MOLAR BASE INSIDE THE FUNCTION ============================================================================================================= ''' '''OBS-1: For while, I don't have specific heat lubrificant oil POE-ISO-VG-10''' MM = np.array([102.03, 425.]) #425. specific_heat_mass_base = np.array( [0.82421, 2.45681] ) * 1.e3 # [J / kg K] @ 20ºC (Coolpropgit available on: http://ibell.pythonanywhere.com; see OBS-1) 2.45681 specific_heat = Tools_Convert.convert_specific_heat_massbase_TO_molarbase( specific_heat_mass_base, MM) #sort as name, molar_mass, Tc, pC, AcF, Cp comp1 = Molecule("R134a", MM[0], 374.21, 40.5928e5, 0.32684, specific_heat[0]) # [SOURCE II] comp2 = Molecule( "POE-ISO-10", MM[1], (595.8 + 273.15), 6.92e5, 1.0659, specific_heat[1] ) # [SOURCE I] ¿specific_heat POE ISO VG 10 não tem no artigo? kij = -0.002851 # [SOURCE I] ''' =============================================================================================================== Do you have kij above? If you don't have it ==> uncomment the CODE's 4 lines below =============================================================================================================== ''' # p_C = np.array([comp1.pC, comp2.pC]) # T_C = np.array([comp1.TC, comp2.TC])
def __call__(self, p, T, z): pC, TR, Tc = self.pC, self.TR, self.Tc AcF, Cp, MM, hR, sR = self.AcF, self.Cp, self.MM, self.hR, self.sR pB, _y_sat, _Sy, _counter = bubble_obj(T, z) pR = pB #<----setting the reference pressure equal bubble pressure if __name__ == '__main__': print(self) print( 'You\'re running pressure = %.3e [Pa] and temperature = %.2f C' % (p, (T - 273.15))) print( 'For this temperature T = (%.2f C) the bubble pressure is: pB = %.3e [Pa]' % ((T - 273.15), pB)) print( '\n---------------------------------------------------------)') if (p >= pB): F_V = 0.0 H_subcooled_molar = prop_obj.calculate_enthalpy( TR, T, pR, p, z, z, hR, Cp, 'liquid') M_L = prop_obj.calculate_weight_molar_mixture(MM, z, 'liquid') h_subcooled_mass = H_subcooled_molar * np.reciprocal(M_L) S_subcooled_molar = prop_obj.calculate_entropy( TR, T, pR, p, z, z, sR, Cp, 'liquid') s_subcooled_mass = S_subcooled_molar * np.reciprocal(M_L) H, h, S, s = H_subcooled_molar, h_subcooled_mass, S_subcooled_molar, s_subcooled_mass if __name__ == '__main__': print('--> This @(p,T) falls into single phase region') print('\nSubcooled liquid enthalpy h = %.3e [J/ kmol]' % H) print('\nSubcooled liquid entropy s = %.3e [J/(kmol K)]' % S) print('\nSubcooled liquid entalpy h = %.3e [J/ kg]' % h) print('\nSubcooled liquid entropy s = %.3e [J/(kg K)]' % s) else: F_V, _is_stable, K_values_newton, _initial_K_values = \ FlashAlgorithm_main.getting_the_results_from_FlashAlgorithm_main(p, T, pC, Tc, AcF, z) x = z / (F_V * (K_values_newton - 1.) + 1.) y = K_values_newton * x x_mass = Tools_Convert.convert_molarfrac_TO_massfrac(MM, x) y_mass = Tools_Convert.convert_molarfrac_TO_massfrac(MM, y) #Enthalpy H_sat_vapor_molar = prop_obj.calculate_enthalpy( TR, T, pR, p, y, z, hR, Cp, 'saturated_vapor') M_V = prop_obj.calculate_weight_molar_mixture( MM, y, 'saturated_vapor') h_sat_vapor_mass = H_sat_vapor_molar * np.reciprocal(M_V) H_sat_liquid_molar = prop_obj.calculate_enthalpy( TR, T, pR, p, x, z, hR, Cp, 'saturated_liquid') M_L = prop_obj.calculate_weight_molar_mixture( MM, x, 'saturated_liquid') h_sat_liquid_mass = H_sat_liquid_molar * np.reciprocal(M_L) H_enthalpy_mixture_molar = ( 1. - F_V) * H_sat_liquid_molar + F_V * H_sat_vapor_molar F_V_mass = np.reciprocal((M_L / M_V) * (1 / F_V - 1.) + 1.) h_enthalpy_mixture_mass = ( 1. - F_V_mass) * h_sat_liquid_mass + F_V_mass * h_sat_vapor_mass #Entropy S_sat_vapor_molar = prop_obj.calculate_entropy( TR, T, pR, p, y, z, sR, Cp, 'vapor') s_sat_vapor_mass = S_sat_vapor_molar * np.reciprocal(M_V) S_sat_liquid_molar = prop_obj.calculate_entropy( TR, T, pR, p, x, z, sR, Cp, 'liquid') s_sat_liquid_mass = S_sat_liquid_molar * np.reciprocal(M_L) S_entropy_mixture_molar = ( 1. - F_V) * S_sat_liquid_molar + F_V * S_sat_vapor_molar s_entropy_mixture_mass = ( 1. - F_V_mass) * s_sat_liquid_mass + F_V_mass * s_sat_vapor_mass H, h, S, s = H_enthalpy_mixture_molar, h_enthalpy_mixture_mass, S_entropy_mixture_molar, s_entropy_mixture_mass if __name__ == '__main__': print('This @(p,T) falls into two phase region') print( 'The mixture\'s state is ELV with a vapor quality = %.3f [molar base]' % F_V) print( 'The mixture\'s state is ELV with a vapor quality = %.3f [mass base]' % F_V_mass) print('x [molar base] = ', x) print('y [molar base] = ', y) print('x_mass [mass base] = ', x_mass) print('y_mass [mass base] = ', y_mass) print( '\n======\nThe mixture liquid/vapor with h = %.3e [J/ kmol]' % H) print( '\n======\nThe mixture liquid/vapor with s = %.3e [J/(kmol K)]' % S) print( 'The mixture liquid/vapor with h_mass = %.3e [J/ kg] {mass base}' % h) print( 'The mixture liquid/vapor with s_mass = %.3e [J/(kg K)] {mass base}' % s) return F_V, h, s
CompN = MM.shape[0] #components number Pbubble_store = np.zeros([LN, CN]) #matrix with LN lines and CN columns # Sy_store = np.zeros([LN, CN]) # y_store = np.zeros([LN, 2 * CN]) ''' ======================== PUTTING TO RUN: with a for loop ======================== ''' for index_out, T in enumerate(T_list): for index, LC_mass in enumerate(LC_mass_list): logging.debug('LC mass concentration =======> ' + str(LC_mass)) logging.debug('Temperatura =======> ' + str(T)) z_mass = np.array([LC_mass, (1. - LC_mass)]) z = Tools_Convert.convert_massfrac_TO_molarfrac(MM, z_mass) pBubble, y, Sy, counter = bubble_obj(T, z) Pbubble_store[index, index_out] = pBubble # Sy_store[index, index_out] = Sy # y_store[index, 2 * index_out:2 * index_out + 2] = y # print('%.2f \t %.2e \t %.5f' % (T, pBubble, Sy)) ''' ===================== PLOTTING ===================== ''' colors = ['r', 'b', 'k', 'y', 'm', 'c', 'g', 'lightgray'] markers = ['o', 'v', '<', '>', '.', 'p', 'P', 's', '*'] plt.title('Bubble Pressure of Mixture of ' + comp1.name + ' $versus$ ' + comp2.name + ' (Dados RefProp)')
=================================== @(PRESSURE, TEMPERATURE, GLOBAL MOLAR FRACTION): These are the conditions you are interested to evaluate =================================== LEGEND: p: Interested pressure (evaluate the enthalpy for this pressure) [Pa] T: Interested temperature (evaluate the enthalpy considering this isotherm) [K] OCR: oil-circulation ratio [-]: it is a mass fraction of oil per total mass mixture z_mass: global mass fraction z: global molar fraction ''' p = 0.3e5 # <=============================== change here T = (30. + 273.15) # <=============================== change here LC, base = 0.40, 'mass' # <=============================== change here zin = np.array([LC, (1. - LC)]) z, z_mass = Tools_Convert.frac_input(MM, zin, base) ''' ======================================= CREATING OBJECTS - [to a better identification, all objects' names are followed by "_obj"] ======================================= ''' rr_obj = RachfordRice() eos_obj = PengRobinsonEos(pC, Tc, AcF, omega_a, omega_b, kij) michelsen_obj = Michelsen() flash_obj = Flash(max_iter=50, tolerance=1.0e-13, print_statistics=False) prop_obj = Properties(pC, Tc, AcF, omega_a, omega_b, kij) def getting_the_results_from_FlashAlgorithm_main(p, T, pC, Tc, AcF, z): initial_K_values = calculate_K_values_wilson(p, T, pC, Tc, AcF)
A VISCOSIDADE DO REFRIGERANTE R134a É OBTIDO VIA CoolProp A VISCOSIDADE DO ÓLEO É CALCULADA VIA EQUAÇÃO DA TESE DO BERTOLDI (page 82) ''' ############################################################## #Testes...Discutir com Prof Jader (pC, Tc, AcF, MM, omega_a, omega_b, kij, Cp) = props LC, base = 0.01/100, 'mass' # <=============================== change here zin = np.array([LC, (1. - LC)]) xRe, xRe_mass = Tools_Convert.frac_input(MM, zin, base) ############################################################ #variables that are necessary to be imported (angleVenturi_in, angleVenturi_out, ks, Ld, D, Dvt, ziv, zig, zfg, zfv) = pipe() Ac_pipe = Area(0.0) (p_e, T_e, mdotL_e, fmR134a) = input_flow_data_function() Gt = mdotL_e / Ac_pipe #creating the object FlowTools_obj = FlowTools_class(pC, Tc, AcF, omega_a, omega_b, kij, mdotL_e)
def edo_2p(l, uph): ''' t: independent variable \n uph: dependent variables (packed), i.e., uph = uph(t) \n return: EDO system with derivative of uph with dt, i.e., d(uph)dt ''' global T_e, z, z_mass, ks, mdotL_e, MM, pR, TR, hR # unpack u, p, h = uph Ac = Area(l) rc = np.sqrt(Ac / np.pi) Dc = 2. * rc Gt = mdotL_e / Ac # see that Gt = Gt(l) Gt2 = np.power(Gt, 2) # ====================================================================== # find(T) # # ====================================================================== TI = 0.95 * T_e TS = 1.05 * T_e def find_temperature(temperature, pressure, molar_composition, enthalpy): _q, helv, _s = hsFv_obj(pressure, temperature, molar_composition) return helv - enthalpy try: T, converged = brentq(find_temperature, TI, TS, args=(p, z, h), xtol=1e-3, full_output=True) if converged is False: raise Exception('Not converged' + str(converged)) except Exception as msg_err: print('It has been difficult to find the roots ' + str(msg_err)) try: q, is_stable, K_values_newton, _initial_K_values = flash( p, T, pC, Tc, AcF, z) if is_stable is False: x = z / (q * (K_values_newton - 1.) + 1.) y = K_values_newton * x else: q, y, x = 0.0, np.zeros_like(z), z raise Exception(' Quality q = ' + str(q)) except Exception as new_err: print( 'This mixture is stable yet! (q < 0.0)! Artificially q and y were set up to ZERO ' + str(new_err)) logging.warning('A mistura ainda Monofásica? = %s' % (is_stable)) logging.warning('(T = %s ), (P = %s ), (i = %s) and (u = %s ) at l = %s ' % (T, p, h, u, l)) logging.warning('Vapor quality = ' + str(q)) x_mass = Tools_Convert.convert_molarfrac_TO_massfrac(MM, x) # ====================================================================== # area derivative # # ====================================================================== dl = 1e-5 avrg_A = (Ac + Area(l + dl)) / 2. dAdl = derivative(Area, l, dl) # ====================================================================== # compressibility # # ====================================================================== def volTP_func(pressure, temperature, quality, molar_weight, liquid_molar_composition, vapor_molar_composition, density=twoPhase_models['density']): ''' This function has been created to evaluate compressibility = (1 / volTP) * dvolTPdp \n Obs: negative signal is omitted here, but it is used ahead \n volTP: specific two-phase volume [m3/kg] according homogeneous model \n Return: volTP ''' volL_local = flowtools_obj.specificVolumeLiquid_Wrap( pressure, temperature, molar_weight, liquid_molar_composition, density) volG_local = flowtools_obj.specificVolumGas(pressure, temperature, molar_weight, vapor_molar_composition) volTP = flowtools_obj.specificVolumeTwoPhase(quality, volG_local, volL_local) return volTP dp = 1e-3 avrg_volTP = (volTP_func(p, T, q, MM, x, y) + volTP_func(p + dp, T, q, MM, x, y)) / 2. dvolTPdp = derivative(volTP_func, p, dp, args=(T, q, MM, x, y)) compressibility = np.power(avrg_volTP, -1) * dvolTPdp # ===================================================================== # calculating dvolTPdh (eq. A.13 Thesis) # # ===================================================================== def volL_func(refrigerant_molar_composition, oil_molar_composition, pressure, temperature, molar_weight, density=twoPhase_models['density']): ''' This function has been created to make possible evaluate dvolTPdh \n where dvolTPdh is the derivative of specific two-phase volume with enthalpy \n Actually, as eq. A.13 shows, volL is part of dvolTPdh evaluation \n volL: specific volume of liquid-phase [m3/kg] \n Return: volL ''' liquid_molar_composition = np.array( [refrigerant_molar_composition, oil_molar_composition]) volL = flowtools_obj.specificVolumeLiquid_Wrap( pressure, temperature, molar_weight, liquid_molar_composition, density) return volL dxR = 1e-2 xR, xO = x dvolLdxR = derivative(volL_func, xR, dxR, args=(xO, p, T, MM)) logging.warning('derivada dvolLdxR = ' + str(dvolLdxR)) def hL_func(refrigerant_molar_composition, oil_molar_composition, feed_molar_composition, pressure, temperature, pR, TR, hR, Cp, molar_weight, fluid_type='saturated_liquid'): ''' This function has been created to make possible evaluate dvolTPdh \n where dvolTPdh is the derivative of specific two-phase volume with enthalpy \n xR: it´s a float xO: it's a float hL: saturated liquid phase [J/kg] (be careful with this unit...is not [J/kmol]) \n Return: hL ''' liquid_molar_composition = np.array( [refrigerant_molar_composition, oil_molar_composition]) H_L_local = prop_obj.calculate_enthalpy(TR, temperature, pR, pressure, liquid_molar_composition, feed_molar_composition, hR, Cp, fluid_type) M_L_local = prop_obj.calculate_weight_molar_mixture( molar_weight, liquid_molar_composition, fluid_type) hL = H_L_local / M_L_local return hL dhLdxR = derivative(hL_func, xR, dxR, args=(xO, z, p, T, pR, TR, hR, Cp, MM)) volL = flowtools_obj.specificVolumeLiquid_Wrap(p, T, MM, x, twoPhase_models['density']) if y.all() == 0.0: volG, H_G, M_V, hG = np.zeros(4) else: volG = flowtools_obj.specificVolumGas(p, T, MM, y) H_G = prop_obj.calculate_enthalpy(TR, T, pR, p, y, z, hR, Cp, 'saturated_vapor') M_V = prop_obj.calculate_weight_molar_mixture(MM, y, 'saturated_vapor') hG = H_G / M_V H_L = prop_obj.calculate_enthalpy(TR, T, pR, p, x, z, hR, Cp, 'saturated_liquid') M_L = prop_obj.calculate_weight_molar_mixture(MM, x, 'saturated_liquid') hL = H_L / M_L vol_fg = volG - volL h_fg = hG - hL xR_mass, xO_mass = x_mass dvolTPdh = (vol_fg - xO_mass * dvolLdxR) / (h_fg - xO_mass * dhLdxR) logging.warning('vaporization enthalpy = ' + str(h_fg)) logging.warning('derivada dhLdxR = ' + str(dhLdxR)) logging.warning('dvolTPdh = ' + str(dvolTPdh)) # ====================================================================== # two-phase multiplier # # ====================================================================== viscL_fo = flowtools_obj.viscosityLiquid_Wrap(p, T, z, z_mass, twoPhase_models['viscosity']) volL_fo = flowtools_obj.specificVolumeLiquid_Wrap( p, T, MM, z, twoPhase_models['density']) viscL = flowtools_obj.viscosityLiquid_Wrap(p, T, x, x_mass, twoPhase_models['viscosity']) volTP = flowtools_obj.specificVolumeTwoPhase(q, volG, volL) viscTP = flowtools_obj.viscosityTwoPhase(q, volG, volTP, viscL, twoPhase_models['viscosityTP']) phiLO2 = flowtools_obj.twoPhaseMultiplier(q, viscTP, viscL, volG, volL) logging.warning('\n rho_fo = %s' % (1. / volL_fo)) logging.warning('\n volTP = %s' % volTP) logging.warning('\n mu_fo = %s' % (viscL_fo * 1e6)) # logging.warning('\n mu_L = %s' % (viscL * 1e6)) # logging.warning('\n mu_bif = %s' % (viscTP * 1e6)) logging.warning('\n Multiplicador Bifasico = %s' % phiLO2) # ====================================================================== # friction factor f_LO # # ====================================================================== Re_mon = flowtools_obj.reynolds_function(Gt, Dc, viscL_fo) f_FLO = flowtools_obj.frictionFactorFanning_Wrap( Re_mon, ks, Dc, twoPhase_models['friction']) logging.warning('\n Re_fo = %s <---> Fanning_fo = %s' % (Re_mon, f_FLO)) # ====================================================================== # setting matrix's coefficients # # ====================================================================== A11, A12, A13 = np.power(u, -1), -compressibility, -(dvolTPdh / volTP) A21, A22, A23 = u, volTP, 0. A31, A32, A33 = u, 0., 1. aux = -volTP * phiLO2 * (2.0 * Gt2 * volL_fo * (f_FLO / Dc)) C1, C2, C3 = (-dAdl / avrg_A), aux, aux # ====================================================================== # matrix solving # # ====================================================================== matrizA = np.array([[A11, A12, A13], [A21, A22, A23], [A31, A32, A33]]) RHS_C = np.array([C1, C2, C3]) dudl, dpdl, dhdl = np.linalg.solve(matrizA, RHS_C) return np.array([dudl, dpdl, dhdl]) #array shape (3,)