summaryrefslogtreecommitdiff
path: root/DockWidgets/DockWidgetDistillationColumn.py
diff options
context:
space:
mode:
Diffstat (limited to 'DockWidgets/DockWidgetDistillationColumn.py')
-rw-r--r--DockWidgets/DockWidgetDistillationColumn.py189
1 files changed, 181 insertions, 8 deletions
diff --git a/DockWidgets/DockWidgetDistillationColumn.py b/DockWidgets/DockWidgetDistillationColumn.py
index dea2391..e98ba03 100644
--- a/DockWidgets/DockWidgetDistillationColumn.py
+++ b/DockWidgets/DockWidgetDistillationColumn.py
@@ -6,11 +6,13 @@ import pandas as pd
from functools import partial
from ComponentSelector import *
from collections import defaultdict
+from DockWidgets.DistillationColumnStagewiseResults import DistillationColumnStagewiseResults
from Graphics import *
ui_dialog,_ = loadUiType('DockWidgets/DockWidgetDistillationColumn.ui')
-class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
+
+class DockWidgetDistillationColumn(QDockWidget, ui_dialog):
def __init__(self,name,comptype,obj,container,parent=None):
QDockWidget.__init__(self,parent)
@@ -25,6 +27,8 @@ class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
self.input_params_list()
self.name_type = None
self.container = container
+ self.stage_res_table = DistillationColumnStagewiseResults()
+ self.stageResultsButton.clicked.connect(self.showStagewiseResults)
# input data tab
@@ -40,7 +44,6 @@ class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
self.lay1.addWidget(l1,0,1, alignment=Qt.AlignLeft)
self.input_dict.append(l1)
-
for i in range(self.obj.variables['Ni']['value']):
print(i)
l = QLineEdit()
@@ -102,6 +105,13 @@ class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
self.input_dict.append(self.cb4)
self.input_dict.append(self.le8)
+ self.lines = [line.rstrip('\n') for line in open('thermopackage.txt')]
+ for j in self.lines:
+ self.cbTP.addItem(str(j))
+ self.cbTP.setCurrentText(self.obj.variables['thermo_package']['value'])
+
+ self.input_dict.append(self.cbTP)
+
# self.input_dict = [self.le1, self.le2, self.le3, self.cb5, self.le5, self.cb1, self.cb2, self.le6, self.le7, self.cb3, self.cb4, self.le8]
except Exception as e:
@@ -154,7 +164,9 @@ class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
print(temp+8)
self.dict.append(int(self.input_dict[temp+9].text()))
print(temp+9)
-
+ self.dict.append(self.input_dict[temp+10].currentText())
+ print(temp + 10)
+
print("param ", self.dict)
self.obj.param_setter(self.dict)
self.hide()
@@ -162,14 +174,175 @@ class DockWidgetDistillationColumn(QDockWidget,ui_dialog):
except Exception as e:
print(e)
+ def showStagewiseResults(self):
+ self.stage_res_table.show()
@staticmethod
def showResult(lst):
- #DockWidget1.flag = True
+ # DockWidget1.flag = True
for i in lst:
- i.resultsCategory(i.name)
- #i.show()
+ try:
+ i.results_category(i.name)
+ except AttributeError:
+ pass
+
+ def clear_results(self):
+ self.tableWidget.setRowCount(0)
+ self.stage_res_table.T_table.setRowCount(0)
+ self.stage_res_table.T_table.setColumnCount(0)
+ self.stage_res_table.x_pc_table.setRowCount(0)
+ self.stage_res_table.x_pc_table.setColumnCount(0)
# result data tab
- def resultsCategory(self,name):
- pass \ No newline at end of file
+ def results_category(self,name):
+ flag = True
+ try:
+ print("Under result category name ", name)
+ result = self.container.result
+ obj = self.container.fetch_object(name)
+ self.tableWidget.setRowCount(0)
+ variKeys = obj.result_parameters
+ print(variKeys)
+ for i, val in enumerate(variKeys):
+ propertyname = name + '.' + val
+ print(i, val, propertyname)
+ if propertyname in result[0]:
+ ind = result[0].index(propertyname)
+ resultval = str(result[-1][ind])
+ obj.variables[val]['value'] = result[-1][ind]
+ print("######Resultsfetch####", val, resultval)
+ rowPosition = self.tableWidget.rowCount()
+ self.tableWidget.insertRow(rowPosition)
+ self.tableWidget.setItem(rowPosition, 0, QTableWidgetItem(obj.variables[val]['name']))
+ self.tableWidget.setItem(rowPosition, 1, QTableWidgetItem(resultval))
+ self.tableWidget.setItem(rowPosition, 2, QTableWidgetItem(obj.variables[val]['unit']))
+ self.tableWidget.resizeColumnsToContents()
+
+ # Stagewise Results
+ Nt = self.obj.variables['Nt']['value']
+ Nc = len(self.obj.compounds)
+ # initializing temporary arrays
+ Stages_T = [None]*Nt
+ # Can be uncommented when F_p and F_pc implemented in modelica table
+ # Stages_F_p = [[None for i in range(3)] for j in range(Nt)]
+ # Stages_F_pc = [[[None for i in range(3)] for j in range(Nc)] for k in range(Nt)]
+ Stages_x_pc = [[[None for i in range(3)] for j in range(Nc)] for k in range(Nt)]
+
+ Stages_res_varikeys = ['T']
+ for i in range(Nc):
+ for j in range(3):
+ Stages_res_varikeys.append('x_pc[' + str(j + 1) + ',' + str(i + 1) + ']')
+
+ for v in Stages_res_varikeys:
+ propertyname = name + '.condenser.' + v
+ if propertyname in result[0]:
+ ind = result[0].index(propertyname)
+ if v == 'T':
+ Stages_T[0] = result[-1][ind]
+ # Can be uncommented when F_p is implemented in modelica model
+ # elif v == 'F_p':
+ # if result[0][ind][result[0][ind].index('[') + 1] == '1':
+ # Stages_F_p[0][0] = result[-1][ind]
+ # elif result[0][ind][result[0][ind].index('[') + 1] == '2':
+ # Stages_F_p[0][1] = result[-1][ind]
+ # else:
+ # Stages_F_p[0][2] = result[-1][ind]
+ else:
+ print(ind)
+ phase_no = int(result[0][ind][result[0][ind].index('[') + 1])
+ comp_no = int(result[0][ind][result[0][ind].index(']') - 1])
+ Stages_x_pc[0][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # Can be uncommented and improved when F_pc implemented in modelica model
+ # if v == 'F_pc':
+ # Stages_F_pc[0][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # else:
+ # Stages_x_pc[0][comp_no - 1][phase_no - 1] = result[-1][ind]
+
+ for i in range(1, Nt - 1):
+ propertyname = name + '.tray[' + str(i) + '].' + v
+ if propertyname in result[0]:
+ ind = result[0].index(propertyname)
+ if v == 'T':
+ Stages_T[i] = result[-1][ind]
+ # Can be uncommented when F_p implemented in modelica model
+ # elif v == 'F_p':
+ # if result[0][ind][result[0][ind].index('[') + 1] == '1':
+ # Stages_F_p[i][0] = result[-1][ind]
+ # elif result[0][ind][result[0][ind].index('[') + 1] == '2':
+ # Stages_F_p[i][1] = result[-1][ind]
+ # else:
+ # Stages_F_p[i][2] = result[-1][ind]
+ else:
+ print(ind)
+ print(result[0][ind])
+ phase_no = int(result[0][ind].split('.')[-1][result[0][ind].split('.')[-1].index('[') + 1])
+ comp_no = int(result[0][ind].split('.')[-1][result[0][ind].split('.')[-1].index(']') - 1])
+ Stages_x_pc[i][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # Can be uncommented when F_pc implemented in modelica model
+ # if v == 'F_pc':
+ # Stages_F_pc[i][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # else:
+ # Stages_x_pc[i][comp_no - 1][phase_no - 1] = result[-1][ind]
+
+ propertyname = name + '.reboiler.' + v
+ if propertyname in result[0]:
+ ind = result[0].index(propertyname)
+ if v == 'T':
+ Stages_T[-1] = result[-1][ind]
+ # Can be uncommented when F_p implemented in modelica model
+ # elif v == 'F_p':
+ # if result[0][ind][result[0][ind].index('[') + 1] == '1':
+ # Stages_F_p[-1][0] = result[-1][ind]
+ # elif result[0][ind][result[0][ind].index('[') + 1] == '2':
+ # Stages_F_p[-1][1] = result[-1][ind]
+ # else:
+ # Stages_F_p[-1][2] = result[-1][ind]
+ else:
+ print(ind)
+ phase_no = int(result[0][ind][result[0][ind].index('[') + 1])
+ comp_no = int(result[0][ind][result[0][ind].index(']') - 1])
+ Stages_x_pc[-1][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # Can be uncommented when F_pc implemented in modelica model
+ # if v == 'F_pc':
+ # Stages_F_pc[-1][comp_no - 1][phase_no - 1] = result[-1][ind]
+ # else:
+ # Stages_x_pc[-1][comp_no - 1][phase_no - 1] = result[-1][ind]
+
+ # Assigning temp variables to obj variabes
+ self.obj.variables['Stages.T']['value'] = Stages_T
+ # Can be uncommented when F_p and F_pc implemented in modelica model
+ # self.obj.variables['Stages.F_p']['value'] = Stages_F_p
+ # self.obj.variables['Stages.F_pc']['value'] = Stages_F_pc
+ self.obj.variables['Stages.x_pc']['value'] = Stages_x_pc
+
+ # filling stagewise result table
+ tables = [self.stage_res_table.T_table, self.stage_res_table.x_pc_table]
+ # Can be uncommented when F_p and F_pc implemented in modelica model
+ # tables = [self.stage_res_table.T_table, self.stage_res_table.F_p_table, self.stage_res_table.F_pc_table, self.stage_res_table.x_pc_table]
+
+ for t in tables:
+ t.setRowCount(Nt)
+ t.setVerticalHeaderItem(0, QTableWidgetItem('Condenser'))
+ t.setVerticalHeaderItem(Nt -1, QTableWidgetItem('Reboiler'))
+ for i in range(1, Nt - 1):
+ t.setVerticalHeaderItem(i, QTableWidgetItem('Stage ' + str(i)))
+
+ T_table = self.stage_res_table.T_table
+ T_table.setColumnCount(1)
+ for i in range(Nt):
+ T_table.setItem(i, 0, QTableWidgetItem(Stages_T[i]))
+
+ x_pc_table = self.stage_res_table.x_pc_table
+ x_pc_table.setColumnCount(2*Nc)
+ for i in range(Nc):
+ x_pc_table.setHorizontalHeaderItem(2*i, QTableWidgetItem(self.obj.compounds[i] + '(Vapor)'))
+ x_pc_table.setHorizontalHeaderItem(2*i + 1, QTableWidgetItem(self.obj.compounds[i] + '(Liquid)'))
+
+ for i in range(Nt):
+ for j in range(Nc):
+ x_pc_table.setItem(i, 2*j, QTableWidgetItem(Stages_x_pc[i][j][1]))
+ x_pc_table.setItem(i, 2 * j + 1, QTableWidgetItem(Stages_x_pc[i][j][2]))
+ for t in tables:
+ t.resizeColumnsToContents()
+ except Exception as e:
+ print(e)