def calculate_Hx(zfDicc, tf, p): Ax = 0.0 Ay = 0.0 Bx = 0.0 By = 0.0 for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Tc = db_values['Tc'] Pc = db_values['Pc'] Ai = burbuja.calculate_Ai(Pc, tf, Tc) Bi = burbuja.calculate_Bi(Pc, tf, Tc) Xia = zfDicc[element]['Xia'] Yia = zfDicc[element]['Yia'] Bx += Bi * Xia By += Bi * Yia Ax += Ai * Xia Ay += Ai * Yia A = math.sqrt(abs(Ax * Ay)) B = math.sqrt(abs(Bx * By)) Z = burbuja.getRoots(A, B, p) Zl = Z['Zl'] Zv = Z['Zv'] Hv = calculate_H(Zv, tf, p, 'Yia', A, B, zfDicc) HL = calculate_H(Zl, tf, p, 'Xia', A, B, zfDicc) print('Hv:', Hv) print('HL:', HL) H = dict() H['HL'] = HL H['Hv'] = Hv return H
def calculate_TxxK(row_pos, columnaP): db_values = db.getElementValues(row_pos) A = db_values['A'] B = db_values['B'] C = db_values['C'] temperatura = (B / (A - math.log(columnaP))) - C return temperatura
def calculate_HF(zfDicc, tf, p): Ax = 0.0 Ay = 0.0 Bx = 0.0 By = 0.0 for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Tc = db_values['Tc'] Pc = db_values['Pc'] Ai = burbuja.calculate_Ai(Pc, tf, Tc) Bi = burbuja.calculate_Bi(Pc, tf, Tc) Xil = zfDicc[element]['Xil'] Yil = zfDicc[element]['Yil'] Bx += Bi * Xil By += Bi * Yil Ax += Ai * Xil Ay += Ai * Yil A = math.sqrt(Ax * Ay) B = math.sqrt(Bx * By) Z = burbuja.getRoots(A, B, p) Zl = Z['Zl'] Zv = Z['Zv'] Hv = calculate_H(Zv, tf, p, 'Yil', A, B, zfDicc) HL = calculate_H(Zl, tf, p, 'Xil', A, B, zfDicc) print('Hv:', Hv) print('HL:', HL) print('HF:', Hv + HL) return Hv + HL
def calculate_Ax(zfDicc, tf): sumatoria = 0.0 for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Tc = db_values['Tc'] Pc = db_values['Pc'] Ai = calculate_Ai(Pc, tf, Tc) xi = zfDicc[element]['Xi'] sumatoria += Ai * xi return sumatoria
def calculate_By(zfDicc, tf, p): sumatoria = 0.0 for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Tc = db_values['Tc'] Pc = db_values['Pc'] Bi = calculate_Bi(Pc, tf, Tc) xi = zfDicc[element]['Xi'] ki = calculate_Ki(p, tf, db_values) yi_supuesta = calculate_yi_supuesta(ki, xi) sumatoria += Bi * yi_supuesta return sumatoria
def calculate_valores_de_arranque(db_values, zfDicc, p, tf): try: Tc = db_values['Tc'] Tc = (Tc + TEMP_CORRECTOR) * 1.8 Pc = db_values['Pc'] Ax = 0.0 Ay = 0.0 Bx = 0.0 By = 0.0 tf = (tf + TEMP_CORRECTOR) * 1.8 Aix = calculate_Ai(Pc, tf, Tc) Bix = calculate_Bi(Pc, tf, Tc) for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Tc_e = db_values['Tc'] Tc_e = (Tc_e + TEMP_CORRECTOR) * 1.8 Pc = db_values['Pc'] Ai = calculate_Ai(Pc, tf, Tc_e) Bi = calculate_Bi(Pc, tf, Tc_e) Xia = zfDicc[element]['Xiad'] Yia = zfDicc[element]['Yiad'] Bx += (Bi * Xia) By += (Bi * Yia) Ax += (Ai * Xia) Ay += (Ai * Yia) A = math.sqrt(Ax * Ay) B = math.sqrt(Bx * By) valores_de_arranque = burbuja.getRoots(A, B, p) Zl = valores_de_arranque['Zl'] Zv = valores_de_arranque['Zv'] FIv = burbuja.coeficiente_de_fugacidad(Zv, p, A, B, Aix, Bix) FIl = burbuja.coeficiente_de_fugacidad(Zl, p, A, B, Aix, Bix) valores_de_arranque['FIv:'] = FIv valores_de_arranque['FIl:'] = FIl Kiad = FIl / FIv valores_de_arranque['Kiad'] = Kiad return valores_de_arranque except Exception as e: return None
def start_flash_isotermico(tf, p, zfDicc): # Set TD td = tf for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Zif = zfDicc[element]['Zi'] Kils = burbuja.calculate_Ki(p, td, db_values) zfDicc[element]['Kils'] = Kils zfDicc[element]['Xils'] = Zif print(element, 'Zi:', Zif, 'Kils:', Kils) zfDicc[element]['Yils'] = Zif * Kils zfDicc[element]['is_normalized'] = False psi = 0.5 normalized_counter = 0 psi_kplus1 = recalculate_psi(zfDicc, psi) while True: psi_abs = abs((psi_kplus1 - psi) / psi_kplus1) print('psi_abs:', psi_abs) if psi_abs < 0.001: print('©- psi_abs pass the error prove, Psi:', psi, 'psi^k+1:', psi_kplus1) #scitter() for element in zfDicc: print(colored(element, 'yellow')) if not zfDicc[element]['is_normalized']: db_values = db.getElementValues(zfDicc[element]['db_row']) Zif = zfDicc[element]['Zi'] Kils = zfDicc[element]['Kils'] xils_supuesta = zfDicc[element]['Xils'] yils_supuesta = zfDicc[element]['Yils'] xil_calculada = Zif / (1 + (psi_kplus1 * (Kils - 1))) yil_calculada = (Zif * Kils) / (1 + (psi_kplus1 * (Kils - 1))) norm_xi = abs(xils_supuesta - xil_calculada) norm_yi = abs(yils_supuesta - yil_calculada) if norm_xi < 0.001 and norm_yi < 0.001: zfDicc[element]['Xil'] = xil_calculada zfDicc[element]['Yil'] = yil_calculada zfDicc[element]['is_normalized'] = True zfDicc[element]['psi'] = psi_kplus1 print( colored('<-- ' + element + 'is normalized !!!', 'cyan')) normalized_counter += 1 break else: print(colored('-- NOT NORMALIZED ' + element, 'red')) print('-> Recalculating Kils for', element, ':', Kils) zfDicc[element]['Xils'] = xil_calculada zfDicc[element]['Yils'] = yil_calculada valores_de_arranque = calculate_valores_de_arranque( db_values, zfDicc, p, td) Kils = valores_de_arranque['Kils'] zfDicc[element]['Kils'] = Kils print('-> Now Kils for', element, ':', Kils) print('-> psi then:', psi, 'psi^k+1 then:', psi_kplus1) psi = 0.5 psi_kplus1 = recalculate_psi(zfDicc, psi) print('-> psi now:', psi, 'psi^k+1 now:', psi_kplus1) # normalized_counter = 0 break else: print('-> psi then:', psi, 'psi^k+1 then :', psi_kplus1) psi = psi_kplus1 psi_kplus1 = recalculate_psi(zfDicc, psi) print('-> psi now:', psi, 'psi^k+1 now:', psi_kplus1) if normalized_counter == len(zfDicc): break HF = calculate_HF(zfDicc, td, p) psi_avg = 0.0 for element in zfDicc: psi_avg += zfDicc[element]['psi'] psi_avg = abs(psi_avg / len(zfDicc)) print('PSI adecuado:', psi_avg) resultado = dict() resultado['HF'] = HF resultado['psi'] = psi_avg return resultado
def temperaturaBurbuja(p, zfDicc, tf): Td_obtenida = 0.0 yis_calculadas = dict() yis_calculadas_list = list() kib_calculadas = dict() result = dict() for element in zfDicc: # Fijar P y composición xi = zfDicc[element]['Xi'] # Estimar Td td = tf # Obtener valores de BD para el elemento db_values = db.getElementValues(zfDicc[element]['db_row']) # Calcular Ki como primera aprox Ki = calculate_Ki(p, td, db_values) # Calcular yi_supuesta yi_supuesta = calculate_yi_supuesta(Ki, xi) # Obtner Kib Kib = calculate_Kib(db_values, zfDicc, td, p) while True: # Calcular yi_calculada yi_calculada = Kib * xi #print('yi calculada = ', Kib,'*',xi, '=', yi_calculada) normalizado = abs(yi_supuesta - yi_calculada) #print('abs(yi_supuesta - yi_calculada) => ', yi_supuesta, '-', yi_calculada, '=', normalizado) if (normalizado < 0.001): yis_calculadas[element] = yi_calculada kib_calculadas[element] = Kib yis_calculadas_list.append(yi_calculada) #print('->Yis calculadas totales:', len(yis_calculadas), 'Cantidad de componentes:', len(zfDicc)) if len(yis_calculadas_list) == len(zfDicc): f = 1 - sum(yis_calculadas_list) if f >= -0.01 and f <= 0.01: print( '<------------------------------------------------>' ) Td_obtenida = td result['status'] = True result['Td'] = Td_obtenida result['yis_calculadas'] = yis_calculadas result['kib_calculadas'] = kib_calculadas return result else: delta_td = 0 if f < 0: print('delta_td -0.01') delta_td = -0.01 else: print('delta_td +0.01') delta_td = 0.01 td = td + delta_td print('Td=', td) result['status'] = False result['Td'] = td return result else: break else: yi_supuesta = yi_calculada Kib = calculate_Kib(db_values, zfDicc, td, p)
def start_flash_adiabatico(tf, columnaP, zfDicc): # Set TD td = tf for element in zfDicc: db_values = db.getElementValues(zfDicc[element]['db_row']) Zif = zfDicc[element]['Zi'] Kiad = burbuja.calculate_Ki(columnaP, td, db_values) zfDicc[element]['Kiad'] = Kiad zfDicc[element]['Xiad'] = Zif print(element, 'Zi:', Zif, 'Kiad:', Kiad) zfDicc[element]['Yiad'] = Zif * Kiad zfDicc[element]['is_normalized'] = False psi = 0.5 normalized_counter = 0 psi_kplus1 = recalculate_psi(zfDicc, psi) rand_psi_counter = 0 while True: psi_abs = abs((psi_kplus1 - psi) / psi_kplus1) print('psi_abs:', psi_abs) if psi_abs < 0.001: print('©- psi_abs pass the error probe, Psi:', psi, 'psi^k+1:', psi_kplus1) for element in zfDicc: print(colored(element, 'yellow')) if not zfDicc[element]['is_normalized']: db_values = db.getElementValues(zfDicc[element]['db_row']) Zif = zfDicc[element]['Zi'] Kiad = zfDicc[element]['Kiad'] xils_supuesta = zfDicc[element]['Xiad'] yils_supuesta = zfDicc[element]['Yiad'] xil_calculada = Zif / (1 + (psi_kplus1 * (Kiad - 1))) yil_calculada = (Zif * Kiad) / (1 + (psi_kplus1 * (Kiad - 1))) norm_xi = abs(xils_supuesta - xil_calculada) norm_yi = abs(yils_supuesta - yil_calculada) if norm_xi < 0.001 and norm_yi < 0.001: zfDicc[element]['Xia'] = xil_calculada zfDicc[element]['Yia'] = yil_calculada zfDicc[element]['is_normalized'] = True zfDicc[element]['psi'] = psi_kplus1 print( colored('<-- ' + element + 'is normalized !!!', 'cyan')) normalized_counter += 1 break else: print(colored('-- NOT NORMALIZED ' + element, 'red')) if rand_psi_counter == 1000: zfDicc[element]['Xia'] = xil_calculada zfDicc[element]['Yia'] = yil_calculada zfDicc[element]['is_normalized'] = True zfDicc[element]['psi'] = random.random() normalized_counter += 1 rand_psi_counter = 0 print('-> Recalculating Kiad for', element, ':', Kiad) zfDicc[element]['Xiad'] = xil_calculada zfDicc[element]['Yiad'] = yil_calculada valores_de_arranque = calculate_valores_de_arranque( db_values, zfDicc, columnaP, td) if valores_de_arranque == None: rand_psi_counter = 1000 break Kiad = valores_de_arranque['Kiad'] zfDicc[element]['Kiad'] = Kiad print('-> Now Kiad for', element, ':', Kiad) print('-> psi then:', psi, 'psi^k+1 then:', psi_kplus1) psi = 0.5 psi_kplus1 = recalculate_psi(zfDicc, psi) print('-> psi now:', psi, 'psi^k+1 now:', psi_kplus1) # normalized_counter = 0 rand_psi_counter += 1 break else: print('-> psi then:', psi, 'psi^k+1 then :', psi_kplus1) psi = psi_kplus1 psi_kplus1 = recalculate_psi(zfDicc, psi) print('-> psi now:', psi, 'psi^k+1 now:', psi_kplus1) return brutter() if normalized_counter == len(zfDicc): break H = calculate_Hx(zfDicc, td, columnaP) psi_avg = 0.0 for element in zfDicc: psi_avg += zfDicc[element]['psi'] psi_avg = abs(psi_avg / len(zfDicc)) print('PSI adecuado:', psi_avg) resultado = dict() resultado['HL_A'] = H['HL'] resultado['Hv_A'] = H['Hv'] resultado['psi_A'] = psi_avg resultado['TvAd'] = td return resultado