diff --git a/entrada.py b/entrada.py index f412a0c..907d884 100755 --- a/entrada.py +++ b/entrada.py @@ -9,10 +9,10 @@ sys.path.append(pyENL_dirpath) from solver import solver from utils import variables, random_lim, variables_string +from utils import ajustaUnidades from numpy import inf from CoolProp.CoolProp import PropsSI as prop from CoolProp.CoolProp import HAPropsSI as haprop -from re import sub from time import time import optparse from pint import _DEFAULT_REGISTRY as pyENLu @@ -98,11 +98,7 @@ def entradaTexto(ecuaciones, pyENL_timeout, varsObj=None, tol=None, method='hybr expresion = expresion.replace('\t','') # Capacidad de interpretar pow expresion = expresion.replace("^", "**") - if "hour" not in expresion: - expresion = sub(r'\[([A-z0-9\*{1,2}\/\^)]*)h([A-z0-9\*{1,2}\/\^)]*)]', - '[\g<1>hour\g<2>]', expresion) - expresion = sub(r'\[([A-z0-9\*{1,2}\/\^)]*)°C([A-z0-9\*{1,2}\/\^)]*)]', - '[\g<1>degree_Celsius\g<2>]', expresion) + expresion = ajustaUnidades(expresion) izq_der = expresion.split('=') operandos = ["+", "-", "*", "/", "("] # Revisar que no haya operadores incompletos diff --git a/pyENL.py b/pyENL.py index faad18c..a641005 100755 --- a/pyENL.py +++ b/pyENL.py @@ -35,7 +35,6 @@ pyENLu.load_definitions(pyENL_units_file) from CoolProp.CoolProp import FluidsList, get_parameter_index, get_parameter_information, is_trivial_parameter from pyENL_fcns.functions import dicc_coolprop -from re import sub # Cargar ahora interfaz desde archivo .py haciendo conversión con: # $ pyuic4 GUI/MainWindow.ui -o GUI/MainWindow.py # Icono: QtWidgets.QPixmap(_fromUtf8("GUI/imgs/icon.ico") @@ -858,11 +857,7 @@ def actualizaVarsTable(self): lowerlim = float(self.varsTable.item(i, 2).text()) upperlim = float(self.varsTable.item(i, 3).text()) units = self.varsTable.item(i, 4).text() - if not "hour" in units: - units = sub(r'([A-z0-9\*{1,2}\/\^)]*)h([A-z0-9\*{1,2}\/\^)]*)', - '\g<1>hour\g<2>', units) - units = sub(r'([A-z0-9\*{1,2}\/\^)]*)°C([A-z0-9\*{1,2}\/\^)]*)', - '\g<1>degree_Celsius\g<2>', units) + units = ajustaUnidades(units) comment = self.varsTable.item(i, 5).text() if lowerlim >= upperlim: raise Exception(self.traduccion['El número '] + str(lowerlim) + diff --git a/utils.py b/utils.py index e4cee67..196252d 100644 --- a/utils.py +++ b/utils.py @@ -549,6 +549,7 @@ def variablesProperties(texto_eqn,vars_ecuacion,posibles): if variable_unique in terminos_eqn: to_eval = texto_eqn.replace(variable_unique,'') to_eval =to_eval.replace("[", "*pyENLu.parse_units('").replace("]", "')") + to_eval = ajustaUnidades(to_eval) result_var = eval(to_eval) dic_vars = {variable_unique: {}} @@ -559,4 +560,17 @@ def variablesProperties(texto_eqn,vars_ecuacion,posibles): else: dic_vars[variable_unique]['guess'] = - result_var - return dic_vars \ No newline at end of file + return dic_vars + +def ajustaUnidades(texto): + ''' + Regresa el texto con unidades modificadas para soporte de + pyENL, como h para hour y °C para degree_Celsius + ''' + salida = texto + if 'hour' not in salida: + salida = re.sub(r'([A-z0-9\*{1,2}\/\^)]*)h([A-z0-9\*{1,2}\/\^)]*)', + '\g<1>hour\g<2>', salida) + salida = re.sub(r'([A-z0-9\*{1,2}\/\^)]*)°C([A-z0-9\*{1,2}\/\^)]*)', + '\g<1>degree_Celsius\g<2>', salida) + return salida \ No newline at end of file