1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
from OMChem.Flowsheet import Flowsheet
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 component_selector import *
class UnitOperation():
counter = 1
def __init__(self):
self.OM_data_eqn = ''
self.OM_data_init = ''
self.InputStms = []
self.OutputStms = []
self.compounds = compound_selected
self.name = ''
self.mode = None
self.modeVal = None
self.type = ''
self.no_of_inputs = 1
self.no_of_outputs = 1
self.Prop = {}
self.x = 2500-30
self.y = 2500-30
self.pos = QPointF(self.x, self.y)
self.Prop = {}
self.modeslist = []
self.parameters = {}
self.extra = []
self.ForNaming = []
self.multidict = []
self.ThermoPackReq = False
self.thermoPackage = None
def paramgetter(self,mode=None):
params = {}
if mode == None:
self.mode = self.modeslist[0]
else:
self.mode = mode
# print("Hello hello ", self.mode)
params = self.parameters.copy()
params[self.mode] = None
return params
def paramsetter(self,params):
print(params)
for k,v in params.items():
print(k,v)
if k != self.mode:
self.k = v
self.parameters[k] = v
else:
self.modeVal = params[self.mode]
def add_connection(self,flag,UnitOpr):
if flag==1:
# Input stream if flag is 1
self.InputStms.append(UnitOpr)
print("INPUT CONNECTION")
else :
print("OUTPUT CONNECTION")
self.OutputStms.append(UnitOpr)
def setPos(self,pos):
self.pos = pos
def OM_Flowsheet_Initialize(self):
self.OM_data_init = ''
if(self.ThermoPackReq):
if len(self.extra)>1:
for i in range(self.extra):
latest = ''
for j in range(self.extra[i]):
if self.extra[i][j]!='.':
latest += self.extra[i][j]
self.ForNaming[i] = latest
if(self.ThermoPackReq):
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.thermoPackage+';\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.ForNaming[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.thermoPackage+';\n')
self.OM_data_init += ('end '+self.ForNaming[i]+str(self.counter)+';\n')
else:
self.OM_data_init += ('model '+self.ForNaming[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.ForNaming[j] + str(self.counter) +' ' + self.ForNaming[j] + '#' + self.multidict[j] + ';\n')
self.OM_data_init += ('end '+self.ForNaming[i]+str(self.counter)+';\n')
self.OM_data_init += self.ForNaming[i] + str(self.counter) + ' ' + self.ForNaming + '(Nc = ' + str(len(self.compounds))
C = str(self.compounds).strip('[').strip(']')
C = C.replace("'", "")
self.OM_data_init += ',C = {' + C + '}'
for k,v in self.parameters.items():
self.OM_data_init += ', '
self.OM_data_init += k + ' = ' + str(v)
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,v in self.parameters.items():
self.OM_data_init += ', '
self.OM_data_init += k + ' = ' + str(v)
self.OM_data_init += ');\n'
return self.OM_data_init
def OM_Flowsheet_Equation(self):
self.OM_data_eqn = ''
if len(self.InputStms)>1:
strcount = 1
for strm in self.InputStms:
self.OM_data_eqn += ('connect(' + strm.name + '.Out,' + self.name + '.In[' + str(strcount) + ']);\n')
strcount += 1
else:
self.OM_data_eqn += ('connect(' + self.name + '.In,' + self.InputStms[0].name + '.Out);\n')
if len(self.OutputStms)>1:
strcount = 1
for strm in self.OutputStms:
self.OM_data_eqn += ('connect(' + strm.name + '.In,' + self.name + '.Out[' + str(strcount) + ']);\n')
strcount += 1
else:
self.OM_data_eqn += ('connect(' + self.name + '.Out,' + self.OutputStms[0].name + '.In);\n')
if self.mode:
self.OM_data_eqn += (self.name + '.' + self.mode + '=' + self.modeVal + ';\n')
return self.OM_data_eqn
class Heater(UnitOperation):
def __init__(self, name='Heater',Pdel='None', Eff='None'):
UnitOperation.__init__(self)
self.name = name + str(type(self).counter)
self.type = 'Heater'
self.no_of_inputs = 1
self.no_of_outputs = 1
self.Prop = {
'Pdel':None,
'Eff':None,
'Tout':None,
'Tdel':None,
'Q':None,
}
self.modesList = ["Q","Tout","xvapout","Tdel"]
self.extra = None
self.ForNaming = None
self.Pdel = Pdel
self.Eff = Eff
self.parameters = {'Pdel':self.Pdel, 'Eff':self.Eff}
type(self).counter += 1
class Cooler(UnitOperation):
def __init__(self, name='Cooler', Pdel='None', Eff='None'):
UnitOperation.__init__(self)
self.name = name + str(type(self).counter)
self.type = 'Cooler'
self.no_of_inputs = 1
self.no_of_outputs = 1
self.Prop = {
'Pdel':None,
'Eff':None,
'Tout':None,
'Tdel':None,
'Q':None,
}
self.modesList = ["Q","Tout","xvapout","Tdel","enFlo"]
self.extra = None
self.ForNaming = None
self.Pdel = Pdel
self.Eff = Eff
self.parameters = {'Pdel':self.Pdel, 'Eff':self.Eff}
type(self).counter += 1
class AdiabaticCompressor(UnitOperation):
def __init__(self, name='AdiabaticCompressor', Eff='None'):
UnitOperation.__init__(self)
self.name = name + str(type(self).counter)
self.type = 'AdiabaticCompressor'
self.no_of_inputs = 1
self.no_of_outputs = 1
self.Prop = {
'Pdel':None,
'Tdel':None,
'Pout':None,
'Tout':None,
'Q':None
}
self.modesList = ["Pdel","Pout","Q"]
self.extra = ['AdiabaticCompressor']
self.ForNaming = ['AdiabaticCompressor']
self.ThermoPackReq = True
self.thermoPackage ="RaoultsLaw"
self.Eff = Eff
self.parameters = {'Eff':self.Eff}
type(self).counter += 1
class AdiabaticExpander(UnitOperation):
def __init__(self, name='AdiabaticExpander', Eff='None'):
UnitOperation.__init__(self)
self.name = name + str(type(self).counter)
self.type = 'AdiabaticExpander'
self.no_of_inputs = 1
self.no_of_outputs = 1
self.Prop = {
'Pdel':None,
'Tdel':None,
'Pout':None,
'Tout':None,
'Q':None
}
self.modesList = ["Pdel","Pout","Q"]
self.extra = ['AdiabaticExpander']
self.ForNaming = ['AdiabaticExpander']
self.ThermoPackReq = True
self.thermoPackage ="RaoultsLaw"
self.Eff = Eff
self.parameters = {'Eff':self.Eff}
type(self).counter += 1
|