def setColumn(self, columna, data, **format): while len(data) > self.rowCount() - self.verticalOffset: self.addRow() self.blockSignals(True) for fila, dato in enumerate(data): self.item(fila, columna).setText(representacion(dato, **format)) self.blockSignals(False)
def __init__(self, config=None, parent=None): super(ConfFormat, self).__init__(parent) self.setColumnCount(2) self.setRowCount(len(unidades._magnitudes)) labels = [QtWidgets.QApplication.translate("pychemqt", "Format"), QtWidgets.QApplication.translate("pychemqt", "Sample")] self.setHorizontalHeaderLabels(labels) self.config = [] for i in range(self.rowCount()): item = QtWidgets.QTableWidgetItem(unidades._magnitudes[i][1]) self.setVerticalHeaderItem(i, item) self.setRowHeight(i, 22) self.setItem(i, 0, QtWidgets.QTableWidgetItem("")) self.item(i, 0).setTextAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.setItem(i, 1, QtWidgets.QTableWidgetItem("")) self.item(i, 1).setTextAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) if config.has_section("NumericFormat"): for i, magnitud in enumerate(unidades._magnitudes): formato = eval(config.get("NumericFormat", magnitud[0])) self.config.append(formato) self.item(i, 0).setText(self.txt(formato)) self.item(i, 1).setText(representacion(pi, **formato)) self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers) self.cellDoubleClicked.connect(self.showConfDialog)
def showConfDialog(self, fila, columna): dialog = NumericFactor(self.config[fila], parent=self) if dialog.exec_(): config = dialog.args() self.config[fila] = config self.item(fila, 0).setText(self.txt(config)) self.item(fila, 1).setText(representacion(pi, **config))
def cambiar_unidades(self, col, unit, magn, i): text = self.Tabla.getColumn(col) old_i = self.oldIndices[col] self.Tabla.blockSignals(True) for fila in range(0, len(text)): a = unit(text[fila], units[magn][old_i]).__getattribute__(units[magn][i]) self.Tabla.item(fila + 1, col).setText(representacion(a)) self.Tabla.blockSignals(False) self.oldIndices[col] = i
def setValue(self, value): self.value=self.unidad(value) if value or self.showNull: if self.magnitud: self.entrada.setText(self.value.format(magnitud=self.UIconfig)+self.suffix) elif self.unidad==float: self.entrada.setText(representacion(self.value, self.decimales, self.tolerancia)+self.suffix) else: self.entrada.setText(str(self.value)+self.suffix) self.setToolTip()
def unidades_clicked(self): if self.magnitud == "Currency": dialog = moneda(self.value) else: dialog = UI_conversorUnidades(self.unidad, self.value) if dialog.exec_() and self.retornar: self.entrada.setText(representacion(dialog.value.config(self.UIconfig)) + self.suffix) oldvalue = self.value self.value = dialog.value if oldvalue != self.value: self.valueChanged.emit(self.value)
def setStr(self): """Add data as string to cell table""" for fila, array in enumerate(self.data): if fila >= self.rowCount(): self.addRow() for columna, data in enumerate(array): if isinstance(data, str): txt = data else: txt = representacion(data, **self.format[columna]) self.setValue(fila, columna, txt)
def rellenarTablaRendimientos(self): self.Rendimientos.clearContents() self.Rendimientos.setRowCount(len(self.entrada.solido.distribucion)) self.Rendimientos.setHorizontalHeaderLabels([QtGui.QApplication.translate("equipment", "Diámetro, µm", None, QtGui.QApplication.UnicodeUTF8), QtGui.QApplication.translate("equipment", "Rendimiento", None, QtGui.QApplication.UnicodeUTF8)]) for i in range(len(self.entrada.solido.distribucion)): self.Rendimientos.setRowHeight(i, 22) self.Rendimientos.setItem(i, 0, QtGui.QTableWidgetItem(representacion(1e6*self.entrada.solido.diametros[i]))) self.Rendimientos.item(i, 0).setTextAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter) self.Rendimientos.item(i, 0).setFlags(QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEnabled) self.Rendimientos.setItem(i, 1, QtGui.QTableWidgetItem("")) self.Rendimientos.item(i, 1).setTextAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
def rellenarTablaRendimientos(self): self.Rendimientos.clearContents() self.Rendimientos.setRowCount(len(self.entrada.solido.distribucion)) self.Rendimientos.setHorizontalHeaderLabels([QtWidgets.QApplication.translate("equipment", "Diámetro, µm", None), QtWidgets.QApplication.translate("equipment", "Rendimiento", None)]) for i in range(len(self.entrada.solido.distribucion)): self.Rendimientos.setRowHeight(i, 22) self.Rendimientos.setItem(i, 0, QtWidgets.QTableWidgetItem(representacion(1e6*self.entrada.solido.diametros[i]))) self.Rendimientos.item(i, 0).setTextAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter) self.Rendimientos.item(i, 0).setFlags(QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEnabled) self.Rendimientos.setItem(i, 1, QtWidgets.QTableWidgetItem("")) self.Rendimientos.item(i, 1).setTextAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
def unidades_clicked(self): if self.magnitud == "Currency": dialog = moneda(self.value) else: dialog = UI_conversorUnidades(self.unidad, self.value) if dialog.exec_() and self.retornar: self.entrada.setText( representacion(dialog.value.config(self.UIconfig)) + self.suffix) oldvalue = self.value self.value = dialog.value if oldvalue != self.value: self.valueChanged.emit(self.value)
def setValue(self, value): self.value = self.unidad(value) if value or self.showNull: if self.magnitud: self.entrada.setText( self.value.format(magnitud=self.UIconfig) + self.suffix) elif self.unidad == float: self.entrada.setText( representacion(self.value, self.decimales, self.tolerancia) + self.suffix) else: self.entrada.setText(str(self.value) + self.suffix) self.setToolTip()
def readListFromStream(self, stream, key): """Personalizar en el caso de equipos con listas complejas""" valor = [] if key == "material": valor.append(stream.readString()) valor.append(stream.readString()) valor.append(float(representacion(stream.readFloat()))) valor.append(stream.readString()) for i in range(6): valor.append(float(representacion(stream.readFloat()))) valor.append(stream.readInt32()) valor.append(stream.readInt32()) elif key == "accesorios": for i in range(stream.readInt32()): accesorio = [] accesorio.append(stream.readInt32()) accesorio.append(stream.readInt32()) accesorio.append(float(representacion(stream.readFloat()))) accesorio.append(stream.readInt32()) for j in range(4): accesorio.append(stream.readString()) valor.append(accesorio) return valor
def readListFromStream(self, stream, key): """Personalizar en el caso de equipos con listas complejas""" valor=[] if key=="material": valor.append(stream.readString()) valor.append(stream.readString()) valor.append(float(representacion(stream.readFloat()))) valor.append(stream.readString()) for i in range(6): valor.append(float(representacion(stream.readFloat()))) valor.append(stream.readInt32()) valor.append(stream.readInt32()) elif key=="accesorios": for i in range(stream.readInt32()): accesorio=[] accesorio.append(stream.readInt32()) accesorio.append(stream.readInt32()) accesorio.append(float(representacion(stream.readFloat()))) accesorio.append(stream.readInt32()) for j in range(4): accesorio.append(stream.readString()) valor.append(accesorio) return valor
def setToolTip(self): Preferences=ConfigParser() Preferences.read(config.conf_dir+"pychemqtrc") if Preferences.getboolean("Tooltip", "Show"): Config=ConfigParser() Config.read(config.conf_dir+"pychemqtrc") try: lista=eval(Config.get('Tooltip',self.magnitud)) except: lista=[] if len(lista)>0: valores=[] for i in lista: valores.append(representacion(self.value.__getattribute__(self.value.__units__[i]), self.decimales, self.tolerancia)+" "+self.value.__text__[i]) self.entrada.setToolTip(os.linesep.join(valores))
def entrada_editingFinished(self): if not self.readOnly: if self.suffix: txt=self.entrada.text().split(self.suffix).replace(',', '.') else: txt=self.entrada.text().replace(',', '.') if self.unidad!=int: self.entrada.setText(representacion(float(txt), self.decimales, self.tolerancia)+self.suffix) oldvalue=self.value if self.magnitud: self.value=self.unidad(float(txt), "conf", magnitud=self.UIconfig) else: self.value=self.unidad(txt) if self.value!=oldvalue: self.valueChanged.emit(self.value) self.setToolTip()
def setMatrix(self, matriz): self.blockSignals(True) for i in range(self.rowCount(), len(matriz) + self.verticalOffset): self.addRow() for fila in range(self.rowCount() - self.verticalOffset): for columna, dato in enumerate(matriz[fila]): self.setItem(fila + self.verticalOffset, columna, QtGui.QTableWidgetItem(representacion(dato))) self.item(fila + self.verticalOffset, columna).setTextAlignment(self.orientacion | QtCore.Qt.AlignVCenter) for i in range(self.verticalOffset, self.rowCount()): self.setRowHeight(i + self.verticalOffset, 20) self.editingFinished.emit() self.blockSignals(False)
def addRow(self, data=None, index=None): if not data: data = [""] * self.columnas else: data = [representacion(i) for i in data] self.blockSignals(True) if index: i = index else: i = self.rowCount() self.insertRow(i) # self.setRowCount(i+1) self.setRowHeight(i, 22) if self.delegateforRow: delegate = self.delegateforRow(self.parent()) self.setItemDelegateForRow(i, delegate) Config = ConfigParser() Config.read(config.conf_dir + "pychemqtrc") for j in range(self.columnCount()): self.setItem(i, j, QtGui.QTableWidgetItem(data[j])) self.item(i, j).setTextAlignment(self.orientacion | QtCore.Qt.AlignVCenter) inactivo = QtGui.QColor(Config.get("General", 'Color_ReadOnly')) activo = QtGui.QColor(Config.get("General", 'Color_Resaltado')) if self.columnReadOnly[j]: flags = QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable self.item(i, j).setBackground(inactivo) else: flags = QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable self.item(i, j).setFlags(flags) if self.verticalHeaderBool: if self.encabezadoVertical: self.setVerticalHeaderItem( i, QtGui.QTableWidgetItem(self.encabezadoVertical[i])) elif self.verticalHeaderModel: self.setVerticalHeaderItem( i, QtGui.QTableWidgetItem(self.verticalHeaderModel + str(i))) self.blockSignals(False) if self.dinamica and self.rowCount() > 1: columna = self.columnReadOnly.index(False) self.setCurrentCell(i, columna)
def __plot(self, metodo=0, eD=[]): """Plot the Moody chart using the indicate method método de cálculo: 0 - Colebrook 1 - Chen (1979) 2 - Romeo (2002) 3 - Goudar-Sonnad 4 - Manadilli (1997) 5 - Serghides 6 - Churchill (1977) 7 - Zigrang-Sylvester (1982) 8 - Swamee-Jain (1976)") eD: lista con las líneas de rugosidades relativas a dibujar Prmin: escala del eje x, minimo valor de Pr a representar Prmax: escala del eje y, maximo valor de Pr a representar """ if not eD: eD=[0, 1e-6, 5e-6, 1e-5, 2e-5, 5e-5, 1e-4, 2e-4, 4e-4, 6e-4, 8e-4, 0.001, 0.0015, 0.002, 0.003, 0.004, 0.006, 0.008, 0.01, 0.0125, 0.015, 0.0175, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05, 0.06, 0.07] F=f_list[metodo] #laminar Re=[600, 2400] f=[64./R for R in Re] self.diagrama.axes2D.plot(Re, f, "k") #turbulento Re=logspace(log10(2400), 8, 50) for e in eD: self.diagrama.axes2D.plot(Re, [F(Rei, e) for Rei in Re], "k") self.diagrama.axes2D.annotate(representacion(e, tol=4.5), (Re[45], F(Re[45], e)), size="small", horizontalalignment="center", verticalalignment="bottom", rotation=arctan((log10(F(Re[47], e))-log10(F(Re[35], e)))/(log10(Re[47])-log10(Re[35])))*360/2/pi) #Transición f=[(1/(1.14-2*log10(3500/R)))**2 for R in Re] self.diagrama.axes2D.plot(Re, f, "k", lw=0.5, linestyle=":") self.diagrama.axes2D.add_artist(ConnectionPatch((600, 0.009), (2400, 0.009), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w")) self.diagrama.axes2D.add_artist(ConnectionPatch((2400, 0.009), (6000, 0.009), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w")) self.diagrama.axes2D.add_artist(ConnectionPatch((6000, 0.095), (40000, 0.095), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w")) self.diagrama.axes2D.add_artist(ConnectionPatch((40000, 0.095), (9.9e7, 0.095), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w")) self.diagrama.axes2D.text(15000, 0.094, QtGui.QApplication.translate("pychemqt", "Transition Zone"), size="small", verticalalignment="top", horizontalalignment="center") self.diagrama.axes2D.text(2e6, 0.094, QtGui.QApplication.translate("pychemqt", "Turbulent flux fully desarrolled"), size="small", verticalalignment="top", horizontalalignment="center") self.diagrama.axes2D.text(4000, 0.0091, QtGui.QApplication.translate("pychemqt", "Critic\nzone"), size="small", verticalalignment="bottom", horizontalalignment="center") self.diagrama.axes2D.text(1200, 0.0091, QtGui.QApplication.translate("pychemqt", "Laminar flux"), size="small", verticalalignment="bottom", horizontalalignment="center")
def setToolTip(self): Preferences = ConfigParser() Preferences.read(config.conf_dir + "pychemqtrc") if Preferences.getboolean("Tooltip", "Show"): Config = ConfigParser() Config.read(config.conf_dir + "pychemqtrc") try: lista = eval(Config.get('Tooltip', self.magnitud)) except: lista = [] if len(lista) > 0: valores = [] for i in lista: valores.append( representacion( self.value.__getattribute__( self.value.__units__[i]), self.decimales, self.tolerancia) + " " + self.value.__text__[i]) self.entrada.setToolTip(os.linesep.join(valores))
def addRow(self, data=None, index=None): if not data: data = [""] * self.columnas else: data = [representacion(i) for i in data] self.blockSignals(True) if index: i = index else: i = self.rowCount() self.insertRow(i) # self.setRowCount(i+1) self.setRowHeight(i, 22) if self.delegateforRow: delegate = self.delegateforRow(self.parent()) self.setItemDelegateForRow(i, delegate) Config = ConfigParser() Config.read(config.conf_dir + "pychemqtrc") for j in range(self.columnCount()): self.setItem(i, j, QtWidgets.QTableWidgetItem(data[j])) self.item(i, j).setTextAlignment(self.orientacion | QtCore.Qt.AlignVCenter) inactivo = QtGui.QColor(Config.get("General", "Color_ReadOnly")) activo = QtGui.QColor(Config.get("General", "Color_Resaltado")) if self.columnReadOnly[j]: flags = QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable self.item(i, j).setBackground(inactivo) else: flags = QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable self.item(i, j).setFlags(flags) if self.verticalHeaderBool: if self.encabezadoVertical: self.setVerticalHeaderItem(i, QtWidgets.QTableWidgetItem(self.encabezadoVertical[i])) elif self.verticalHeaderModel: self.setVerticalHeaderItem(i, QtWidgets.QTableWidgetItem(self.verticalHeaderModel + str(i))) self.blockSignals(False) if self.dinamica and self.rowCount() > 1: columna = self.columnReadOnly.index(False) self.setCurrentCell(i, columna)
def entrada_editingFinished(self): if not self.readOnly: if self.suffix: txt = self.entrada.text().split(self.suffix).replace(',', '.') else: txt = self.entrada.text().replace(',', '.') if self.unidad != int: self.entrada.setText( representacion(float(txt), self.decimales, self.tolerancia) + self.suffix) oldvalue = self.value if self.magnitud: self.value = self.unidad(float(txt), "conf", magnitud=self.UIconfig) else: self.value = self.unidad(txt) if self.value != oldvalue: self.valueChanged.emit(self.value) self.setToolTip()
def setRow(self, row, data): """Add data to a row""" self.blockSignals(True) self.data.insert(row, data) for column, data in enumerate(data): if isinstance(data, str): txt = data else: txt = representacion(data, **self.format[column]) self.setValue(row, column, txt) self.resizeColumnsToContents() # Set calculate point readOnly if not self.readOnly: flags = QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable color = config.Preferences.get("General", 'Color_ReadOnly') for i, bool in enumerate(self.columnReadOnly): if not bool: self.item(row, i).setFlags(flags) self.item(row, i).setBackground(QtGui.QColor(color)) self.blockSignals(False)
def __plot(self): """Plot the Moody chart using the indicate method """ fanning = Preferences.getboolean("Moody", "fanning") method = Preferences.getint("Moody", "method") if fanning: x = 4 else: x = 1 self.diagrama.ax.clear() self.diagrama.ax.set_autoscale_on(False) xlabel = QtWidgets.QApplication.translate("pychemqt", "Reynolds number") + ", " + r"$Re=\frac{V\rho D}{\mu}$" self.diagrama.ax.set_xlabel(xlabel, ha="center", size="10") if fanning: ylabel = QtWidgets.QApplication.translate("pychemqt", "Fanning Friction factor") formula = r"$f_f=\frac{2hDg}{LV^2}$" else: ylabel = QtWidgets.QApplication.translate("pychemqt", "Darcy Friction factor") formula = r"$f_d=\frac{2hDg}{LV^2}$" self.diagrama.ax.set_ylabel(ylabel + ", " + formula, size="10") txt = QtWidgets.QApplication.translate("pychemqt", "Relative roughness") + ", " + r"$r=\frac{\epsilon}{D}$" self.diagrama.fig.text(0.97, 0.5, txt, rotation=90, size="10", va="center", ha="center") self.diagrama.ax.grid(True) self.diagrama.ax.set_xlim(600, 1e8) self.diagrama.ax.set_ylim(0.008 / x, 0.11 / x) self.diagrama.ax.set_xscale("log") self.diagrama.ax.set_yscale("log") xticks = [ 7e2, 8e2, 9e2, 1e3, 2e3, 3e3, 4e3, 5e3, 6e3, 7e3, 8e3, 9e3, 1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 9e4, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 1e6, 2e6, 3e6, 4e6, 5e6, 6e6, 7e6, 8e6, 9e6, 1e7, 2e7, 3e7, 4e7, 5e7, 6e7, 7e7, 8e7, 9e7, ] self.diagrama.ax.set_xticks(xticks, minor=False) self.diagrama.ax.set_yticks([], minor=True) if fanning: yticks = [ 2e-3, 2.5e-3, 3e-3, 3.5e-3, 4e-3, 5e-3, 6e-3, 7e-3, 8e-3, 9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2, ] ytickslabel = [ 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5, ] else: yticks = [ 9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2, 2.6e-2, 2.7e-2, 2.8e-2, 2.9e-2, 3e-2, 3.2e-2, 3.4e-2, 3.6e-2, 3.8e-2, 4e-2, 4.2e-2, 4.4e-2, 4.6e-2, 4.8e-2, 5e-2, 5.2e-2, 5.4e-2, 5.6e-2, 5.8e-2, 6e-2, 6.2e-2, 6.4e-2, 6.6e-2, 6.8e-2, 7e-2, 7.5e-2, 8e-2, 8.5e-2, 9e-2, 9.5e-2, 1e-1, ] ytickslabel = [ 9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5, "", "", "", "", 3, "", "", "", "", 4, "", "", "", "", 5, "", "", "", "", 6, "", "", "", "", 7, "", 8, "", 9, "", r"$10^{-1}$", ] self.diagrama.ax.set_yticks(yticks) self.diagrama.ax.set_yticklabels(ytickslabel) eD = [ 0, 1e-6, 5e-6, 1e-5, 2e-5, 5e-5, 1e-4, 2e-4, 4e-4, 6e-4, 8e-4, 0.001, 0.0015, 0.002, 0.003, 0.004, 0.006, 0.008, 0.01, 0.0125, 0.015, 0.0175, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05, 0.06, 0.07, ] F = f_list[method] if not os.path.isfile(conf_dir + "moody.dat"): calculate(eD, F) load = False with open(conf_dir + "moody.dat", "r") as file: try: dat = json.load(file) except ValueError: calculate(eD, F) load = True if dat["fanning"] != fanning or dat["method"] != method: calculate(eD, F) load = True # Reload file if is create in las with statement if load: with open(conf_dir + "moody.dat", "r") as file: dat = json.load(file) # Plot data self.diagrama.ax.plot(Re_laminar, dat["laminar"], "k") for eD, f in dat["turbulent"].items(): self.diagrama.ax.plot(Re_turbulent, f, "k") title = " " + representacion(eD, tol=4.5) if f[-1] > 0.008 / x: self.diagrama.ax.text(1e8, f[-1], title, size="x-small", ha="left", va="center") # self.diagrama.ax.plot(Re_fully, dat["fully"], "k", lw=0.5, ls=":") # Add explicative legend # Laminar zone self.diagrama.ax.add_artist( ConnectionPatch( (600, 0.009 / x), (2400, 0.009 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w" ) ) txt = QtWidgets.QApplication.translate("pychemqt", "Laminar flux") self.diagrama.ax.text(1200, 0.0091 / x, txt, size="small", va="bottom", ha="center") # Critic zone self.diagrama.ax.add_artist( ConnectionPatch( (2400, 0.009 / x), (4000, 0.009 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w" ) ) txt = QtWidgets.QApplication.translate("pychemqt", "Critic\nzone") self.diagrama.ax.text(3200, 0.0091 / x, txt, size="small", va="bottom", ha="center") # Transition zone self.diagrama.ax.add_artist( ConnectionPatch( (4000, 0.095 / x), (10000, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w" ) ) txt = QtWidgets.QApplication.translate("pychemqt", "Transition Zone") self.diagrama.ax.text(7000, 0.104 / x, txt, size="small", va="top", ha="center") # Turbulent zone self.diagrama.ax.add_artist( ConnectionPatch( (10000, 0.095 / x), (9.9e7, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w" ) ) txt = QtWidgets.QApplication.translate("pychemqt", "Turbulent flux fully developed") self.diagrama.ax.text(1e6, 0.104 / x, txt, size="small", va="top", ha="center") # Smooth tubes self.diagrama.ax.add_artist( ConnectionPatch( (1e6, 0.009 / x), (1.5e6, 0.011 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w" ) ) txt = QtWidgets.QApplication.translate("pychemqt", "Smooth tubes") self.diagrama.ax.text(1e6, 0.009 / x, txt, size="small", va="top", ha="right") # Laminar equation if fanning: txt = r"$f=\frac{16}{Re}$" else: txt = r"$f=\frac{64}{Re}$" self.diagrama.ax.text(1.4e3, 0.042 / x, txt, size="12", va="top", ha="center", rotation=-66)
def __init__(self, unit, ConfSection, config, section="MEOS", parent=None): """Constructor unit: subclass of unidad to define the isoline type ConfSection: title of isoline config: config of pychemqt project """ super(Isolinea, self).__init__(parent) self.ConfSection = ConfSection self.magnitud = unit.__name__ self.unidad = unit self.section = section layout = QtWidgets.QGridLayout(self) layout.addWidget(QtWidgets.QLabel( QtWidgets.QApplication.translate("pychemqt", "Start")), 1, 1) self.inicio = Entrada_con_unidades(unit) layout.addWidget(self.inicio, 1, 2, 1, 3) layout.addWidget(QtWidgets.QLabel( QtWidgets.QApplication.translate("pychemqt", "Fin")), 2, 1) self.fin = Entrada_con_unidades(unit) layout.addWidget(self.fin, 2, 2, 1, 3) layout.addWidget(QtWidgets.QLabel( QtWidgets.QApplication.translate("pychemqt", "Intervalo")), 3, 1) if unit.__name__ == "Temperature": self.intervalo = Entrada_con_unidades(unidades.DeltaT) elif unit.__name__ == "Pressure": self.intervalo = Entrada_con_unidades(unidades.DeltaP) else: self.intervalo = Entrada_con_unidades(unit) layout.addWidget(self.intervalo, 3, 2, 1, 3) self.Personalizar = QtWidgets.QCheckBox( QtWidgets.QApplication.translate("pychemqt", "Customize")) layout.addWidget(self.Personalizar, 4, 1, 1, 4) self.Lista = QtWidgets.QLineEdit() layout.addWidget(self.Lista, 5, 1, 1, 4) self.Personalizar.toggled.connect(self.inicio.setDisabled) self.Personalizar.toggled.connect(self.fin.setDisabled) self.Personalizar.toggled.connect(self.intervalo.setDisabled) self.Personalizar.toggled.connect(self.Lista.setEnabled) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 6, 1, 1, 4) if unit.__name__ != "float" and section != "Psychr": self.Critica = QtWidgets.QCheckBox( QtWidgets.QApplication.translate( "pychemqt", "Include critic point line")) layout.addWidget(self.Critica, 7, 1, 1, 4) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 8, 1, 1, 4) self.lineconfig = LineConfig( ConfSection, QtWidgets.QApplication.translate("pychemqt", "Line Style")) layout.addWidget(self.lineconfig, 9, 1, 1, 4) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed), 10, 1) self.label = QtWidgets.QCheckBox( QtWidgets.QApplication.translate("pychemqt", "Label")) layout.addWidget(self.label, 11, 1) self.variable = QtWidgets.QCheckBox( QtWidgets.QApplication.translate("pychemqt", "Variable in Label")) layout.addWidget(self.variable, 12, 1, 1, 4) self.unit = QtWidgets.QCheckBox( QtWidgets.QApplication.translate("pychemqt", "Units in Label")) layout.addWidget(self.unit, 13, 1, 1, 4) layout.addWidget(QtWidgets.QLabel( QtWidgets.QApplication.translate("pychemqt", "Position")), 14, 1) self.label5 = Entrada_con_unidades(int, value=0, width=25, frame=False, readOnly=True) self.label5.setFixedWidth(30) layout.addWidget(self.label5, 14, 2) self.Posicion = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.Posicion.valueChanged.connect(self.label5.setValue) layout.addWidget(self.Posicion, 14, 3, 1, 2) layout.addItem(QtWidgets.QSpacerItem( 10, 10, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding), 15, 4) if config.has_section(section): self.inicio.setValue(config.getfloat(section, ConfSection+'Start')) self.fin.setValue(config.getfloat(section, ConfSection+'End')) self.intervalo.setValue( config.getfloat(section, ConfSection+'Step')) self.Personalizar.setChecked( config.getboolean(section, ConfSection+'Custom')) if config.get(section, ConfSection+'List') != "": T = [] for i in config.get(section, ConfSection+'List').split(','): if unit.__name__ == "float": T.append(representacion(float(i))) else: T.append(representacion(unit(float(i)).config())) self.Lista.setText(",".join(T)) if unit.__name__ != "float" and section != "Psychr": self.Critica.setChecked( config.getboolean(section, ConfSection+'Critic')) self.inicio.setDisabled(self.Personalizar.isChecked()) self.fin.setDisabled(self.Personalizar.isChecked()) self.intervalo.setDisabled(self.Personalizar.isChecked()) self.Lista.setEnabled(self.Personalizar.isChecked()) self.label.setChecked( config.getboolean(section, ConfSection+'Label')) self.variable.setChecked( config.getboolean(section, ConfSection+'Variable')) self.unit.setChecked( config.getboolean(section, ConfSection+'Units')) self.Posicion.setValue( config.getint(section, ConfSection+'Position')) self.lineconfig.setConfig(config, section)
def setMatrix(self, matriz): self.blockSignals(True) for i in range(self.rowCount(), len(matriz) + self.verticalOffset): self.addRow() for fila in range(self.rowCount() - self.verticalOffset): for columna, dato in enumerate(matriz[fila]): self.setItem(fila + self.verticalOffset, columna, QtWidgets.QTableWidgetItem(representacion(dato))) self.item(fila + self.verticalOffset, columna).setTextAlignment( self.orientacion | QtCore.Qt.AlignVCenter ) for i in range(self.verticalOffset, self.rowCount()): self.setRowHeight(i + self.verticalOffset, 20) self.editingFinished.emit() self.blockSignals(False)
def plot(self): """Plot the Moody chart using the indicate method """ fanning = self.Preferences.getboolean("Moody", "fanning") method = self.Preferences.getint("Moody", "method") if fanning: x = 4 else: x = 1 self.plt.ax.set_autoscale_on(False) self.plt.ax.clear() kw = formatLine(self.Preferences, "Moody", "crux") self.plt.lx = self.plt.ax.axhline(**kw) # the horiz line self.plt.ly = self.plt.ax.axvline(**kw) # the vert line xlabel = QtWidgets.QApplication.translate( "pychemqt", "Reynolds number") + ", " + r"$Re=\frac{V\rho D}{\mu}$" self.plt.ax.set_xlabel(xlabel, ha='center', size='10') if fanning: ylabel = QtWidgets.QApplication.translate( "pychemqt", "Fanning Friction factor") formula = r"$f_f=\frac{2hDg}{LV^2}$" else: ylabel = QtWidgets.QApplication.translate( "pychemqt", "Darcy Friction factor") formula = r"$f_d=\frac{2hDg}{LV^2}$" self.plt.ax.set_ylabel(ylabel+", " + formula, size='10') self.plt.ax.grid(True) self.plt.ax.set_xlim(600, 1e8) self.plt.ax.set_ylim(0.008/x, 0.11/x) self.plt.ax.set_xscale("log") self.plt.ax.set_yscale("log") xticks = [7e2, 8e2, 9e2, 1e3, 2e3, 3e3, 4e3, 5e3, 6e3, 7e3, 8e3, 9e3, 1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 9e4, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 1e6, 2e6, 3e6, 4e6, 5e6, 6e6, 7e6, 8e6, 9e6, 1e7, 2e7, 3e7, 4e7, 5e7, 6e7, 7e7, 8e7, 9e7] self.plt.ax.set_xticks(xticks, minor=False) self.plt.ax.set_yticks([], minor=True) if fanning: yticks = [2e-3, 2.5e-3, 3e-3, 3.5e-3, 4e-3, 5e-3, 6e-3, 7e-3, 8e-3, 9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2] ytickslabel = [2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5] else: yticks = [9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2, 2.6e-2, 2.7e-2, 2.8e-2, 2.9e-2, 3e-2, 3.2e-2, 3.4e-2, 3.6e-2, 3.8e-2, 4e-2, 4.2e-2, 4.4e-2, 4.6e-2, 4.8e-2, 5e-2, 5.2e-2, 5.4e-2, 5.6e-2, 5.8e-2, 6e-2, 6.2e-2, 6.4e-2, 6.6e-2, 6.8e-2, 7e-2, 7.5e-2, 8e-2, 8.5e-2, 9e-2, 9.5e-2, 1e-1] ytickslabel = [9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5, "", "", "", "", 3, "", "", "", "", 4, "", "", "", "", 5, "", "", "", "", 6, "", "", "", "", 7, "", 8, "", 9, "", r"$10^{-1}$"] self.plt.ax.set_yticks(yticks) self.plt.ax.set_yticklabels(ytickslabel) if not os.path.isfile(conf_dir+"moody.dat"): calculate(self.Preferences) load = False with open(conf_dir+"moody.dat", "r") as file: try: dat = json.load(file) except ValueError: calculate(self.Preferences) load = True if dat["fanning"] != fanning or dat["method"] != method: calculate(self.Preferences) load = True # Reload file if it's created in last with statement if load: with open(conf_dir+"moody.dat", "r") as file: dat = json.load(file) # Plot data kw = formatLine(self.Preferences, "Moody", "line") self.plt.ax.plot(Re_laminar, dat["laminar"], **kw) for ed, f in dat["turbulent"].items(): self.plt.ax.plot(Re_turbulent, f, **kw) title = " " + representacion(ed, tol=4.5) if f[-1] > 0.008/x: self.plt.ax.text(1e8, f[-1], title, size="x-small", ha='left', va='center') self.plt.ax.plot(Re_fully, dat["fully"], "k", lw=0.5, ls=":") # Add explicative legend # Laminar zone self.plt.ax.add_artist( ConnectionPatch((600, 0.01/x), (2400, 0.01/x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Laminar flux") self.plt.ax.text(1200, 0.0095/x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Critic zone self.plt.ax.add_artist( ConnectionPatch((2400, 0.01/x), (4000, 0.01/x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Critic\nzone") self.plt.ax.text(3200, 0.0095/x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Transition zone self.plt.ax.add_artist( ConnectionPatch((4000, 0.095/x), (40000, 0.095/x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Transition Zone") self.plt.ax.text(11000, 0.098/x, txt, size="small", va="bottom", ha="center", backgroundcolor="#ffffff") # Turbulent zone self.plt.ax.add_artist( ConnectionPatch((40000, 0.095/x), (9.9e7, 0.095/x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate( "pychemqt", "Turbulent flux fully developed") self.plt.ax.text(1e6, 0.098/x, txt, size="small", va="bottom", ha="center", backgroundcolor="#ffffff") # Smooth tubes self.plt.ax.add_artist( ConnectionPatch((1e6, 0.0095/x), (1.5e6, 0.011/x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Smooth tubes") self.plt.ax.text(1e6, 0.009/x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Laminar equation if fanning: txt = r"$f=\frac{16}{Re}$" else: txt = r"$f=\frac{64}{Re}$" self.plt.ax.text(1.4e3, 0.042/x, txt, size="12", va="top", ha="center", rotation=-66) # TODO: Calculate the angle dynamically self.plt.draw()
def plot(self): """Plot the Moody chart using the indicate method """ fanning = self.Preferences.getboolean("Moody", "fanning") method = self.Preferences.getint("Moody", "method") if fanning: x = 4 else: x = 1 self.plt.ax.set_autoscale_on(False) self.plt.ax.clear() kw = formatLine(self.Preferences, "Moody", "crux") self.plt.lx = self.plt.ax.axhline(**kw) # the horiz line self.plt.ly = self.plt.ax.axvline(**kw) # the vert line xlabel = QtWidgets.QApplication.translate( "pychemqt", "Reynolds number") + ", " + r"$Re=\frac{V\rho D}{\mu}$" self.plt.ax.set_xlabel(xlabel, ha='center', size='10') if fanning: ylabel = QtWidgets.QApplication.translate( "pychemqt", "Fanning Friction factor") formula = r"$f_f=\frac{2hDg}{LV^2}$" else: ylabel = QtWidgets.QApplication.translate("pychemqt", "Darcy Friction factor") formula = r"$f_d=\frac{2hDg}{LV^2}$" self.plt.ax.set_ylabel(ylabel + ", " + formula, size='10') self.plt.ax.grid(True) self.plt.ax.set_xlim(600, 1e8) self.plt.ax.set_ylim(0.008 / x, 0.11 / x) self.plt.ax.set_xscale("log") self.plt.ax.set_yscale("log") xticks = [ 7e2, 8e2, 9e2, 1e3, 2e3, 3e3, 4e3, 5e3, 6e3, 7e3, 8e3, 9e3, 1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 9e4, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 1e6, 2e6, 3e6, 4e6, 5e6, 6e6, 7e6, 8e6, 9e6, 1e7, 2e7, 3e7, 4e7, 5e7, 6e7, 7e7, 8e7, 9e7 ] self.plt.ax.set_xticks(xticks, minor=False) self.plt.ax.set_yticks([], minor=True) if fanning: yticks = [ 2e-3, 2.5e-3, 3e-3, 3.5e-3, 4e-3, 5e-3, 6e-3, 7e-3, 8e-3, 9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2 ] ytickslabel = [ 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5 ] else: yticks = [ 9e-3, 1e-2, 1.1e-2, 1.2e-2, 1.3e-2, 1.4e-2, 1.5e-2, 1.6e-2, 1.7e-2, 1.8e-2, 1.9e-2, 2e-2, 2.1e-2, 2.2e-2, 2.3e-2, 2.4e-2, 2.5e-2, 2.6e-2, 2.7e-2, 2.8e-2, 2.9e-2, 3e-2, 3.2e-2, 3.4e-2, 3.6e-2, 3.8e-2, 4e-2, 4.2e-2, 4.4e-2, 4.6e-2, 4.8e-2, 5e-2, 5.2e-2, 5.4e-2, 5.6e-2, 5.8e-2, 6e-2, 6.2e-2, 6.4e-2, 6.6e-2, 6.8e-2, 7e-2, 7.5e-2, 8e-2, 8.5e-2, 9e-2, 9.5e-2, 1e-1 ] ytickslabel = [ 9, r"$10^{-2}$", "", 1.2, "", 1.4, "", 1.6, "", 1.8, "", 2, "", "", "", "", 2.5, "", "", "", "", 3, "", "", "", "", 4, "", "", "", "", 5, "", "", "", "", 6, "", "", "", "", 7, "", 8, "", 9, "", r"$10^{-1}$" ] self.plt.ax.set_yticks(yticks) self.plt.ax.set_yticklabels(ytickslabel) if not os.path.isfile(conf_dir + "moody.dat"): calculate(self.Preferences) load = False with open(conf_dir + "moody.dat", "r") as file: try: dat = json.load(file) except ValueError: calculate(self.Preferences) load = True if dat["fanning"] != fanning or dat["method"] != method: calculate(self.Preferences) load = True # Reload file if it's created in last with statement if load: with open(conf_dir + "moody.dat", "r") as file: dat = json.load(file) # Plot data kw = formatLine(self.Preferences, "Moody", "line") self.plt.ax.plot(Re_laminar, dat["laminar"], **kw) for ed, f in dat["turbulent"].items(): self.plt.ax.plot(Re_turbulent, f, **kw) title = " " + representacion(ed, tol=4.5) if f[-1] > 0.008 / x: self.plt.ax.text(1e8, f[-1], title, size="x-small", ha='left', va='center') self.plt.ax.plot(Re_fully, dat["fully"], "k", lw=0.5, ls=":") # Add explicative legend # Laminar zone self.plt.ax.add_artist( ConnectionPatch((600, 0.01 / x), (2400, 0.01 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Laminar flux") self.plt.ax.text(1200, 0.0095 / x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Critic zone self.plt.ax.add_artist( ConnectionPatch((2400, 0.01 / x), (4000, 0.01 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Critic\nzone") self.plt.ax.text(3200, 0.0095 / x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Transition zone self.plt.ax.add_artist( ConnectionPatch((4000, 0.095 / x), (40000, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Transition Zone") self.plt.ax.text(11000, 0.098 / x, txt, size="small", va="bottom", ha="center", backgroundcolor="#ffffff") # Turbulent zone self.plt.ax.add_artist( ConnectionPatch((40000, 0.095 / x), (9.9e7, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate( "pychemqt", "Turbulent flux fully developed") self.plt.ax.text(1e6, 0.098 / x, txt, size="small", va="bottom", ha="center", backgroundcolor="#ffffff") # Smooth tubes self.plt.ax.add_artist( ConnectionPatch((1e6, 0.0095 / x), (1.5e6, 0.011 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=15, fc="w")) txt = QtWidgets.QApplication.translate("pychemqt", "Smooth tubes") self.plt.ax.text(1e6, 0.009 / x, txt, size="small", va="top", ha="center", backgroundcolor="#ffffff") # Laminar equation if fanning: txt = r"$f=\frac{16}{Re}$" else: txt = r"$f=\frac{64}{Re}$" self.plt.ax.text(1.4e3, 0.042 / x, txt, size="12", va="top", ha="center", rotation=-66) # TODO: Calculate the angle dynamically self.plt.draw()