summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--OMChem/Flowsheet.py118
-rw-r--r--OMChem/UnitOprns.py198
-rw-r--r--UnitOperations.py24
-rw-r--r--container.py1
4 files changed, 223 insertions, 118 deletions
diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py
index 59134b9..a113d66 100644
--- a/OMChem/Flowsheet.py
+++ b/OMChem/Flowsheet.py
@@ -23,6 +23,102 @@ class Flowsheet():
self.stdout=None
self.stderr=None
+ def OM_Flowsheet_Initialize(self,unitOpr):
+ unitOpr.OM_data_init = ''
+
+ if(unitOpr.ThermoPackReq):
+ if len(unitOpr.extra)>1:
+ for i in range(unitOpr.extra):
+ latest = ''
+ for j in range(unitOpr.extra[i]):
+ if unitOpr.extra[i][j]!='.':
+ latest += unitOpr.extra[i][j]
+ unitOpr.ForNaming[i] = latest
+
+
+
+ if(unitOpr.ThermoPackReq):
+ 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.thermoPack+';\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))
+
+ 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.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')
+ 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))
+
+ comp = str(self.compounds).strip('[').strip(']')
+ comp = comp.replace("'", "")
+ unitOpr.OM_data_init += ',comp = {' + comp + '}'
+
+
+
+ for k,v in unitOpr.parameters.items():
+ unitOpr.OM_data_init += ', '
+ unitOpr.OM_data_init += k + ' = ' + str(v)
+ 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 + '}'
+
+ for k,v in unitOpr.parameters.items():
+ unitOpr.OM_data_init += ', '
+ unitOpr.OM_data_init += k + ' = ' + str(v)
+
+ unitOpr.OM_data_init += ');\n'
+
+ #print("HERE WE GO")
+ #print(unitOpr.OM_data_init)
+
+ return unitOpr.OM_data_init
+
+
+
+
+ def OM_Flowsheet_Equation(self,unitOpr):
+ unitOpr.OM_data_eqn = ''
+
+ 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')
+ strcount += 1
+ else:
+ unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.inlet,' + unitOpr.InputStms[0].name + '.outlet);\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')
+ strcount += 1
+ else:
+ unitOpr.OM_data_eqn += ('connect(' + unitOpr.name + '.outlet,' + unitOpr.OutputStms[0].name + '.inlet);\n')
+
+ if unitOpr.mode:
+ unitOpr.OM_data_eqn += (unitOpr.name + '.' + unitOpr.mode + '=' + unitOpr.modeVal + ';\n')
+
+ return unitOpr.OM_data_eqn
+
def get_omc_path(self):
try:
@@ -233,7 +329,7 @@ class Flowsheet():
for unitop in self.UnitOpn:
if unitop.type != 'MatStm':
- self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(unitop))
else:
self.data.append(unitop.OM_Flowsheet_Init(self.compounds))
@@ -256,7 +352,7 @@ class Flowsheet():
if unitop.type == 'MatStm':
self.data.append(unitop.OM_Flowsheet_Eqn(self.compounds,'Eqn'))
else:
- self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds))
+ self.data.append(self.OM_Flowsheet_Equation(unitop))
else:
pass
with open(self.Flomo_path, 'w') as txtfile:
@@ -330,27 +426,27 @@ class Flowsheet():
self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n")
print("##############compounds added")
- self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(unitop))
if type(outstms) is list:
for stm in outstms:
- self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(stm))
else:
- self.data.append(outstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(outstms))
if engstms:
- self.data.append(engstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(engstms))
if type(inpstms) is list:
for stm in inpstms:
- self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(stm))
else:
- self.data.append(inpstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds))
+ self.data.append(self.OM_Flowsheet_Initialize(inpstms))
self.data.append('equation\n')
print("##################equation")
- self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds))
+ self.data.append(self.OM_Flowsheet_Equation(unitop))
'''
if type(outstms) is list:
for stm in outstms:
@@ -363,10 +459,10 @@ class Flowsheet():
if type(inpstms) is list:
for stm in inpstms:
#stm.GetEquationValues()
- self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds,'SM'))
+ self.data.append(self.OM_Flowsheet_Equation(stm))
else:
#inpstms.GetEquationValues()
- self.data.append(inpstms.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds,'SM'))
+ self.data.append(self.OM_Flowsheet_Equation(inpstms))
# os.chdir(self.sim_dir_path)
unitmofile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mo')
diff --git a/OMChem/UnitOprns.py b/OMChem/UnitOprns.py
index 4cafe0d..d2608f2 100644
--- a/OMChem/UnitOprns.py
+++ b/OMChem/UnitOprns.py
@@ -1,138 +1,140 @@
-from OMChem.EngStm import EngStm
-from collections import defaultdict
+# This file can be deleted
-class UnitOpr():
+# from OMChem.EngStm import EngStm
+
+# class UnitOpr():
- def __init__(self,name,counter,Type,parameters={},mode=None,modeVal=None,ThermoPackReq = False,thermoPack = None,extra=[], multidict=[],inputs=1,outputs=1):
- self.OM_data_eqn = ''
- self.OM_data_init = ''
- self.InputStms = []
- self.OutputStms = []
- self.EngStms = EngStm(name='EngStm'+name)
- self.name = name
- self.mode = mode
- self.modeVal = modeVal
- self.thermoPack = thermoPack
- self.extra = extra
- self.type = Type
- self.ForNaming = extra;
- self.no_of_inputs = inputs
- self.no_of_outputs = outputs
- self.counter=counter
- self.parameters = parameters
- self.ThermoPackReq = ThermoPackReq
+# def __init__(self,name,counter,Type,parameters={},mode=None,modeVal=None,ThermoPackReq = False,thermoPack = None,extra=[], multidict=[],inputs=1,outputs=1):
+# self.OM_data_eqn = ''
+# self.OM_data_init = ''
+# self.InputStms = []
+# self.OutputStms = []
+# self.EngStms = EngStm(name='EngStm'+name)
+# self.name = name
+# self.mode = mode
+# self.modeVal = modeVal
+# self.thermoPack = thermoPack
+# self.extra = extra
+# self.multidict = multidict
+# self.type = Type
+# self.ForNaming = extra
+# self.no_of_inputs = inputs
+# self.no_of_outputs = outputs
+# self.counter=counter
+# self.parameters = parameters
+# self.ThermoPackReq = ThermoPackReq
- def connect(self,InputStms = [],OutputStms = []):
- self.InputStms = InputStms
- self.OutputStms = OutputStms
- print('INPUT')
- print(InputStms)
- print('OUTPUT')
- print(OutputStms)
+# # def connect(self,InputStms = [],OutputStms = []):
+# # self.InputStms = InputStms
+# # self.OutputStms = OutputStms
+# # print('INPUT')
+# # print(InputStms)
+# # print('OUTPUT')
+# # print(OutputStms)
- def OM_Flowsheet_Initialize(self,addedcomp):
- self.OM_data_init = ''
+# def OM_Flowsheet_Initialize(self,addedcomp):
+# 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 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.Unit_Operations.'+i+';\n')
- self.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+self.thermoPack+';\n')
- self.OM_data_init += ('end '+i+str(self.counter)+';\n')
+# 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.Unit_Operations.'+i+';\n')
+# self.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+self.thermoPack+';\n')
+# self.OM_data_init += ('end '+i+str(self.counter)+';\n')
- self.OM_data_init += i+str(self.counter) + ' ' + self.name + '(NOC = ' + str(len(addedcomp))
+# self.OM_data_init += i+str(self.counter) + ' ' + self.name + '(NOC = ' + str(len(addedcomp))
- 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.Unit_Operations.'+self.extra[i]+';\n')
- self.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+self.thermoPack+';\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.Unit_Operations.'+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] + '#' + multidict[j] + ';\n')
+# 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.Unit_Operations.'+self.extra[i]+';\n')
+# self.OM_data_init += ('extends Simulator.Files.Thermodynamic_Packages.'+self.thermoPack+';\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.Unit_Operations.'+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 += ('end '+self.ForNaming[i]+str(self.counter)+';\n')
- self.OM_data_init += self.ForNaming[i] + str(self.counter) + ' ' + self.ForNaming + '(NOC = ' + str(len(addedcomp))
+# self.OM_data_init += self.ForNaming[i] + str(self.counter) + ' ' + self.ForNaming + '(NOC = ' + str(len(addedcomp))
- comp = str(addedcomp).strip('[').strip(']')
- comp = comp.replace("'", "")
- self.OM_data_init += ',comp = {' + comp + '}'
+# comp = str(addedcomp).strip('[').strip(']')
+# comp = comp.replace("'", "")
+# self.OM_data_init += ',comp = {' + comp + '}'
- for k,v in self.parameters.items():
- self.OM_data_init += ', '
- self.OM_data_init += k + ' = ' + str(v)
- self.OM_data_init += ');\n'
+# 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.Unit_Operations.' + self.type + ' ' + self.name + '(NOC = ' + str(len(addedcomp))
- comp = str(addedcomp).strip('[').strip(']')
- comp = comp.replace("'", "")
- self.OM_data_init += ',comp = {' + comp + '}'
+# else:
+# self.OM_data_init += 'Simulator.Unit_Operations.' + self.type + ' ' + self.name + '(NOC = ' + str(len(addedcomp))
+# comp = str(addedcomp).strip('[').strip(']')
+# comp = comp.replace("'", "")
+# self.OM_data_init += ',comp = {' + comp + '}'
- for k,v in self.parameters.items():
- self.OM_data_init += ', '
- self.OM_data_init += k + ' = ' + str(v)
+# for k,v in self.parameters.items():
+# self.OM_data_init += ', '
+# self.OM_data_init += k + ' = ' + str(v)
- self.OM_data_init += ');\n'
+# self.OM_data_init += ');\n'
- #print("HERE WE GO")
- #print(self.OM_data_init)
+# #print("HERE WE GO")
+# #print(self.OM_data_init)
- return self.OM_data_init
+# return self.OM_data_init
- def OM_Flowsheet_Equation(self,addedcomp):
- OM_data_eqn = ''
+# def OM_Flowsheet_Equation(self,addedcomp):
+# self.OM_data_eqn = ''
- if len(self.InputStms)>1:
- strcount = 1
- for strm in self.InputStms:
- self.OM_data_eqn += ('connect(' + strm.name + '.outlet,' + self.name + '.inlet[' + str(strcount) + ']);\n')
- strcount += 1
- else:
- self.OM_data_eqn += ('connect(' + self.name + '.inlet,' + self.InputStms[0].name + '.outlet);\n')
+# if len(self.InputStms)>1:
+# strcount = 1
+# for strm in self.InputStms:
+# self.OM_data_eqn += ('connect(' + strm.name + '.outlet,' + self.name + '.inlet[' + str(strcount) + ']);\n')
+# strcount += 1
+# else:
+# self.OM_data_eqn += ('connect(' + self.name + '.inlet,' + self.InputStms[0].name + '.outlet);\n')
- if len(self.OutputStms)>1:
- strcount = 1
- for strm in self.OutputStms:
- self.OM_data_eqn += ('connect(' + strm.name + '.inlet,' + self.name + '.outlet[' + str(strcount) + ']);\n')
- strcount += 1
- else:
- self.OM_data_eqn += ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n')
+# if len(self.OutputStms)>1:
+# strcount = 1
+# for strm in self.OutputStms:
+# self.OM_data_eqn += ('connect(' + strm.name + '.inlet,' + self.name + '.outlet[' + str(strcount) + ']);\n')
+# strcount += 1
+# else:
+# self.OM_data_eqn += ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n')
- if self.mode:
- self.OM_data_eqn += (self.name + '.' + self.mode + '=' + self.modeVal + ';\n')
+# if self.mode:
+# self.OM_data_eqn += (self.name + '.' + self.mode + '=' + self.modeVal + ';\n')
- return self.OM_data_eqn
+# return self.OM_data_eqn
diff --git a/UnitOperations.py b/UnitOperations.py
index b9bbb0b..0b71ab3 100644
--- a/UnitOperations.py
+++ b/UnitOperations.py
@@ -15,7 +15,6 @@ import PyQt5.QtCore as QtCore
import PyQt5.QtWidgets as QtWidgets
from component_selector import *
-
class UnitOperation():
counter = 1
@@ -37,6 +36,7 @@ class UnitOperation():
self.parameters = {}
# self.input_parameters = {}
self.extra = None
+ self.ForNaming = None
self.multidict = None
self.ThermoPackReq = False
self.thermoPackage = None
@@ -61,9 +61,9 @@ class UnitOperation():
else:
self.modeVal = params[self.mode]
- def connect(self,InputStms,OutputStms):
- self.InputStms = InputStms
- self.OutputStms = OutputStms
+ # def connect(self,InputStms,OutputStms):
+ # self.InputStms = InputStms
+ # self.OutputStms = OutputStms
def add_connection(self,flag,UnitOpr):
if flag==1:
@@ -74,10 +74,12 @@ class UnitOperation():
print("OUTPUT CONNECTION")
self.OutputStms.append(UnitOpr)
- def send_to_flowsheet(self):
- Inst = UnitOpr(name=self.name,counter=type(self).counter,Type='Heater',parameters=self.parameters,mode=self.mode,modeVal=self.modeVal,ThermoPackReq=self.ThermoPackReq,thermoPack=self.thermoPackage,extra=self.extra,multidict=self.multidict,inputs=self.no_of_inputs,outputs=self.no_of_outputs)
- Inst.connect(self.InputStms,self.OutputStms)
- return Inst
+ # def send_to_flowsheet(self):
+ # Inst = UnitOpr(name=self.name,counter=type(self).counter,Type='Heater',parameters=self.parameters,mode=self.mode,modeVal=self.modeVal,ThermoPackReq=self.ThermoPackReq,thermoPack=self.thermoPackage,extra=self.extra,multidict=self.multidict,inputs=self.no_of_inputs,outputs=self.no_of_outputs)
+ # # Inst.connect(self.InputStms,self.OutputStms)
+ # Inst.InputStms = self.InputStms
+ # Inst.OutputStms = self.OutputStms
+ # return Inst
class HeaterClass(UnitOperation):
@@ -96,6 +98,7 @@ class HeaterClass(UnitOperation):
}
self.modesList = ["heatAdd","outT","outVapPhasMolFrac","tempInc","enFlo"]
self.extra = None
+ self.ForNaming = None
self.pressDrop = pressDrop
self.eff = eff
self.parameters = {'pressDrop':self.pressDrop, 'eff':self.eff}
@@ -119,6 +122,7 @@ class CoolerClass(UnitOperation):
}
self.modesList = ["heatRem","outT","outVapPhasMolFrac","tempDrop","enFlo"]
self.extra = None
+ self.ForNaming = None
self.pressDrop = pressDrop
self.eff = eff
self.parameters = {'pressDrop':self.pressDrop, 'eff':self.eff}
@@ -135,6 +139,7 @@ class AdiaCompClass(UnitOperation):
self.no_of_outputs = 1
self.modesList = ["pressInc","outP","reqPow"]
self.extra = ['Adiabatic_Compressor']
+ self.ForNaming = ['Adiabatic_Compressor']
self.ThermoPackReq = True
self.thermoPackage ="Raoults_Law"
self.eff = eff
@@ -152,6 +157,7 @@ class AdiaExpClass(UnitOperation):
self.no_of_outputs = 1
self.modesList = ["pressDrop","outP","genPow"]
self.extra = ['Adiabatic_Expander']
+ self.ForNaming = ['Adiabatic_Expander']
self.ThermoPackReq = True
self.thermoPackage ="Raoults_Law"
self.eff = eff
@@ -162,7 +168,7 @@ class AdiaExpClass(UnitOperation):
def helperFunc(type):
if(type=="MatStm"):
- return MatStm(CompNames=compound_selected)
+ return MatStm(CompNames=compound_selected)
else:
return eval(type+"Class")()
diff --git a/container.py b/container.py
index 3652031..ba67be0 100644
--- a/container.py
+++ b/container.py
@@ -92,6 +92,7 @@ class Container():
for i in self.unitOp:
if(i.name==name):
return i
+
def addCompounds(self,comp):
self.compounds = comp