summaryrefslogtreecommitdiff
path: root/src/main/python/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/python/utils')
-rw-r--r--src/main/python/utils/Bin_Phase_env.py241
-rw-r--r--src/main/python/utils/ComponentSelector.py177
-rw-r--r--src/main/python/utils/Container.py250
-rw-r--r--src/main/python/utils/Graphics.py702
-rw-r--r--src/main/python/utils/Streams.py470
-rw-r--r--src/main/python/utils/UnitOperations.py737
-rw-r--r--src/main/python/utils/__init__.py0
-rw-r--r--src/main/python/utils/__pycache__/Bin_Phase_env.cpython-37.pycbin7968 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/ComponentSelector.cpython-37.pycbin5514 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/Container.cpython-37.pycbin7735 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/Graphics.cpython-37.pycbin23723 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/Streams.cpython-37.pycbin12744 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/UnitOperations.cpython-37.pycbin26682 -> 0 bytes
-rw-r--r--src/main/python/utils/__pycache__/__init__.cpython-37.pycbin202 -> 0 bytes
-rw-r--r--src/main/python/utils/thermopackage.txt6
15 files changed, 0 insertions, 2583 deletions
diff --git a/src/main/python/utils/Bin_Phase_env.py b/src/main/python/utils/Bin_Phase_env.py
deleted file mode 100644
index dd6f938..0000000
--- a/src/main/python/utils/Bin_Phase_env.py
+++ /dev/null
@@ -1,241 +0,0 @@
-import sys
-import pandas as pd
-import numpy as np
-import os
-import csv
-from subprocess import Popen, PIPE
-
-from PyQt5.QtCore import *
-from PyQt5.QtWidgets import *
-from PyQt5.QtGui import *
-import PyQt5.QtGui as QtGui
-import PyQt5.QtCore as QtCore
-import PyQt5.QtWidgets as QtWidgets
-from PyQt5.uic import loadUiType
-
-
-import pyqtgraph as pg
-import pyqtgraph.exporters
-
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parentPath)
-
-ui_dialog,_ = loadUiType(parentPath+'/ui/utils/Binary_Phase_Env.ui')
-pg.CONFIG_OPTIONS['crashWarning'] = False
-
-class BinPhaseEnv(QWidget,ui_dialog):
- def __init__(self,comp):
- QWidget.__init__(self)
- self.setupUi(self)
-
- self.comp = comp
- self.compunds = self.comp.get_compounds()
-
- for i in self.compunds:
- self.comboBox.addItem(str(i))
-
- for i in range(len(self.compunds)):
- if i!=0:
- self.comboBox_2.addItem(str(self.compunds[i]))
-
- self.comboBox_2.addItem(str(self.compunds[0]))
-
- self.lines = [line.rstrip('\n') for line in open(parentPath+'/python/utils/thermopackage.txt')]
- for j in self.lines:
- self.comboBox_3.addItem(str(j))
-
- self.radioButton.setChecked(False)
- self.radioButton_2.setChecked(False)
-
- self.button_handler()
- self.counter = 1
-
- def button_handler(self):
- self.radioButton.clicked.connect(lambda:self.T_xy())
- self.radioButton_2.clicked.connect(lambda:self.P_xy())
- self.pushButton_2.clicked.connect(lambda:self.plot())
-
- def T_xy(self):
- self.radioButton.setChecked(True)
- self.radioButton_2.setChecked(False)
- for i in reversed(range(self.formLayout.count())):
- self.formLayout.itemAt(i).widget().setParent(None)
-
- self.first = QLineEdit()
- self.type = "P"
- self.other = "T"
- self.otherunit = "(K)"
- self.formLayout.addRow(QLabel("P(Pa)"),self.first)
- self.points = QLineEdit()
- self.points.setText("40")
- self.formLayout.addRow(QLabel("Number of data points"),self.points)
-
- def P_xy(self):
- self.radioButton_2.setChecked(True)
- self.radioButton.setChecked(False)
- for i in reversed(range(self.formLayout.count())):
- self.formLayout.itemAt(i).widget().setParent(None)
-
- self.first = QLineEdit()
- self.type = "T"
- self.other = "P"
- self.otherunit = "(Pa)"
- self.points = QLineEdit()
- self.points.setText("40")
- self.formLayout.addRow(QLabel("T(K)"),self.first)
- self.formLayout.addRow(QLabel("Number of data points"),self.points)
-
- def get_omc_path(self):
- try:
- self.omhome = os.environ.get('OPENMODELICAHOME')
- if self.omhome is None:
- self.omhome = os.path.split(os.path.split(os.path.realpath(spawn.find_executable("omc")))[0])[0]
- elif os.path.exists('/opt/local/bin/omc'):
- self.omhome = '/opt/local'
- elif os.path.exists('/usr/bin/omc'):
- self.omhome = '/usr'
- return os.path.join(self.omhome, 'bin', 'omc')
- except BaseException:
- #print("The OpenModelica compiler is missing in the System path please install it" )
- raise
-
- def plot(self):
- try:
- val = int(self.first.text(),10)
- except:
- val = 0
- try:
- data_points = int(self.points.text(),10)
- except:
- data_points = 0
-
- self.curr_path = os.getcwd()
- self.sim_dir_path = os.path.join(self.curr_path,'./../Simulator')
- self.Graphmo_path = os.path.join(self.sim_dir_path,'Graph.mo')
- self.plot_mos_path = os.path.join(self.sim_dir_path,'PlotGraph.mos')
-
- self.data = []
-
- self.comp1 = self.comboBox.currentText()
- self.comp2 = self.comboBox_2.currentText()
- self.comp_1 = self.comboBox.currentText().split('(')[0]
- self.comp_2 = self.comboBox_2.currentText().split('(')[0]
-
- self.thermoPack = self.comboBox_3.currentText()
-
- self.data.append("model Graph\n")
- self.data.append("import data = Simulator.Files.ChemsepDatabase;\n")
- self.data.append("parameter data."+self.comp_1+" comp1;\n")
- self.data.append("parameter data."+self.comp_2+" comp2;\n")
- self.data.append("extends BinaryEnvelopes."+self.thermoPack+"(Nc = 2, data_points = "+str(data_points)+ ", comp = { comp1, comp2 }, "+self.type+" = fill( "+str(val)+", "+str(data_points)+"));\n")
- self.data.append("end Graph;")
-
- with open(self.Graphmo_path, 'w') as txtfile:
- for d in self.data:
- txtfile.write(str(d))
-
- with open(self.plot_mos_path, 'w') as mosFile:
- mosFile.write("loadModel(Modelica);\n")
- mosFile.write("loadFile(\"Simulator/package.mo\");\n")
- mosFile.write("loadFile(\"BinaryEnvelopes.mo\");\n")
- mosFile.write("loadFile(\"Graph.mo\");\n")
- mosFile.write("simulate(Graph, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n")
-
- self.resdata = []
- self.omc_path = self.get_omc_path()
- simpath = self.plot_mos_path
- os.chdir(self.sim_dir_path)
-
- process = Popen([self.omc_path, '-s',simpath], stdout=PIPE, stderr=PIPE)
- self.stdout, self.stderr = process.communicate()
-
- os.chdir(self.curr_path)
-
- csvpath = os.path.join(self.sim_dir_path,'Graph_res.csv')
-
- self.datay = []
- self.datax1 = []
- self.datax2 = []
- self.rows = []
-
- with open (csvpath,'r') as resultFile:
- self.resdata = []
- csvreader = csv.reader(resultFile,delimiter=',')
- for row in csvreader:
- self.resdata.append(row)
- self.rows.append(row)
-
- if self.type=='T':
- for k in range(len(self.rows[0])):
- if self.rows[0][k][0]=='P':
- self.datay.append(float(self.rows[1][k]))
- length = len(self.rows[0][k])
- if self.rows[0][k][0]=='x' and self.rows[0][k][length-2]=='1':
- self.datax1.append(float(self.rows[1][k]))
- if self.rows[0][k][0]=='y' and self.rows[0][k][length-2]=='1':
- self.datax2.append(float(self.rows[1][k]))
- else:
- for k in range(len(self.rows[0])):
- if self.rows[0][k][0]=='T':
- self.datay.append(float(self.rows[1][k]))
- length = len(self.rows[0][k])
- if self.rows[0][k][0]=='x' and self.rows[0][k][length-2]=='1':
- self.datax1.append(float(self.rows[1][k]))
-
- if self.rows[0][k][0]=='y' and self.rows[0][k][length-2]=='1':
- self.datax2.append(float(self.rows[1][k]))
-
- plt = pg.PlotWidget()
- plt.showGrid(x=True,y=True)
- plt.addLegend()
- plt.setXRange(0,1)
-
- c1 = plt.plot(self.datax1, self.datay,pen=pg.mkPen('b',width = 1), name='dew points')
- c2 = plt.plot(self.datax2, self.datay,pen=pg.mkPen('r',width = 1), name='bubble points')
- view_box = plt.plotItem.vb
- self.tool_tip = ""
-
- def press_event(evt):
- a = 10
- pos = evt
- mousepoint = view_box.mapSceneToView(pos)
- roi = pg.ROI(pos)
- find_color = plt.mapToGlobal(pos.toPoint())
-
- screen = QGuiApplication.primaryScreen()
- image = screen.grabWindow(QApplication.desktop().winId()).toImage()
- colour = QtGui.QColor(image.pixel(find_color.x(),find_color.y()))
-
- if colour.red()==255 or colour.blue()==255:
- self.lineEdit_x.setText(str(round(mousepoint.x(),3)))
- self.lineEdit_y.setText(str(round(mousepoint.y(),3)))
- self.tool_tip = str(round(mousepoint.x(),3)) + ", " + str(round(mousepoint.y(),3))
- QApplication.setOverrideCursor(QCursor(QtCore.Qt.CrossCursor))
- else:
- self.lineEdit_x.setText("")
- self.lineEdit_y.setText("")
- self.tool_tip = ""
- QApplication.setOverrideCursor(QCursor(QtCore.Qt.ArrowCursor))
-
- def entered(items):
- for i in items:
- if i.__class__.__name__ =="LegendItem":
- self.lineEdit_x.setText("")
- self.lineEdit_y.setText("")
- QApplication.setOverrideCursor(QCursor(QtCore.Qt.ArrowCursor))
- else:
- i.setToolTip(self.tool_tip)
-
- plt.scene().sigMouseMoved.connect(press_event)
- plt.scene().sigMouseHover.connect(entered)
-
- plt.setLabel('left',self.other+self.otherunit,units = '')
- plt.setLabel('bottom',self.comp1+'(mol. frac.)',units = '')
-
- self.new_tab = plt
- self.new_tab.setObjectName("Plot "+str(self.counter))
-
- self.tabWidget.addTab(self.new_tab,"Plot "+str(self.counter))
- self.counter+=1
diff --git a/src/main/python/utils/ComponentSelector.py b/src/main/python/utils/ComponentSelector.py
deleted file mode 100644
index 44a2696..0000000
--- a/src/main/python/utils/ComponentSelector.py
+++ /dev/null
@@ -1,177 +0,0 @@
-from PyQt5.QtCore import *
-from PyQt5.QtWidgets import *
-from PyQt5.QtGui import *
-from PyQt5.uic import loadUiType
-import os, sys
-import pandas as pd
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parent)
-
-from Simulator.Databases.Databases import ChemsepDatabase
-ui_dialog,_ = loadUiType(parentPath+'/ui/utils/ComponentSelector.ui')
-
-
-#df = pd.read_csv("compoundsDatabase.csv")
-
-compound_selected = [] #list storing components that are selected inintialised as empty
-
-class ComponentSelector(QDialog,ui_dialog):
- def __init__(self,parent=None):
- QDialog.__init__(self,parent)
-
- self.setupUi(self)
-
- self.dict1=dict()#empty dictionary which will store the obj and its compound
- self.instance=[ChemsepDatabase()] #list of all the instances
- self.lines=[]
-
- for i in self.instance:
- x=i.get_comp_name_list()
- self.dict1[i]=x
- self.lines+=x
- #print(self.lines)
-
- self.model = QStringListModel()
- self.model.setStringList(self.lines)
-
- self.completer = QCompleter()
- self.completer.setCaseSensitivity(Qt.CaseInsensitive)
- self.completer.setModel(self.model)
-
- # QCompleter completes the text written in lineedit
- self.lineEdit.setCompleter(self.completer)
- self.compoundSelectButton.clicked.connect(self.compound_selection)
- self.compoundSelectButton.setAutoDefault(False)
- self.pushButton.clicked.connect(self.accept)
- self.pushButton_2.clicked.connect(self.cancel)
- self.pushButton_3.clicked.connect(self.remove_items)
-
- def final_list(self,*list_name):
- self.list_final=[]
- #add multiple lists
- for i in list_name:
- self.list_final+=i
- return (self.list_final)
-
- def is_compound_selected(self):
- if not compound_selected:
- return False
- else:
- return True
-
- #attrib:
- #CAS fro CAS Number
- #CompoundID for Name
- #Smiles for Molecular Formula
- #MolecularWeight for Molecular Weight
-
-#the below function will match the entered compound and get the database obj
- #of the corresponding database
-
- def get_object(self,component):
- for ele in self.dict1:
- values=self.dict1[ele]
- for ind in values:
- if ind ==component:
- return(ele)
-
-
-#the below finction removes the before added extra string from the cmpounds
- def get_original_name(self,component,removing_attrib):
- self.temp_comp= component.replace(removing_attrib,'')
- return(self.temp_comp)
-
- def compound_selection(self, *args):
- if len(args) == 2:
- self.comp = args[1] #helpful when loading saved data
- else:
- self.comp = self.lineEdit.text() #gets entered text
- if self.comp in self.lines: #matches with the db
- if self.comp not in compound_selected:
- compound_selected.append(self.comp) # appending compound in the list
- self.obj=self.get_object(self.comp) #obj will store the key of the dictionary
- #and thus store the instance of the class to which the component belongs
- self.removing_attrib='(' + self.obj.name + ')' #getting the attribute that is to be removed
- self.comp=self.get_original_name(self.comp,self.removing_attrib)
- #getting only air, water etc from air chemsep etc
-
-
- self.prop_list=self.obj.get_comp_prop(self.comp) #getting prop of the comp
- #obj is the required class object
- # self.creating_mo_file()
- self.final_mo()
-
- self.lineEdit.clear()
- #print(compound_selected)
-
- self.CAS=self.obj.get_value(self.comp,'CAS')
- self.name=self.comp
- self.molecular_formula=self.obj.get_value(self.comp, 'StructureFormula')
- self.molecular_weight=self.obj.get_value(self.comp, 'MolecularWeight')
-
- dict={'CAS':self.CAS,'Name':self.name,'Molecular Formula':self.molecular_formula,'Molecular Weight':self.molecular_weight}
- #converted everything to a dictionary which will be passes to addtable
- #function as a parameter.
- #print(dict)
- self.add_to_table(dict)
- else:
- self.show_error()
-
- @staticmethod
- def set_compounds(compounds):
- # compound_selected = compounds
- for i in compounds:
- compound_selected.append(i)
-
- def add_to_table(self,a):
- try:
- row_position = self.tableWidget.rowCount()
- self.tableWidget.insertRow(row_position)
- self.tableWidget.setItem(row_position , 0, QTableWidgetItem(str(a['CAS'])))
- self.tableWidget.setItem(row_position , 1, QTableWidgetItem(str(a['Name'])))
- self.tableWidget.setItem(row_position , 2, QTableWidgetItem(str(a['Molecular Formula'])))
- self.tableWidget.setItem(row_position , 3, QTableWidgetItem(str(a['Molecular Weight'])))
- except Exception as e:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- #print(exc_type, fname, exc_tb.tb_lineno)
-
- def add_compounds_to_list(self,comp): # which list?
- self.item = QListWidgetItem()
- self.item.setText(comp)
- self.listWidget.addItem(self.item)
-
- def remove_items(self):
- try:
- item = self.tableWidget.item(self.tableWidget.currentRow(),1).text() + '(chemsep)'
- self.tableWidget.removeRow(self.tableWidget.currentRow())
- compound_selected.remove(item)
- except Exception as e:
- print(e)
-
- def show_error(self):
- QMessageBox.about(self, 'Important', "Selected Compound is not Available")
-
- def cancel(self):
- compound_selected.clear()
- self.tableWidget.setRowCount(0)
- self.reject()
-
- def get_compounds(self):
- return compound_selected
-
- def final_mo(self):
- self.f_mo=open(parentPath+'/Simulator/database.mo','w+')
- self.f_mo.write('package database\n')
- for line in self.prop_list:
- self.f_mo.write(line)
- self.f_mo.write('\n')
- self.f_mo.write('\nend database;')
- self.f_mo.close()
-
- def accept(self):
- #self.parent().container.update_compounds()
- return super().accept()
- \ No newline at end of file
diff --git a/src/main/python/utils/Container.py b/src/main/python/utils/Container.py
deleted file mode 100644
index 486169f..0000000
--- a/src/main/python/utils/Container.py
+++ /dev/null
@@ -1,250 +0,0 @@
-from collections import defaultdict
-import datetime
-import pickle
-import os,sys
-
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parentPath)
-
-from python.OMChem.Flowsheet import Flowsheet
-from python.utils.ComponentSelector import *
-from python.utils.Graphics import NodeItem, Graphics, dock_widget_lst
-from python.DockWidgets.DockWidget import DockWidget
-
-class Container():
- def __init__(self,msgbrowser, graphicsView):
- self.unit_operations = []
- self.thermo_package = None
- self.compounds = None
- self.flowsheet = None
- self.conn = defaultdict(list)
- self.op=defaultdict(list)
- self.ip=defaultdict(list)
- self.msg = msgbrowser
- self.graphicsView = graphicsView
- self.msg.setText("")
- self.opl=[]
- self.result=[]
- self.graphics = Graphics(self.unit_operations, self.graphicsView)
- self.scene = self.graphics.get_scene()
-
- def current_time(self):
- now = datetime.datetime.now()
- time = str(now.hour) + ":" + str(now.minute) + ":" +str(now.second)
- return time
-
- def add_unit_operation(self, obj):
- box = None
- self.obj = obj
- self.scene = self.graphics.get_scene()
- box = self.graphics.create_node_item(self.obj, self)
- if box is not None:
- self.scene.addItem(box)
- box.setPos(2500-30, 2500-30)
-
- if(obj in self.unit_operations):
- pass
- else:
- self.unit_operations.append(obj)
- data = self.unit_operations[:]
- data.append(compound_selected)
- push('Undo', data)
- self.msg.append("<span style=\"color:blue\">["+str(self.current_time())+"]<b> "+obj.name+" </b>is instantiated .""</span>")
-
- '''
- Deletes the selected item from the canvas and also the objects created for that type.
- '''
- def delete(self,l):
- for item in l:
- self.scene.removeItem(item)
- for i in dock_widget_lst:
- if i.name == item.name:
- i.hide()
- del i
- break
-
- if hasattr(item,'input'):
- for x in item.input:
- if x.new_line:
- self.scene.removeItem(x.new_line)
- del x.new_line
- if x.other_line:
- self.scene.removeItem(x.other_line)
- del x.other_line
- if hasattr(item,'output'):
- for x in item.output:
- if x.new_line:
- self.scene.removeItem(x.new_line)
- del x.new_line
- if x.other_line:
- self.scene.removeItem(x.other_line)
- del x.other_line
- if hasattr(item,'obj'):
- self.unit_operations.remove(item.obj)
- for k in list(self.conn):
- if item.obj==k:
- del self.conn[k]
- elif item.obj in self.conn[k]:
- self.conn[k].remove(item.obj)
- self.msg.append("<span style=\"color:blue\">["+str(self.current_time())+"]<b> "+item.obj.name+" </b>is deleted .""</span>")
- del item.obj
- del item
-
- clean_file('Redo')
- data = self.unit_operations[:]
- data.append(compound_selected)
- push('Undo', data)
-
- def fetch_object(self,name):
- for i in self.unit_operations:
- if(i.name==name):
- return i
-
- def add_compounds(self,comp):
- self.compounds = comp
-
- def update_compounds(self):
- self.graphics.update_compounds()
-
- def add_thermo_package(self,thermo):
- self.thermo_package = thermo
-
- def msg_browser(self):
- std = self.flowsheet.stdout.decode("utf-8")
- if(std):
- stdout = str(std)
- stdout = stdout.replace("\n","<br/>")
- self.msg.append("<span style=\"color:green\">"+stdout+"</span>")
-
- stde = self.flowsheet.stderr.decode("utf-8")
- if(stde):
- stdout = str(stde)
- stdout = stdout.replace("\n","<br/>")
- self.msg.append("<span style=\"color:red\">"+stdout+"</span>")
-
- def simulate(self,mode):
-
- self.disableInterfaceforSimulation(True)
-
- for i in self.graphics.scene.items():
- if (isinstance(i, NodeItem)):
- try:
- i.dock_widget.clear_results()
- except AttributeError:
- pass
-
- #print("SIMULATE")
- #print(mode)
- self.compounds = compound_selected
- self.flowsheet = Flowsheet()
- self.flowsheet.add_compound_list([c[:c.index('(')] for c in self.compounds])
- #print("######## connection master#########\n",self.conn)
- for i in self.unit_operations :
- self.flowsheet.add_unit_operations(i)
-
-
- if mode=='SM':
- self.msg.append("<span>["+str(self.current_time())+"] Simulating in <b>Sequential</b> mode ... </span>")
- self.flowsheet.simulate_SM(self.ip,self.op)
- self.msg_browser()
- self.result=self.flowsheet.result_data
-
- elif mode=='EQN':
- self.msg.append("<span>["+str(self.current_time())+"] Simulating in <b>equation</b> mode ... </span>")
- self.flowsheet.simulate_EQN(self.msg)
- self.result=self.flowsheet.result_data
-
- if(len(self.result)== 4):
- #self.msg_browser()
- self.msg.append("<span style=\"color:green\">["+str(self.current_time())+"] Simulation <b>Successful.</b></span>")
- else:
- self.msg.append("<span style=\"color:red\">["+str(self.current_time())+"] Simulation <b>Failed.</b></span>")
- #print("under Eqn mode simulation")
-
- if(len(self.result)== 4):
- DockWidget.show_result(NodeItem.get_dock_widget())
-
- for i in self.graphics.scene.items():
- if (isinstance(i, NodeItem) and i.type == 'MaterialStream'):
- i.update_tooltip_selectedVar()
- no_input_lines = len(i.input[0].in_lines)
- no_output_lines = len(i.output[0].out_lines)
- if(no_input_lines>0): #Checks if material stream is input or output stream if it is output stream it continues
- i.obj.disableInputDataTab(i.dock_widget)
-
- self.disableInterfaceforSimulation(False)
-
- def enableToolbar(self,status):
- self.graphicsView.parent().parent().actionNew.setProperty('enabled',status)
- self.graphicsView.parent().parent().actionZoomIn.setProperty('enabled',status)
- self.graphicsView.parent().parent().actionZoomOut.setProperty('enabled',status)
- self.graphicsView.parent().parent().actionResetZoom.setProperty('enabled',status)
- self.graphicsView.parent().parent().actionEquationOriented.setProperty('enabled',status)
- self.graphicsView.parent().parent().actionTerminate.setProperty('enabled',not status)
- self.graphicsView.parent().parent().actionSelectCompounds.setProperty('enabled',status)
-
- def disableInterfaceforSimulation(self,status):
- self.graphicsView.parent().parent().menubar.setProperty('enabled',not status)
- self.enableToolbar(not status)
- self.graphicsView.parent().parent().dockWidget.setProperty('enabled',not status)
- self.graphicsView.setInteractive(not status)
- if status:
- QApplication.instance().setOverrideCursor(QCursor(Qt.WaitCursor))
- else:
- QApplication.instance().restoreOverrideCursor()
- QApplication.instance().setOverrideCursor(QCursor(Qt.ArrowCursor))
-
-def flat_list(lst):
- flat_lst=[]
- for sublist in lst:
- for item in sublist:
- flat_lst.append(item)
- return flat_lst
-
-def push(file_name, data):
- with open(f"{file_name}.dat", "ab") as obj:
- pickle.dump(data, obj)
-
-def clean_file(file_name):
- with open(f"{file_name}.dat", "wb") as clean:
- pass
-
-def pop(file_name):
- last_command = None
- if os.stat(f"{file_name}.dat").st_size != 0:
- commands = []
- with open(f"{file_name}.dat", "rb") as objs:
- while True:
- try:
- command = pickle.load(objs)
- commands.append(command)
- except EOFError:
- break
-
- last_command = commands[-1]
- commands.remove(commands[-1])
- if len(commands) != 0:
- with open(f"{file_name}.dat", "wb") as updated_data:
- for i in range(len(commands)):
- pickle.dump(commands[i], updated_data)
- else:
- clean_file(file_name)
-
- return last_command
-
-def get_last_list(file_name):
- commands = []
- if os.stat(f"{file_name}.dat").st_size != 0:
- with open(f"{file_name}.dat", "rb") as objs:
- while True:
- try:
- command = pickle.load(objs)
- commands.append(command)
- except EOFError:
- break
- if len(commands) is not 0:
- return commands[-1]
- else:
- return None
diff --git a/src/main/python/utils/Graphics.py b/src/main/python/utils/Graphics.py
deleted file mode 100644
index e3eab7a..0000000
--- a/src/main/python/utils/Graphics.py
+++ /dev/null
@@ -1,702 +0,0 @@
-from PyQt5.QtCore import *
-from PyQt5.QtWidgets import *
-from PyQt5.QtGui import *
-import PyQt5.QtGui as QtGui
-import PyQt5.QtCore as QtCore
-import PyQt5.QtWidgets as QtWidgets
-from PyQt5.QtWidgets import QLineEdit
-import os, sys
-
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parentPath)
-
-from python.DockWidgets.DockWidget import *
-from python.DockWidgets.DockWidgetMaterialStream import *
-from python.DockWidgets.DockWidgetDistillationColumn import *
-from python.DockWidgets.DockWidgetShortcutColumn import *
-from python.DockWidgets.DockWidgetMixer import *
-from python.DockWidgets.DockWidgetSplitter import *
-from python.DockWidgets.DockWidgetFlash import *
-from python.DockWidgets.DockWidgetCompoundSeparator import *
-from python.DockWidgets.DockWidgetCompressorExpander import *
-from python.utils.Container import *
-from python.utils.Streams import *
-from python.utils.UnitOperations import *
-from python.utils.ComponentSelector import *
-
-class Graphics(QDialog, QtWidgets.QGraphicsItem):
-
- def __init__(self, unit_operations, graphicsView):
- QDialog.__init__(self)
- QtWidgets.QGraphicsItem.__init__(self)
- self.scene = QGraphicsScene()
- self.scene.setItemIndexMethod(QGraphicsScene.BspTreeIndex)
- self.graphicsView = graphicsView
- self.pos = None
- self.unit_operations = unit_operations
- self.graphicsView.horizontalScrollBarVal = self.graphicsView.horizontalScrollBar().value()
-
- def get_scene(self):
- return self.scene
-
- def create_node_item(self,unit_operation, container):
- tempItem = NodeItem(unit_operation, container, self.graphicsView)
- if tempItem.ok:
- return tempItem
- else:
- return None
-
- def update_compounds(self):
- for i in self.graphicsView.items():
- if isinstance(i, NodeItem):
- i.update_compounds()
-
- def load_canvas(self, obj, container):
- stm = ['MaterialStream','EngStm']
- for i in obj:
- if i in self.unit_operations:
- pass
- else:
- self.unit_operations.append(i)
- type(i).counter += 1
- #print(self.unit_operations)
- new_box = self.create_node_item(i, container)
- new_box.setPos(i.pos.toPoint().x(), i.pos.toPoint().y())
- self.scene.addItem(new_box)
-
- for i in obj:
- if i.type == "MaterialStream":
- pass
- #print(eval(i.type))
- elif i.type not in stm:
- ip = i.input_stms
- op = i.output_stms
- for k, v in ip.items():
- pointA = NodeItem.get_instances(v.name)
- pointB = NodeItem.get_instances(i.name)
- rect = pointA.output[0].boundingRect()
- pointAA = QtCore.QPointF(rect.x() + rect.width()/(2), rect.y() + rect.height()/(2))
- pointAA = pointA.output[0].mapToScene(pointAA)
- socketB = next((s for s in pointB.input if k == s.id))
- rectB = socketB.boundingRect()
- pointBB = QtCore.QPointF(rectB.x() + rectB.width()/(2), rectB.y() + rectB.height()/(2))
- pointBB = socketB.mapToScene(pointBB)
- self.new_line = NodeLine(pointAA, pointBB, 'in')
- self.new_line.source = pointA.output[0]
- self.new_line.target = socketB
- pointA.output[0].out_lines.append(self.new_line)
- socketB.in_lines.append(self.new_line)
- pointA.output[0].other_line = self.new_line
- socketB.other_line = self.new_line
- self.scene.addItem(self.new_line)
- self.new_line.updatePath()
- for k, v in op.items():
- pointA = NodeItem.get_instances(i.name)
- pointB = NodeItem.get_instances(v.name)
- socketA = next(s for s in pointA.output if k == s.id)
- rect = socketA.boundingRect()
- pointAA = QtCore.QPointF(rect.x() + rect.width()/(2), rect.y() + rect.height()/(2))
- pointAA = socketA.mapToScene(pointAA)
- rectB = pointB.input[0].boundingRect()
- pointBB = QtCore.QPointF(rectB.x() + rectB.width()/(2), rectB.y() + rectB.height()/(2))
- pointBB = pointB.input[0].mapToScene(pointBB)
- self.new_line = NodeLine(pointAA, pointBB, 'out')
- self.new_line.source = socketA
- self.new_line.target = pointB.input[0]
- socketA.out_lines.append(self.new_line)
- pointB.input[0].in_lines.append(self.new_line)
- socketA.other_line = self.new_line
- pointB.input[0].other_line = self.new_line
- self.scene.addItem(self.new_line)
- self.new_line.updatePath()
-
-
-class NodeLine(QtWidgets.QGraphicsPathItem):
- def __init__(self, pointA, pointB , socket):
- super(NodeLine, self).__init__()
- self._pointA = pointA
- self._pointB = pointB
- self.socket = socket
- self._source = None
- self._target = None
- self.setZValue(-1)
- self.setBrush(QtGui.QColor(0,70,70,120))
- self.pen = QtGui.QPen()
- self.pen.setStyle(QtCore.Qt.SolidLine)
- self.pen.setWidth(2)
- self.pen.setColor(QtGui.QColor(0,70,70,220))
- self.setPen(self.pen)
-
- def updatePath(self):
-
- if (self._pointB.x() - self._pointA.x()) < 30:
- path = QtGui.QPainterPath()
- midptx = (self.pointA.x() + 13)
-
- ctrl1_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
- ctrl2_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
- pt1 = QtCore.QPointF(midptx , self.pointA.y())
- path.moveTo(pt1)
- path.cubicTo(ctrl1_1, ctrl2_1, pt1)
-
- if abs(self.pointB.x()-midptx) > 150:
- ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y())
- ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y())
- pt2 = QtCore.QPointF(midptx , self.pointA.y()+100)
- path.cubicTo(ctrl1_2, ctrl2_2, pt2)
- path.moveTo(pt2)
-
- ctrl1_3 = QtCore.QPointF(midptx, self.pointA.y()+100)
- ctrl2_3 = QtCore.QPointF(midptx, self.pointA.y()+100)
- pt3 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100)
- path.cubicTo(ctrl1_3, ctrl2_3, pt3)
- path.moveTo(pt3)
-
- ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100)
- ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, self.pointA.y()+100)
- pt4 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- path.cubicTo(ctrl1_4, ctrl2_4, pt4)
- path.moveTo(pt4)
-
- ctrl1_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- ctrl2_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- pt5 = QtCore.QPointF(self.pointB.x(), self.pointB.y())
- path.cubicTo(ctrl1_5, ctrl2_5, pt5)
- path.moveTo(pt5)
-
- self.setPath(path)
- return
- else:
- ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y())
- ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y())
- pt2 = QtCore.QPointF(midptx , max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- path.cubicTo(ctrl1_2, ctrl2_2, pt2)
- path.moveTo(pt2)
-
- ctrl1_3 = QtCore.QPointF(midptx, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- ctrl2_3 = QtCore.QPointF(midptx, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- pt3 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- path.cubicTo(ctrl1_3, ctrl2_3, pt3)
- path.moveTo(pt3)
-
- ctrl1_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- ctrl2_4 = QtCore.QPointF(self.pointB.x()-13, max(self.pointB.y(), self.pointA.y())-(abs(self.pointA.y()-self.pointB.y())/2))
- pt4 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- path.cubicTo(ctrl1_4, ctrl2_4, pt4)
- path.moveTo(pt4)
-
- ctrl1_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- ctrl2_5 = QtCore.QPointF(self.pointB.x()-13, self.pointB.y())
- pt5 = QtCore.QPointF(self.pointB.x(), self.pointB.y())
- path.cubicTo(ctrl1_5, ctrl2_5, pt5)
- path.moveTo(pt5)
-
- self.setPath(path)
- return
-
- path = QtGui.QPainterPath()
- path.moveTo(self.pointA)
- midptx = 0.5*(self.pointA.x() + self.pointB.x())
-
- ctrl1_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
- ctrl2_1 = QtCore.QPointF(self.pointA.x(), self.pointA.y())
- pt1 = QtCore.QPointF(midptx , self.pointA.y())
- path.cubicTo(ctrl1_1, ctrl2_1, pt1)
- path.moveTo(pt1)
-
- ctrl1_2 = QtCore.QPointF(midptx, self.pointA.y())
- ctrl2_2 = QtCore.QPointF(midptx, self.pointA.y())
- pt2 = QtCore.QPointF(midptx , self.pointB.y())
- path.cubicTo(ctrl1_2, ctrl2_2, pt2)
- path.moveTo(pt2)
-
- ctrl1_3 = QtCore.QPointF(midptx, self.pointB.y())
- ctrl2_3 = QtCore.QPointF(midptx, self.pointB.y())
- path.cubicTo(ctrl1_3, ctrl2_3, self.pointB)
- path.moveTo(self.pointB)
- self.setPath(path)
-
- def paint(self, painter, option, widget):
- painter.setPen(self.pen)
- painter.drawPath(self.path())
-
- @property
- def pointA(self):
- return self._pointA
-
- @pointA.setter
- def pointA(self, point):
- self._pointA = point
- self.updatePath()
-
- @property
- def pointB(self):
- return self._pointB
-
- @pointB.setter
- def pointB(self, point):
- self._pointB = point
- self.updatePath()
-
- @property
- def source(self):
- return self._source
-
- @source.setter
- def source(self, widget):
- self._source = widget
-
- @property
- def target(self):
- return self._target
-
- @target.setter
- def target(self, widget):
- self._target = widget
-
- def __delete__(self,instance):
- del self._source
- del self._target
- del self._pointA
- del self._pointB
-
-class NodeSocket(QtWidgets.QGraphicsItem):
- def __init__(self, rect, parent, socketType, id):
- super(NodeSocket, self).__init__(parent)
- self.rect = rect
- self.type = socketType
- self.parent=parent
- self.id = id
- self.setAcceptHoverEvents(True)
- self.new_line=None
- self.other_line=None
-
- # Brush
- self.brush = QtGui.QBrush(Qt.transparent)
- # Pen
- self.pen = QtGui.QPen(Qt.NoPen)
-
- # Lines
- self.out_lines = []
- self.in_lines = []
-
- def shape(self):
- path = QtGui.QPainterPath()
- path.addEllipse(self.boundingRect())
- return path
-
- def boundingRect(self):
- return QtCore.QRectF(self.rect)
-
- def paint(self, painter, option, widget):
-
- painter.setPen(self.pen)
- painter.drawEllipse(self.rect.x(),self.rect.y(),self.rect.height(),self.rect.width())
- painter.setBrush(self.brush)
- painter.drawEllipse(self.rect.x()+2,self.rect.y()+2,(self.rect.height()/3)*2,(self.rect.width()/3)*2)
-
- def mousePressEvent(self, event):
- cursor = QCursor( Qt.ArrowCursor )
- QApplication.instance().setOverrideCursor(cursor)
-
- if self.type == 'op'and len(self.out_lines) == 0:
- rect = self.boundingRect()
- pointA = QtCore.QPointF(rect.x() + rect.width()/(2), rect.y() + rect.height()/(2))
- pointA = self.mapToScene(pointA)
- pointB = self.mapToScene(event.pos())
- self.new_line = NodeLine(pointA, pointB ,'op')
- self.out_lines.append(self.new_line)
- self.scene().addItem(self.new_line)
- elif self.type == 'in' and len(self.in_lines) == 0:
- rect = self.boundingRect()
- pointA = self.mapToScene(event.pos())
- pointB = QtCore.QPointF(rect.x() + rect.width()/(2), rect.y() + rect.height()/(2))
- pointB = self.mapToScene(pointB)
- self.new_line = NodeLine(pointA, pointB, 'in')
- self.in_lines.append(self.new_line)
- self.scene().addItem(self.new_line)
- else:
- super(NodeSocket, self).mousePressEvent(event)
-
- def mouseMoveEvent(self, event):
-
- if self.type == 'op':
- item = self.scene().itemAt(event.scenePos().toPoint(),QtGui.QTransform())
- if(isinstance(item,NodeSocket)):
- QApplication.instance().setOverrideCursor(QCursor( Qt.PointingHandCursor))
- else:
- QApplication.instance().restoreOverrideCursor()
- QApplication.instance().setOverrideCursor(QCursor( Qt.ArrowCursor))
- pointB = self.mapToScene(event.pos())
- self.new_line.pointB = pointB
- if self.other_line:
- self.other_line.pointB=pointB
- elif self.type == 'in':
- pointA = self.mapToScene(event.pos())
- self.new_line.pointA = pointA
- if self.other_line:
- self.other_line.pointA=pointA
- else:
- super(NodeSocket, self).mouseMoveEvent(event)
-
- def mouseReleaseEvent(self, event):
- cursor = QCursor( Qt.ArrowCursor )
- QApplication.instance().setOverrideCursor(cursor)
-
- item = self.scene().itemAt(event.scenePos().toPoint(),QtGui.QTransform())
- stm = ['MaterialStream','EngStm']
- item.other_line=self.new_line
- if self.type == 'op' and item.type == 'in' and len(item.in_lines) == 0:
- self.new_line.source = self
- self.new_line.target = item
- item.in_lines.append(self.new_line)
- self.new_line.pointB = item.get_center()
- #print(type(self.new_line.source))
- if self.new_line.source.parent.obj.type not in stm:
- self.new_line.source.parent.obj.add_connection(0, self.new_line.source.id, self.new_line.target.parent.obj)
- if self.new_line.target.parent.obj.type not in stm:
- self.new_line.target.parent.obj.add_connection(1, self.new_line.target.id, self.new_line.source.parent.obj) # Input stream if flag is 1
-
- sc = self.new_line.source.parent
- tg = self.new_line.target.parent
- if(sc.obj.type == 'MaterialStream'):
- sc_no_input_lines = len(sc.input[0].in_lines)
- if(sc_no_input_lines > 0):
- sc.obj.disableInputDataTab(sc.dock_widget)
- if(tg.obj.type == 'MaterialStream'):
- tg_no_input_lines = len(tg.input[0].in_lines)
- if(tg_no_input_lines > 0):
- tg.obj.disableInputDataTab(tg.dock_widget)
-
- elif self.type =='in' and item.type == 'op' and len(item.out_lines) == 0:
- self.new_line.source = item
- self.new_line.target = self
- item.out_lines.append(self.new_line)
- self.new_line.pointA = item.get_center()
- #print(type(self.new_line.source))
- if self.new_line.source.parent.obj.type not in stm:
- self.new_line.source.parent.obj.add_connection(0, self.new_line.source.id, self.new_line.target.parent.obj)
- if self.new_line.target.parent.obj.type not in stm:
- self.new_line.target.parent.obj.add_connection(1, self.new_line.target.id, self.new_line.source.parent.obj)
-
- sc = self.new_line.source.parent
- tg = self.new_line.target.parent
- if(sc.obj.type == 'MaterialStream'):
- sc_no_input_lines = len(sc.input[0].in_lines)
- if(sc_no_input_lines > 0):
- sc.obj.disableInputDataTab(sc.dock_widget)
- if(tg.obj.type == 'MaterialStream'):
- tg_no_input_lines = len(tg.input[0].in_lines)
- if(tg_no_input_lines > 0):
- tg.obj.disableInputDataTab(tg.dock_widget)
-
- else:
- self.scene().removeItem(self.new_line)
- if(self.new_line in self.in_lines):
- self.in_lines.remove(self.new_line)
- if(self.new_line in self.out_lines):
- self.out_lines.remove(self.new_line)
- del self.new_line
- super(NodeSocket, self).mouseReleaseEvent(event)
-
- try:
- data = get_last_list('Undo')
- comp_selected = data[-1]
- data.remove(comp_selected)
- for i in range(len(data)):
- if data[i].name == self.new_line.source.parent.obj.name:
- data[i] = self.new_line.source.parent.obj
- elif data[i].name == self.new_line.target.parent.obj.name:
- data[i] = self.new_line.target.parent.obj
- data.append(comp_selected)
- push('Undo', data)
- except Exception as e:
- print(e)
-
- def get_center(self):
- rect = self.boundingRect()
- center = QtCore.QPointF(rect.x() + rect.width()/(2), rect.y() + rect.height()/(2))
- center = self.mapToScene(center)
- return center
-
- def hoverEnterEvent(self, event):
- cursor = QCursor( Qt.PointingHandCursor)
- QApplication.instance().setOverrideCursor(cursor)
-
- def hoverLeaveEvent(self, event):
- cursor = QCursor( Qt.ArrowCursor )
- QApplication.instance().setOverrideCursor(cursor)
-
- def show(self):
- # set pen to show
- self.pen = QPen(QtGui.QColor(0,70,70,220), 1, Qt.SolidLine)
- self.brush = QBrush(QtGui.QColor(140,199,198,255))
-
- def hide(self):
- # set pen to transparent
- self.pen = QPen(Qt.NoPen)
- self.brush = QBrush(Qt.transparent)
-
-# all created node items will be put inside this list
-# it is used for recreating the node lines by returning the node item object based on unit operation object's name
-lst = []
-dock_widget_lst = []
-stack = []
-
-class NodeItem(QtWidgets.QGraphicsItem):
-
- @staticmethod
- def get_instances(namee):
- for i in lst:
- if i.name == namee:
- return i
-
- @staticmethod
- def get_dock_widget():
- return dock_widget_lst
-
- def __init__(self,unit_operation, container, graphicsView):
- l = ['Splitter','Mixer', 'DistillationColumn', 'Flash', 'CompoundSeparator', 'ShortcutColumn']
- stm = ['MaterialStream', 'EnergyStream']
- super(NodeItem, self).__init__()
- self.obj = unit_operation
- self.container = container
- self.graphicsView = graphicsView
- self.setAcceptHoverEvents(True)
- self.name = self.obj.name
- self.type = self.obj.type
- self.ok = True
- if (self.obj.modes_list):
- default_tooltip = f"{self.name}\n\n"
- default_tooltip_dict = self.obj.param_getter_tooltip(self.obj.mode)
- for i, j in default_tooltip_dict.items():
- if j is not None:
- default_tooltip = default_tooltip + f" {i} : {j}\n"
- self.setToolTip(default_tooltip)
-
- dlg = QMessageBox()
- dlg.setWindowTitle("Error")
- dlg.setIcon(QMessageBox.Critical)
- dlg.setText('Enter valid input value!')
-
- if self.obj.type == 'Mixer' and not self.obj.saved:
- text, self.ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input(2-4):',
- echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs))
- while self.ok and (int(text)< 2 or int(text) > 4):
- dlg.exec_()
- text, self.ok = QInputDialog.getText(self.container.graphicsView, 'Mixer', 'Enter number of input(2-4):',
- echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs))
- if self.ok:
- self.nin = int(text)
- self.obj.no_of_inputs = self.nin
- self.obj.variables['NI']['value'] = self.nin
- elif self.obj.type == 'DistillationColumn'and not self.obj.saved:
- text, self.ok = QInputDialog.getText(self.container.graphicsView, 'DistillationColumn', 'Enter number of input(1-8):',
- echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs))
- while self.ok and (int(text)< 1 or int(text) > 8):
- dlg.exec_()
- text, self.ok = QInputDialog.getText(self.container.graphicsView, 'DistillationColumn', 'Enter number of input(1-8):',
- echo=QLineEdit.Normal, text=str(self.obj.no_of_inputs))
- if self.ok:
- self.nin = int(text)
- self.obj.no_of_inputs = self.nin
- self.obj.variables['Ni']['value'] = self.nin
-
- self.nin = self.obj.no_of_inputs
- self.nop = self.obj.no_of_outputs
-
- self.dock_widget = None
- lst.append(self)
- if self.obj.type in l:
- self.dock_widget = eval("DockWidget"+self.obj.type)(self.obj.name,self.obj.type,self.obj,self.container)
- elif self.obj.type in stm:
- self.dock_widget = eval("DockWidget"+self.obj.type)(self.obj.name,self.obj.type,self.obj,self.container)
- elif self.obj.type == "AdiabaticCompressor" or self.obj.type == "AdiabaticExpander":
- self.dock_widget = eval("DockWidgetCompressorExpander")(self.obj.name,self.obj.type,self.obj,self.container)
- else:
- self.dock_widget = DockWidget(self.obj.name,self.obj.type,self.obj,self.container)
- dock_widget_lst.append(self.dock_widget)
- self.main_window= findMainWindow(self)
- self.dock_widget.setFixedWidth(360)
- self.dock_widget.setFixedHeight(640)
- self.dock_widget.DockWidgetFeature(QDockWidget.AllDockWidgetFeatures)
- self.main_window.addDockWidget(Qt.LeftDockWidgetArea, self.dock_widget)
-
- # updating input values
- if self.dock_widget.obj.type != 'MaterialStream':
- pass
- try:
- self.dock_widget.obj.param_setter(self.dock_widget.obj.param_getter(self.dock_widget.obj.mode))
- except Exception as e:
- print(e)
- # self.dock_widget.param()
-
- self.dock_widget.hide()
-
- self.pic=QtGui.QPixmap(parentPath+"/resources/base/Icons/"+self.type+".png")
- self.rect = QtCore.QRect(0,0,self.pic.width(),self.pic.height())
- self.text = QGraphicsTextItem(self)
- f = QFont()
- f.setPointSize(8)
- self.text.setFont(f)
- self.text.setDefaultTextColor(QtGui.QColor(0,70,70,220))
- self.text.setParentItem(self)
- self.text.setPos(self.rect.width()-(self.rect.width()*0.9), self.rect.height())
- self.text.setPlainText(self.name)
-
- self.setFlag(QtWidgets.QGraphicsPixmapItem.ItemIsMovable)
- self.setFlag(QtWidgets.QGraphicsPixmapItem.ItemIsSelectable)
- self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
-
- # Brush
- self.brush = QtGui.QBrush()
- self.brush.setStyle(QtCore.Qt.SolidPattern)
- self.brush.setColor(QtGui.QColor(80,0,90,255))
- # Pen
- self.pen = QtGui.QPen()
- self.pen.setStyle(QtCore.Qt.SolidLine)
- self.pen.setWidth(1)
- self.pen.setColor(QtGui.QColor(20,20,20,255))
-
- self.sel_pen = QtGui.QPen()
- self.sel_pen.setStyle(QtCore.Qt.SolidLine)
- self.sel_pen.setWidth(1)
- self.sel_pen.setColor(QtGui.QColor(220,220,220,255))
-
- # initializing the node sockets
- self.input , self.output = self.initialize_sockets(self.type)
-
- def shape(self):
- path = QtGui.QPainterPath()
- path.addRect(self.boundingRect())
- return path
-
- def boundingRect(self):
- return QtCore.QRectF(self.rect)
-
- def paint(self, painter, option, widget):
- if self.isSelected():
- painter.setPen(self.sel_pen)
- painter.drawRect(QtCore.QRectF(self.rect))
- else:
- painter.setPen(self.pen)
- painter.drawPixmap(self.rect,self.pic)
-
- def initialize_sockets(self,type):
- if(self.type=="Flash" or self.type=="CompoundSeparator"):
- input = [NodeSocket(QtCore.QRect(1,(self.rect.height()*x/(self.nin+1)-6),4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-13,(self.rect.height()*x*1/(self.nop+1))-4,4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
- elif(self.type=="AdiabaticCompressor" or self.type=="AdiabaticExpander" or self.type =="Mixer" or self.type =="Splitter" or self.type =="Valve" ):
- input = [NodeSocket(QtCore.QRect(-6.5, (self.rect.height()*x/(self.nin+1))-6,4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-6.5,(self.rect.height()*x/(self.nop+1))-6,4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
- elif(self.type=="Cooler" or self.type=="Heater"):
- input = [NodeSocket(QtCore.QRect(-0.5, (self.rect.height()*x/(self.nin+1))-6,4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-12.0,(self.rect.height()*x/(self.nop+1))-6,4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
- elif(self.type=="CentrifugalPump"):
- input = [NodeSocket(QtCore.QRect(-6.5,(self.rect.height()*x/(self.nin+1))-11, 4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-6.5,-5.5,4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
- elif(self.type=="DistillationColumn" or self.type=="ShortcutColumn"):
- input = [NodeSocket(QtCore.QRect(-6.5,(self.rect.height()*x/(self.nin+1)-4),4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-9.5,(self.rect.height()*1.44*x/(self.nop+1))-59,4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
- elif(self.type=="MaterialStream"):
- input = [NodeSocket(QtCore.QRect(-6.5,(self.rect.height()*x/(self.nin+1)-6),4*3,4*3), self, 'in', x) for x in range(1,self.nin+1) ]
- output = [NodeSocket(QtCore.QRect(self.rect.width()-6.5,(self.rect.height()*x/(self.nin+1)-6),4*3,4*3), self, 'op', x) for x in range(1,self.nop+1)]
- return input,output
-
- def mouseMoveEvent(self, event):
- super(NodeItem, self).mouseMoveEvent(event)
- items = self.graphicsView.items()
- for i in items:
- if(type(i) == NodeItem):
- for op in i.output:
- for line in op.out_lines:
- line.pointA = line.source.get_center()
- line.pointB = line.target.get_center()
- for ip in i.input:
- for line in ip.in_lines:
- line.pointA = line.source.get_center()
- line.pointB = line.target.get_center()
- self.pos = event.scenePos()
- self.obj.set_pos(self.pos)
-
- def mouseDoubleClickEvent(self, event):
-
- self.graphicsView.horizontalScrollBarVal = self.graphicsView.horizontalScrollBar().value()
- self.graphicsView.setInteractive(False)
- if len(stack):
- stack[-1].hide()
- self.dock_widget.show()
- stack.append(self.dock_widget)
- self.graphicsView.setInteractive(True)
-
- def update_tooltip(self):
- default_tooltip = f"{self.name}\n\n"
- default_tooltip_dict = self.obj.param_getter_tooltip(self.obj.mode)
- for i, j in default_tooltip_dict.items():
- if j is not None:
- default_tooltip = default_tooltip + f" {i} : {j}\n"
- self.setToolTip(default_tooltip)
-
- def update_tooltip_selectedVar(self):
- default_tooltip = f"{self.name}\n\n"
- default_tooltip_dict = self.obj.param_getter_tooltip_selectedVar()
- for i, j in default_tooltip_dict.items():
- if j is not None:
- default_tooltip = default_tooltip + f" {i} : {j}\n"
- self.setToolTip(default_tooltip)
-
- def update_compounds(self):
- try:
- self.obj.update_compounds()
- self.dock_widget.update_compounds()
- except AttributeError:
- pass
-
- def hoverEnterEvent(self, event):
- super(NodeItem,self).hoverEnterEvent(event)
- for i in self.graphicsView.items():
- if(isinstance(i,NodeItem)):
- for ip in i.input:
- ip.show()
- for op in i.output:
- op.show()
-
- def hoverLeaveEvent(self, event):
- super(NodeItem,self).hoverLeaveEvent(event)
- for i in self.graphicsView.items():
- if(isinstance(i,NodeItem)):
- for ip in i.input:
- ip.hide()
- for op in i.output:
- op.hide()
-
- def itemChange(self, change, value):
- newPos = value
- if change == self.ItemPositionChange and self.scene():
- rect = self.container.graphicsView.sceneRect()
- width = self.boundingRect().width()
- height = self.boundingRect().height()
- eWH1 = QPointF(newPos.x()+width,newPos.y()+height)
- eWH2 = QPointF(newPos.x()-width,newPos.y()-height)
- if not rect.__contains__(eWH1) or not rect.__contains__(eWH2) :
- newPos.setX(min(rect.right()-width-40, max(newPos.x(), rect.left())))
- newPos.setY(min(rect.bottom()-height-35, max(newPos.y(), rect.top())))
- self.obj.set_pos(newPos)
- return super(NodeItem,self).itemChange(change, newPos)
-
-def findMainWindow(self):
- '''
- Global function to find the (open) QMainWindow in application
- '''
- app = QApplication.instance()
- for widget in app.topLevelWidgets():
- if isinstance(widget, QMainWindow):
- return widget
- return None
diff --git a/src/main/python/utils/Streams.py b/src/main/python/utils/Streams.py
deleted file mode 100644
index 05ec014..0000000
--- a/src/main/python/utils/Streams.py
+++ /dev/null
@@ -1,470 +0,0 @@
-import json
-import sys,os
-
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parentPath)
-
-from PyQt5.QtCore import *
-from python.utils.ComponentSelector import compound_selected
-
-class MaterialStream():
- counter = 1
- def __init__(self, compound_names = []):
-
- self.name = 'MaterialStream' + str(MaterialStream.counter)
- self.type = 'MaterialStream'
-
- self.compound_names = compound_names
- self.count = MaterialStream.counter
- self.thermo_package ="RaoultsLaw"
- self.mode1 = "P"
- self.mode2 = "T"
-
- self.mode1_val = ""
- self.mode2_val = ""
- self.OM_data_init = ''
- self.OM_data_eqn = ''
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.x = 2500-30
- self.y = 2500-30
- self.pos = QPointF(self.x, self.y)
- MaterialStream.counter+=1
- self.start_dict = {}
- self.eqn_dict = {}
- self.modes_list = ["PT", "PH", "PVF", "TVF", "PS"]
- self.saved = False
- self.mode = self.modes_list[0]
-
- self.variables = {
- 'P' : {'name':'Pressure', 'value':101325, 'unit':'Pa'},
- 'T' : {'name':'Temperature', 'value':300, 'unit':'K'},
-
- 'xvap' : {'name':'Vapour Mole Fraction', 'value':None, 'unit':''},
- 'H_p[1]' : {'name':'Mixture Molar Enthalpy', 'value':None, 'unit':'J/mol'},
- 'S_p[1]' : {'name':'Mixture Molar Entropy', 'value':None, 'unit':'J/mol.K'},
- 'F_p[1]' : {'name':'Mixture Molar Flow', 'value':100, 'unit':'mol/s'},
- 'Fm_p[1]' : {'name':'Mixture Mass Flow', 'value':None, 'unit':'g/s'},
-
- 'H_p[2]' : {'name':'Liquid Molar Enthalpy', 'value':None, 'unit':'J/mol'},
- 'S_p[2]' : {'name':'Liquid Molar Entropy', 'value':None, 'unit':'J/mol.K'},
- 'F_p[2]' : {'name':'Liquid Molar Flow', 'value':None, 'unit':'mol/s'},
-
- 'H_p[3]' : {'name':'Vapour Molar Enthalpy', 'value':None, 'unit':'J/mol'},
- 'S_p[3]' : {'name':'Vapour Molar Entropy', 'value':None, 'unit':'J/mol.K'},
- 'F_p[3]' : {'name':'Vapour Molar Flow', 'value':None, 'unit':'mol/s'},
-
- 'x_pc' : {'name':'Mole Fraction', 'value':[], 'unit':''},
- 'xm_pc' : {'name':'Mass Fraction', 'value':None, 'unit':''},
-
- 'F_pc' : {'name':'Mole Flow', 'value':100, 'unit':'mol/s'},
- 'Fm_pc' : {'name':'Mass Flow', 'value':None, 'unit':'g/s'},
- }
- self.init_variables()
-
- def update_compounds(self):
- self.compound_names = compound_selected
-
- def init_variables(self):
- Nc = len(self.compound_names)
- for i, val in enumerate(self.compound_names):
- self.variables['x_pc[1,'+ str(i+1)+']'] = {'name':val + ' Mixture Mole Fraction', 'value':round(1/Nc,4), 'unit':''}
- self.variables['xm_pc[1,'+ str(i+1)+']'] = {'name':val + ' Mixture Mass Fraction', 'value':None, 'unit':''}
- self.variables['F_pc[1,'+ str(i+1)+']'] = {'name':val + ' Mixture Mole Flow', 'value':None, 'unit':'mol/s'}
- self.variables['Fm_pc[1,'+ str(i+1)+']'] = {'name':val + ' Mixture Mass Flow', 'value':None, 'unit':'g/s'}
-
- self.variables['x_pc[2,'+ str(i+1)+']'] = {'name':[val + ' Liquid Mole Fraction'], 'value':None, 'unit':''}
- self.variables['xm_pc[2,'+ str(i+1)+']'] = {'name':[val + ' Liquid Mass Fraction'], 'value':None, 'unit':''}
- self.variables['F_pc[2,'+ str(i+1)+']'] = {'name':[val + ' Liquid Mole Flow'], 'value':None, 'unit':'mol/s'}
- self.variables['Fm_pc[2,'+ str(i+1)+']'] = {'name':[val + ' Liquid Mass Flow'], 'value':None, 'unit':'g/s'}
-
- self.variables['x_pc[3,'+ str(i+1)+']'] = {'name':[val + ' Vapour Mole Fraction'], 'value':None, 'unit':''}
- self.variables['xm_pc[3,'+ str(i+1)+']'] = {'name':[val + ' Vapour Mass Fraction'], 'value':None, 'unit':''}
- self.variables['F_pc[3,'+ str(i+1)+']'] = {'name':[val + ' Vapour Mole Flow'], 'value':None, 'unit':'mol/s'}
- self.variables['Fm_pc[3,'+ str(i+1)+']'] = {'name':[val + ' Vapour Mass Flow'], 'value':None, 'unit':'g/s'}
-
- for i in self.compound_names:
- self.variables[i] = {'value':''}
-
- def param_getter_tooltip(self,mode):
- dict = {}
-
- temp = []
- for i, val in enumerate(self.compound_names):
- try:
- temp.append(self.variables['x_pc[1,' + str(i+1) + ']']['value'])
- except:
- pass
- self.variables['x_pc']['value'] = temp
-
- if(mode=="PT"):
- self.mode1 = 'P'
- self.mode2 = 'T'
- mode1_n = self.variables['P']['name']
- mode2_n = self.variables['T']['name']
- dict = {mode1_n:str(self.variables['P']['value'])+' '+self.variables['P']['unit'],
- mode2_n:str(self.variables['T']['value'])+' '+self.variables['T']['unit']}
- elif(mode=="PH"):
- self.mode1 = 'P'
- self.mode2 = 'H_p[1]'
- mode1_n = self.variables['P']['name']
- mode2_n = self.variables['H_p[1]']['name']
-
- dict = {mode1_n:str(self.variables['P']['value'])+' '+self.variables['P']['unit'],
- mode2_n:str(self.variables['H_p[1]']['value'])+' '+self.variables['H_p[1]']['unit']}
- elif(mode=="PVF"):
- self.mode1 = 'P'
- self.mode2 = 'xvap'
- mode1_n = self.variables['P']['name']
- mode2_n = self.variables['xvap']['name']
-
- dict = {mode1_n:str(self.variables['P']['value'])+' '+self.variables['P']['unit'],
- mode2_n:str(self.variables['xvap']['value'])+' '+self.variables['xvap']['unit']}
- elif(mode=="TVF"):
- self.mode1 = 'T'
- self.mode2 = 'xvap'
- mode1_n = self.variables['T']['name']
- mode2_n = self.variables['xvap']['name']
- dict = {mode1_n:str(self.variables['T']['value'])+' '+self.variables['T']['unit'],
- mode2_n:str(self.variables['xvap']['value'])+' '+self.variables['xvap']['unit']}
-
- elif(mode=="PS"):
- self.mode1 = 'P'
- self.mode2 = 'S_p[1]'
- mode1_n = self.variables['P']['name']
- mode2_n = self.variables['S_p[1]']['name']
-
- dict = {mode1_n:str(self.variables['P']['value'])+' '+self.variables['P']['unit'],
- mode2_n:str(self.variables['S_p[1]']['value'])+' '+self.variables['S_p[1]']['unit']}
-
- dict['Mole Flow'] = str(self.variables['F_p[1]']['value'])+' '+self.variables['F_p[1]']['unit']
- dict[self.variables['x_pc']['name']] = str(self.variables['x_pc']['value'])+' '+self.variables['x_pc']['unit']
- dict['Thermo Package'] = self.thermo_package
- return dict
-
- def param_getter_tooltip_selectedVar(self):
- dict = {}
-
- pressure_name = self.variables['P']['name']
- pressure_val = self.variables['P']['value']
- pressure_unit = self.variables['P']['unit']
- temp_name = self.variables['T']['name']
- temp_val = self.variables['T']['value']
- temp_unit = self.variables['T']['unit']
- mixMolEntal_name = self.variables['H_p[1]']['name']
- mixMolEntal_val = round(float(self.variables['H_p[1]']['value']),4)
- mixMolEntal_unit = self.variables['H_p[1]']['unit']
- mixMolEntro_name = self.variables['S_p[1]']['name']
- mixMolEntro_val = round(float(self.variables['S_p[1]']['value']),4)
- mixMolEntro_unit = self.variables['S_p[1]']['unit']
- vapMolFrac_name = self.variables['xvap']['name']
- vapMolFrac_val = self.variables['xvap']['value']
- vapMolFrac_unit = self.variables['xvap']['unit']
- mixMolFlo_name = self.variables['F_p[1]']['name']
- mixMolFlo_val = self.variables['F_p[1]']['value']
- mixMolFlo_unit = self.variables['F_p[1]']['unit']
- mixMassFlo_name = self.variables['Fm_p[1]']['name']
- mixMassFlo_val = round(float(self.variables['Fm_p[1]']['value']),4)
- mixMassFlo_unit = self.variables['Fm_p[1]']['unit']
-
- dict = {pressure_name:str(pressure_val)+' '+pressure_unit,
- temp_name:str(temp_val)+' '+temp_unit,
- vapMolFrac_name:str(vapMolFrac_val)+' '+vapMolFrac_unit,
- mixMolEntal_name:str(mixMolEntal_val)+' '+mixMolEntal_unit,
- mixMolEntro_name:str(mixMolEntro_val)+' '+mixMolEntro_unit,
- mixMolFlo_name:str(mixMolFlo_val)+' '+mixMolFlo_unit,
- mixMassFlo_name:str(mixMassFlo_val)+' '+mixMassFlo_unit}
- return dict
-
- def param_getter(self,mode):
- dict = {}
-
- temp = []
- for i, val in enumerate(self.compound_names):
- try:
- temp.append(self.variables['x_pc[1,' + str(i+1) + ']']['value'])
- except:
- pass
- self.variables['x_pc']['value'] = temp
-
- pressure_val = self.variables['P']['value']
- temp_val = self.variables['T']['value']
- mixMolFlo_val = self.variables['F_p[1]']['value']
- mixMolEntal_val = self.variables['H_p[1]']['value']
- vapMolFrac_val = self.variables['xvap']['value']
- mixMolEntro_val = self.variables['S_p[1]']['value']
-
- if pressure_val != None:
- pressure_val = round(float(self.variables['P']['value']),4)
- if temp_val != None:
- temp_val = round(float(self.variables['T']['value']),4)
- if mixMolFlo_val != None:
- mixMolFlo_val = round(float(self.variables['F_p[1]']['value']),4)
- if mixMolEntal_val != None:
- mixMolEntal_val = round(float(self.variables['H_p[1]']['value']),4)
- if vapMolFrac_val != None:
- vapMolFrac_val = round(float(self.variables['xvap']['value']),4)
- if mixMolEntro_val != None:
- mixMolEntro_val = round(float(self.variables['S_p[1]']['value']),4)
- if(mode=="PT"):
- self.mode1 = 'P'
- self.mode2 = 'T'
-
- dict = {self.mode1:pressure_val, self.mode2:temp_val,
- "MolFlow":mixMolFlo_val,"x_pc":self.variables['x_pc']['value'],
- "Thermo Package": self.thermo_package}
- #print('dictionary is :' + str(dict))
-
- elif(mode=="PH"):
- self.mode1 = 'P'
- self.mode2 = 'H_p[1]'
- dict = {self.mode1:pressure_val, self.mode2:mixMolEntal_val,
- "MolFlow":mixMolFlo_val, "x_pc":self.variables['x_pc']['value'],
- "Thermo Package": self.thermo_package}
- elif(mode=="PVF"):
- self.mode1 = 'P'
- self.mode2 = 'xvap'
- dict = {self.mode1:pressure_val, self.mode2:vapMolFrac_val,
- "MolFlow":mixMolFlo_val, "x_pc":self.variables['x_pc']['value'],
- "Thermo Package": self.thermo_package}
- elif(mode=="TVF"):
- self.mode1 = 'T'
- self.mode2 = 'xvap'
- dict = {self.mode1:temp_val, self.mode2:vapMolFrac_val,
- "MolFlow":mixMolFlo_val, "x_pc":self.variables['x_pc']['value'],
- "Thermo Package": self.thermo_package}
- elif(mode=="PS"):
- self.mode1 = 'P'
- self.mode2 = 'S_p[1]'
- dict = {self.mode1:pressure_val, self.mode2: mixMolEntro_val,
- "MolFlow":mixMolFlo_val, "x_pc":self.variables['x_pc']['value'],
- "Thermo Package": self.thermo_package}
-
- return dict
-
- def param_setter(self,dict):
- self.variables['x_pc']['value'] = dict['x_pc'].split(",")
- #print('xpc is :' + str(self.variables['x_pc']['value']))
- self.thermo_package = dict['Thermo Package']
- self.variables['F_p[1]']['value'] = dict['MolFlow']
- self.variables[self.mode1]['value'] = dict[self.mode1]
- self.variables[self.mode2]['value'] = dict[self.mode2]
-
- for i in range(len(self.compound_names)):
- if self.variables['x_pc']['value'][i]:
- self.variables['x_pc[1,'+str(i+1)+']']['value'] = self.variables['x_pc']['value'][i]
- else:
- self.variables['x_pc[1,'+str(i+1)+']']['value'] = None
- self.variables['xm_pc[1,'+str(i+1)+']']['value'] = self.variables['xm_pc']['value']
-
- self.variables['F_pc[1,'+str(i+1)+']']['value'] = None
- self.variables['Fm_pc[1,'+str(i+1)+']']['value'] = None
- for i in range(0,len(self.compound_names)):
- self.variables['x_pc[2,'+str(i+1)+']']['value'] = None
- self.variables['xm_pc[2,'+str(i+1)+']']['value'] = None
- self.variables['F_pc[2,'+str(i+1)+']']['value'] = None
- self.variables['Fm_pc[2,'+str(i+1)+']']['value'] = None
-
- self.variables['x_pc[3,'+str(i+1)+']']['value'] = None
- self.variables['xm_pc[3,'+str(i+1)+']']['value'] = None
- self.variables['F_pc[3,'+str(i+1)+']']['value'] = None
- self.variables['Fm_pc[3,'+str(i+1)+']']['value'] = None
-
- def set_pos(self,pos):
- self.pos = pos
-
- def get_min_eqn_values(self):
- x_pclist = []
- for i in range(0,len(self.compound_names)):
- x_pclist.append(self.variables['x_pc[1,'+str(i+1)+']']['value'])
- x_pc = json.dumps(x_pclist)
- x_pc = x_pc.replace('[','{')
- x_pc = x_pc.replace(']','}')
- x_pc = x_pc.replace('"','')
-
- if self.variables[self.mode1]['value']:
- self.eqn_dict[self.mode1] = self.variables[self.mode1]['value']
- if self.variables[self.mode2]['value']:
- self.eqn_dict[self.mode2] = self.variables[self.mode2]['value']
- if self.variables['x_pc']['value']:
- self.eqn_dict['x_pc[1,:]'] = x_pc
- if self.variables['F_pc']['value']:
- self.eqn_dict['F_p[1]'] = self.variables['F_p[1]']['value']
-
- def get_start_values(self):
- try:
- if self.variables[self.mode1]['value']:
- self.start_dict[self.mode1] = self.variables[self.mode1]['value']
-
- if self.variables[self.mode2]['value']:
- self.start_dict[self.mode2] = self.variables[self.mode2]['value']
-
-
- if self.variables['x_pc[2,1]']['value'] != None:
- x_pcarr = []
- for i in range(1,4):
- cmf = []
- for j in range(1,len(self.compound_names)+1):
- cmf.append(str(self.variables['x_pc['+str(i)+','+str(j)+']']['value']))
- x_pcarr.append(cmf)
- x_pcstr = json.dumps(x_pcarr)
- x_pcstr = x_pcstr.replace('[','{')
- x_pcstr = x_pcstr.replace(']','}')
- x_pcstr = x_pcstr.replace('"','')
- self.start_dict['x_pc'] = x_pcstr
-
- if self.variables['xm_pc[2,1]']['value'] != None:
- xm_pcarr = []
- for i in range(1,4):
- cmf = []
- for j in range(1,len(self.compound_names)+1):
- cmf.append(str(self.variables['xm_pc['+str(i)+','+str(j)+']']['value']))
- xm_pcarr.append(cmf)
- xm_pcstr = json.dumps(x_pcarr)
- xm_pcstr = xm_pcstr.replace('[','{')
- xm_pcstr = xm_pcstr.replace(']','}')
- xm_pcstr = xm_pcstr.replace('"','')
- self.start_dict['xm_pc'] = xm_pcstr
-
- if self.variables['Fm_pc[2,1]']['value'] != None:
- Fm_pcarr = []
- for i in range(1,4):
- cmf = []
- for j in range(1,len(self.compound_names)+1):
- cmf.append(str(self.variables['Fm_pc['+str(i)+','+str(j)+']']['value']))
- Fm_pcarr.append(cmf)
- Fm_pcstr = json.dumps(x_pcarr)
- Fm_pcstr = Fm_pcstr.replace('[','{')
- Fm_pcstr = Fm_pcstr.replace(']','}')
- Fm_pcstr = Fm_pcstr.replace('"','')
- self.start_dict['Fm_pc'] = Fm_pcstr
-
- if self.variables['F_pc[2,1]']['value'] != None:
- F_pcarr = []
- for i in range(1,4):
- cmf = []
- for j in range(1,len(self.compound_names)+1):
- cmf.append(str(self.variables['F_pc['+str(i)+','+str(j)+']']['value']))
- F_pcarr.append(cmf)
- F_pcstr = json.dumps(F_pcarr)
- F_pcstr = F_pcstr.replace('[','{')
- F_pcstr = F_pcstr.replace(']','}')
- F_pcstr = F_pcstr.replace('"','')
- self.start_dict['F_pc'] = F_pcstr
-
- if self.variables['MW_p[2]']['value'] != None:
- MW_pArr = []
- for i in range(1,4):
- MW_pArr.append(self.variables['MW_p['+str(i)+']']['value'])
- MW_pStr = json.dumps(MW_pArr)
- MW_pStr = MW_pStr.replace('[','{')
- MW_pStr = MW_pStr.replace(']','}')
- MW_pStr = MW_pStr.replace('"','')
- self.start_dict['MW_p'] = MW_pStr
-
- if self.variables['F_p[2]']['value'] != None:
- F_pArr = []
- for i in range(1,4):
- F_pArr.append(self.variables['F_p['+str(i)+']']['value'])
- F_pStr = json.dumps(F_pArr)
- F_pStr = F_pStr.replace('[','{')
- F_pStr = F_pStr.replace(']','}')
- F_pStr = F_pStr.replace('"','')
- self.start_dict['F_p'] = F_pStr
-
- if self.variables['Cp_p[2]']['value'] != None:
- Cp_pArr = []
- for i in range(1,4):
- Cp_pArr.append(self.variables['Cp_p['+str(i)+']']['value'])
- Cp_pStr = json.dumps(Cp_pArr)
- Cp_pStr = Cp_pStr.replace('[','{')
- Cp_pStr = Cp_pStr.replace(']','}')
- Cp_pStr = Cp_pStr.replace('"','')
- self.start_dict['Cp_p'] = Cp_pStr
-
- if self.variables['H_p[2]']['value'] != None:
- H_pArr = []
- for i in range(1,4):
- H_pArr.append(self.variables['H_p['+str(i)+']']['value'])
- H_pStr = json.dumps(H_pArr)
- H_pStr = H_pStr.replace('[','{')
- H_pStr = H_pStr.replace(']','}')
- H_pStr = H_pStr.replace('"','')
- self.start_dict['H_p'] = H_pStr
-
-
- if self.variables['S_p[2]']['value'] != None:
- S_pArr = []
- for i in range(1,4):
- S_pArr.append(self.variables['S_p['+str(i)+']']['value'])
- S_pStr = json.dumps(S_pArr)
- S_pStr = S_pStr.replace('[','{')
- S_pStr = S_pStr.replace(']','}')
- S_pStr = S_pStr.replace('"','')
- self.start_dict['S_p'] = S_pStr
-
- if self.variables['Fm_p[2]']['value'] != None:
- Fm_pArr = []
- for i in range(1,4):
- Fm_pArr.append(self.variables['Fm_p['+str(i)+']']['value'])
- Fm_pStr = json.dumps(Fm_pArr)
- Fm_pStr = Fm_pStr.replace('[','{')
- Fm_pStr = Fm_pStr.replace(']','}')
- Fm_pStr = Fm_pStr.replace('"','')
- self.start_dict['Fm_p'] = Fm_pStr
-
- except Exception as e:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- # print(exc_type,exc_tb.tb_lineno)
- # print(e)
- # print('error')
-
- def OM_Flowsheet_Initialize(self,addedcomp):
- self.OM_data_init = ''
- self.OM_data_init = self.OM_data_init + ("model ms"+str(self.count)+"\n")
- self.OM_data_init = self.OM_data_init + ("extends Simulator.Streams.MaterialStream;\n" )
- self.OM_data_init = self.OM_data_init + ("extends Simulator.Files.ThermodynamicPackages."+self.thermo_package+";\n")
- self.OM_data_init = self.OM_data_init + ("end ms"+str(self.count)+";\n")
- comp_count = len(addedcomp)
-
- self.OM_data_init = self.OM_data_init + "ms"+str(self.count) +" " + self.name +"(Nc = " + str(comp_count)
- self.OM_data_init = self.OM_data_init + ",C = {"
- C = str(addedcomp).strip('[').strip(']')
- C = C.replace("'","")
- self.OM_data_init = self.OM_data_init + C + "},"
-
- self.OM_data_init = self.OM_data_init[:-1]
- self.OM_data_init = self.OM_data_init + ');\n'
- return self.OM_data_init
-
- def OM_Flowsheet_Equation(self,addedcomp,method):
- self.OM_data_eqn = ''
- self.comp_count = len(addedcomp)
- if method == 'Eqn':
- self.eqn_dict = {}
- self.get_min_eqn_values()
- if method == 'SM':
- self.eqn_dict = {}
- self.get_min_eqn_values()
-
- for key,value in self.eqn_dict.items():
- self.OM_data_eqn = self.OM_data_eqn + self.name + '.'+ key + ' = ' + str(value) + ';\n'
- return self.OM_data_eqn
-
- def disableInputDataTab(self,dockwidget):
- #setting the value of input data tab in dock widget and disabling them
- dockwidget.comboBox.setDisabled(True)
- dockwidget.input_dict['P'].setText(str(round(float(self.variables['P']['value']),4)))
- dockwidget.input_dict['P'].setDisabled(True)
- dockwidget.input_dict['T'].setText(str(round(float(self.variables['T']['value']),4)))
- dockwidget.input_dict['T'].setDisabled(True)
- dockwidget.input_dict['MolFlow'].setText(str(round(float(self.variables['F_p[1]']['value']),4)))
- dockwidget.input_dict['MolFlow'].setDisabled(True)
- dockwidget.cbTP.setCurrentText(str(self.thermo_package))
- dockwidget.cbTP.setDisabled(True)
- dockwidget.pushButton_2.setDisabled(True)
- for index,k in enumerate(dockwidget.x_pclist):
- k.setText(str(round(float(self.variables['x_pc[1,'+ str(index+1)+']']['value']),4)))
- k.setDisabled(True)
diff --git a/src/main/python/utils/UnitOperations.py b/src/main/python/utils/UnitOperations.py
deleted file mode 100644
index 2b16c7d..0000000
--- a/src/main/python/utils/UnitOperations.py
+++ /dev/null
@@ -1,737 +0,0 @@
-import os,sys
-import json
-current = os.path.dirname(os.path.realpath(__file__))
-parent = os.path.dirname(current)
-parentPath = os.path.dirname(parent)
-sys.path.append(parentPath)
-
-from python.OMChem.Flowsheet import Flowsheet
-from python.OMChem.EngStm import EngStm
-from python.utils.ComponentSelector import *
-from python.utils.Container import *
-from PyQt5.QtCore import *
-
-class UnitOperation():
- counter = 1
- def __init__(self):
- self.OM_data_eqn = ''
- self.OM_data_init = ''
- self.input_stms = {}
- self.output_stms = {}
- self.compounds = [c[:c.index('(')] for c in compound_selected]
- self.name = ''
- self.mode = None
- self.mode_val = None
- self.type = ''
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.x = 2500-30
- self.y = 2500-30
- self.pos = QPointF(self.x, self.y)
- self.count = UnitOperation.counter
- self.variables = {}
- self.modes_list = []
- self.parameters = []
- self.extra = []
- self.for_naming = []
- self.multidict = []
- self.thermo_pack_req = False
- self.thermo_package = 'RaoultsLaw'
- self.saved = False
-
- def param_getter(self,mode=None):
- params = {}
- if mode == None and self.modes_list:
- self.mode = self.modes_list[0]
- else:
- self.mode = mode
- params[self.mode] = None
- for i in self.parameters:
- params[i] = self.variables[i]['value']
-
- return params
-
- def param_getter_tooltip(self,mode=None):
- params = {}
- if mode == None and self.modes_list:
- self.mode = self.modes_list[0]
- else:
- self.mode = mode
- params[self.mode] = None
- for i in self.parameters:
- params[self.variables[i]['name']] = str(self.variables[i]['value'])+' '+self.variables[i]['unit']
-
- return params
-
- def param_setter(self,params):
- #print("param_setter ", params)
- try:
- self.mode = list(params.keys())[0]
- except Exception as e:
- print(e)
- for k,v in params.items():
- if k == 'Thermo Package':
- self.thermo_package = v
- elif k != self.mode:
- self.k = v
- self.variables[k]['value'] = v
- else:
- self.variables[k]['value'] = v
- self.mode_val = params[self.mode]
-
-
- def add_connection(self,flag,sourceId, UnitOpr):
- if flag==1: # Input stream if flag is 1
- self.input_stms[sourceId] = UnitOpr
- else :
- self.output_stms[sourceId] = UnitOpr
-
- def set_pos(self,pos):
- self.pos = pos
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def OM_Flowsheet_Initialize(self):
- self.OM_data_init = ''
-
- if(self.thermo_pack_req):
- if len(self.extra)>1:
- for i in range(len(self.extra)):
- latest = ''
- for j in range(self.extra[i]):
- if self.extra[i][j]!='.':
- latest += self.extra[i][j]
- self.for_naming[i] = latest
-
- if(self.thermo_pack_req):
- if len(self.extra)==1:
- for i in self.extra:
- self.OM_data_init += ('model '+i+str(self.counter)+'\n')
- self.OM_data_init += ('extends Simulator.UnitOperations.'+i+';\n')
- self.OM_data_init += ('extends Simulator.Files.ThermodynamicPackages.'+self.thermo_package+';\n')
- self.OM_data_init += ('end '+i+str(self.counter)+';\n')
-
- self.OM_data_init += i+str(self.counter) + ' ' + self.name + '(Nc = ' + str(len(self.compounds))
- else:
- for i in range(len(self.extra)):
- if i!=(len(self.extra)-1):
- self.OM_data_init += ('model '+self.for_naming[i]+str(self.counter)+'\n')
- self.OM_data_init += ('extends Simulator.UnitOperations.'+self.extra[i]+';\n')
- self.OM_data_init += ('extends Simulator.Files.ThermodynamicPackages.'+self.thermo_package+';\n')
- self.OM_data_init += ('end '+self.for_naming[i]+str(self.counter)+';\n')
- else:
- self.OM_data_init += ('model '+self.for_naming[i]+str(self.counter)+'\n')
- self.OM_data_init += ('extends Simulator.UnitOperations.'+self.extra[i]+';\n')
- for j in range(len(self.extra)-1):
- self.OM_data_init += (self.for_naming[j] + str(self.counter) +' ' + self.for_naming[j] + '#' + self.multidict[j] + ';\n')
-
- self.OM_data_init += ('end '+self.for_naming[i]+str(self.counter)+';\n')
-
- self.OM_data_init += self.for_naming[i] + str(self.counter) + ' ' + self.for_naming + '(Nc = ' + str(len(self.compounds))
-
- C = str(self.compounds).strip('[').strip(']')
- C = C.replace("'", "")
- self.OM_data_init += ',C = {' + C + '}'
-
- for k in self.parameters:
- if(k == 'HKey_x_pc' or k == 'LKey_x_pc'):
- continue
- self.OM_data_init += ', '
- self.OM_data_init += k + ' = ' + (json.dumps(self.variables[k]['value']) if json.dumps(self.variables[k]['value']).replace('"', '').replace('_', '').isalpha()
- else json.dumps(self.variables[k]['value']).replace('[', '{').replace(']', '}').replace('"', ''))
-
- self.OM_data_init += ');\n'
-
- else:
- self.OM_data_init += 'Simulator.UnitOperations.' + self.type + ' ' + self.name + '(Nc = ' + str(len(self.compounds))
- C = str(self.compounds).strip('[').strip(']')
- C = C.replace("'", "")
- self.OM_data_init += ',C = {' + C + '}'
-
- for k in self.parameters:
- self.OM_data_init += ', '
- self.OM_data_init += k + ' = ' + (json.dumps(self.variables[k]['value']) if json.dumps(self.variables[k]['value']).replace('"', '').replace('_', '').isalpha()
- else json.dumps(self.variables[k]['value']).replace('[', '{').replace(']', '}').replace('"', ''))
-
- self.OM_data_init += ');\n'
- return self.OM_data_init
-
-
- def OM_Flowsheet_Equation(self):
- self.OM_data_eqn = ''
-
- if len(self.input_stms)>1 or self.type == 'Mixer':
- strcount = 1
- for strm in self.input_stms.values():
- self.OM_data_eqn += ('connect(' + strm.name + '.Out,' + self.name + '.In[' + str(strcount) + ']);\n')
- strcount += 1
- else:
- #print(self.input_stms)
- self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[1].name + '.Out);\n')
-
- if len(self.output_stms)>1:
- strcount = 1
- for strm in self.output_stms.values():
- self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out[' + str(strcount) + ']);\n')
- strcount += 1
- else:
- #print("self.output_stms ", self.output_stms)
- self.OM_data_eqn += ('connect(' + self.name + '.Out,' + self.output_stms[1].name + '.In);\n')
-
- if self.mode:
- self.OM_data_eqn += (self.name + '.' + self.mode + '=' + str(self.mode_val) + ';\n')
-
- return self.OM_data_eqn
-
-class ShortcutColumn(UnitOperation):
- def __init__(self, CompNames = [], name='ShortcutColumn'):
- UnitOperation.__init__(self)
- self.name = name + str(ShortcutColumn.counter)
- self.type = 'ShortcutColumn'
- self.no_of_inputs = 1
- self.no_of_outputs = 2
- self.EngStm1 = EngStm(name='EngStm1'+self.name)
- self.EngStm2 = EngStm(name='EngStm2'+self.name)
- self.count = ShortcutColumn.counter
-
- self.extra = ['ShortcutColumn']
- self.for_naming = ['ShortcutColumn']
- self.thermo_pack_req = True
-
- self.parameters = ['HKey', 'LKey', 'HKey_x_pc', 'LKey_x_pc', 'Ctype', 'Pcond', 'Preb', 'RR']
- self.result_parameters = ['RRmin', 'Ntmin', 'Nt', 'Intray', 'Fliqstrip', 'Fliqrec', 'Fvapstrip', 'Fvaprec', 'Qc', 'Qr']
- type(self).counter += 1
-
- self.variables = {
- 'HKey' : {'name':'Heavy Key', 'value': 0, 'unit':''},
- 'LKey' : {'name':'Light Key', 'value': 0, 'unit':''},
- 'HKey_x_pc' : {'name':'Heavy Key Mole Fraction', 'value':0.01, 'unit':''},
- 'LKey_x_pc' : {'name':'Light Key Mole Fraction', 'value':0.01, 'unit':''},
- 'Ctype' : {'name':'Condenser Type', 'value':'Total', 'unit':''},
- 'thermo_package' : {'name':'Thermo Package', 'value':'Raoults_Law', 'unit':''},
- 'Pcond' : {'name':'Condenser Pressure', 'value':101325, 'unit':'Pa'},
- 'Preb' : {'name':'Reboiler Pressure', 'value':101325, 'unit':'Pa'},
- 'RR' : {'name':'Reflux Ratio', 'value':1.5, 'unit':''},
-
- 'RRmin' : {'name':'Minimum Reflux Ratio', 'value': None , 'unit':''},
- 'Ntmin' : {'name':'Minimum Number of Stages', 'value': None, 'unit':''},
- 'Nt' : {'name':'Actual Number of Stages', 'value': None, 'unit':''},
- 'Intray' : {'name':'Optimal Feed Stage', 'value': None, 'unit':''},
- 'Fliqstrip' : {'name':'Stripping Liquid', 'value': None, 'unit':'mol/s'},
- 'Fliqrec' : {'name':'Rectification Liquid', 'value': None, 'unit':'mol/s'},
- 'Fvapstrip' : {'name':'Stripping Vapor', 'value': None, 'unit':'mol/s'},
- 'Fvaprec' : {'name':'Recification Vapour', 'value': None, 'unit':'mol/s'},
- 'Qc' : {'name':'Conderser Duty', 'value': None, 'unit':'W'},
- 'Qr' : {'name':'Reboiler Duty', 'value': None, 'unit':'W'},
-
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self,params):
- #print("param_setter ", params)
- self.variables['HKey']['value'] = self.compounds.index(params[0]) + 1
- self.variables['LKey']['value'] = self.compounds.index(params[1]) + 1
- self.variables['HKey_x_pc']['value'] = params[2]
- self.variables['LKey_x_pc']['value'] = params[3]
- self.variables['Ctype']['value'] = params[4]
- self.variables['Pcond']['value'] = params[5]
- self.variables['Preb']['value'] = params[6]
- self.variables['RR']['value'] = params[7]
- self.variables['thermo_package']['value'] = params[8]
-
- def OM_Flowsheet_Equation(self):
- self.OM_data_eqn = ''
-
- self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[1].name + '.Out);\n')
-
- strcount = 1
- for strm in self.output_stms.values():
- self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out' + str(strcount) + ');\n')
- strcount += 1
-
- self.OM_data_eqn += (self.name + '.x_pc[2, ' + self.name + '.HKey] = ' + str(self.variables['HKey_x_pc']['value']) + ';\n')
- self.OM_data_eqn += (self.name + '.x_pc[3, ' + self.name + '.LKey] = ' + str(self.variables['LKey_x_pc']['value']) + ';\n')
-
- return self.OM_data_eqn
-
-class DistillationColumn(UnitOperation):
- def __init__(self,name='DistillationColumn'):
- UnitOperation.__init__(self)
- self.name = name + str(DistillationColumn.counter)
- self.type = 'DistillationColumn'
- self.no_of_inputs = 1
- self.no_of_outputs = 2
- self.EngStm1 = EngStm(name='EngStm1'+self.name)
- self.EngStm2 = EngStm(name='EngStm2'+self.name)
- self.count = DistillationColumn.counter
- self.thermo_pack_req = True
- self.modes_list = []
- self.parameters = ['Nt', 'Ni', 'Ctype', 'Pcond', 'condmode', 'C_comp', 'C_Spec', 'Preb', 'rebmode', 'rebcomp', 'R_Spec']
- self.result_parameters = ['Cduty.Q', 'Rduty.Q']
- self.Cspec_list = ['Reflux Ratio','Product Molar Flow (mol/s)', 'Temperature (K)', 'Compound Molar Fraction', 'Compound Molar Flow (mol/s)']
- self.Rspec_list = ['Product Molar Flow (mol/s)', 'Temperature (K)', 'Compound Molar Fraction', 'Compound Molar Flow (mol/s)']
-
- type(self).counter += 1
- self.variables = {
- 'Ni' : {'name':'Number of Input', 'value':1, 'unit':''},
- 'RR' : {'name':'Reflux Ratio', 'value':None, 'unit':''},
- 'T' : {'name':'Temperature', 'value':300, 'unit':'K'},
- 'Nout' : {'name':'No of Sidedraws', 'value':None, 'unit':''},
- 'Nt' : {'name':'No of Stages', 'value':12, 'unit':''},
- 'InT_s' : {'name':'Feed Stage', 'value':[], 'unit':''},
- 'thermo_package' : {'name':'Thermo Package', 'value':'Raoults_Law', 'unit':''},
- 'Ctype' : {'name':'Condenser Type', 'value':'Total', 'unit':''},
- 'Pcond' : {'name':'Condenser Pressure', 'value':101325, 'unit':'Pa'},
- 'Preb' : {'name':'Reboiler Pressure', 'value':101325, 'unit':'Pa'},
- 'C_Spec': {'name':'Condenser Specification', 'type':self.Cspec_list[0], 'value':'', 'comp':compound_selected[0], 'unit':''},
- 'R_Spec': {'name':'Reboiler Specification', 'type':self.Rspec_list[0], 'value':'', 'comp':compound_selected[0], 'unit':''},
- 'Cduty.Q': {'name':'Condenser Duty', 'value': '', 'unit':'W'},
- 'Rduty.Q': {'name':'Reboiler Duty', 'value': '', 'unit': 'W'},
- 'Stages.T': {'name':'Stagewise Temperature', 'value':[], 'unit':'K'},
- 'Stages.x_pc': {'name': 'Stagewise Component Mole Fraction', 'value':[],'unit':''}
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self,params):
- #print("param_setter ", params)
- temp = 0
- self.variables['Nt']['value'] = params[0]
- for i in range(self.variables['Ni']['value']):
- self.variables['InT_s']['value'].append(params[i+1])
- temp = i + 1
-
- self.variables['Ctype']['value'] = params[temp+1]
- self.variables['Pcond']['value'] = params[temp+2]
- self.variables['C_Spec']['type'] = params[temp+3]
- if 'Compound' in self.variables['C_Spec']['type']:
- self.variables['C_Spec']['comp'] = params[temp+4]
- # C_Spec variable value won't be updated to class here. It will be updated in result
- self.variables['C_Spec']['value'] = params[temp+5]
- for var in self.variables:
- if self.variables[var]['name'] == self.variables['C_Spec']['type']:
- self.variables[var]['value'] = params[temp+5]
-
- self.variables['Preb']['value'] = params[temp+6]
- # R_Spec variable value won't be updated to class here. It will be updated in result
- self.variables['R_Spec']['type'] = params[temp+7]
- if 'Compound' in self.variables['R_Spec']['type']:
- self.variables['R_Spec']['comp'] = params[temp+8]
- self.variables['R_Spec']['value'] = params[temp+9]
- self.variables['thermo_package']['value'] = params[temp+10]
- #print(self.variables)
-
- def OM_Flowsheet_Initialize(self):
- self.OM_data_init = ''
- self.OM_data_init = self.OM_data_init + 'model Condenser\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.UnitOperations.DistillationColumn.Cond;\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.Files.ThermodynamicPackages.' + self.thermo_package + ';\n'
- self.OM_data_init = self.OM_data_init + 'end Condenser;\n'
- self.OM_data_init = self.OM_data_init + 'model Tray\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.UnitOperations.DistillationColumn.DistTray;\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.Files.ThermodynamicPackages.' + self.thermo_package + ';\n'
- self.OM_data_init = self.OM_data_init + 'end Tray;\n'
- self.OM_data_init = self.OM_data_init + 'model Reboiler\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.UnitOperations.DistillationColumn.Reb;\n'
- self.OM_data_init = self.OM_data_init + 'extends Simulator.Files.ThermodynamicPackages.' + self.thermo_package + ';\n'
- self.OM_data_init = self.OM_data_init + 'end Reboiler;\n'
- self.OM_data_init = self.OM_data_init + ("model distCol" + str(self.count) + "\n")
- self.OM_data_init = self.OM_data_init + ("extends Simulator.UnitOperations.DistillationColumn.DistCol;\n")
- self.OM_data_init = self.OM_data_init + (
- "Condenser condenser(Nc = Nc, C = C, Ctype =Ctype, Bin = Bin_t[1], T(start = 300));\n")
- self.OM_data_init = self.OM_data_init + (
- "Reboiler reboiler(Nc = Nc, C = C, Bin = Bin_t[Nt]);\n")
- self.OM_data_init = self.OM_data_init + (
- "Tray tray[Nt - 2](each Nc = Nc, each C = C, Bin = Bin_t[2:Nt - 1]);\n")
- self.OM_data_init = self.OM_data_init + ("end distCol" + str(self.count) + ";\n")
- comp_count = len(self.compounds)
- self.OM_data_init = self.OM_data_init + (
- "distCol" + str(self.count) + " " + self.name + "(Nc = " + str(comp_count))
- self.OM_data_init = self.OM_data_init + (", C= C")
-
- self.OM_data_init = self.OM_data_init + "," + (
- "Nt=" + str(self.variables['Nt']['value']) + "," + "Ni="
- + str(self.variables['Ni']['value']) + ",InT_s=" + "{" +
- str(self.variables['InT_s']['value']).strip('[').strip(']') + "}" + ',Ctype ="' +
- self.variables['Ctype']['value'] + '");\n')
- return self.OM_data_init
-
- def OM_Flowsheet_Equation(self):
- self.OM_data_eqn = ''
- self.OM_data_eqn = self.OM_data_eqn + (
- 'connect(' + self.name + '.Dist' + ", " + self.output_stms[1].name + '.In);\n')
- self.OM_data_eqn = self.OM_data_eqn + (
- 'connect(' + self.name + '.Bot' + ", " + self.output_stms[2].name + '.In);\n')
- for i in range(len(self.input_stms)):
- self.OM_data_eqn = self.OM_data_eqn + (
- 'connect(' + self.input_stms[i +1].name + '.Out' + ", " + self.name + '.In_s[' + str(
- i + 1) + ']);\n')
- # ['Product Molar Flow (mol/s)', 'Temperature (K)', 'Compound Molar Fraction',
- # 'Compound Molar Flow (mol/s)']
- if self.variables['C_Spec']['type'] == "Reflux Ratio":
- self.OM_data_eqn = self.OM_data_eqn + (
- self.name + '.' + 'RR' + '=' + str(self.variables['RR']['value']) + ';\n')
- elif self.variables['C_Spec']['type'] == "Product Molar Flow (mol/s)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[1].name + '.' + 'F_p[1] = ' + str(
- self.variables['C_Spec']['value']) + ';\n')
- elif self.variables['C_Spec']['type'] == "Temperature (K)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[1].name + '.' + 'T = ' + str(
- self.variables['C_Spec']['value']) + ';\n')
- elif self.variables['C_Spec']['type'] == "Compound Molar Fraction":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[1].name + '.x_pc[1,:' +
- str(self.compounds.index(self.variables['C_Spec']['comp']) + 1) + '] = ' + str(
- self.variables['C_Spec']['value']) + ';\n')
- elif self.variables['C_Spec']['type'] == "Compound Molar Flow (mol/s)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[1].name + '.F_pc[1,:' +
- str(self.compounds.index(self.variables['C_Spec']['comp']) + 1) + '] = ' + str(
- self.variables['C_Spec']['value']) + ';\n')
- else:
- self.OM_data_eqn = self.OM_data_eqn + (
- self.name + '.Condenser.' + self.mode + '=' + str(self.modeVal) + ';\n')
-
- if self.variables['R_Spec']['type'] == "Product Molar Flow (mol/s)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[2].name + '.' + 'F_p[1] = ' + str(
- self.variables['R_Spec']['value']) + ';\n')
- elif self.variables['R_Spec']['type'] == "Temperature (K)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[2].name + '.' + 'T = ' + str(
- self.variables['R_Spec']['value']) + ';\n')
- elif self.variables['R_Spec']['type'] == "Compound Molar Fraction":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[2].name + '.x_pc[1,:' +
- str(self.compounds.index(self.variables['R_Spec']['comp']) + 1) + '] = ' + str(
- self.variables['R_Spec']['value']) + ';\n')
- elif self.variables['R_Spec']['type'] == "Compound Molar Flow (mol/s)":
- self.OM_data_eqn = self.OM_data_eqn + (self.output_stms[2].name + '.F_pc[1,:' +
- str(self.compounds.index(self.variables['R_Spec']['comp']) + 1) + '] = ' + str(
- self.variables['R_Spec']['value']) + ';\n')
-
-
- self.OM_data_eqn = self.OM_data_eqn + self.name + '.reboiler.P=' + str(
- self.variables['Preb']['value']) + ';\n'
- self.OM_data_eqn = self.OM_data_eqn + self.name + '.condenser.P=' + str(
- self.variables['Pcond']['value']) + ';\n'
- return self.OM_data_eqn
-
-class ConvertionReactor(UnitOperation):
- def __init__(self,name='',Nr=None,b=None,X=None,Z=None,a=[],operation=None,Tdef=None):
- UnitOperation.__init__(self)
- self.name = name
- self.type = 'ConvertionReactor'
-
- self.Nr = str(Nr)
- self.b = str(b)
- self.X = str(X)
- self.Z = str(Z)
- self.a = json.dumps(a).replace('[','{').replace(']','}')
- self.operation = str(operation)
- self.Tdef = str(Tdef)
-
-class CompoundSeparator(UnitOperation):
- def __init__(self, name='CompoundSeparator'):
- UnitOperation.__init__(self)
- self.name = name + str(CompoundSeparator.counter)
- self.type = 'CompoundSeparator'
- self.no_of_inputs = 1
- self.no_of_outputs = 2
-
- self.SepFact_modes = ['Molar_Flow (mol/s)', 'Mass_Flow (g/s)', 'Inlet_Molar_Flow_Percent', 'Outlet_Molar_Flow_Percent']
-
- type(self).counter += 1
- self.variables = {
- 'SepStrm' : {'name':'Separation Stream', 'value':1, 'unit':''},
- 'SepVal_c' : {'name':'Separation Value', 'value':['']*len(self.compounds), 'unit':''},
- 'SepFact_c' : {'name':'Separaction Factor', 'value':['']*len(self.compounds), 'unit':''},
- }
-
- def init_variables(self):
- self.variables = {
- 'SepStrm' : {'name':'Separation Stream', 'value':1, 'unit':''},
- 'SepVal_c' : {'name':'Separation Value', 'value':['']*len(self.compounds), 'unit':''},
- 'SepFact_c' : {'name':'Separaction Factor', 'value':['']*len(self.compounds), 'unit':''},
- }
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self,params):
- #print("param_setter CompSep ", params)
-
- if (params[0]):
- self.variables['SepStrm']['value'] = 1
- else:
- self.variables['SepStrm']['value'] = 2
- for index, i in enumerate(range(2, len(params))):
- if (i %2 != 0):
- self.variables['SepVal_c']['value'][index//2] = float(params[i])
- else:
- self.variables['SepFact_c']['value'][index//2] = params[i]
-
- def OM_Flowsheet_Initialize(self):
- SepStrm = str(self.variables['SepStrm']['value'])
- SepFact = []
- for i in range(len(self.compounds)):
- SepFact.append(self.variables['SepFact_c']['value'][i].split(' ')[0])
- SepFact = json.dumps(SepFact).replace('[', '{').replace(']', '}')
- self.OM_data_init = ''
- comp_count = len(self.compounds)
- self.OM_data_init = self.OM_data_init + (
- "Simulator.UnitOperations.CompoundSeparator " + self.name + "(Nc = " + str(comp_count))
- self.OM_data_init = self.OM_data_init + (", C = {")
- comp = str(self.compounds).strip('[').strip(']')
- comp = comp.replace("'", "")
- self.OM_data_init = self.OM_data_init + comp + ("},")
- self.OM_data_init = self.OM_data_init + ("SepFact_c = " + SepFact + ",SepStrm = " + SepStrm + ");\n")
-
- return self.OM_data_init
-
-
- def OM_Flowsheet_Equation(self):
- SepVal = json.dumps(self.variables['SepVal_c']['value']).replace('[','{').replace(']','}')
- self.OM_data_eqn = ''
-
- self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[1].name + '.Out);\n')
-
- strcount = 1
- for strm in self.output_stms.values():
- self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out' + str(strcount) + ');\n')
- strcount += 1
-
- self.OM_data_eqn += (self.name + '.SepVal_c ' + '=' + SepVal + ';\n')
-
- return self.OM_data_eqn
-
-class Flash(UnitOperation):
- def __init__(self,name='Flash'):
- UnitOperation.__init__(self)
- self.name = name + str(Flash.counter)
- self.type = 'Flash'
- self.extra = ['Flash']
- self.for_naming = ['Flash']
- self.no_of_inputs = 1
- self.no_of_outputs = 2
- self.count = Flash.counter
- self.thermo_pack_req = True
- self.parameters = ['BTdef', 'Tdef', 'BPdef', 'Pdef']
-
- type(self).counter += 1
- self.variables = {
- 'thermo_package' : {'name':'Thermo Package', 'value':None, 'unit':''},
- 'BTdef' : {'name':'Separation Temperature Boolean', 'value':False, 'unit':''},
- 'BPdef' : {'name':'Separation Pressure Boolean', 'value':False, 'unit':''},
- 'Tdef' : {'name':'Separation Temperature', 'value':298.15, 'unit':'K'},
- 'Pdef' : {'name':'Separation Pressure', 'value':101325, 'unit':'Pa'}
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self,params):
- #print("param_setter ", params)
- self.variables['thermo_package']['value'] = params[0]
- self.variables['BTdef']['value'] = params[1]
- self.variables['Tdef']['value'] = params[2]
- self.variables['BPdef']['value'] = params[3]
- self.variables['Pdef']['value'] = params[4]
-
- def OM_Flowsheet_Equation(self):
- self.OM_data_eqn = ''
-
- self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[1].name + '.Out);\n')
-
- strcount = 1
- for strm in self.output_stms.values():
- self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out' + str(strcount) + ');\n')
- strcount += 1
-
- return self.OM_data_eqn
-
-class CentrifugalPump(UnitOperation):
- def __init__(self,name='CentrifugalPump'):
- UnitOperation.__init__(self)
- self.name = name + str(CentrifugalPump.counter)
- self.type = 'CentrifugalPump'
- self.modes_list = ['Pdel', 'Pout', 'Q'] #"enFlo"
- self.parameters = ['Eff']
-
- type(self).counter += 1
- self.variables = {
- 'Eff' : {'name':'Efficiency', 'value':1, 'unit':''},
- 'Pdel' : {'name':'Pressure Increase', 'value':None, 'unit':'Pa'},
- 'Pout' : {'name':'Outlet Pressure', 'value':None, 'unit':'Pa'},
- 'Q' : {'name':'Power Required', 'value':None, 'unit':'W'},
- }
-
-class Valve(UnitOperation):
- def __init__(self,name='Valve'):
- UnitOperation.__init__(self)
- self.name = name + str(Valve.counter)
- self.type = 'Valve'
- self.modes_list = ['Pdel', 'Pout']
-
- type(self).counter += 1
- self.variables = {
- 'Pdel' : {'name':'Pressure Drop', 'value':None, 'unit':'Pa'},
- 'Pout' : {'name':'Outlet Pressure', 'value':None, 'unit':'Pa'}
- }
-
-class Splitter(UnitOperation):
- def __init__(self,name='Splitter'):
- UnitOperation.__init__(self)
- self.name = name + str(Splitter.counter)
- self.type = 'Splitter'
- self.no_of_outputs = 2
-
- self.CalcType_modes = ['Split_Ratio', 'Molar_Flow', 'Mass_Flow']
-
- self.parameters = ['No', 'CalcType', 'SpecVal_s']
- type(self).counter += 1
-
- self.variables = {
- 'No' : {'name':'No. of Output', 'value':2, 'unit':''},
- 'CalcType' : {'name':'Calculation Type', 'value':self.CalcType_modes[0], 'unit':''},
- 'SpecVal_s' : {'name':'Specification Value', 'value':[0.5,0.5], 'unit':''}
- }
-
- specval = self.variables['SpecVal_s']['value']
- self.specval = json.dumps(specval).replace('[','{').replace(']','}')
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self,params):
- #print("param_setter ", params)
- self.variables['No']['value'] = int(params[0])
- self.variables['CalcType']['value'] = params[1]
- self.variables['SpecVal_s']['value'] = [float(params[2]), float(params[3])]
- if self.variables['CalcType']['value'] == 'Molar_Flow':
- self.variables['SpecVal_s']['unit'] = 'mol/s'
- elif self.variables['CalcType']['value'] == 'Mass_Flow':
- self.variables['SpecVal_s']['unit'] = 'g/s'
- else:
- self.variables['SpecVal_s']['unit'] = ''
-
-class Mixer(UnitOperation):
-
- def __init__(self,name='Mixer'):
- UnitOperation.__init__(self)
- self.name = name + str(Mixer.counter)
- self.type = 'Mixer'
- self.no_of_inputs = 2
-
- self.Pout_modes = ['Inlet_Minimum', 'Inlet_Average', 'Inlet_Maximum']
- self.parameters = ['NI', 'outPress']
- type(self).counter += 1
-
- self.variables = {
- 'NI' : {'name':'Number of Input', 'value':6, 'unit':''},
- 'outPress' : {'name':'Outlet Pressure', 'value':'Inlet_Average', 'unit':''},
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
- def param_setter(self, params):
- self.variables['NI']['value'] = int(params[0])
- self.variables['outPress']['value'] = params[1]
-
-class Heater(UnitOperation):
-
- def __init__(self, name='Heater'):
- UnitOperation.__init__(self)
- self.name = name + str(type(self).counter)
- self.type = 'Heater'
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.modes_list = ['Q','Tout','xvapout','Tdel']
- self.parameters = ['Pdel', 'Eff']
- self.extra = None
- self.for_naming = None
- type(self).counter += 1
-
- self.variables = {
- 'Pdel' : {'name':'Pressure Drop', 'value':0, 'unit':'Pa'},
- 'Eff' : {'name':'Efficiency', 'value':1, 'unit':''},
- 'Tout' : {'name':'Outlet Temperature', 'value':298.15, 'unit':'K'},
- 'Tdel' : {'name':'Temperature Increase', 'value':0, 'unit':'K'},
- 'Q' : {'name':'Heat Added', 'value':0, 'unit':'W'},
- 'xvapout': {'name':'Outlet Vapour', 'value':None, 'unit':''}
- }
-
-class Cooler(UnitOperation):
-
- def __init__(self, name='Cooler'):
- UnitOperation.__init__(self)
- self.name = name + str(type(self).counter)
- self.type = 'Cooler'
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.modes_list = ['Q','Tout','Tdel','xvap']
- self.extra = None
- self.for_naming = None
- self.parameters = ['Pdel', 'Eff']
- type(self).counter += 1
-
- self.variables = {
- 'Pdel' : {'name':'Pressure Drop', 'value':0, 'unit':'Pa'},
- 'Eff' : {'name':'Efficiency', 'value':1, 'unit':''},
- 'Tout' : {'name':'Outlet Temperature', 'value':298.15, 'unit':'K'},
- 'Tdel' : {'name':'Temperature Increase', 'value':0, 'unit':'K'},
- 'Q' : {'name':'Heat Added', 'value':0, 'unit':'W'},
- 'xvap' : {'name':'Vapour Phase Mole Fraction', 'value':None, 'unit':'g/s'},
- }
-
-class AdiabaticCompressor(UnitOperation):
-
- def __init__(self, name='AdiabaticCompressor'):
- UnitOperation.__init__(self)
- self.name = name + str(type(self).counter)
- self.type = 'AdiabaticCompressor'
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.modes_list = ["Pdel","Pout","Q"]
- self.extra = ['AdiabaticCompressor']
- self.for_naming = ['AdiabaticCompressor']
- self.thermo_pack_req = True
- self.thermo_package ="RaoultsLaw"
- self.parameters = ['Eff']
- type(self).counter += 1
- self.variables = {
- 'Pdel' : {'name':'Pressure Increase', 'value':0, 'unit':'Pa'},
- 'Tdel' : {'name':'Temperature Increase', 'value':0, 'unit':'K'},
- 'Pout' : {'name':'Outlet Pressure', 'value':101325, 'unit':'Pa'},
- 'Tout' : {'name':'Outlet Temperature', 'value':298.15, 'unit':'K'},
- 'Q' : {'name':'Heat Added', 'value':0, 'unit':'W'},
- 'Eff' : {'name':'Efficiency', 'value':1, 'unit':''}
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected]
-
-class AdiabaticExpander(UnitOperation):
-
- def __init__(self, name='AdiabaticExpander'):
- UnitOperation.__init__(self)
- self.name = name + str(type(self).counter)
- self.type = 'AdiabaticExpander'
- self.no_of_inputs = 1
- self.no_of_outputs = 1
- self.modes_list = ["Pdel","Pout","Q"]
- self.extra = ['AdiabaticExpander']
- self.for_naming = ['AdiabaticExpander']
- self.thermo_pack_req = True
- self.thermo_package ="RaoultsLaw"
- self.parameters = ['Eff']
- type(self).counter += 1
- self.variables = {
- 'Pdel' : {'name':'Pressure Drop', 'value':0, 'unit':'Pa'},
- 'Tdel' : {'name':'Temperature Increase', 'value':0, 'unit':'K'},
- 'Pout' : {'name':'Outlet Pressure', 'value':101325, 'unit':'Pa'},
- 'Tout' : {'name':'Outlet Temperature', 'value':298.15, 'unit':'K'},
- 'Q' : {'name':'Heat Added', 'value':0, 'unit':'W'},
- 'Eff' : {'name':'Efficiency', 'value':1, 'unit':''}
- }
-
- def update_compounds(self):
- self.compounds = [c[:c.index('(')] for c in compound_selected] \ No newline at end of file
diff --git a/src/main/python/utils/__init__.py b/src/main/python/utils/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/src/main/python/utils/__init__.py
+++ /dev/null
diff --git a/src/main/python/utils/__pycache__/Bin_Phase_env.cpython-37.pyc b/src/main/python/utils/__pycache__/Bin_Phase_env.cpython-37.pyc
deleted file mode 100644
index 35c4753..0000000
--- a/src/main/python/utils/__pycache__/Bin_Phase_env.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/ComponentSelector.cpython-37.pyc b/src/main/python/utils/__pycache__/ComponentSelector.cpython-37.pyc
deleted file mode 100644
index b6bceec..0000000
--- a/src/main/python/utils/__pycache__/ComponentSelector.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/Container.cpython-37.pyc b/src/main/python/utils/__pycache__/Container.cpython-37.pyc
deleted file mode 100644
index 98797d2..0000000
--- a/src/main/python/utils/__pycache__/Container.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/Graphics.cpython-37.pyc b/src/main/python/utils/__pycache__/Graphics.cpython-37.pyc
deleted file mode 100644
index 7426c2f..0000000
--- a/src/main/python/utils/__pycache__/Graphics.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/Streams.cpython-37.pyc b/src/main/python/utils/__pycache__/Streams.cpython-37.pyc
deleted file mode 100644
index 18287f2..0000000
--- a/src/main/python/utils/__pycache__/Streams.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/UnitOperations.cpython-37.pyc b/src/main/python/utils/__pycache__/UnitOperations.cpython-37.pyc
deleted file mode 100644
index ac4d056..0000000
--- a/src/main/python/utils/__pycache__/UnitOperations.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/__pycache__/__init__.cpython-37.pyc b/src/main/python/utils/__pycache__/__init__.cpython-37.pyc
deleted file mode 100644
index a687f51..0000000
--- a/src/main/python/utils/__pycache__/__init__.cpython-37.pyc
+++ /dev/null
Binary files differ
diff --git a/src/main/python/utils/thermopackage.txt b/src/main/python/utils/thermopackage.txt
deleted file mode 100644
index f9155f5..0000000
--- a/src/main/python/utils/thermopackage.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-RaoultsLaw
-NRTL
-UNIQUAC
-UNIFAC
-PengRobinson
-GraysonStreed \ No newline at end of file