Skip to content

Commit

Permalink
Made GUI compatible with the new Simulator, abbreviations updated to …
Browse files Browse the repository at this point in the history
…new convention and few bugs eliminated with code clean up at places
  • Loading branch information
SaurabhAgarwala committed Jan 3, 2020
1 parent 4138fd7 commit 8dfb7d8
Show file tree
Hide file tree
Showing 1,163 changed files with 11,429 additions and 13,939 deletions.
2 changes: 1 addition & 1 deletion Bin_Phase_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def plot(self):
self.data.append("import data = Simulator.Files.Chemsep_Database;\n")
self.data.append("parameter data."+self.comp1+" comp1;\n")
self.data.append("parameter data."+self.comp2+" comp2;\n")
self.data.append("extends BinaryEnvelopes."+self.thermoPack+"(NOC = 2, data_points = "+str(data_points)+ ", comp = { comp1, comp2 }, "+self.type+" = fill( "+str(val)+", "+str(data_points)+"));\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:
Expand Down
8 changes: 3 additions & 5 deletions Graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import sys
import numpy as np
from OMChem.Flowsheet import Flowsheet
from OMChem.MatStm import MatStm

import pandas as pd
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
Expand Down Expand Up @@ -208,7 +206,7 @@ def mouseMoveEvent(self, event):

def mouseReleaseEvent(self, event):
item = self.scene().itemAt(event.scenePos().toPoint(),QtGui.QTransform())
stm = ['MatStm','EngStm']
stm = ['MaterialStream','EngStm']
item.otherLine=self.newLine
if (self.type == 'op') and (item.type == 'in'):
self.newLine.source = self
Expand Down Expand Up @@ -321,7 +319,7 @@ def initializeSockets(self,type):
Input = [NodeSocket(QtCore.QRect(-2.5+5.5,(self.rect.height()*x/(self.nin+1))-8,4,4), self, 'in') for x in range(1,self.nin+1) ]
Output = [NodeSocket(QtCore.QRect(self.rect.width()-7.5,(self.rect.height()*x*0.90/(self.nop+1))-4,4,4), self, 'op') for x in range(1,self.nop+1)]
return Input,Output
elif(self.type=="AdiaComp" or self.type=="AdiaExp" or self.type =="Mixer" or self.type =="Splitter" or self.type =="Valve" ):
elif(self.type=="AdiabaticCompressor" or self.type=="AdiabaticExpander" or self.type =="Mixer" or self.type =="Splitter" or self.type =="Valve" ):
Input = [NodeSocket(QtCore.QRect(-3.5,(self.rect.height()*x/(self.nin+1))-6,4,4), self, 'in') for x in range(1,self.nin+1) ]
Output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nop+1))-6,4,4), self, 'op') for x in range(1,self.nop+1)]
return Input,Output
Expand All @@ -337,7 +335,7 @@ def initializeSockets(self,type):
Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-12,5,5), self, 'in') for x in range(1,self.nin+1) ]
Output = [NodeSocket(QtCore.QRect(self.rect.width()-5.5,(self.rect.height()*1.44*x/(self.nop+1))-67,5,5), self, 'op') for x in range(1,self.nop+1)]
return Input,Output
elif(self.type=="MatStm"):
elif(self.type=="MaterialStream"):
Input = [NodeSocket(QtCore.QRect(-2.5,(self.rect.height()*x/(self.nin+1))-1,4,4), self, 'in') for x in range(1,self.nin+1) ]
Output = [NodeSocket(QtCore.QRect(self.rect.width()-2.5,(self.rect.height()*x/(self.nin+1))-1,4,4), self, 'op') for x in range(1,self.nop+1)]
return Input,Output
Expand Down
2 changes: 1 addition & 1 deletion OMChem/CompSep.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def OM_Flowsheet_Init(self, addedcomp):
comp_count = len(addedcomp)
self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStms.name+';\n'
self.OM_data_init = self.OM_data_init + (
"Simulator.Unit_Operations.Compound_Separator " + self.name + "(NOC = " + str(comp_count))
"Simulator.Unit_Operations.Compound_Separator " + self.name + "(Nc = " + str(comp_count))
self.OM_data_init = self.OM_data_init + (",comp = {")
comp = str(addedcomp).strip('[').strip(']')
comp = comp.replace("'", "")
Expand Down
2 changes: 1 addition & 1 deletion OMChem/Cooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def OM_Flowsheet_Init(self, addedcomp):
comp_count = len(addedcomp)
self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStms.name+';\n'
self.OM_data_init = self.OM_data_init + (
"Simulator.Unit_Operations.Cooler " + self.name + "(NOC = " + str(comp_count))
"Simulator.Unit_Operations.Cooler " + self.name + "(Nc = " + str(comp_count))
self.OM_data_init = self.OM_data_init + (",comp = {")
comp = str(addedcomp).strip('[').strip(']')
comp = comp.replace("'", "")
Expand Down
8 changes: 4 additions & 4 deletions OMChem/DistCol.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def OM_Flowsheet_Init(self, addedcomp):
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.Unit_Operations.Distillation_Column.DistCol;\n" )
self.OM_data_init = self.OM_data_init + ("Condensor condensor(NOC = NOC, comp = comp, condType =condType, boolFeed = boolFeed[1], T(start = 300));\n" )
self.OM_data_init = self.OM_data_init + ("Reboiler reboiler(NOC = NOC, comp = comp, boolFeed = boolFeed[noOfStages]);\n" )
self.OM_data_init = self.OM_data_init + ("Tray tray[noOfStages - 2](each NOC = NOC, each comp = comp, boolFeed = boolFeed[2:noOfStages -1]);\n" )
self.OM_data_init = self.OM_data_init + ("Condensor condensor(Nc = Nc, comp = comp, condType =condType, boolFeed = boolFeed[1], T(start = 300));\n" )
self.OM_data_init = self.OM_data_init + ("Reboiler reboiler(Nc = Nc, comp = comp, boolFeed = boolFeed[noOfStages]);\n" )
self.OM_data_init = self.OM_data_init + ("Tray tray[noOfStages - 2](each Nc = Nc, each comp = comp, boolFeed = boolFeed[2:noOfStages -1]);\n" )
self.OM_data_init = self.OM_data_init + ("end distCol"+str(self.count)+";\n")
comp_count = len(addedcomp)
self.OM_data_init = self.OM_data_init + (
"distCol"+str(self.count)+" "+ self.name + "(NOC = " + str(comp_count))
"distCol"+str(self.count)+" "+ self.name + "(Nc = " + str(comp_count))
self.OM_data_init = self.OM_data_init + (",comp = {")
comp = str(addedcomp).strip('[').strip(']')
comp = comp.replace("'", "")
Expand Down
2 changes: 1 addition & 1 deletion OMChem/Flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def OM_Flowsheet_Init(self, addedcomp):
self.OM_data_init = self.OM_data_init + ("end fls"+str(self.count)+";\n")
comp_count = len(addedcomp)
self.OM_data_init = self.OM_data_init + (
"fls"+str(self.count)+" "+ self.name + "(NOC = " + str(comp_count))
"fls"+str(self.count)+" "+ self.name + "(Nc = " + str(comp_count))
self.OM_data_init = self.OM_data_init + (",comp = {")
comp = str(addedcomp).strip('[').strip(']')
comp = comp.replace("'", "")
Expand Down
91 changes: 46 additions & 45 deletions OMChem/Flowsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,32 @@ def OM_Flowsheet_Initialize(self,unitOpr):
if len(unitOpr.extra)==1:
for i in unitOpr.extra:
unitOpr.OM_data_init += ('model '+i+str(unitOpr.counter)+'\n')
unitOpr.OM_data_init += ('extends Simulator.Unit_Operations.'+i+';\n')
unitOpr.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+unitOpr.thermoPackage+';\n')
unitOpr.OM_data_init += ('extends Simulator.UnitOperations.'+i+';\n')
unitOpr.OM_data_init += ('extends Simulator.Files.ThermodynamicPackages.'+unitOpr.thermoPackage+';\n')
unitOpr.OM_data_init += ('end '+i+str(unitOpr.counter)+';\n')

unitOpr.OM_data_init += i+str(unitOpr.counter) + ' ' + unitOpr.name + '(NOC = ' + str(len(self.compounds))
unitOpr.OM_data_init += i+str(unitOpr.counter) + ' ' + unitOpr.name + '(Nc = ' + str(len(self.compounds))

else:
for i in range(len(unitOpr.extra)):
if i!=(len(unitOpr.extra)-1):
unitOpr.OM_data_init += ('model '+unitOpr.ForNaming[i]+str(unitOpr.counter)+'\n')
unitOpr.OM_data_init += ('extends Simulator.Unit_Operations.'+unitOpr.extra[i]+';\n')
unitOpr.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+unitOpr.thermoPackage+';\n')
unitOpr.OM_data_init += ('extends Simulator.UnitOperations.'+unitOpr.extra[i]+';\n')
unitOpr.OM_data_init += ('extends Simulator.Files.ThermodynamicPackages.'+unitOpr.thermoPack+';\n')
unitOpr.OM_data_init += ('end '+unitOpr.ForNaming[i]+str(unitOpr.counter)+';\n')
else:
unitOpr.OM_data_init += ('model '+unitOpr.ForNaming[i]+str(unitOpr.counter)+'\n')
unitOpr.OM_data_init += ('extends Simulator.Unit_Operations.'+unitOpr.extra[i]+';\n')
unitOpr.OM_data_init += ('extends Simulator.UnitOperations.'+unitOpr.extra[i]+';\n')
for j in range(len(unitOpr.extra)-1):
unitOpr.OM_data_init += (unitOpr.ForNaming[j] + str(unitOpr.counter) +' ' + unitOpr.ForNaming[j] + '#' + unitOpr.multidict[j] + ';\n')

unitOpr.OM_data_init += ('end '+unitOpr.ForNaming[i]+str(unitOpr.counter)+';\n')

unitOpr.OM_data_init += unitOpr.ForNaming[i] + str(unitOpr.counter) + ' ' + unitOpr.ForNaming + '(NOC = ' + str(len(self.compounds))
unitOpr.OM_data_init += unitOpr.ForNaming[i] + str(unitOpr.counter) + ' ' + unitOpr.ForNaming + '(Nc = ' + str(len(self.compounds))

comp = str(self.compounds).strip('[').strip(']')
comp = comp.replace("'", "")
unitOpr.OM_data_init += ',comp = {' + comp + '}'
C = str(self.compounds).strip('[').strip(']')
C = C.replace("'", "")
unitOpr.OM_data_init += ',C = {' + C + '}'



Expand All @@ -76,10 +76,10 @@ def OM_Flowsheet_Initialize(self,unitOpr):
unitOpr.OM_data_init += ');\n'

else:
unitOpr.OM_data_init += 'Simulator.Unit_Operations.' + unitOpr.type + ' ' + unitOpr.name + '(NOC = ' + str(len(self.compounds))
comp = str(self.compounds).strip('[').strip(']')
comp = comp.replace("'", "")
unitOpr.OM_data_init += ',comp = {' + comp + '}'
unitOpr.OM_data_init += 'Simulator.UnitOperations.' + unitOpr.type + ' ' + unitOpr.name + '(Nc = ' + str(len(self.compounds))
C = str(self.compounds).strip('[').strip(']')
C = C.replace("'", "")
unitOpr.OM_data_init += ',C = {' + C + '}'

for k,v in unitOpr.parameters.items():
unitOpr.OM_data_init += ', '
Expand All @@ -101,18 +101,18 @@ def OM_Flowsheet_Equation(self,unitOpr):
if len(unitOpr.InputStms)>1:
strcount = 1
for strm in unitOpr.InputStms:
unitOpr.OM_data_eqn += ('connect(' + strm.name + '.outlet,' + unitOpr.name + '.inlet[' + str(strcount) + ']);\n')
unitOpr.OM_data_eqn += ('connect(' + strm.name + '.Out,' + unitOpr.name + '.In[' + str(strcount) + ']);\n')
strcount += 1
else:
unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.inlet,' + unitOpr.InputStms[0].name + '.outlet);\n')
unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.In,' + unitOpr.InputStms[0].name + '.Out);\n')

if len(unitOpr.OutputStms)>1:
strcount = 1
for strm in unitOpr.OutputStms:
unitOpr.OM_data_eqn += ('connect(' + strm.name + '.inlet,' + unitOpr.name + '.outlet[' + str(strcount) + ']);\n')
unitOpr.OM_data_eqn += ('connect(' + strm.name + '.In,' + unitOpr.name + '.Out[' + str(strcount) + ']);\n')
strcount += 1
else:
unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.outlet,' + unitOpr.OutputStms[0].name + '.inlet);\n')
unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.Out,' + unitOpr.OutputStms[0].name + '.In);\n')

if unitOpr.mode:
unitOpr.OM_data_eqn += (unitOpr.name + '.' + unitOpr.mode + '=' + unitOpr.modeVal + ';\n')
Expand Down Expand Up @@ -140,8 +140,8 @@ def add_UnitOpn(self,unitop):
def remove_UnitOpn(self,unitop):
self.UnitOpn.remove(unitop)

def add_comp_list(self,comp):
self.compounds = comp
def add_comp_list(self,C):
self.compounds = C

def send_for_simulationEqn(self):
self.resdata = []
Expand Down Expand Up @@ -203,7 +203,7 @@ def send_for_simulationSM(self,unitop):
# if self.sim_method == 'SM':
# for unitop in self.UnitOpn:
# self.resdata = []
# if unitop.type != 'MatStm':
# if unitop.type != 'MaterialStream':
# print 'Simulating '+unitop.name+'...'
# csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv')
# with open(csvpath,'r') as resultFile:
Expand All @@ -228,7 +228,7 @@ def send_for_simulationSM(self,unitop):

def ExtData(self):
for unit in self.UnitOpn:
if unit[0].type == 'MatStm':
if unit[0].type == 'MaterialStream':
for key, value in unit[0].Prop.items():
propertyname = unit[0].name + '.' + key
if propertyname in self.resdata[0]:
Expand Down Expand Up @@ -325,19 +325,19 @@ def simulateEQN(self):
for c in self.compounds:
ucase = c.title()
lcase = c.lower()
self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n")
self.data.append("parameter database." + ucase +' '+ ucase + "; \n")

for unitop in self.UnitOpn:
if unitop.type != 'MatStm':
if unitop.type != 'MaterialStream':
self.data.append(self.OM_Flowsheet_Initialize(unitop))
else:
self.data.append(unitop.OM_Flowsheet_Init(self.compounds))
self.data.append(unitop.OM_Flowsheet_Initialize(self.compounds))


self.data.append("equation\n")

self.outlist = []
self.stm = ['MatStm','EngStm']
self.stm = ['MaterialStream','EngStm']
for unitop in self.UnitOpn:
if unitop.type not in self.stm:
for j in unitop.OutputStms:
Expand All @@ -349,10 +349,10 @@ def simulateEQN(self):
for unitop in self.UnitOpn:
if unitop not in self.outlist:

if unitop.type == 'MatStm':
self.data.append(unitop.OM_Flowsheet_Eqn(self.compounds,'Eqn'))
if unitop.type == 'MaterialStream':
self.data.append(unitop.OM_Flowsheet_Equation(self.compounds,'Eqn'))
else:
self.data.append(self.OM_Flowsheet_Equation(unitop))
self.data.append(unitop.OM_Flowsheet_Equation())
else:
pass
with open(self.Flomo_path, 'w') as txtfile:
Expand All @@ -362,9 +362,10 @@ def simulateEQN(self):

with open(self.eqn_mos_path, 'w') as mosFile:
mosFile.write('loadModel(Modelica);\n')
mosFile.write("loadFile(\"Simulator/package.mo\");\n")
mosFile.write("loadFile(\"Flowsheet.mo\");\n")
mosFile.write("simulate(Flowsheet, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n")
mosFile.write('loadFile(\"Simulator/package.mo\");\n')
mosFile.write('loadFile(\"database.mo\");\n')
mosFile.write('loadFile(\"Flowsheet.mo\");\n')
mosFile.write('simulate(Flowsheet, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n')

print('Initiating Simulation in Equation Oriented Mode')

Expand Down Expand Up @@ -409,7 +410,7 @@ def simulateSM(self,ip,op):
for unitop in self.unit:
os.chdir(self.root_dir)
self.data = []
if unitop.type not in ['MatStm','EngStm']:
if unitop.type not in ['MaterialStream','EngStm']:
inpstms = unitop.InputStms
outstms = unitop.OutputStms

Expand All @@ -426,43 +427,43 @@ def simulateSM(self,ip,op):
self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n")

print("##############compounds added")
self.data.append(self.OM_Flowsheet_Initialize(unitop))
self.data.append(unitop.OM_Flowsheet_Initialize())

if type(outstms) is list:
for stm in outstms:
self.data.append(self.OM_Flowsheet_Initialize(stm))
self.data.append(stm.OM_Flowsheet_Initialize())
else:
self.data.append(self.OM_Flowsheet_Initialize(outstms))
self.data.append(outstms.OM_Flowsheet_Initialize())


if engstms:
self.data.append(self.OM_Flowsheet_Initialize(engstms))
self.data.append(engstms.OM_Flowsheet_Initialize())

if type(inpstms) is list:
for stm in inpstms:
self.data.append(self.OM_Flowsheet_Initialize(stm))
self.data.append(stm.OM_Flowsheet_Initialize())
else:
self.data.append(self.OM_Flowsheet_Initialize(inpstms))
self.data.append(inpstms.OM_Flowsheet_Initialize())

self.data.append('equation\n')
print("##################equation")
self.data.append(self.OM_Flowsheet_Equation(unitop))
self.data.append(unitop.OM_Flowsheet_Equation())
'''
if type(outstms) is list:
for stm in outstms:
#stm.GetEquationValues()
self.data.append(stm.OM_Flowsheet_Eqn(self.compounds,'SM'))
self.data.append(stm.OM_Flowsheet_Equation(self.compounds,'SM'))
else:
#outstms.GetEquationValues()
self.data.append(outstms.OM_Flowsheet_Eqn(self.compounds,'SM'))
self.data.append(outstms.OM_Flowsheet_Equation(self.compounds,'SM'))
'''
if type(inpstms) is list:
for stm in inpstms:
#stm.GetEquationValues()
self.data.append(self.OM_Flowsheet_Equation(stm))
self.data.append(stm.OM_Flowsheet_Equation())
else:
#inpstms.GetEquationValues()
self.data.append(self.OM_Flowsheet_Equation(inpstms))
self.data.append(inpstms.OM_Flowsheet_Equation())

# os.chdir(self.sim_dir_path)
unitmofile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mo')
Expand Down Expand Up @@ -509,7 +510,7 @@ def simulateSM(self,ip,op):
os.chdir(self.root_dir)
if type(inpstms) is list:
for stm in inpstms:
for key, value in stm.Prop.items():
for key,value in stm.Prop.items():
propertyname = stm.name + '.' + key
if propertyname in self.resdata[0]:
ind = self.resdata[0].index(propertyname)
Expand Down
2 changes: 1 addition & 1 deletion OMChem/Heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def OM_Flowsheet_Init(self, addedcomp):
comp_count = len(addedcomp)
self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStms.name+';\n'
self.OM_data_init = self.OM_data_init + (
"Simulator.Unit_Operations.Heater " + self.name + "(NOC = " + str(comp_count))
"Simulator.Unit_Operations.Heater " + self.name + "(Nc = " + str(comp_count))
self.OM_data_init = self.OM_data_init + (",comp = {")
comp = str(addedcomp).strip('[').strip(']')
comp = comp.replace("'", "")
Expand Down
Loading

0 comments on commit 8dfb7d8

Please sign in to comment.