summaryrefslogtreecommitdiff
path: root/UnitOperations.py
diff options
context:
space:
mode:
Diffstat (limited to 'UnitOperations.py')
-rw-r--r--UnitOperations.py231
1 files changed, 145 insertions, 86 deletions
diff --git a/UnitOperations.py b/UnitOperations.py
index 006c015..5c53f59 100644
--- a/UnitOperations.py
+++ b/UnitOperations.py
@@ -1,17 +1,8 @@
from OMChem.Flowsheet import Flowsheet
from OMChem.EngStm import EngStm
-from PyQt5.QtCore import *
-from PyQt5.QtWidgets import *
-from PyQt5.QtGui import QTextDocument ,QTextCursor ,QTextCharFormat ,QFont ,QPixmap
-from PyQt5.uic import loadUiType
-from PyQt5.QtCore import Qt
-from PyQt5.QtWidgets import QGraphicsProxyWidget, QGraphicsObject, QGraphicsEllipseItem ,QGraphicsPixmapItem,QApplication, QGraphicsView, QGraphicsScene, QHBoxLayout, QWidget, QLabel
-from PyQt5.QtGui import QBrush ,QTransform ,QMouseEvent
-from PyQt5.QtGui import *
-import PyQt5.QtCore as QtCore
-import PyQt5.QtWidgets as QtWidgets
from ComponentSelector import *
from Container import *
+from PyQt5.QtCore import *
class UnitOperation():
counter = 1
@@ -38,7 +29,7 @@ class UnitOperation():
self.for_naming = []
self.multidict = []
self.thermo_pack_req = False
- self.thermo_package = None
+ self.thermo_package = 'RaoultsLaw'
def param_getter(self,mode=None):
params = {}
@@ -55,21 +46,20 @@ class UnitOperation():
def param_setter(self,params):
print("param_setter ", params)
for k,v in params.items():
- print(k,v)
- if k != self.mode:
+ if k == 'Thermo Package':
+ self.thermo_package = v
+ print('haha')
+ elif k != self.mode:
self.k = v
self.variables[k]['value'] = v
else:
self.variables[k]['value'] = v
self.mode_val = params[self.mode]
- print(self.variables)
def add_connection(self,flag,UnitOpr):
if flag==1: # Input stream if flag is 1
- print("INPUT CONNECTION")
self.input_stms.append(UnitOpr)
else :
- print("OUTPUT CONNECTION")
self.output_stms.append(UnitOpr)
def set_pos(self,pos):
@@ -116,11 +106,15 @@ class UnitOperation():
C = str(self.compounds).strip('[').strip(']')
C = C.replace("'", "")
self.OM_data_init += ',C = {' + C + '}'
-
- for k,v in self.parameters.items():
+
+ 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 + ' = ' + str(v)
- self.OM_data_init += ');\n'
+ 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))
@@ -130,16 +124,17 @@ class UnitOperation():
for k in self.parameters:
self.OM_data_init += ', '
- self.OM_data_init += k + ' = ' + ('"' + self.variables[k]['value'] + '"' if isinstance(self.variables[k]['value'], str)
- else str(self.variables[k]['value']))
+ 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:
+ if len(self.input_stms)>1 or self.type == 'Mixer':
strcount = 1
for strm in self.input_stms:
self.OM_data_eqn += ('connect(' + strm.name + '.Out,' + self.name + '.In[' + str(strcount) + ']);\n')
@@ -153,6 +148,7 @@ class UnitOperation():
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[0].name + '.In);\n')
if self.mode:
@@ -167,13 +163,16 @@ class ShortcutColumn(UnitOperation):
self.type = 'ShortcutColumn'
self.no_of_inputs = 1
self.no_of_outputs = 2
- self.input_stms = None
- self.output_stms = None
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 = {
@@ -182,31 +181,57 @@ class ShortcutColumn(UnitOperation):
'HKey_x_pc' : {'name':'Heavy Key Mole Fraction', 'value':0.01, 'unit':'mol/s'},
'LKey_x_pc' : {'name':'Light Key Mole Fraction', 'value':0.01, 'unit':'mol/s'},
'Ctype' : {'name':'Condensor Type', 'value':None, 'unit':''},
- 'thermo_package' : {'name':'Thermo Package', 'value':'Raoults_Law', 'unit':''},
+ 'thermo_package' : {'name':'Thermo Package', 'value':'Raoults_Law', 'unit':''},
'Pcond' : {'name':'Condensor 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 param_setter(self,params):
print("param_setter ", params)
- self.variables['HKey']['value'] = params[0]
- self.variables['LKey']['value'] = params[1]
+ 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.thermo_package = params[8]
- print(self.variables)
+ def OM_Flowsheet_Equation(self):
+ self.OM_data_eqn = ''
+
+ self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[0].name + '.Out);\n')
+ strcount = 1
+ for strm in self.output_stms:
+ 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 = 2
+ self.no_of_inputs = 1
self.no_of_outputs = 2
self.compounds = compound_selected
@@ -215,23 +240,21 @@ class DistillationColumn(UnitOperation):
self.EngStm2 = EngStm(name='EngStm2'+self.name)
self.count = DistillationColumn.counter
- self.input_stms = None
- self.output_stms = None
# self.modes_list = ['RR', 'Nout', 'T']
self.modes_list = []
- self.parameters = ['']
+ self.parameters = ['Nt', 'Ni', 'InT_s', 'Ctype']
#self.parameters = ['Nt', 'InT_s', 'In_s', 'thermo_package', 'Ctype', 'Pcond', 'Preb']
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':2, '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':'No of Feed Stages', 'value':None, 'unit':''},
- 'In_s' : {'name':'No of Feeds', 'value':None, 'unit':''},
+ 'InT_s' : {'name':'Feed Stage', 'value':[], 'unit':''},
'thermo_package' : {'name':'Thermo Package', 'value':'Raoults_Law', 'unit':''},
'Ctype' : {'name':'Condensor Type', 'value':'', 'unit':''},
'Pcond' : {'name':'Condensor Pressure', 'value':101325, 'unit':'Pa'},
@@ -239,22 +262,26 @@ class DistillationColumn(UnitOperation):
'C_Spec': {'name':'Condensor Specification', 'type':'Reflux Ratio', 'value':'', 'comp':'', 'unit':''},
'R_Spec': {'name':'Reboiler Specification', 'type':'', 'value':'', 'comp':'', 'unit':''},
}
+
def param_setter(self,params):
print("param_setter ", params)
+ temp = 0
self.variables['Nt']['value'] = params[0]
- self.variables['In_s']['value'] = params[1]
- self.variables['InT_s']['value'] = params[2]
- self.variables['Ctype']['value'] = params[3]
- self.variables['Pcond']['value'] = params[4]
- self.variables['C_Spec']['type'] = params[5]
+ 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[6]
- self.variables['C_Spec']['value'] = params[7]
- self.variables['Preb']['value'] = params[8]
- self.variables['R_Spec']['type'] = params[9]
+ self.variables['C_Spec']['comp'] = params[temp+4]
+ self.variables['C_Spec']['value'] = params[temp+5]
+ self.variables['Preb']['value'] = params[temp+6]
+ self.variables['R_Spec']['type'] = params[temp+7]
if 'Compound' in self.variables['R_Spec']['type']:
- self.variables['R_Spec']['comp'] = params[10]
- self.variables['R_Spec']['value'] = params[11]
+ self.variables['R_Spec']['comp'] = params[temp+8]
+ self.variables['R_Spec']['value'] = params[temp+9]
print(self.variables)
class ConvertionReactor(UnitOperation):
@@ -284,40 +311,70 @@ class CompoundSeparator(UnitOperation):
type(self).counter += 1
self.variables = {
'SepStrm' : {'name':'Separation Stream', 'value':1, 'unit':''},
- #'SepVal' : {'name':'Separation Value', 'value':[], 'unit':''},
- #'SepFact' : {'name':'Separaction Factor', 'value':'', 'unit':''},
+ 'SepVal_c' : {'name':'Separation Value', 'value':[], 'unit':''},
+ 'SepFact_c' : {'name':'Separaction Factor', 'value':[], 'unit':''},
}
-
- for i in self.compounds:
- self.variables[i] = {'name':'SepVal_'+i, 'value':'', 'type':'', 'unit':''}
- # self.SepFact = json.dumps(self.variables['SepFact']['value']).replace('[','{').replace(']','}')
- # self.SepStrm = str(self.variables['SepStrm']['value'])
- # self.SepVal = json.dumps(self.variables['SepVal']['value']).replace('[','{').replace(']','}')
def param_setter(self,params):
- print("param_setter ", params)
- if params[0]:
+ print("param_setter CompSep ", params)
+
+ if (params[0]):
self.variables['SepStrm']['value'] = 1
- elif params[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'].append(float(params[i]))
+ else:
+ self.variables['SepFact_c']['value'].append(params[i].split(' ')[0])
- j = 2
- for i in self.compounds:
- self.variables[i]['type'] = params[j]
- self.variables[i]['value'] = float(params[j+1])
- j += 2
- print(self.variables)
+ self.variables['SepFact_c']['value'] = json.dumps(self.variables['SepFact_c']['value']).replace('[','{').replace(']','}')
+ self.variables['SepStrm']['value'] = str(self.variables['SepStrm']['value'])
+ self.variables['SepVal_c']['value'] = json.dumps(self.variables['SepVal_c']['value']).replace('[','{').replace(']','}')
+
+
+ def OM_Flowsheet_Initialize(self):
+ 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 = "+self.variables['SepFact_c']['value']+",SepStrm = " + self.variables['SepStrm']['value'] + ");\n") #+ ", sepFactVal = " + self.variables['SepVal_c']['value']
+
+ return self.OM_data_init
+
+
+ def OM_Flowsheet_Equation(self):
+ self.OM_data_eqn = ''
+
+ self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[0].name + '.Out);\n')
+
+ strcount = 1
+ for strm in self.output_stms:
+ self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out' + str(strcount) + ');\n')
+ strcount += 1
+
+ self.OM_data_eqn += (self.name + '.SepVal_c ' + '=' + self.variables['SepVal_c']['value'] + ';\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.input_stms = []
self.output_stms = []
self.count = Flash.counter
+ self.thermo_pack_req = True
+ self.parameters = ['BTdef', 'Tdef', 'BPdef', 'Pdef']
type(self).counter += 1
self.variables = {
@@ -327,6 +384,7 @@ class Flash(UnitOperation):
'Tdef' : {'name':'Separation Temperature', 'value':298.15, 'unit':'K'},
'Pdef' : {'name':'Separation Pressure', 'value':101325, 'unit':'Pa'}
}
+
def param_setter(self,params):
print("param_setter ", params)
self.variables['thermo_package']['value'] = params[0]
@@ -334,7 +392,18 @@ class Flash(UnitOperation):
self.variables['Tdef']['value'] = params[2]
self.variables['BPdef']['value'] = params[3]
self.variables['Pdef']['value'] = params[4]
- print(self.variables)
+
+ def OM_Flowsheet_Equation(self):
+ self.OM_data_eqn = ''
+
+ self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.input_stms[0].name + '.Out);\n')
+
+ strcount = 1
+ for strm in self.output_stms:
+ self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out' + str(strcount) + ');\n')
+ strcount += 1
+
+ return self.OM_data_eqn
class Pump(UnitOperation):
def __init__(self,name='Pump'):
@@ -359,8 +428,6 @@ class Valve(UnitOperation):
UnitOperation.__init__(self)
self.name = name + str(Valve.counter)
self.type = 'Valve'
- self.input_stms = None
- self.output_stms = None
self.modes_list = ['Pdel', 'Pout']
type(self).counter += 1
@@ -376,31 +443,29 @@ class Splitter(UnitOperation):
self.type = 'Splitter'
self.no_of_outputs = 3
- # self.input_stms = None
- self.CalcType_modes = ['Split Ratios', 'Mole Flow Specs', 'Mass Flow Specs']
+ self.CalcType_modes = ['Split_Ratio', 'Molar_Flow', 'Mass_Flow']
- self.parameters = ['NOO', 'CalcType']#, 'SpecVal_s'
+ self.parameters = ['No', 'CalcType', 'SpecVal_s']
type(self).counter += 1
self.variables = {
- 'NOO' : {'name':'No. of Output', 'value':3, 'unit':''},
+ 'No' : {'name':'No. of Output', 'value':3, 'unit':''},
'CalcType' : {'name':'Calculation Type', 'value':self.CalcType_modes[0], 'unit':''},
'SpecVal_s' : {'name':'Specification Value', 'value':[50,50], 'unit':''}
}
- specval = self.variables['SpecVal_s']['value'] # [50,50]
+ specval = self.variables['SpecVal_s']['value']
self.specval = json.dumps(specval).replace('[','{').replace(']','}')
def param_setter(self,params):
print("param_setter ", params)
- self.variables['NOO']['value'] = int(params[0])
+ 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'] == 'Mole Flow Specs':
+ if self.variables['CalcType']['value'] == 'Molar_Flow':
self.variables['SpecVal_s']['unit'] = 'mol/s'
- elif self.variables['CalcType']['value'] == 'Mass Flow Specs':
- self.variables['SpecVal_s']['unit'] = 'kg/s'
- print(self.variables)
+ elif self.variables['CalcType']['value'] == 'Mass_Flow':
+ self.variables['SpecVal_s']['unit'] = 'g/s'
class Mixer(UnitOperation):
@@ -410,25 +475,19 @@ class Mixer(UnitOperation):
self.type = 'Mixer'
self.no_of_inputs = 6
- self.Pout_modes = ['Inlet Minimum', 'Inlet Average', 'Inlet Maximum']
+ self.Pout_modes = ['Inlet_Minimum', 'Inlet_Average', 'Inlet_Maximum']
self.parameters = ['NI', 'outPress']
- # self.output_stms = None
type(self).counter += 1
self.variables = {
- 'NI' : {'name':'Number of Input', 'value':6, 'unit':''},
+ 'NI' : {'name':'Number of Input', 'value':6, 'unit':''},
'outPress' : {'name':'Outlet Pressure', 'value':'Inlet_Average', 'unit':''},
}
+
def param_setter(self, params):
- print(self.input_stms, self.output_stms)
- self.output_stms = []
- print(self.input_stms, self.output_stms)
- print("param_setter ", params)
self.variables['NI']['value'] = int(params[0])
self.variables['outPress']['value'] = params[1]
- print(self.variables)
-
class Heater(UnitOperation):
def __init__(self, name='Heater'):
@@ -491,7 +550,7 @@ class AdiabaticCompressor(UnitOperation):
self.parameters = ['Eff']
type(self).counter += 1
self.variables = {
- 'Pdel' : {'name':'Pressure Drop', 'value':0, 'unit':'Pa'},
+ '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'},