From e2113828e404349f15b98d6c29e119a11abdab01 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Mon, 23 Dec 2019 07:48:16 +0530 Subject: Removed pycache files --- OMChem/__pycache__/CompSep.cpython-36.pyc | Bin 2609 -> 0 bytes OMChem/__pycache__/Cooler.cpython-36.pyc | Bin 2500 -> 0 bytes OMChem/__pycache__/DistCol.cpython-36.pyc | Bin 4393 -> 0 bytes OMChem/__pycache__/EngStm.cpython-36.pyc | Bin 883 -> 0 bytes OMChem/__pycache__/Flash.cpython-36.pyc | Bin 2145 -> 0 bytes OMChem/__pycache__/Flowsheet.cpython-36.pyc | Bin 8631 -> 0 bytes OMChem/__pycache__/Heater.cpython-36.pyc | Bin 2495 -> 0 bytes OMChem/__pycache__/MatStm.cpython-36.pyc | Bin 8847 -> 0 bytes OMChem/__pycache__/Mixer.cpython-36.pyc | Bin 2016 -> 0 bytes OMChem/__pycache__/Pump.cpython-36.pyc | Bin 2290 -> 0 bytes OMChem/__pycache__/ShortcutColumn.cpython-36.pyc | Bin 3410 -> 0 bytes OMChem/__pycache__/Splitter.cpython-36.pyc | Bin 2253 -> 0 bytes OMChem/__pycache__/Valve.cpython-36.pyc | Bin 2010 -> 0 bytes OMChem/__pycache__/adiabatic_comp.cpython-36.pyc | Bin 2569 -> 0 bytes OMChem/__pycache__/adiabatic_exp.cpython-36.pyc | Bin 2559 -> 0 bytes 15 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 OMChem/__pycache__/CompSep.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Cooler.cpython-36.pyc delete mode 100644 OMChem/__pycache__/DistCol.cpython-36.pyc delete mode 100644 OMChem/__pycache__/EngStm.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Flash.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Flowsheet.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Heater.cpython-36.pyc delete mode 100644 OMChem/__pycache__/MatStm.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Mixer.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Pump.cpython-36.pyc delete mode 100644 OMChem/__pycache__/ShortcutColumn.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Splitter.cpython-36.pyc delete mode 100644 OMChem/__pycache__/Valve.cpython-36.pyc delete mode 100644 OMChem/__pycache__/adiabatic_comp.cpython-36.pyc delete mode 100644 OMChem/__pycache__/adiabatic_exp.cpython-36.pyc (limited to 'OMChem') diff --git a/OMChem/__pycache__/CompSep.cpython-36.pyc b/OMChem/__pycache__/CompSep.cpython-36.pyc deleted file mode 100644 index dc4410b..0000000 Binary files a/OMChem/__pycache__/CompSep.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Cooler.cpython-36.pyc b/OMChem/__pycache__/Cooler.cpython-36.pyc deleted file mode 100644 index be8d9fe..0000000 Binary files a/OMChem/__pycache__/Cooler.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/DistCol.cpython-36.pyc b/OMChem/__pycache__/DistCol.cpython-36.pyc deleted file mode 100644 index 518410e..0000000 Binary files a/OMChem/__pycache__/DistCol.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/EngStm.cpython-36.pyc b/OMChem/__pycache__/EngStm.cpython-36.pyc deleted file mode 100644 index 8799e46..0000000 Binary files a/OMChem/__pycache__/EngStm.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Flash.cpython-36.pyc b/OMChem/__pycache__/Flash.cpython-36.pyc deleted file mode 100644 index 3c55d7e..0000000 Binary files a/OMChem/__pycache__/Flash.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Flowsheet.cpython-36.pyc b/OMChem/__pycache__/Flowsheet.cpython-36.pyc deleted file mode 100644 index dd8f589..0000000 Binary files a/OMChem/__pycache__/Flowsheet.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Heater.cpython-36.pyc b/OMChem/__pycache__/Heater.cpython-36.pyc deleted file mode 100644 index 1139a24..0000000 Binary files a/OMChem/__pycache__/Heater.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/MatStm.cpython-36.pyc b/OMChem/__pycache__/MatStm.cpython-36.pyc deleted file mode 100644 index 9b5b187..0000000 Binary files a/OMChem/__pycache__/MatStm.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Mixer.cpython-36.pyc b/OMChem/__pycache__/Mixer.cpython-36.pyc deleted file mode 100644 index c75307b..0000000 Binary files a/OMChem/__pycache__/Mixer.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Pump.cpython-36.pyc b/OMChem/__pycache__/Pump.cpython-36.pyc deleted file mode 100644 index c351aba..0000000 Binary files a/OMChem/__pycache__/Pump.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/ShortcutColumn.cpython-36.pyc b/OMChem/__pycache__/ShortcutColumn.cpython-36.pyc deleted file mode 100644 index 1ea4727..0000000 Binary files a/OMChem/__pycache__/ShortcutColumn.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Splitter.cpython-36.pyc b/OMChem/__pycache__/Splitter.cpython-36.pyc deleted file mode 100644 index 2830093..0000000 Binary files a/OMChem/__pycache__/Splitter.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/Valve.cpython-36.pyc b/OMChem/__pycache__/Valve.cpython-36.pyc deleted file mode 100644 index aba6ad1..0000000 Binary files a/OMChem/__pycache__/Valve.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/adiabatic_comp.cpython-36.pyc b/OMChem/__pycache__/adiabatic_comp.cpython-36.pyc deleted file mode 100644 index c5e8b65..0000000 Binary files a/OMChem/__pycache__/adiabatic_comp.cpython-36.pyc and /dev/null differ diff --git a/OMChem/__pycache__/adiabatic_exp.cpython-36.pyc b/OMChem/__pycache__/adiabatic_exp.cpython-36.pyc deleted file mode 100644 index 1138bdc..0000000 Binary files a/OMChem/__pycache__/adiabatic_exp.cpython-36.pyc and /dev/null differ -- cgit From 9f86138b86efebb816a2289bf84b96d688615f41 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Mon, 23 Dec 2019 13:25:49 +0530 Subject: Feature implementation - saving and partial loading --- OMChem/CompSep.py | 19 ++++++++++++++----- OMChem/ConvReactor.py | 37 ------------------------------------- OMChem/Cooler.py | 14 ++++++++++++-- OMChem/DistCol.py | 17 ++++++++++++++--- OMChem/Flash.py | 18 +++++++++++++++--- OMChem/Heater.py | 12 +++++++++++- OMChem/MatStm.py | 25 +++++++++++++++++-------- OMChem/Mixer.py | 17 +++++++++++++---- OMChem/Pump.py | 12 ++++++++++-- OMChem/ShortcutColumn.py | 18 +++++++++++++++--- OMChem/Splitter.py | 13 +++++++++++-- OMChem/Valve.py | 13 +++++++++++-- OMChem/adiabatic_comp.py | 17 ++++++++++++++--- OMChem/adiabatic_exp.py | 17 ++++++++++++++--- 14 files changed, 171 insertions(+), 78 deletions(-) (limited to 'OMChem') diff --git a/OMChem/CompSep.py b/OMChem/CompSep.py index 54b6415..5bdfd51 100644 --- a/OMChem/CompSep.py +++ b/OMChem/CompSep.py @@ -1,11 +1,12 @@ from OMChem.EngStm import EngStm import json class CompSep(): - def __init__(self,CompNames = [],name='compoundseparator',SepFact=['Molar_Flow','Mass_Flow'],SepStrm=1,SepFactValue=[]): + counter = 1 + def __init__(self,CompNames = [],name='CompSep',SepFact=['Molar_Flow','Mass_Flow'],SepStrm=1,SepFactValue=[]): self.SepFact = json.dumps(SepFact).replace('[','{').replace(']','}') self.SepStrm = str(SepStrm) self.SepFactValue = json.dumps(SepFactValue).replace('[','{').replace(']','}') - self.name = name + #self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = [] @@ -13,8 +14,18 @@ class CompSep(): self.type = 'CompSep' self.EngStms = EngStm(name='EngStm') + # new + self.name = name + str(CompSep.counter) + self.no_of_input = 1 + self.no_of_output = 2 + CompSep.counter += 1 + + def getname(self): + return self.name + def modesList(self): - return [] + return [] + def paramgetter(self,mode=None): dict = {"SepStrm":None,"SepFactValue":None,"SepFact":None} return dict @@ -42,7 +53,6 @@ class CompSep(): self.InputStms = InputStms self.OutputStms = OutputStms - def OM_Flowsheet_Eqn(self, addedcomp): self.OM_data_eqn = '' comp_count = len(addedcomp) @@ -57,7 +67,6 @@ class CompSep(): sepFac = str(self.SepFactValue).strip('[').strip(']') self.OM_data_eqn = self.OM_data_eqn + (self.name+'.sepFactVal= {'+ sepFac + '};\n') - return self.OM_data_eqn diff --git a/OMChem/ConvReactor.py b/OMChem/ConvReactor.py index b9958a9..9ad35da 100644 --- a/OMChem/ConvReactor.py +++ b/OMChem/ConvReactor.py @@ -41,40 +41,3 @@ class ConvReactor(): self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.inlet,' + self.name + '.EnergyStream);\n') return self.OM_data_eqn - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OMChem/Cooler.py b/OMChem/Cooler.py index 577b181..32fe594 100644 --- a/OMChem/Cooler.py +++ b/OMChem/Cooler.py @@ -1,9 +1,10 @@ from OMChem.EngStm import EngStm class Cooler(): - def __init__(self,name='cooler',PressureDrop = None, eff = None): + counter = 1 + def __init__(self,name='Cooler',PressureDrop = None, eff = None): self.PressureDrop = PressureDrop self.eff = eff - self.name = name + # self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None @@ -21,6 +22,15 @@ class Cooler(): 'tempDrop':None, 'heatRem':None, } + # new + self.name = name + str(Cooler.counter) + self.no_of_input = 1 + self.no_of_output = 1 + Cooler.counter += 1 + + def getname(self): + return self.name + def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms self.OutputStms = OutputStms diff --git a/OMChem/DistCol.py b/OMChem/DistCol.py index 35054da..4f9f2fb 100644 --- a/OMChem/DistCol.py +++ b/OMChem/DistCol.py @@ -1,17 +1,20 @@ from OMChem.EngStm import EngStm class DistCol(): - def __init__(self,name=('DistCol',1), numStage = None,numFeeds = None,feedStages = None): + counter = 1 + def __init__(self,name='DistCol', numStage = None,numFeeds = None,feedStages = None): self.numStage = numStage self.numFeeds=numFeeds self.feedStages=feedStages - self.name = name[0] + #self.name = name[0] + self.name = name + str(DistCol.counter) self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None self.EngStm1 = EngStm(name='EngStm1'+self.name) self.EngStm2 = EngStm(name='EngStm2'+self.name) - self.count = name[1] + #self.count = name[1] + self.count = DistCol.counter self.thermoPackage='Raoults_Law' self.type = 'DistCol' self.mode = None @@ -20,6 +23,14 @@ class DistCol(): self.condP=None self.rebP=None + # new + self.no_of_input = 2 + self.no_of_output = 2 + DistCol.counter += 1 + + def getname(self): + return self.name + def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms self.OutputStms = OutputStms diff --git a/OMChem/Flash.py b/OMChem/Flash.py index 22335a5..68294ea 100644 --- a/OMChem/Flash.py +++ b/OMChem/Flash.py @@ -1,13 +1,25 @@ class Flash(): - def __init__(self,name=("flash",1)): - self.name = name[0] + counter = 1 + def __init__(self,name='Flash'): + #self.name = name[0] self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None self.type = 'flash' - self.count = name[1] + #self.count = name[1] + self.count = Flash.counter self.thermoPackage =None + + # new + self.name = name + str(Flash.counter) + self.no_of_input = 1 + self.no_of_output = 2 + Flash.counter += 1 + + def getname(self): + return self.name + def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms self.OutputStms = OutputStms diff --git a/OMChem/Heater.py b/OMChem/Heater.py index c0d8d95..ebdae9e 100644 --- a/OMChem/Heater.py +++ b/OMChem/Heater.py @@ -1,9 +1,10 @@ from OMChem.EngStm import EngStm class Heater(): + counter = 1 def __init__(self,name='Heater',PressureDrop = None, eff = None): self.PressureDrop = PressureDrop self.eff = eff - self.name = name + #self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None @@ -23,6 +24,15 @@ class Heater(): 'heatAdd':None, } + # new + self.name = name + str(Heater.counter) + self.no_of_input = 1 + self.no_of_output = 1 + Heater.counter += 1 + + def getname(self): + return self.name + def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms self.OutputStms = OutputStms diff --git a/OMChem/MatStm.py b/OMChem/MatStm.py index f27b3da..7635fbe 100644 --- a/OMChem/MatStm.py +++ b/OMChem/MatStm.py @@ -4,8 +4,10 @@ import sys from collections import defaultdict class MatStm(): - def __init__(self,name =None,CompNames = [],Temperature=300,Pressure=101325,VapPhasMolFrac=None,VapPhasMasFrac=None,LiqPhasMolFrac=None,LiqPhasMasFrac=None,CompMolFrac = [1.0], CompMasFrac = [], MolFlow=100, MasFlow=None,**kwargs): - self.name = name[0] + counter = 1 + def __init__(self,name ='MatStm',CompNames = [],Temperature=300,Pressure=101325,VapPhasMolFrac=None,VapPhasMasFrac=None,LiqPhasMolFrac=None,LiqPhasMasFrac=None,CompMolFrac = [1.0], CompMasFrac = [], MolFlow=100, MasFlow=None,**kwargs): + # self.name = name[0] + self.name = name + str(MatStm.counter) self.type = 'MatStm' self.T = Temperature self.P = Pressure @@ -20,7 +22,8 @@ class MatStm(): self.MasFlow = MasFlow self.OM_data_init = '' self.OM_data_eqn = '' - self.count = name[1] + # self.count = name[1] + self.count = MatStm.counter self.thermoPackage ="Raoults_Law" self.mode1 = "P" self.mode1val = "" @@ -28,8 +31,6 @@ class MatStm(): self.mode2val = "" # self.ValEntList = {"T":T," P":P," VapPhasMolFrac":vapPhasMolFrac," CompNames":CompNames," CompMolFrac[1]":CompMolFrac," CompMasFrac":CompMasFrac," MolFlow[1]":MolFlow," MasFlow[1]":MasFlow} - - # self.OMProp = { # 'Pressure': self.mode1, # 'Temperature': self.mode2, @@ -50,7 +51,6 @@ class MatStm(): # } self.startDict = {} self.eqnDict = {} - self.Prop = { @@ -106,12 +106,20 @@ class MatStm(): 'totMasFlo[2]':None, 'totMolFlo[3]':None, 'totMasFlo[3]':None - } + + # new + self.no_of_input = 1 + self.no_of_output = 1 + MatStm.counter += 1 + + def getname(self): + return self.name + def modesList(self): return ["PT","PH","PVF","TVF","PS"] - + def paramgetter(self,mode): dict = {} if(mode=="PT"): @@ -136,6 +144,7 @@ class MatStm(): dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} return dict + def paramsetter(self,dict): self.mode1val = dict[self.mode1] self.mode2val = dict[self.mode2] diff --git a/OMChem/Mixer.py b/OMChem/Mixer.py index 9419de1..b0e0a66 100644 --- a/OMChem/Mixer.py +++ b/OMChem/Mixer.py @@ -1,22 +1,33 @@ class Mixer(): - def __init__(self,name='mixer',NOI=5,Pcal = 'Inlet_Average'): + counter = 1 # + def __init__(self,name='Mixer',NOI=5,Pcal = 'Inlet_Average'): self.NOI = NOI self.Pcal = Pcal - self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = [] self.OutputStms = None self.type = 'Mixer' + # new + self.name = name + str(Mixer.counter) + self.no_of_input = 4 + self.no_of_output = 1 + Mixer.counter += 1 + + def getname(self): + return self.name + def modesList(self): return [] def paramgetter(self,mode=None): dict = {} return dict + def paramsetter(self,dict): self.NOI = dict["NOI"] + def OM_Flowsheet_Init(self, addedcomp): self.OM_data_init = '' comp_count = len(addedcomp) @@ -35,7 +46,6 @@ class Mixer(): self.InputStms = InputStms self.OutputStms = OutputStms - def OM_Flowsheet_Eqn(self, addedcomp): self.OM_data_eqn = '' comp_count = len(addedcomp) @@ -46,4 +56,3 @@ class Mixer(): strcount += 1 self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') return self.OM_data_eqn - diff --git a/OMChem/Pump.py b/OMChem/Pump.py index 04c8425..a63c9f0 100644 --- a/OMChem/Pump.py +++ b/OMChem/Pump.py @@ -1,8 +1,9 @@ from OMChem.EngStm import EngStm class Pump(): + counter = 1 def __init__(self,name='Pump',eff = None): self.eff = eff - self.name = name + #self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None @@ -13,6 +14,14 @@ class Pump(): self.type = 'Pump' self.mode = None self.modeVal = None + # new + self.name = name + str(Pump.counter) + self.no_of_input = 1 + self.no_of_output = 1 + Pump.counter += 1 + + def getname(self): + return self.name def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms @@ -27,7 +36,6 @@ class Pump(): return dict def paramsetter(self,dict): - self.eff = dict['eff'] self.modeVal = dict[self.mode] diff --git a/OMChem/ShortcutColumn.py b/OMChem/ShortcutColumn.py index 13cffea..5c42545 100644 --- a/OMChem/ShortcutColumn.py +++ b/OMChem/ShortcutColumn.py @@ -1,25 +1,37 @@ from OMChem.EngStm import EngStm class ShortcutColumn(): - def __init__(self,name=("ShortcutCol",1),condP = None, rebP = None, LKey = None, HKey = None): + counter = 1 + def __init__(self,name='ShortCol',condP = None, rebP = None, LKey = None, HKey = None): self.condP = condP self.rebP = rebP self.LKey = LKey self.HKey = HKey self.LKeyMolFrac = None self.HKeyMolFrac = None - self.name = name[0] + #self.name = name[0] + self.name = name + str(ShortcutColumn.counter) self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None + self.EngStm1 = EngStm(name='EngStm1'+self.name) self.EngStm2 = EngStm(name='EngStm2'+self.name) - self.count = name[1] + #self.count = name[1] + self.count = ShortcutColumn.counter self.condType='' self.actR = None self.thermoPackage='Raoults_Law' self.type = 'ShortCol' + # new + self.no_of_input = 1 + self.no_of_output = 2 + ShortcutColumn.counter += 1 + + def getname(self): + return self.name + def modesList(self): return [] diff --git a/OMChem/Splitter.py b/OMChem/Splitter.py index a055851..ed79c9d 100644 --- a/OMChem/Splitter.py +++ b/OMChem/Splitter.py @@ -1,7 +1,8 @@ import json class Splitter(): - def __init__(self,name='splitter',NOO=5,calcType = 'Molar_Flow',specval = [50,50]): + counter = 1 + def __init__(self,name='Splitter',NOO=5,calcType = 'Molar_Flow',specval = [50,50]): self.NOO = NOO self.calcType = calcType self.name = name @@ -11,7 +12,15 @@ class Splitter(): self.OutputStms = [] self.type = 'Splitter' self.specval = json.dumps(specval).replace('[','{').replace(']','}') - + # new + self.name = name + str(Splitter.counter) + self.no_of_input = 1 + self.no_of_output = 4 + Splitter.counter += 1 + + def getname(self): + return self.name + def modesList(self): return [] def paramgetter(self,mode=None): diff --git a/OMChem/Valve.py b/OMChem/Valve.py index f8f61b6..f1f8ac3 100644 --- a/OMChem/Valve.py +++ b/OMChem/Valve.py @@ -1,9 +1,10 @@ class Valve(): - def __init__(self,name='valve'): + counter = 1 + def __init__(self,name='Valve'): #self.PressDrop = PressureDrop self.mode = None self.modeVal = None - self.name = name + #self.name = name self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None @@ -14,6 +15,14 @@ class Valve(): 'pressDrop':None, 'outP':None } + # new + self.name = name + str(Valve.counter) + self.no_of_input = 1 + self.no_of_output = 1 + Valve.counter += 1 + + def getname(self): + return self.name def modesList(self): return ["pressDrop","outP"] diff --git a/OMChem/adiabatic_comp.py b/OMChem/adiabatic_comp.py index b8849fd..5399ed0 100644 --- a/OMChem/adiabatic_comp.py +++ b/OMChem/adiabatic_comp.py @@ -1,18 +1,29 @@ from OMChem.EngStm import EngStm class AdiaComp(): - def __init__(self,name=('AdiaComp',1), eff = None): + counter = 1 + def __init__(self,name='AdiaComp', eff = None): self.eff = eff - self.name = name[0] + #self.name = name[0] + self.name = name + str(AdiaComp.counter) + self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None self.EngStms = EngStm(name='EngStm'+self.name) - self.count = name[1] + #self.count = name[1] + self.count = AdiaComp.counter self.type = 'AdiaComp' self.thermoPackage ="Raoults_Law" self.mode = None self.modeVal = None + # new + self.no_of_input = 1 + self.no_of_output = 1 + AdiaComp.counter += 1 + + def getname(self): + return self.name def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms diff --git a/OMChem/adiabatic_exp.py b/OMChem/adiabatic_exp.py index 102596d..0dfb541 100644 --- a/OMChem/adiabatic_exp.py +++ b/OMChem/adiabatic_exp.py @@ -1,19 +1,30 @@ from OMChem.EngStm import EngStm class AdiaExp(): - def __init__(self,name=('AdiaExp',1), eff = None): + counter = 1 + def __init__(self,name='AdiaExp', eff = None): self.eff = eff - self.name = name[0] + #self.name = name[0] + self.name = name + str(AdiaExp.counter) self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None self.EngStms = EngStm(name='EngStm'+self.name) - self.count = name[1] + #self.count = name[1] + self.count = AdiaExp.counter self.type = 'AdiaExp' self.thermoPackage ="Raoults_Law" self.mode = None self.modeVal = None + # new + self.no_of_input = 1 + self.no_of_output = 1 + AdiaExp.counter += 1 + + def getname(self): + return self.name + def connect(self,InputStms = None,OutputStms = None): self.InputStms = InputStms self.OutputStms = OutputStms -- cgit From 5bc560d00c42b9a60b20dae4f237bf37570793ec Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Mon, 23 Dec 2019 16:51:37 +0530 Subject: root_dir and threading added --- OMChem/Flowsheet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index cfd9bae..0cf870a 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -14,8 +14,8 @@ class Flowsheet(): self.compounds = [] self.interface = '' self.omc_path = None - self.curr_path = os.getcwd() # Chemical-Simulator-GUI - self.sim_dir_path = os.path.join(self.curr_path, self.sim_name) # Chemical-Simulator-GUI/Simulator + self.root_dir = os.getcwd() # Chemical-Simulator-GUI + self.sim_dir_path = os.path.join(self.root_dir, self.sim_name) # Chemical-Simulator-GUI/Simulator self.Flomo_path = os.path.join(self.sim_dir_path,'Flowsheet.mo') self.eqn_mos_path = os.path.join(self.sim_dir_path,'simulateEQN.mos') self.sm_mos_path = os.path.join(self.sim_dir_path,'simulateSM.mos') @@ -61,7 +61,7 @@ class Flowsheet(): #print(s) #print("############### StdOut ################") print(self.stdout) - os.chdir(self.curr_path) + os.chdir(self.root_dir) #os.system(self.omc_path + ' -s ' + simpath) print("Hello") if self.sim_method == 'Eqn': @@ -297,7 +297,7 @@ class Flowsheet(): print("################################11") for unitop in self.unit: - os.chdir(self.curr_path) + os.chdir(self.root_dir) self.data = [] if unitop.type not in ['MatStm','EngStm']: inpstms = unitop.InputStms @@ -379,7 +379,7 @@ class Flowsheet(): sim = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) self.stdout, self.stderr = process.communicate() - os.chdir(self.curr_path) + os.chdir(self.root_dir) #s = subprocess.check_output([self.omc_path, '-s',simpath]) #print(s) print("############### StdOut ################") @@ -396,7 +396,7 @@ class Flowsheet(): for row in csvreader: self.resdata.append(row) - os.chdir(self.curr_path) + os.chdir(self.root_dir) if type(inpstms) is list: for stm in inpstms: for key, value in stm.Prop.items(): -- cgit From e9b132bbfe89334e4656c2bb3a63693bf85c3ec5 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Mon, 23 Dec 2019 18:43:41 +0530 Subject: Termination function implemented --- OMChem/Flowsheet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index 0cf870a..f223ede 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -55,8 +55,8 @@ class Flowsheet(): simpath = self.eqn_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() + self.process = Popen([self.omc_path, '-s',simpath], stdout=PIPE, stderr=PIPE) + self.stdout, self.stderr = self.process.communicate() #s = subprocess.check_output([self.omc_path, '-s',simpath]) #print(s) #print("############### StdOut ################") @@ -84,8 +84,8 @@ class Flowsheet(): self.omc_path = self.get_omc_path() os.chdir(self.sim_dir_path) #os.system(self.omc_path + ' -s ' + unitop.name+'.mos') - process = Popen([self.omc_path, '-s',unitop.name,'.mos'], stdout=PIPE, stderr=PIPE) - stdout, stderr = process.communicate() + self.process = Popen([self.omc_path, '-s',unitop.name,'.mos'], stdout=PIPE, stderr=PIPE) + stdout, stderr = self.process.communicate() #s = subprocess.check_output([self.omc_path, '-s',simpath]) #print(s) print("############### StdOut ################") @@ -377,8 +377,8 @@ class Flowsheet(): #os.system(self.omc_path + ' -s ' + unitop[0].name.lower()+"SEQ"+'.mos') print("SIM directory Path 1 ###",self.sim_dir_path) sim = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') - process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) - self.stdout, self.stderr = process.communicate() + self.process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) + self.stdout, self.stderr = self.process.communicate() os.chdir(self.root_dir) #s = subprocess.check_output([self.omc_path, '-s',simpath]) #print(s) -- cgit From 7df9dbb0e57f2eeb03ab7fbf7de0b9f4cd658048 Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Tue, 24 Dec 2019 16:27:14 +0530 Subject: Restructured the API, and the front-end --- OMChem/Flowsheet.py | 908 +++++++++++++++++++++++++++------------------------- OMChem/MatStm.py | 158 +-------- OMChem/UnitOprns.py | 154 +++++++++ 3 files changed, 629 insertions(+), 591 deletions(-) create mode 100644 OMChem/UnitOprns.py (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index cfd9bae..6b6c9ad 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -6,454 +6,472 @@ from subprocess import Popen, PIPE import pandas as pd class Flowsheet(): - def __init__(self): - self.sim_name = 'Simulator' - self.sim_method = '' - self.UnitOpn = [] - self.data = [] - self.compounds = [] - self.interface = '' - self.omc_path = None - self.curr_path = os.getcwd() # Chemical-Simulator-GUI - self.sim_dir_path = os.path.join(self.curr_path, self.sim_name) # Chemical-Simulator-GUI/Simulator - self.Flomo_path = os.path.join(self.sim_dir_path,'Flowsheet.mo') - self.eqn_mos_path = os.path.join(self.sim_dir_path,'simulateEQN.mos') - self.sm_mos_path = os.path.join(self.sim_dir_path,'simulateSM.mos') - self.resdata = [] - self.stdout=None - self.stderr=None - - - 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' - 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 add_UnitOpn(self,unitop,flag): - f=(unitop,flag) - self.UnitOpn.append(f) - - def remove_UnitOpn(self,unitop): - self.UnitOpn.remove(unitop) - - def add_comp_list(self,comp): - self.compounds = comp - - def send_for_simulationEqn(self): - self.resdata = [] - self.omc_path = self.get_omc_path() - print(self.omc_path) - - if self.sim_method == 'Eqn': - simpath = self.eqn_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() - #s = subprocess.check_output([self.omc_path, '-s',simpath]) - #print(s) - #print("############### StdOut ################") - print(self.stdout) - os.chdir(self.curr_path) - #os.system(self.omc_path + ' -s ' + simpath) - print("Hello") - if self.sim_method == 'Eqn': - print("hhhh") - csvpath = os.path.join(self.sim_dir_path,'Flowsheet_res.csv') - print("csvPath",csvpath) - with open (csvpath,'r') as resultFile: - self.resdata = [] - print("opened") - csvreader = csv.reader(resultFile,delimiter=',') - for row in csvreader: - print("124125") - self.resdata.append(row) - #self.ExtData() - - - def send_for_simulationSM(self,unitop): - - self.resdata = [] - self.omc_path = self.get_omc_path() - os.chdir(self.sim_dir_path) - #os.system(self.omc_path + ' -s ' + unitop.name+'.mos') - process = Popen([self.omc_path, '-s',unitop.name,'.mos'], stdout=PIPE, stderr=PIPE) - stdout, stderr = process.communicate() - #s = subprocess.check_output([self.omc_path, '-s',simpath]) - #print(s) - print("############### StdOut ################") - print(stdout) - self.resdata = [] - print('Simulating '+unitop.name+'...') - csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv') - with open(csvpath,'r') as resultFile: - csvreader = csv.reader(resultFile,delimiter=',') - for row in csvreader: - self.resdata.append(row) - self.ExtData() - - - - - - # if self.sim_method == 'SM': - # for unitop in self.UnitOpn: - # self.resdata = [] - # if unitop.type != 'MatStm': - # print 'Simulating '+unitop.name+'...' - # csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv') - # with open(csvpath,'r') as resultFile: - # csvreader = csv.reader(resultFile,delimiter=',') - # for row in csvreader: - # self.resdata.append(row) - # self.ExtData() - - - - - - # if self.interface == 'OMPython': - # omc = OMCSession() - # omc.sendExpression("loadModel(Modelica)") - # omc.sendExpression("loadFile(\"Simulator.mo\")") - # omc.sendExpression("loadFile(\"Flowsheet.mo\")") - # execsim = omc.sendExpression("simulate(Flowsheet, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1)") - - # else: - # os.system(self.omc_path + ' -s ') - - def ExtData(self): - for unit in self.UnitOpn: - if unit[0].type == 'MatStm': + def __init__(self): + self.sim_name = 'Simulator' + self.sim_method = '' + self.UnitOpn = [] + self.data = [] + self.compounds = [] + self.interface = '' + self.omc_path = None + self.curr_path = os.getcwd() + self.sim_dir_path = os.path.join(self.curr_path, self.sim_name) + self.Flomo_path = os.path.join(self.sim_dir_path,'Flowsheet.mo') + self.eqn_mos_path = os.path.join(self.sim_dir_path,'simulateEQN.mos') + self.sm_mos_path = os.path.join(self.sim_dir_path,'simulateSM.mos') + self.resdata = [] + self.stdout=None + self.stderr=None + + + 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 add_UnitOpn(self,unitop): + self.UnitOpn.append(unitop) + + def remove_UnitOpn(self,unitop): + self.UnitOpn.remove(unitop) + + def add_comp_list(self,comp): + self.compounds = comp + + + def send_for_simulationEqn(self): + self.resdata = [] + self.omc_path = self.get_omc_path() + print(self.omc_path) + + if self.sim_method == 'Eqn': + simpath = self.eqn_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() + #s = subprocess.check_output([self.omc_path, '-s',simpath]) + #print(s) + #print("############### StdOut ################") + print(self.stdout) + os.chdir(self.curr_path) + #os.system(self.omc_path + ' -s ' + simpath) + print("Hello") + if self.sim_method == 'Eqn': + print("hhhh") + csvpath = os.path.join(self.sim_dir_path,'Flowsheet_res.csv') + print("csvPath",csvpath) + with open (csvpath,'r') as resultFile: + self.resdata = [] + print("opened") + csvreader = csv.reader(resultFile,delimiter=',') + for row in csvreader: + print("124125") + self.resdata.append(row) + #self.ExtData() + + + def send_for_simulationSM(self,unitop): + + self.resdata = [] + self.omc_path = self.get_omc_path() + os.chdir(self.sim_dir_path) + #os.system(self.omc_path + ' -s ' + unitop.name+'.mos') + process = Popen([self.omc_path, '-s',unitop.name,'.mos'], stdout=PIPE, stderr=PIPE) + stdout, stderr = process.communicate() + #s = subprocess.check_output([self.omc_path, '-s',simpath]) + #print(s) + print("############### StdOut ################") + print(stdout) + self.resdata = [] + print('Simulating '+unitop.name+'...') + csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv') + with open(csvpath,'r') as resultFile: + csvreader = csv.reader(resultFile,delimiter=',') + for row in csvreader: + self.resdata.append(row) + self.ExtData() + + + + + + # if self.sim_method == 'SM': + # for unitop in self.UnitOpn: + # self.resdata = [] + # if unitop.type != 'MatStm': + # print 'Simulating '+unitop.name+'...' + # csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv') + # with open(csvpath,'r') as resultFile: + # csvreader = csv.reader(resultFile,delimiter=',') + # for row in csvreader: + # self.resdata.append(row) + # self.ExtData() + + + + + + # if self.interface == 'OMPython': + # omc = OMCSession() + # omc.sendExpression("loadModel(Modelica)") + # omc.sendExpression("loadFile(\"Simulator.mo\")") + # omc.sendExpression("loadFile(\"Flowsheet.mo\")") + # execsim = omc.sendExpression("simulate(Flowsheet, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1)") + + # else: + # os.system(self.omc_path + ' -s ') + + def ExtData(self): + for unit in self.UnitOpn: + if unit[0].type == 'MatStm': # - for key, value in unit[0].Prop.items(): - - - propertyname = unit[0].name + '.' + key - if propertyname in self.resdata[0]: - ind = self.resdata[0].index(propertyname) - resultval = str(self.resdata[-1][ind]) - #resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - print(resultval) - unit[0].Prop[key] = resultval - #print(unit[0].Prop) - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.Prop[key][i] = resultval - # i = i + 1 - - # for key, value in unit.OMVapProp.iteritems(): - # i = 0 - - # if type(value) is str: - # propertyname = unit.name + '.' + value - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.VapProp[key] = resultval - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.VapProp[key][i] = resultval - # i = i + 1 - - - # for key, value in unit.OMLiqProp.iteritems(): - # i = 0 - - # if type(value) is str: - # propertyname = unit.name + '.' + value - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.LiqProp[key] = resultval - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.LiqProp[key][i] = resultval - # i = i + 1 - # for key, value in unit.OMVapProp.iteritems(): - # i = 0 - - # if type(value) is str: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.VapProp[key] = resultval - # else: - # for v in value: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.VapProp[key][i] = resultval - # i = i + 1 - - - # for key, value in unit.OMLiqProp.iteritems(): - # i = 0 - - # if type(value) is str: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.LiqProp[key] = resultval - # else: - # for v in value: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.LiqProp[key][i] = resultval - # i = i + 1 - - - - def simulateEQN(self): - self.data = [] - print("##################################################") - print("##################################################") - self.sim_method = 'Eqn' - self.data.append("model Flowsheet\n") - - for c in self.compounds: - ucase = c.title() - lcase = c.lower() - self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") - - for unitop in self.UnitOpn: - self.data.append(unitop[0].OM_Flowsheet_Init(self.compounds)) - - self.data.append("equation\n") + for key, value in unit[0].Prop.items(): + + + propertyname = unit[0].name + '.' + key + if propertyname in self.resdata[0]: + ind = self.resdata[0].index(propertyname) + resultval = str(self.resdata[-1][ind]) + #resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) + print(resultval) + unit[0].Prop[key] = resultval + #print(unit[0].Prop) + # else: + # for v in value: + # propertyname = unit.name + '.' + v + # if propertyname in self.resdata[0]: + # ind = self.resdata[0].index(propertyname) + # resultval = str(self.resdata[-1][ind]) + # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) + # unit.Prop[key][i] = resultval + # i = i + 1 + + # for key, value in unit.OMVapProp.iteritems(): + # i = 0 + + # if type(value) is str: + # propertyname = unit.name + '.' + value + # if propertyname in self.resdata[0]: + # ind = self.resdata[0].index(propertyname) + # resultval = str(self.resdata[-1][ind]) + # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) + # unit.VapProp[key] = resultval + # else: + # for v in value: + # propertyname = unit.name + '.' + v + # if propertyname in self.resdata[0]: + # ind = self.resdata[0].index(propertyname) + # resultval = str(self.resdata[-1][ind]) + # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) + # unit.VapProp[key][i] = resultval + # i = i + 1 + + + # for key, value in unit.OMLiqProp.iteritems(): + # i = 0 + + # if type(value) is str: + # propertyname = unit.name + '.' + value + # if propertyname in self.resdata[0]: + # ind = self.resdata[0].index(propertyname) + # resultval = str(self.resdata[-1][ind]) + # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) + # unit.LiqProp[key] = resultval + # else: + # for v in value: + # propertyname = unit.name + '.' + v + # if propertyname in self.resdata[0]: + # ind = self.resdata[0].index(propertyname) + # resultval = str(self.resdata[-1][ind]) + # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) + # unit.LiqProp[key][i] = resultval + # i = i + 1 + # for key, value in unit.OMVapProp.iteritems(): + # i = 0 + + # if type(value) is str: + # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) + # unit.VapProp[key] = resultval + # else: + # for v in value: + # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) + # unit.VapProp[key][i] = resultval + # i = i + 1 + + + # for key, value in unit.OMLiqProp.iteritems(): + # i = 0 + + # if type(value) is str: + # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) + # unit.LiqProp[key] = resultval + # else: + # for v in value: + # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) + # unit.LiqProp[key][i] = resultval + # i = i + 1 + + + + def simulateEQN(self): + self.data = [] + print("##################################################") + print("##################################################") + self.sim_method = 'Eqn' + self.data.append("model Flowsheet\n") - for unitop in self.UnitOpn: - if unitop[1]==0: - - if unitop[0].type == 'MatStm': - self.data.append(unitop[0].OM_Flowsheet_Eqn(self.compounds,'Eqn')) - else: - self.data.append(unitop[0].OM_Flowsheet_Eqn(self.compounds)) - else: - pass - with open(self.Flomo_path, 'w') as txtfile: - for d in self.data: - txtfile.write(d) - txtfile.write('end Flowsheet;\n') - - 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") - - print('Initiating Simulation in Equation Oriented Mode') - - self.send_for_simulationEqn() - - - def simulateSM(self,ip,op): - self.sim_method = 'SM' - self.data = [] - self.resdata = [] - self.unit = [] - self.csvlist = [] - print("op list",op) - print("ip list",ip) - for i in ip: - common = ip[i] - print("common #############3",common) - print("*********** i *********",i) - for k,v in op.items(): - print("Print K",k) - if(set(v) & set(common)): - print("*****************common matstm***************") - if((i in self.unit) and (k in self.unit)): - print("both exist") - pass - elif(i in self.unit): - print("output exist") - self.unit.insert(self.unit.index(i),k) - elif(k in self.unit): - print("input exists") - self.unit.append(i) - else: - print("nothing exists") - self.unit.append(k) - self.unit.append(i) - print("##############################33") - print(self.unit) - print("################################11") - - for unitop in self.unit: - os.chdir(self.curr_path) - self.data = [] - if unitop.type not in ['MatStm','EngStm']: - inpstms = unitop.InputStms - outstms = unitop.OutputStms - - try: - engstms = unitop.EngStms - except: - engstms = None - - self.data.append("model "+unitop.name.lower()+'\n') - - for c in self.compounds: - ucase = c.title() - lcase = c.lower() - self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") - - print("##############compounds added") - self.data.append(unitop.OM_Flowsheet_Init(self.compounds)) - - if type(outstms) is list: - for stm in outstms: - self.data.append(stm.OM_Flowsheet_Init(self.compounds)) - else: - self.data.append(outstms.OM_Flowsheet_Init(self.compounds)) - - - if engstms: - self.data.append(engstms.OM_Flowsheet_Init(self.compounds)) - - if type(inpstms) is list: - for stm in inpstms: - self.data.append(stm.OM_Flowsheet_Init(self.compounds)) - else: - self.data.append(inpstms.OM_Flowsheet_Init(self.compounds)) - - self.data.append('equation\n') - print("##################equation") - self.data.append(unitop.OM_Flowsheet_Eqn(self.compounds)) - ''' - if type(outstms) is list: - for stm in outstms: - #stm.GetEquationValues() - self.data.append(stm.OM_Flowsheet_Eqn(self.compounds,'SM')) - else: - #outstms.GetEquationValues() - self.data.append(outstms.OM_Flowsheet_Eqn(self.compounds,'SM')) + for c in self.compounds: + ucase = c.title() + lcase = c.lower() + self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") + + for unitop in self.UnitOpn: + if unitop.type != 'MatStm': + self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + else: + self.data.append(unitop.OM_Flowsheet_Init(self.compounds)) + + + self.data.append("equation\n") + + self.outlist = [] + self.stm = ['MatStm','EngStm'] + for unitop in self.UnitOpn: + if unitop.type not in self.stm: + for j in unitop.OutputStms: + self.outlist.append(j) + print(j.name) + + + + 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')) + else: + self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds)) + else: + pass + with open(self.Flomo_path, 'w') as txtfile: + for d in self.data: + txtfile.write(str(d)) + txtfile.write('end Flowsheet;\n') + + 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") + + print('Initiating Simulation in Equation Oriented Mode') + + self.send_for_simulationEqn() + + + + + def simulateSM(self,ip,op): + self.sim_method = 'SM' + self.data = [] + self.resdata = [] + self.unit = [] + self.csvlist = [] + print("op list",op) + print("ip list",ip) + for i in ip: + common = ip[i] + print("common #############3",common) + print("*********** i *********",i) + for k,v in op.items(): + print("Print K",k) + if(set(v) & set(common)): + print("*****************common matstm***************") + if((i in self.unit) and (k in self.unit)): + print("both exist") + pass + elif(i in self.unit): + print("output exist") + self.unit.insert(self.unit.index(i),k) + elif(k in self.unit): + print("input exists") + self.unit.append(i) + else: + print("nothing exists") + self.unit.append(k) + self.unit.append(i) + print("##############################33") + print(self.unit) + print("################################11") + + for unitop in self.unit: + os.chdir(self.curr_path) + self.data = [] + if unitop.type not in ['MatStm','EngStm']: + inpstms = unitop.InputStms + outstms = unitop.OutputStms + + try: + engstms = unitop.EngStms + except: + engstms = None + + self.data.append("model "+unitop.name.lower()+'\n') + + for c in self.compounds: + ucase = c.title() + lcase = c.lower() + self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") + + print("##############compounds added") + self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + + if type(outstms) is list: + for stm in outstms: + self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + else: + self.data.append(outstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + + + if engstms: + self.data.append(engstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + + if type(inpstms) is list: + for stm in inpstms: + self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + else: + self.data.append(inpstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + + self.data.append('equation\n') + print("##################equation") + self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds)) + ''' + if type(outstms) is list: + for stm in outstms: + #stm.GetEquationValues() + self.data.append(stm.OM_Flowsheet_Eqn(self.compounds,'SM')) + else: + #outstms.GetEquationValues() + self.data.append(outstms.OM_Flowsheet_Eqn(self.compounds,'SM')) ''' - if type(inpstms) is list: - for stm in inpstms: - #stm.GetEquationValues() - self.data.append(stm.OM_Flowsheet_Eqn(self.compounds,'SM')) - else: - #inpstms.GetEquationValues() - self.data.append(inpstms.OM_Flowsheet_Eqn(self.compounds,'SM')) - - # os.chdir(self.sim_dir_path) - unitmofile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mo') - - with open(unitmofile,'w') as unitFile: - for d in self.data: - unitFile.write(d) - unitFile.write('end '+unitop.name.lower()+';\n') - - unitmosfile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') - with open(unitmosfile, 'w') as mosFile: - mosFile.write('loadModel(Modelica);\n') - mosFile.write("loadFile(\"Simulator\package.mo\");\n") - - mosFile.write("loadFile(\""+unitop.name.lower()+".mo\");\n") - mosFile.write("simulate("+unitop.name.lower()+", outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n") - - print("Initiating simulation in Sequential Modular Mode") - #self.resdata = [] - self.omc_path = self.get_omc_path() - os.chdir(self.sim_dir_path) - #os.system(self.omc_path + ' -s ' + unitop[0].name.lower()+"SEQ"+'.mos') - print("SIM directory Path 1 ###",self.sim_dir_path) - sim = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') - process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) - self.stdout, self.stderr = process.communicate() - os.chdir(self.curr_path) - #s = subprocess.check_output([self.omc_path, '-s',simpath]) - #print(s) - print("############### StdOut ################") - print(self.stdout) - print("############### StdErr ################") - print(self.stderr) - print('Simulating '+unitop.name.lower()+'...') - csvpath = os.path.join(self.sim_dir_path,unitop.name.lower()+'_res.csv') - - self.csvlist.append(csvpath) - - with open(csvpath,'r') as resultFile: - csvreader = csv.reader(resultFile,delimiter=',') - for row in csvreader: - self.resdata.append(row) - - os.chdir(self.curr_path) - if type(inpstms) is list: - for stm in inpstms: - for key, value in stm.Prop.items(): - propertyname = stm.name + '.' + key - if propertyname in self.resdata[0]: - ind = self.resdata[0].index(propertyname) - resultval = str(self.resdata[-1][ind]) - stm.Prop[key] = resultval - - #print("input",stm.Prop[key]) - - - else: - for key, value in inpstms.Prop.items(): - propertyname = inpstms.name + '.' + key - if propertyname in self.resdata[0]: - ind = self.resdata[0].index(propertyname) - resultval = str(self.resdata[-1][ind]) - inpstms.Prop[key] = resultval - #print("input",inpstms.Prop[key]) - - if type(outstms) is list: - for stm in outstms: - for key, value in stm.Prop.items(): - propertyname = stm.name + '.' + key - if propertyname in self.resdata[0]: - ind = self.resdata[0].index(propertyname) - resultval = str(self.resdata[-1][ind]) - stm.Prop[key] = resultval - print("output key:",key,"value:",stm.Prop[key]) - else: - for key, value in outstms.Prop.items(): - propertyname = outstms.name + '.' + key - if propertyname in self.resdata[0]: - ind = self.resdata[0].index(propertyname) - resultval = str(self.resdata[-1][ind]) - outstms.Prop[key] = resultval - print("output key:",key,"value:",outstms.Prop[key]) - - - self.dataframes = [pd.read_csv(i) for i in self.csvlist] - os.chdir(self.sim_dir_path) - dffinal = pd.concat(self.dataframes,axis=1) - dffinal.to_csv('FlowsheetSEQ.csv',index=False) - self.resdata.clear() - with open(os.path.join(self.sim_dir_path+'/FlowsheetSEQ.csv'),'r') as resultFile: - csvreader = csv.reader(resultFile,delimiter=',') - for row in csvreader: - self.resdata.append(row) - - - - - - - - + if type(inpstms) is list: + for stm in inpstms: + #stm.GetEquationValues() + self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds,'SM')) + else: + #inpstms.GetEquationValues() + self.data.append(inpstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds,'SM')) + + # os.chdir(self.sim_dir_path) + unitmofile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mo') + + with open(unitmofile,'w') as unitFile: + for d in self.data: + unitFile.write(d) + unitFile.write('end '+unitop.name.lower()+';\n') + + unitmosfile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') + with open(unitmosfile, 'w') as mosFile: + mosFile.write('loadModel(Modelica);\n') + mosFile.write("loadFile(\"Simulator\package.mo\");\n") + + mosFile.write("loadFile(\""+unitop.name.lower()+".mo\");\n") + mosFile.write("simulate("+unitop.name.lower()+", outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n") + + print("Initiating simulation in Sequential Modular Mode") + #self.resdata = [] + self.omc_path = self.get_omc_path() + os.chdir(self.sim_dir_path) + #os.system(self.omc_path + ' -s ' + unitop[0].name.lower()+"SEQ"+'.mos') + print("SIM directory Path 1 ###",self.sim_dir_path) + sim = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') + process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) + self.stdout, self.stderr = process.communicate() + os.chdir(self.curr_path) + #s = subprocess.check_output([self.omc_path, '-s',simpath]) + #print(s) + print("############### StdOut ################") + print(self.stdout) + print("############### StdErr ################") + print(self.stderr) + print('Simulating '+unitop.name.lower()+'...') + csvpath = os.path.join(self.sim_dir_path,unitop.name.lower()+'_res.csv') + + self.csvlist.append(csvpath) + + with open(csvpath,'r') as resultFile: + csvreader = csv.reader(resultFile,delimiter=',') + for row in csvreader: + self.resdata.append(row) + + os.chdir(self.curr_path) + if type(inpstms) is list: + for stm in inpstms: + for key, value in stm.Prop.items(): + propertyname = stm.name + '.' + key + if propertyname in self.resdata[0]: + ind = self.resdata[0].index(propertyname) + resultval = str(self.resdata[-1][ind]) + stm.Prop[key] = resultval + + #print("input",stm.Prop[key]) + + + else: + for key, value in inpstms.Prop.items(): + propertyname = inpstms.name + '.' + key + if propertyname in self.resdata[0]: + ind = self.resdata[0].index(propertyname) + resultval = str(self.resdata[-1][ind]) + inpstms.Prop[key] = resultval + #print("input",inpstms.Prop[key]) + + if type(outstms) is list: + for stm in outstms: + for key, value in stm.Prop.items(): + propertyname = stm.name + '.' + key + if propertyname in self.resdata[0]: + ind = self.resdata[0].index(propertyname) + resultval = str(self.resdata[-1][ind]) + stm.Prop[key] = resultval + print("output key:",key,"value:",stm.Prop[key]) + else: + for key, value in outstms.Prop.items(): + propertyname = outstms.name + '.' + key + if propertyname in self.resdata[0]: + ind = self.resdata[0].index(propertyname) + resultval = str(self.resdata[-1][ind]) + outstms.Prop[key] = resultval + print("output key:",key,"value:",outstms.Prop[key]) + + + self.dataframes = [pd.read_csv(i) for i in self.csvlist] + os.chdir(self.sim_dir_path) + dffinal = pd.concat(self.dataframes,axis=1) + dffinal.to_csv('FlowsheetSEQ.csv',index=False) + self.resdata.clear() + with open(os.path.join(self.sim_dir_path+'/FlowsheetSEQ.csv'),'r') as resultFile: + csvreader = csv.reader(resultFile,delimiter=',') + for row in csvreader: + self.resdata.append(row) + + + + + + + + diff --git a/OMChem/MatStm.py b/OMChem/MatStm.py index 7635fbe..69a6845 100644 --- a/OMChem/MatStm.py +++ b/OMChem/MatStm.py @@ -4,10 +4,9 @@ import sys from collections import defaultdict class MatStm(): - counter = 1 - def __init__(self,name ='MatStm',CompNames = [],Temperature=300,Pressure=101325,VapPhasMolFrac=None,VapPhasMasFrac=None,LiqPhasMolFrac=None,LiqPhasMasFrac=None,CompMolFrac = [1.0], CompMasFrac = [], MolFlow=100, MasFlow=None,**kwargs): - # self.name = name[0] - self.name = name + str(MatStm.counter) + counter = 1; + def __init__(self,CompNames = [],Temperature=300,Pressure=101325,VapPhasMolFrac=None,VapPhasMasFrac=None,LiqPhasMolFrac=None,LiqPhasMasFrac=None,CompMolFrac = [1.0], CompMasFrac = [], MolFlow=100, MasFlow=None,**kwargs): + self.name = 'MatStm' + str(MatStm.counter) self.type = 'MatStm' self.T = Temperature self.P = Pressure @@ -22,35 +21,20 @@ class MatStm(): self.MasFlow = MasFlow self.OM_data_init = '' self.OM_data_eqn = '' - # self.count = name[1] self.count = MatStm.counter self.thermoPackage ="Raoults_Law" self.mode1 = "P" self.mode1val = "" self.mode2 = "T" self.mode2val = "" - - # self.ValEntList = {"T":T," P":P," VapPhasMolFrac":vapPhasMolFrac," CompNames":CompNames," CompMolFrac[1]":CompMolFrac," CompMasFrac":CompMasFrac," MolFlow[1]":MolFlow," MasFlow[1]":MasFlow} - # self.OMProp = { - # 'Pressure': self.mode1, - # 'Temperature': self.mode2, - # 'Liquid Phase Mole Fraction': 'liqPhasMolFrac', - # 'Liquid Phase Mas Fraction': 'liqPhasMasFrac', - # 'Vapour Phase Mole Fraction': 'vapPhasMolFrac', - # 'Vapour Phase Mas Fraction': 'vapPhasMasFrac', - # 'Total Molar Flow': 'totMolFlo[1]', - # 'Total Mas Flow': 'totMasFlo[1]', - # 'Av. Molecular Weight': 'MW[1]', - # 'Comp Mole Fraction': ['compMolFrac[1,1]','compMolFrac[1,2]','compMolFrac[1,3]'], - # 'Comp Mas Fraction': ['compMasFrac[1,1]','compMasFrac[1,2]','compMasFrac[1,3]'], - # 'Comp Molar Flow': ['compMolFlo[1,1]','compMolFlo[1,2]','compMolFlo[1,3]'], - # 'Comp Mas Flow': ['compMasFlo[1,1]','compMasFlo[1,2]','compMasFlo[1,3]'], - # 'Molar Specific Heat': 'phasMolSpHeat[1]', - # 'Molar Enthalpy': 'phasMolEnth[1]', - # 'Molar Entropy': 'phasMolEntr[1]' - # } + self.no_of_inputs = 1 + self.no_of_outputs = 1 + self.x = 2500-30 + self.y = 2500-30 + MatStm.counter+=1 self.startDict = {} self.eqnDict = {} + self.Prop = { @@ -106,20 +90,11 @@ class MatStm(): 'totMasFlo[2]':None, 'totMolFlo[3]':None, 'totMasFlo[3]':None - } - - - # new - self.no_of_input = 1 - self.no_of_output = 1 - MatStm.counter += 1 - def getname(self): - return self.name + } def modesList(self): return ["PT","PH","PVF","TVF","PS"] - def paramgetter(self,mode): dict = {} if(mode=="PT"): @@ -144,7 +119,6 @@ class MatStm(): dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} return dict - def paramsetter(self,dict): self.mode1val = dict[self.mode1] self.mode2val = dict[self.mode2] @@ -360,92 +334,7 @@ class MatStm(): print(e) print('error') - # self.OMVapProp = { - # 'Pressure': self.mode1, - # 'Temperature': self.mode2, - # 'Total Molar Flow': 'totMolFlo[3]', - # 'Total Mas Flow': 'totMasFlo[3]', - # 'Comp Mole Fraction': ['compMolFrac[3,1]','compMolFrac[3,2]','compMolFrac[3,3]'], - # 'Comp Mas Fraction': ['compMasFrac[3,1]','compMasFrac[3,2]','compMasFrac[3,3]'], - # 'Comp Molar Flow': ['compMolFlo[3,1]','compMolFlo[3,2]','compMolFlo[3,3]'], - # 'Comp Mas Flow': ['compMasFlo[3,1]','compMasFlo[3,2]','compMasFlo[3,3]'], - # 'Av. Molecular Weight': 'phasMolEnth[3]', - # 'Molar Specific Heat': 'phasMolSpHeat[3]', - # 'Molar Enthalpy': 'phasMolEnth[3]', - # 'Molar Entropy': 'phasMolEntr[3]'} - - - - # self.VapProp = { - # self.mode1:None, - # self.mode2:None, - # 'liqPhasMolFrac':None, - # 'liqPhasMasFrac':None, - # 'vapPhasMolFrac':None, - # 'vapPhasMasFrac':None, - # 'totMolFlo[3]':None, - # 'totMasFlo[3]':None, - # 'MW[1]':None, - # 'compMolFrac[3,1]':None, - # 'compMolFrac[3,2]':None, - # 'compMolFrac[3,3]':None, - # 'compMasFrac[3,1]':None, - # 'compMasFrac[3,2]':None, - # 'compMasFrac[3,3]'None, - # 'compMolFlo[3,1]':None, - # 'compMolFlo[3,2]':None, - # 'compMolFlo[3,3]':None, - # 'compMasFlo[3,1]':None, - # 'compMasFlo[3,2]':None, - # 'compMasFlo[3,3]':None, - # 'phasMolSpHeat[3]':None, - # 'phasMolEnth[3]':None, - # 'phasMolEntr[3]':None - # } - - - # self.OMLiqProp = { - # 'Pressure': self.mode1, - # 'Temperature': self.mode2, - # 'Total Molar Flow': 'totMolFlo[2]', - # 'Total Mas Flow': 'totMasFlo[2]', - # 'Comp Mole Fraction': ['compMolFrac[2,1]','compMolFrac[2,2]','compMolFrac[2,3]'], - # 'Comp Mas Fraction': ['compMasFrac[2,1]','compMasFrac[2,2]','compMasFrac[2,3]'], - # 'Comp Molar Flow': ['compMolFlo[2,1]','compMolFlo[2,2]','compMolFlo[2,3]'], - # 'Comp Mas Flow': ['compMasFlo[2,1]','compMasFlo[2,2]','compMasFlo[2,3]'], - # 'Av. Molecular Weight': 'MW[2]', - # 'Molar Specific Heat': 'phasMolSpHeat[2]', - # 'Molar Enthalpy': 'phasMolEnth[2]', - # 'Molar Entropy': 'phasMolEntr[2]'} - - - # self.LiqProp = { - # self.mode1:P, - # self.mode2:None, - # 'liqPhasMolFrac':None, - # 'liqPhasMasFrac':None, - # 'vapPhasMolFrac':None, - # 'vapPhasMasFrac':None, - # 'totMolFlo[2]':None, - # 'totMasFlo[2]':None, - # 'MW[1]':None, - # 'compMolFrac[2,1]':None, - # 'compMolFrac[2,2]':None, - # 'compMolFrac[2,3]':None, - # 'compMasFrac[2,1]':None, - # 'compMasFrac[2,2]':None, - # 'compMasFrac[2,3]'None, - # 'compMolFlo[2,1]':None, - # 'compMolFlo[2,2]':None, - # 'compMolFlo[2,3]':None, - # 'compMasFlo[2,1]':None, - # 'compMasFlo[2,2]':None, - # 'compMasFlo[2,3]':None, - # 'phasMolSpHeat[2]':None, - # 'phasMolEnth[2]':None, - # 'phasMolEntr[2]':None - # } - + def OM_Flowsheet_Init(self,addedcomp): self.OM_data_init = '' self.OM_data_init = self.OM_data_init + ("model ms"+str(self.count)+"\n") @@ -484,27 +373,4 @@ class MatStm(): self.OM_data_eqn = self.OM_data_eqn + self.name + '.'+ key + ' = ' + str(value) + ';\n' return self.OM_data_eqn - - # if self.P: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + '.P=' + str(self.P) + ';\n') - # if self.T: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + '.T=' + str(self.T) + ';\n') - # if self.VapPhasMolFrac: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + '.vapPhasMolFrac=' + str(self.VapPhasMolFrac) + ';\n') - - - # if self.CompMolFrac != []: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + ".compMolFrac[1,:] = {") - # mf = str(self.CompMolFrac).strip('[').strip(']') - # self.OM_data_eqn = self.OM_data_eqn + mf + ('};\n') - # if self.CompMasFrac != []: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + ".compMasFrac[1,:] = {") - # Mf = str(self.CompMasFrac).strip('[').strip(']') - # self.OM_data_eqn = self.OM_data_eqn + Mf + ('};\n') - - # if self.MolFlow: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + ".totMolFlo[1] = " + str(self.MolFlow) + ";\n") - # if self.MasFlow: - # self.OM_data_eqn = self.OM_data_eqn + (self.name + ".totMasFlo[1] = " + str(self.MasFlow) + ";\n") - - # return self.OM_data_eqn \ No newline at end of file + \ No newline at end of file diff --git a/OMChem/UnitOprns.py b/OMChem/UnitOprns.py new file mode 100644 index 0000000..90cd546 --- /dev/null +++ b/OMChem/UnitOprns.py @@ -0,0 +1,154 @@ +from OMChem.EngStm import EngStm +from collections import defaultdict + +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 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 = '' + + 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') + + 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') + + 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)) + + comp = str(addedcomp).strip('[').strip(']') + comp = comp.replace("'", "") + self.OM_data_init += ',comp = {' + comp + '}' + + + + for i in self.parameters: + self.OM_data_init += ', ' + self.OM_data_init += i[0] + ' = ' + str(i[1]) + 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 + '}' + + for i in self.parameters: + self.OM_data_init += ', ' + self.OM_data_init += i[0] + ' = ' + str(i[1]) + + self.OM_data_init += ');\n' + + #print("HERE WE GO") + #print(self.OM_data_init) + + return self.OM_data_init + + + + + def OM_Flowsheet_Equation(self,addedcomp): + 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.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') + + return self.OM_data_eqn + + + + + + + + + + + + + + + + + + + -- cgit From 262511f8b7999c311f1852007bbe0f8de2006e89 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Tue, 31 Dec 2019 13:23:30 +0530 Subject: Implemented inheritance for Unit Operations --- OMChem/Flowsheet.py | 24 ++++++++++++------------ OMChem/MatStm.py | 5 ++--- OMChem/UnitOprns.py | 10 +++++----- 3 files changed, 19 insertions(+), 20 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index a35f686..59134b9 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -233,7 +233,7 @@ class Flowsheet(): for unitop in self.UnitOpn: if unitop.type != 'MatStm': - self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) else: self.data.append(unitop.OM_Flowsheet_Init(self.compounds)) @@ -256,7 +256,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(self.compounds).OM_Flowsheet_Equation(self.compounds)) + self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds)) else: pass with open(self.Flomo_path, 'w') as txtfile: @@ -266,7 +266,7 @@ class Flowsheet(): with open(self.eqn_mos_path, 'w') as mosFile: mosFile.write('loadModel(Modelica);\n') - mosFile.write("loadFile(\"Simulator\package.mo\");\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") @@ -330,27 +330,27 @@ class Flowsheet(): self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") print("##############compounds added") - self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) if type(outstms) is list: for stm in outstms: - self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) else: - self.data.append(outstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(outstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) if engstms: - self.data.append(engstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(engstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) if type(inpstms) is list: for stm in inpstms: - self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) else: - self.data.append(inpstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Initialize(self.compounds)) + self.data.append(inpstms.send_to_flowsheet().OM_Flowsheet_Initialize(self.compounds)) self.data.append('equation\n') print("##################equation") - self.data.append(unitop.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds)) + self.data.append(unitop.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds)) ''' if type(outstms) is list: for stm in outstms: @@ -363,10 +363,10 @@ class Flowsheet(): if type(inpstms) is list: for stm in inpstms: #stm.GetEquationValues() - self.data.append(stm.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds,'SM')) + self.data.append(stm.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds,'SM')) else: #inpstms.GetEquationValues() - self.data.append(inpstms.send_to_flowsheet(self.compounds).OM_Flowsheet_Equation(self.compounds,'SM')) + self.data.append(inpstms.send_to_flowsheet().OM_Flowsheet_Equation(self.compounds,'SM')) # os.chdir(self.sim_dir_path) unitmofile = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mo') diff --git a/OMChem/MatStm.py b/OMChem/MatStm.py index 69a6845..686231f 100644 --- a/OMChem/MatStm.py +++ b/OMChem/MatStm.py @@ -34,6 +34,7 @@ class MatStm(): MatStm.counter+=1 self.startDict = {} self.eqnDict = {} + self.modesList = ["PT","PH","PVF","TVF","PS"] self.Prop = { @@ -92,9 +93,7 @@ class MatStm(): 'totMasFlo[3]':None } - - def modesList(self): - return ["PT","PH","PVF","TVF","PS"] + def paramgetter(self,mode): dict = {} if(mode=="PT"): diff --git a/OMChem/UnitOprns.py b/OMChem/UnitOprns.py index 90cd546..4cafe0d 100644 --- a/OMChem/UnitOprns.py +++ b/OMChem/UnitOprns.py @@ -85,9 +85,9 @@ class UnitOpr(): - for i in self.parameters: + for k,v in self.parameters.items(): self.OM_data_init += ', ' - self.OM_data_init += i[0] + ' = ' + str(i[1]) + self.OM_data_init += k + ' = ' + str(v) self.OM_data_init += ');\n' else: @@ -96,9 +96,9 @@ class UnitOpr(): comp = comp.replace("'", "") self.OM_data_init += ',comp = {' + comp + '}' - for i in self.parameters: + for k,v in self.parameters.items(): self.OM_data_init += ', ' - self.OM_data_init += i[0] + ' = ' + str(i[1]) + self.OM_data_init += k + ' = ' + str(v) self.OM_data_init += ');\n' @@ -129,7 +129,7 @@ class UnitOpr(): else: self.OM_data_eqn += ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') - if self.mode: + if self.mode: self.OM_data_eqn += (self.name + '.' + self.mode + '=' + self.modeVal + ';\n') return self.OM_data_eqn -- cgit From c350054473ffb5bd7275f2ed939ec2aff6e2afab Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Tue, 31 Dec 2019 19:57:01 +0530 Subject: Flowsheet functions clubbed together, merged UnitOprns.py with UnitOperations.py --- OMChem/Flowsheet.py | 118 ++++++++++++++++++++++++++++--- OMChem/UnitOprns.py | 198 ++++++++++++++++++++++++++-------------------------- 2 files changed, 207 insertions(+), 109 deletions(-) (limited to 'OMChem') 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 -- cgit From 8f2efdc428919fbb800f8fad29c05bcfe2e97a24 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Wed, 1 Jan 2020 15:16:17 +0530 Subject: Resolved a bug, Eliminated helperFunc and some redundant files --- OMChem/UnitOprns.py | 156 ---------------------------------------------------- 1 file changed, 156 deletions(-) delete mode 100644 OMChem/UnitOprns.py (limited to 'OMChem') diff --git a/OMChem/UnitOprns.py b/OMChem/UnitOprns.py deleted file mode 100644 index d2608f2..0000000 --- a/OMChem/UnitOprns.py +++ /dev/null @@ -1,156 +0,0 @@ -# This file can be deleted - -# 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.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 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 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)) - -# 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 += 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 + '}' - - - -# 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 + '}' - -# for k,v in self.parameters.items(): -# self.OM_data_init += ', ' -# self.OM_data_init += k + ' = ' + str(v) - -# self.OM_data_init += ');\n' - -# #print("HERE WE GO") -# #print(self.OM_data_init) - -# return self.OM_data_init - - - - -# 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.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') - -# return self.OM_data_eqn - - - - - - - - - - - - - - - - - - - -- cgit From 4138fd762a45b15dc7dfea661a93a047a0eba4a0 Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Thu, 2 Jan 2020 16:16:18 +0530 Subject: Added Tool-tip in graph --- OMChem/Flowsheet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index a113d66..78552ae 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -42,7 +42,7 @@ class Flowsheet(): 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 += ('extends Simulator.Files.Thermodynamic_Packages.'+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)) @@ -52,7 +52,7 @@ class Flowsheet(): 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 += ('extends Simulator.Files.Thermodynamic_Packages.'+unitOpr.thermoPackage+';\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') -- cgit From 8dfb7d836e438035be2284e49554dac36d0af7bf Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Fri, 3 Jan 2020 15:54:24 +0530 Subject: Made GUI compatible with the new Simulator, abbreviations updated to new convention and few bugs eliminated with code clean up at places --- OMChem/CompSep.py | 2 +- OMChem/Cooler.py | 2 +- OMChem/DistCol.py | 8 +- OMChem/Flash.py | 2 +- OMChem/Flowsheet.py | 91 ++++++------ OMChem/Heater.py | 2 +- OMChem/MatStm.py | 375 ----------------------------------------------- OMChem/Mixer.py | 2 +- OMChem/Pump.py | 2 +- OMChem/ShortcutColumn.py | 2 +- OMChem/Splitter.py | 2 +- OMChem/Valve.py | 2 +- OMChem/adiabatic_comp.py | 16 +- OMChem/adiabatic_exp.py | 16 +- 14 files changed, 75 insertions(+), 449 deletions(-) delete mode 100644 OMChem/MatStm.py (limited to 'OMChem') diff --git a/OMChem/CompSep.py b/OMChem/CompSep.py index 5bdfd51..9579498 100644 --- a/OMChem/CompSep.py +++ b/OMChem/CompSep.py @@ -40,7 +40,7 @@ class CompSep(): 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("'", "") diff --git a/OMChem/Cooler.py b/OMChem/Cooler.py index 32fe594..9a44033 100644 --- a/OMChem/Cooler.py +++ b/OMChem/Cooler.py @@ -54,7 +54,7 @@ class Cooler(): 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("'", "") diff --git a/OMChem/DistCol.py b/OMChem/DistCol.py index 4f9f2fb..1492bc2 100644 --- a/OMChem/DistCol.py +++ b/OMChem/DistCol.py @@ -68,13 +68,13 @@ class DistCol(): 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("'", "") diff --git a/OMChem/Flash.py b/OMChem/Flash.py index 68294ea..a3bf5dc 100644 --- a/OMChem/Flash.py +++ b/OMChem/Flash.py @@ -41,7 +41,7 @@ class Flash(): 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("'", "") diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index 78552ae..3200b7a 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -41,32 +41,32 @@ class Flowsheet(): 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 + '}' @@ -76,10 +76,10 @@ class Flowsheet(): 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 += ', ' @@ -101,18 +101,18 @@ class Flowsheet(): 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') @@ -140,8 +140,8 @@ class Flowsheet(): 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 = [] @@ -203,7 +203,7 @@ class Flowsheet(): # 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: @@ -228,7 +228,7 @@ class Flowsheet(): 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]: @@ -325,19 +325,19 @@ class Flowsheet(): 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: @@ -349,10 +349,10 @@ class Flowsheet(): 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: @@ -362,9 +362,10 @@ class Flowsheet(): 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') @@ -409,7 +410,7 @@ class Flowsheet(): 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 @@ -426,43 +427,43 @@ class Flowsheet(): 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') @@ -509,7 +510,7 @@ class Flowsheet(): 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) diff --git a/OMChem/Heater.py b/OMChem/Heater.py index ebdae9e..cf9b8f1 100644 --- a/OMChem/Heater.py +++ b/OMChem/Heater.py @@ -56,7 +56,7 @@ class Heater(): 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("'", "") diff --git a/OMChem/MatStm.py b/OMChem/MatStm.py deleted file mode 100644 index 686231f..0000000 --- a/OMChem/MatStm.py +++ /dev/null @@ -1,375 +0,0 @@ -from OMPython import OMCSession -import json -import sys -from collections import defaultdict - -class MatStm(): - counter = 1; - def __init__(self,CompNames = [],Temperature=300,Pressure=101325,VapPhasMolFrac=None,VapPhasMasFrac=None,LiqPhasMolFrac=None,LiqPhasMasFrac=None,CompMolFrac = [1.0], CompMasFrac = [], MolFlow=100, MasFlow=None,**kwargs): - self.name = 'MatStm' + str(MatStm.counter) - self.type = 'MatStm' - self.T = Temperature - self.P = Pressure - self.VapPhasMolFrac = VapPhasMolFrac - self.VapPhasMasFrac = VapPhasMasFrac - self.LiqPhasMolFrac = LiqPhasMolFrac - self.LiqPhasMasFrac = LiqPhasMasFrac - self.CompNames = CompNames - self.CompMolFrac = CompMolFrac - self.CompMasFrac = CompMasFrac - self.MolFlow = MolFlow - self.MasFlow = MasFlow - self.OM_data_init = '' - self.OM_data_eqn = '' - self.count = MatStm.counter - self.thermoPackage ="Raoults_Law" - self.mode1 = "P" - self.mode1val = "" - self.mode2 = "T" - self.mode2val = "" - self.no_of_inputs = 1 - self.no_of_outputs = 1 - self.x = 2500-30 - self.y = 2500-30 - MatStm.counter+=1 - self.startDict = {} - self.eqnDict = {} - self.modesList = ["PT","PH","PVF","TVF","PS"] - - - self.Prop = { - - self.mode1:self.mode1val, - self.mode2:self.mode2val, - 'liqPhasMolFrac':LiqPhasMolFrac, - 'liqPhasMasFrac':LiqPhasMasFrac, - 'vapPhasMolFrac':VapPhasMolFrac, - 'vapPhasMasFrac':VapPhasMasFrac, - 'totMolFlo[1]':MolFlow, - 'totMasFlo[1]':MasFlow, - 'MW[1]':None, - 'MW[2]':None, - 'MW[3]':None, - 'phasMolSpHeat[1]':None, - 'phasMolEnth[1]':None, - '[1]':None, - 'phasMolSpHeat[2]':None, - 'phasMolEnth[2]':None, - 'phasMolEntr[2]':None, - 'phasMolSpHeat[3]':None, - 'phasMolEnth[3]':None, - 'phasMolEntr[3]':None, - 'totMolFlo[2]':None, - 'totMasFlo[2]':None, - 'totMolFlo[3]':None, - 'totMasFlo[3]':None - - } - - self.Prop1 = { - self.mode1:self.mode1val, - self.mode2:self.mode2val, - 'liqPhasMolFrac':LiqPhasMolFrac, - 'liqPhasMasFrac':LiqPhasMasFrac, - 'vapPhasMolFrac':VapPhasMolFrac, - 'vapPhasMasFrac':VapPhasMasFrac, - 'totMolFlo[1]':MolFlow, - 'totMasFlo[1]':MasFlow, - 'MW[1]':None, - 'MW[2]':None, - 'MW[3]':None, - 'phasMolSpHeat[1]':None, - 'phasMolEnth[1]':None, - 'phasMolEntr[1]':None, - 'phasMolSpHeat[2]':None, - 'phasMolEnth[2]':None, - 'phasMolEntr[2]':None, - 'phasMolSpHeat[3]':None, - 'phasMolEnth[3]':None, - 'phasMolEntr[3]':None, - 'totMolFlo[2]':None, - 'totMasFlo[2]':None, - 'totMolFlo[3]':None, - 'totMasFlo[3]':None - - } - - def paramgetter(self,mode): - dict = {} - if(mode=="PT"): - self.mode1 = 'P' - self.mode2 = 'T' - dict = {self.mode2:None,self.mode1:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} - elif(mode=="PH"): - self.mode1 = 'P' - self.mode2 = 'phasMolEnth[1]' - dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} - elif(mode=="PVF"): - self.mode1 = 'P' - self.mode2 = 'vapPhasMolFrac' - dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} - elif(mode=="TVF"): - self.mode1 = 'T' - self.mode2 = 'vapPhasMolFrac' - dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} - elif(mode=="PS"): - self.mode1 = 'P' - self.mode2 = 'phasMolEntr[1]' - dict = {self.mode1:None,self.mode2:None,"CompMolFrac":None,"MolFlow":None,"thermoPackage":None} - - return dict - def paramsetter(self,dict): - self.mode1val = dict[self.mode1] - self.mode2val = dict[self.mode2] - self.MolFlow = dict['MolFlow'] - self.CompMolFrac = dict['CompMolFrac'].split(",") - self.thermoPackage = dict['thermoPackage'] - self.Prop['totMolFlo[1]'] = self.MolFlow - self.Prop[self.mode2] = dict[self.mode2] - self.Prop[self.mode1] = dict[self.mode1] - for i in range(len(self.CompNames)): - print('####### compmolfrac #########\n',self.CompMolFrac[i]) - if self.CompMolFrac: - self.Prop['compMolFrac[1,'+str(i+1)+']'] = self.CompMolFrac[i] - else: - self.Prop['compMolFrac[1,'+str(i+1)+']'] = None - - if self.CompMasFrac: - self.Prop['compMasFrac[1,'+str(i+1)+']'] = self.CompMasFrac[i] - else: - self.Prop['compMasFrac[1,'+str(i+1)+']'] = None - self.Prop['compMolFlo[1,'+str(i+1)+']'] = None - self.Prop['compMasFlo[1,'+str(i+1)+']'] = None - for i in range(0,len(self.CompNames)): - self.Prop['compMolFrac[2,'+str(i+1)+']'] = None - self.Prop['compMasFrac[2,'+str(i+1)+']'] = None - self.Prop['compMolFlo[2,'+str(i+1)+']'] = None - self.Prop['compMasFlo[2,'+str(i+1)+']'] = None - self.Prop['compMolFrac[3,'+str(i+1)+']'] = None - self.Prop['compMasFrac[3,'+str(i+1)+']'] = None - self.Prop['compMolFlo[3,'+str(i+1)+']'] = None - self.Prop['compMasFlo[3,'+str(i+1)+']'] = None - - def GetMinEqnValues(self): - compmolfraclist = [] - for i in range(0,len(self.CompNames)): - print(self.Prop['compMolFrac[1,'+str(i+1)+']']) - compmolfraclist.append(self.Prop['compMolFrac[1,'+str(i+1)+']']) - print(compmolfraclist) - #compmolfraclist = list(self.Prop(compMolFrac[1,1)]) - compmolfrac = json.dumps(compmolfraclist) - print(compmolfrac) - compmolfrac = compmolfrac.replace('[','{') - compmolfrac = compmolfrac.replace(']','}') - compmolfrac = compmolfrac.replace('"','') - ''' - compmolfracstr = json.dumps(self.CompMolFrac) - compmolfracstr = compmolfracstr.replace('[','{') - compmolfracstr = compmolfracstr.replace(']','}') - compmolfracstr = compmolfracstr.replace('"','') - ''' - if self.Prop[self.mode1]: - self.eqnDict[self.mode1] = self.Prop[self.mode1] - if self.Prop[self.mode2]: - self.eqnDict[self.mode2] = self.Prop[self.mode2] - if self.CompMolFrac: - self.eqnDict['compMolFrac[1,:]'] = compmolfrac - if self.MolFlow: - self.eqnDict['totMolFlo[1]'] = self.Prop['totMolFlo[1]']#self.MolFlow - - print("##############$GetMinVEqnValuesStart$##################") - print("P:",self.Prop[self.mode1]) - print("T:",self.Prop[self.mode2]) - print("CompMolFrac",compmolfrac) - print("totMolFlo",self.Prop['totMolFlo[1]']) - print("##############$GetMinVEqnValuesEnd$##################") - - def GetEquationValues(self): - if self.Prop[self.mode1]: - self.eqnDict[self.mode1] = self.Prop[self.mode1] - - if self.Prop[self.mode2]: - self.eqnDict[self.mode2] = self.Prop[self.mode2] - - if self.Prop['compMolFrac[1,1]']: - cfa = [] - for i in range(1,len(self.CompNames)+1): - cfa.append(self.Prop['compMolFrac[1,'+str(i)+']']) - cmpMolFracstr = json.dumps(cfa) - cmpMolFracstr = cmpMolFracstr.replace('[','{') - cmpMolFracstr = cmpMolFracstr.replace(']','}') - cmpMolFracstr = cmpMolFracstr.replace('"','') - self.eqnDict['compMolFrac[1,:]'] = cmpMolFracstr - - if self.Prop['totMolFlo[1]']: - self.eqnDict['totMolFlo[1]'] = self.Prop['totMolFlo[1]'] - - - def GetStartValues(self): - try: - if self.Prop[self.mode1]: - self.startDict[self.mode1] = self.Prop[self.mode1] - - if self.Prop[self.mode2]: - self.startDict[self.mode2] = self.Prop[self.mode2] - - - if self.Prop['compMolFrac[2,1]'] != None: - compMolFracarr = [] - for i in range(1,4): - cmf = [] - for j in range(1,len(self.CompNames)+1): - cmf.append(str(self.Prop['compMolFrac['+str(i)+','+str(j)+']'])) - compMolFracarr.append(cmf) - compMolFracstr = json.dumps(compMolFracarr) - compMolFracstr = compMolFracstr.replace('[','{') - compMolFracstr = compMolFracstr.replace(']','}') - compMolFracstr = compMolFracstr.replace('"','') - self.startDict['compMolFrac'] = compMolFracstr - - if self.Prop['compMasFrac[2,1]'] != None: - compMasFracarr = [] - for i in range(1,4): - cmf = [] - for j in range(1,len(self.CompNames)+1): - cmf.append(str(self.Prop['compMasFrac['+str(i)+','+str(j)+']'])) - compMasFracarr.append(cmf) - compMasFracstr = json.dumps(compMolFracarr) - compMasFracstr = compMasFracstr.replace('[','{') - compMasFracstr = compMasFracstr.replace(']','}') - compMasFracstr = compMasFracstr.replace('"','') - self.startDict['compMasFrac'] = compMasFracstr - - if self.Prop['compMasFlo[2,1]'] != None: - compMasFloarr = [] - for i in range(1,4): - cmf = [] - for j in range(1,len(self.CompNames)+1): - cmf.append(str(self.Prop['compMasFlo['+str(i)+','+str(j)+']'])) - compMasFloarr.append(cmf) - compMasFlostr = json.dumps(compMolFracarr) - compMasFlostr = compMasFlostr.replace('[','{') - compMasFlostr = compMasFlostr.replace(']','}') - compMasFlostr = compMasFlostr.replace('"','') - self.startDict['compMasFlo'] = compMasFlostr - - if self.Prop['compMolFlo[2,1]'] != None: - compMolFloarr = [] - for i in range(1,4): - cmf = [] - for j in range(1,len(self.CompNames)+1): - cmf.append(str(self.Prop['compMolFlo['+str(i)+','+str(j)+']'])) - compMolFloarr.append(cmf) - compMolFlostr = json.dumps(compMolFloarr) - compMolFlostr = compMolFlostr.replace('[','{') - compMolFlostr = compMolFlostr.replace(']','}') - compMolFlostr = compMolFlostr.replace('"','') - self.startDict['compMolFlo'] = compMolFlostr - - if self.Prop['MW[2]'] != None: - MWArr = [] - for i in range(1,4): - MWArr.append(self.Prop['MW['+str(i)+']']) - MWStr = json.dumps(MWArr) - MWStr = MWStr.replace('[','{') - MWStr = MWStr.replace(']','}') - MWStr = MWStr.replace('"','') - self.startDict['MW'] = MWStr - - if self.Prop['totMolFlo[2]'] != None: - totMolFloArr = [] - for i in range(1,4): - totMolFloArr.append(self.Prop['totMolFlo['+str(i)+']']) - totMolFloStr = json.dumps(totMolFloArr) - totMolFloStr = totMolFloStr.replace('[','{') - totMolFloStr = totMolFloStr.replace(']','}') - totMolFloStr = totMolFloStr.replace('"','') - self.startDict['totMolFlo'] = totMolFloStr - - if self.Prop['phasMolSpHeat[2]'] != None: - phasMolSpHeatArr = [] - for i in range(1,4): - phasMolSpHeatArr.append(self.Prop['phasMolSpHeat['+str(i)+']']) - phasMolSpHeatStr = json.dumps(phasMolSpHeatArr) - phasMolSpHeatStr = phasMolSpHeatStr.replace('[','{') - phasMolSpHeatStr = phasMolSpHeatStr.replace(']','}') - phasMolSpHeatStr = phasMolSpHeatStr.replace('"','') - self.startDict['phasMolSpHeat'] = phasMolSpHeatStr - - if self.Prop['phasMolEnth[2]'] != None: - phasMolEnthArr = [] - for i in range(1,4): - phasMolEnthArr.append(self.Prop['phasMolEnth['+str(i)+']']) - phasMolEnthStr = json.dumps(phasMolEnthArr) - phasMolEnthStr = phasMolEnthStr.replace('[','{') - phasMolEnthStr = phasMolEnthStr.replace(']','}') - phasMolEnthStr = phasMolEnthStr.replace('"','') - self.startDict['phasMolEnth'] = phasMolEnthStr - - - if self.Prop['phasMolEntr[2]'] != None: - phasMolEntrArr = [] - for i in range(1,4): - phasMolEntrArr.append(self.Prop['phasMolEntr['+str(i)+']']) - phasMolEntrStr = json.dumps(phasMolEntrArr) - phasMolEntrStr = phasMolEntrStr.replace('[','{') - phasMolEntrStr = phasMolEntrStr.replace(']','}') - phasMolEntrStr = phasMolEntrStr.replace('"','') - self.startDict['phasMolEntr'] = phasMolEntrStr - - if self.Prop['totMasFlo[2]'] != None: - totMasFloArr = [] - for i in range(1,4): - totMasFloArr.append(self.Prop['totMasFlo['+str(i)+']']) - totMasFloStr = json.dumps(totMasFloArr) - totMasFloStr = totMasFloStr.replace('[','{') - totMasFloStr = totMasFloStr.replace(']','}') - totMasFloStr = totMasFloStr.replace('"','') - self.startDict['totMasFlo'] = totMasFloStr - - 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_Init(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.Material_Stream;\n" ) - self.OM_data_init = self.OM_data_init + ("extends Simulator.Files.Thermodynamic_Packages."+self.thermoPackage+";\n") - self.OM_data_init = self.OM_data_init + ("end ms"+str(self.count)+";\n") - comp_count = len(addedcomp) - self.GetStartValues() - - #self.OM_data_init = "Simulator.Streams.Mat_Stm_RL " + self.name +"(NOC = " + str(comp_count) - self.OM_data_init = self.OM_data_init + "ms"+str(self.count) +" " + self.name +"(NOC = " + str(comp_count) - self.OM_data_init = self.OM_data_init + ",comp = {" - comp = str(addedcomp).strip('[').strip(']') - comp = comp.replace("'","") - self.OM_data_init = self.OM_data_init + comp + "}," - #for key, value in self.startDict.items(): - # self.OM_data_init = self.OM_data_init + key + '(start = ' + str(value) + '),' - 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_Eqn(self,addedcomp,method): - self.OM_data_eqn = '' - self.comp_count = len(addedcomp) - if method == 'Eqn': - self.eqnDict = {} - self.GetMinEqnValues() - if method == 'SM': - self.eqnDict = {} - self.GetMinEqnValues() - #self.GetEquationValues() - #self.GetEquationValues() - - for key,value in self.eqnDict.items(): - self.OM_data_eqn = self.OM_data_eqn + self.name + '.'+ key + ' = ' + str(value) + ';\n' - return self.OM_data_eqn - - \ No newline at end of file diff --git a/OMChem/Mixer.py b/OMChem/Mixer.py index b0e0a66..c726cdc 100644 --- a/OMChem/Mixer.py +++ b/OMChem/Mixer.py @@ -33,7 +33,7 @@ class Mixer(): comp_count = len(addedcomp) self.OM_data_init = self.OM_data_init + ( - "Simulator.Unit_Operations.Mixer " + self.name + "(NOC = " + str(comp_count)) + "Simulator.Unit_Operations.Mixer " + self.name + "(Nc = " + str(comp_count)) self.OM_data_init = self.OM_data_init + (",comp = {") comp = str(addedcomp).strip('[').strip(']') comp = comp.replace("'", "") diff --git a/OMChem/Pump.py b/OMChem/Pump.py index a63c9f0..3b6ed2c 100644 --- a/OMChem/Pump.py +++ b/OMChem/Pump.py @@ -44,7 +44,7 @@ class Pump(): 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.Centrifugal_Pump " + self.name + "(NOC = " + str(comp_count)) + "Simulator.Unit_Operations.Centrifugal_Pump " + self.name + "(Nc = " + str(comp_count)) self.OM_data_init = self.OM_data_init + (",comp = {") comp = str(addedcomp).strip('[').strip(']') comp = comp.replace("'", "") diff --git a/OMChem/ShortcutColumn.py b/OMChem/ShortcutColumn.py index 5c42545..a018873 100644 --- a/OMChem/ShortcutColumn.py +++ b/OMChem/ShortcutColumn.py @@ -59,7 +59,7 @@ class ShortcutColumn(): self.OM_data_init = self.OM_data_init + ("extends Simulator.Files.Thermodynamic_Packages."+self.thermoPackage+";\n") self.OM_data_init = self.OM_data_init + ("end sc"+str(self.count)+";\n") comp_count = len(addedcomp) - self.OM_data_init = self.OM_data_init + "sc"+str(self.count)+ " " + self.name + "(NOC = " + str(comp_count) + self.OM_data_init = self.OM_data_init + "sc"+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("'", "") diff --git a/OMChem/Splitter.py b/OMChem/Splitter.py index ed79c9d..f873146 100644 --- a/OMChem/Splitter.py +++ b/OMChem/Splitter.py @@ -33,7 +33,7 @@ class Splitter(): self.OM_data_init = '' comp_count = len(addedcomp) self.OM_data_init = self.OM_data_init + ( - "Simulator.Unit_Operations.Splitter " + self.name + "(NOC = " + str(comp_count)) + "Simulator.Unit_Operations.Splitter " + self.name + "(Nc = " + str(comp_count)) self.OM_data_init = self.OM_data_init + (",comp = {") comp = str(addedcomp).strip('[').strip(']') comp = comp.replace("'", "") diff --git a/OMChem/Valve.py b/OMChem/Valve.py index f1f8ac3..9e8494b 100644 --- a/OMChem/Valve.py +++ b/OMChem/Valve.py @@ -44,7 +44,7 @@ class Valve(): self.OM_data_init = '' comp_count = len(addedcomp) self.OM_data_init = self.OM_data_init + ( - "Simulator.Unit_Operations.Valve " + self.name + "(NOC = " + str(comp_count)) + "Simulator.Unit_Operations.Valve " + self.name + "(Nc = " + str(comp_count)) self.OM_data_init = self.OM_data_init + (",comp = {") comp = str(addedcomp).strip('[').strip(']') comp = comp.replace("'", "") diff --git a/OMChem/adiabatic_comp.py b/OMChem/adiabatic_comp.py index 5399ed0..d0a6b72 100644 --- a/OMChem/adiabatic_comp.py +++ b/OMChem/adiabatic_comp.py @@ -1,10 +1,10 @@ from OMChem.EngStm import EngStm -class AdiaComp(): +class AdiabaticCompressor(): counter = 1 - def __init__(self,name='AdiaComp', eff = None): + def __init__(self,name='AdiabaticCompressor', eff = None): self.eff = eff #self.name = name[0] - self.name = name + str(AdiaComp.counter) + self.name = name + str(AdiabaticCompressor.counter) self.OM_data_eqn = '' self.OM_data_init = '' @@ -12,15 +12,15 @@ class AdiaComp(): self.OutputStms = None self.EngStms = EngStm(name='EngStm'+self.name) #self.count = name[1] - self.count = AdiaComp.counter - self.type = 'AdiaComp' - self.thermoPackage ="Raoults_Law" + self.count = AdiabaticCompressor.counter + self.type = 'AdiabaticCompressor' + self.thermoPackage ="RaoultsLaw" self.mode = None self.modeVal = None # new self.no_of_input = 1 self.no_of_output = 1 - AdiaComp.counter += 1 + AdiabaticCompressor.counter += 1 def getname(self): return self.name @@ -50,7 +50,7 @@ class AdiaComp(): self.OM_data_init = self.OM_data_init + ("end adiaComp"+str(self.count)+";\n") comp_count = len(addedcomp) self.OM_data_init = self.OM_data_init + ( - "adiaComp"+str(self.count)+" "+ self.name + "(NOC = " + str(comp_count)) + "adiaComp"+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("'", "") diff --git a/OMChem/adiabatic_exp.py b/OMChem/adiabatic_exp.py index 0dfb541..2754f0a 100644 --- a/OMChem/adiabatic_exp.py +++ b/OMChem/adiabatic_exp.py @@ -1,26 +1,26 @@ from OMChem.EngStm import EngStm -class AdiaExp(): +class AdiabaticExpander(): counter = 1 - def __init__(self,name='AdiaExp', eff = None): + def __init__(self,name='AdiabaticExpander', eff = None): self.eff = eff #self.name = name[0] - self.name = name + str(AdiaExp.counter) + self.name = name + str(AdiabaticExpander.counter) self.OM_data_eqn = '' self.OM_data_init = '' self.InputStms = None self.OutputStms = None self.EngStms = EngStm(name='EngStm'+self.name) #self.count = name[1] - self.count = AdiaExp.counter - self.type = 'AdiaExp' - self.thermoPackage ="Raoults_Law" + self.count = AdiabaticExpander.counter + self.type = 'AdiabaticExpander' + self.thermoPackage ="RaoultsLaw" self.mode = None self.modeVal = None # new self.no_of_input = 1 self.no_of_output = 1 - AdiaExp.counter += 1 + AdiabaticExpander.counter += 1 def getname(self): return self.name @@ -50,7 +50,7 @@ class AdiaExp(): self.OM_data_init = self.OM_data_init + ("end adiaComp"+str(self.count)+";\n") comp_count = len(addedcomp) self.OM_data_init = self.OM_data_init + ( - "adiaComp"+str(self.count)+" "+ self.name + "(NOC = " + str(comp_count)) + "adiaComp"+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("'", "") -- cgit From 39ecc236c572ae17343b9afb39997233e7eb28f0 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Fri, 3 Jan 2020 17:09:38 +0530 Subject: Merged changes, load implemented (WIP) --- OMChem/Flowsheet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index 3200b7a..010b6b3 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -389,7 +389,7 @@ class Flowsheet(): for k,v in op.items(): print("Print K",k) if(set(v) & set(common)): - print("*****************common matstm***************") + print("*****************common MaterialStream***************") if((i in self.unit) and (k in self.unit)): print("both exist") pass -- cgit From 79c81eaa67a545db570c083c3852e09b26e5bf87 Mon Sep 17 00:00:00 2001 From: SaurabhAgarwala Date: Fri, 3 Jan 2020 19:14:01 +0530 Subject: Redundant code removed and a bug eliminated from Flowsheet --- OMChem/Flowsheet.py | 101 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 99 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index 010b6b3..92d040c 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -23,103 +23,6 @@ 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.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 + '(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.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.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 + '(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 += ', ' - unitOpr.OM_data_init += k + ' = ' + str(v) - unitOpr.OM_data_init += ');\n' - - else: - 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 += ', ' - 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 + '.Out,' + unitOpr.name + '.In[' + str(strcount) + ']);\n') - strcount += 1 - else: - 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 + '.In,' + unitOpr.name + '.Out[' + str(strcount) + ']);\n') - strcount += 1 - else: - 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') - - return unitOpr.OM_data_eqn - - def get_omc_path(self): try: self.omhome = os.environ.get('OPENMODELICAHOME') @@ -329,7 +232,7 @@ class Flowsheet(): for unitop in self.UnitOpn: if unitop.type != 'MaterialStream': - self.data.append(self.OM_Flowsheet_Initialize(unitop)) + self.data.append(unitop.OM_Flowsheet_Initialize()) else: self.data.append(unitop.OM_Flowsheet_Initialize(self.compounds)) @@ -341,7 +244,7 @@ class Flowsheet(): for unitop in self.UnitOpn: if unitop.type not in self.stm: for j in unitop.OutputStms: - self.outlist.append(j) + self.outlist.append(j) print(j.name) -- cgit From 38dbff48f57c403abdc575a9cd9d0bbf512bfef6 Mon Sep 17 00:00:00 2001 From: lucaszhao19 Date: Wed, 5 Feb 2020 17:58:00 +0530 Subject: Input/Results DockWidgets, Newly implemented variables for MaterialStream and four UnitOps --- OMChem/Flowsheet.py | 148 ++-------------------------------------------------- 1 file changed, 5 insertions(+), 143 deletions(-) (limited to 'OMChem') diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index 92d040c..25143ce 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -75,8 +75,8 @@ class Flowsheet(): for row in csvreader: print("124125") self.resdata.append(row) + print(self.resdata) #self.ExtData() - def send_for_simulationSM(self,unitop): @@ -99,36 +99,6 @@ class Flowsheet(): self.resdata.append(row) self.ExtData() - - - - - # if self.sim_method == 'SM': - # for unitop in self.UnitOpn: - # self.resdata = [] - # 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: - # csvreader = csv.reader(resultFile,delimiter=',') - # for row in csvreader: - # self.resdata.append(row) - # self.ExtData() - - - - - - # if self.interface == 'OMPython': - # omc = OMCSession() - # omc.sendExpression("loadModel(Modelica)") - # omc.sendExpression("loadFile(\"Simulator.mo\")") - # omc.sendExpression("loadFile(\"Flowsheet.mo\")") - # execsim = omc.sendExpression("simulate(Flowsheet, outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1)") - - # else: - # os.system(self.omc_path + ' -s ') - def ExtData(self): for unit in self.UnitOpn: if unit[0].type == 'MaterialStream': @@ -140,84 +110,7 @@ class Flowsheet(): #resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) print(resultval) unit[0].Prop[key] = resultval - #print(unit[0].Prop) - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.Prop[key][i] = resultval - # i = i + 1 - - # for key, value in unit.OMVapProp.iteritems(): - # i = 0 - - # if type(value) is str: - # propertyname = unit.name + '.' + value - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.VapProp[key] = resultval - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.VapProp[key][i] = resultval - # i = i + 1 - - - # for key, value in unit.OMLiqProp.iteritems(): - # i = 0 - - # if type(value) is str: - # propertyname = unit.name + '.' + value - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.LiqProp[key] = resultval - # else: - # for v in value: - # propertyname = unit.name + '.' + v - # if propertyname in self.resdata[0]: - # ind = self.resdata[0].index(propertyname) - # resultval = str(self.resdata[-1][ind]) - # # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.LiqProp[key][i] = resultval - # i = i + 1 - # for key, value in unit.OMVapProp.iteritems(): - # i = 0 - - # if type(value) is str: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.VapProp[key] = resultval - # else: - # for v in value: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.VapProp[key][i] = resultval - # i = i + 1 - - - # for key, value in unit.OMLiqProp.iteritems(): - # i = 0 - - # if type(value) is str: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - # unit.LiqProp[key] = resultval - # else: - # for v in value: - # resultval = str(omc.sendExpression("val("+unit.name+ "." + v + ", 0.5)")) - # unit.LiqProp[key][i] = resultval - # i = i + 1 - - - + def simulateEQN(self): self.data = [] print("##################################################") @@ -247,8 +140,6 @@ class Flowsheet(): self.outlist.append(j) print(j.name) - - for unitop in self.UnitOpn: if unitop not in self.outlist: @@ -274,10 +165,9 @@ class Flowsheet(): self.send_for_simulationEqn() - - def simulateSM(self,ip,op): + print("ip op = ", ip, op) self.sim_method = 'SM' self.data = [] self.resdata = [] @@ -351,15 +241,7 @@ class Flowsheet(): self.data.append('equation\n') print("##################equation") self.data.append(unitop.OM_Flowsheet_Equation()) - ''' - if type(outstms) is list: - for stm in outstms: - #stm.GetEquationValues() - self.data.append(stm.OM_Flowsheet_Equation(self.compounds,'SM')) - else: - #outstms.GetEquationValues() - self.data.append(outstms.OM_Flowsheet_Equation(self.compounds,'SM')) -''' + if type(inpstms) is list: for stm in inpstms: #stm.GetEquationValues() @@ -419,9 +301,7 @@ class Flowsheet(): ind = self.resdata[0].index(propertyname) resultval = str(self.resdata[-1][ind]) stm.Prop[key] = resultval - - #print("input",stm.Prop[key]) - + #print("input",stm.Prop[key]) else: for key, value in inpstms.Prop.items(): @@ -449,7 +329,6 @@ class Flowsheet(): resultval = str(self.resdata[-1][ind]) outstms.Prop[key] = resultval print("output key:",key,"value:",outstms.Prop[key]) - self.dataframes = [pd.read_csv(i) for i in self.csvlist] os.chdir(self.sim_dir_path) @@ -460,20 +339,3 @@ class Flowsheet(): csvreader = csv.reader(resultFile,delimiter=',') for row in csvreader: self.resdata.append(row) - - - - - - - - - - - - - - - - - -- cgit