diff options
Diffstat (limited to 'OMChem')
-rw-r--r-- | OMChem/CompSep.py | 71 | ||||
-rw-r--r-- | OMChem/ConvReactor.py | 44 | ||||
-rw-r--r-- | OMChem/Cooler.py | 76 | ||||
-rw-r--r-- | OMChem/DistCol.py | 103 | ||||
-rw-r--r-- | OMChem/EngStm.py | 18 | ||||
-rw-r--r-- | OMChem/Flash.py | 55 | ||||
-rw-r--r-- | OMChem/Flowsheet.py | 306 | ||||
-rw-r--r-- | OMChem/Heater.py | 75 | ||||
-rw-r--r-- | OMChem/Mixer.py | 58 | ||||
-rw-r--r-- | OMChem/Pump.py | 62 | ||||
-rw-r--r-- | OMChem/ShortcutColumn.py | 86 | ||||
-rw-r--r-- | OMChem/Splitter.py | 61 | ||||
-rw-r--r-- | OMChem/Valve.py | 58 | ||||
-rw-r--r-- | OMChem/__init__.py | 0 | ||||
-rw-r--r-- | OMChem/adiabatic_comp.py | 67 | ||||
-rw-r--r-- | OMChem/adiabatic_exp.py | 67 | ||||
-rw-r--r-- | OMChem/setup.py | 54 |
17 files changed, 1261 insertions, 0 deletions
diff --git a/OMChem/CompSep.py b/OMChem/CompSep.py new file mode 100644 index 0000000..d538acb --- /dev/null +++ b/OMChem/CompSep.py @@ -0,0 +1,71 @@ +from OMChem.EngStm import EngStm +import json +class CompSep(): + 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.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = [] + self.OutputStms = [] + 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 [] + + def paramgetter(self,mode=None): + dict = {"SepStrm":None,"SepFactValue":None,"SepFact":None} + return dict + + def paramsetter(self,dict): + self.SepStrm = dict['SepStrm'] + self.SepFactValue = dict['SepFactValue'] + self.SepFact = dict['SepFact'] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + 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 + "(Nc = " + 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 + ("},") + self.OM_data_init = self.OM_data_init + ("sepFact = "+self.SepFact+",sepStrm = " + self.SepStrm + ", sepFactVal = " + self.SepFactValue + ");\n") + + return self.OM_data_init + + def connect(self,InputStms = None,OutputStms = []): + self.InputStms = InputStms + self.OutputStms = OutputStms + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + comp_count = len(addedcomp) + strcount = 1 + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + + for strm in self.OutputStms: + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + strm.name + '.inlet,' + self.name + '.outlet'+str(strcount)+');\n') + strcount += 1 + + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,' + self.name + '.energy);\n') + 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 new file mode 100644 index 0000000..5c83106 --- /dev/null +++ b/OMChem/ConvReactor.py @@ -0,0 +1,44 @@ +import json +from OMChem.EngStm import EngStm +class ConvReactor(): + def __init__(self,name='',Nr=None,b=None,X=None,Z=None,a=[],operation=None,Tdef=None): + self.Nr = str(Nr) + self.b = str(b) + self.X = str(X) + self.Z = str(Z) + self.a = json.dumps(a).replace('[','{').replace(']','}') + self.operation = str(operation) + self.name = name + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = [] + self.OutputStms = [] + self.Tdef = str(Tdef) + + self.type = 'ConvReactor' + self.EngStms = EngStm(name="EngStm") + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + 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.ConversionReactor " + self.name + "(Nr = " + self.Nr + ',b = ' + self.b + ',X = ' + self.X + ',Z = ' + self.Z + ',a = ' + self.a + ',operation = ' + self.operation + ',Tdef = ' + self.Tdef + ');\n') + return self.OM_data_init + + def connect(self,InputStms = None,OutputStms = None): + self.InputStms = InputStms + self.OutputStms = OutputStms + + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + comp_count = len(addedcomp) + strcount = 1 + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.OutputStms[0].name + '.inlet,' + self.name + '.outlet);\n') + + + 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 new file mode 100644 index 0000000..9a44033 --- /dev/null +++ b/OMChem/Cooler.py @@ -0,0 +1,76 @@ +from OMChem.EngStm import EngStm +class Cooler(): + counter = 1 + def __init__(self,name='Cooler',PressureDrop = None, eff = None): + self.PressureDrop = PressureDrop + self.eff = eff + # self.name = name + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + #self.heatRem = heatRem + self.EngStms = EngStm(name='EngStm') + self.type = 'Cooler' + self.mode = None + self.modeVal = None + + self.Prop = { + 'pressDrop':None, + 'eff':None, + 'outT':None, + '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 + + def modesList(self): + return ["heatRem","outT","outVapPhasMolFrac","tempDrop","enFlo"] + + def paramgetter(self,mode="heatRem"): + self.mode = mode + dict = {"PressureDrop":None,"eff":None,self.mode:None} + return dict + + def paramsetter(self,dict): + + self.PressureDrop = dict['PressureDrop'] + self.eff = dict['eff'] + self.modeVal = dict[self.mode] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + 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 + "(Nc = " + 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 + ("},") + self.OM_data_init = self.OM_data_init + 'pressDrop = ' + str(self.PressureDrop) + ',' + self.OM_data_init = self.OM_data_init + 'eff = ' + str(self.eff) + ');\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + # self.OM_data_eqn = self.name + '.pressDrop = ' + str(self.PressDrop) + ';\n' + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,'+ self.name + '.energy);\n') + if(self.mode =="enFlo"): + self.OM_data_eqn = self.OM_data_eqn + (self.EngStms.name+'.'+self.mode+'='+ self.modeVal + ';\n') + else: + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + return self.OM_data_eqn
\ No newline at end of file diff --git a/OMChem/DistCol.py b/OMChem/DistCol.py new file mode 100644 index 0000000..c4a88c3 --- /dev/null +++ b/OMChem/DistCol.py @@ -0,0 +1,103 @@ +from OMChem.EngStm import EngStm +class DistCol(): + 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 + 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 = DistCol.counter + self.thermoPackage='Raoults_Law' + self.type = 'DistCol' + self.mode = None + self.condType='' + self.modeVal = None + 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 + + def modesList(self): + return ["refluxRatio","sideDrawMolFlo","T"] + + def paramgetter(self,mode="refluxRatio"): + self.mode=mode + dict = { "numStage" : None,"numFeeds" :None,"feedStages" :None,"thermoPackage":None,"condType":None,self.mode:None,"condensor.P":None,"reboiler.P":None} + return dict + + def paramsetter(self,dict): + self.numStage = dict["numStage"] + self.numFeeds = dict["numFeeds"] + self.feedStages = dict["feedStages"].split(",") + self.modeVal=dict[self.mode] + self.condP=dict["condensor.P"] + self.rebP=dict["reboiler.P"] + self.condType=dict["condType"] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + 'model Condensor\n' + self.OM_data_init = self.OM_data_init + 'extends Simulator.Unit_Operations.Distillation_Column.Cond;\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 Condensor;\n' + self.OM_data_init = self.OM_data_init + 'model Tray\n' + self.OM_data_init = self.OM_data_init + 'extends Simulator.Unit_Operations.Distillation_Column.DistTray;\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 Tray;\n' + self.OM_data_init = self.OM_data_init + 'model Reboiler\n' + self.OM_data_init = self.OM_data_init + 'extends Simulator.Unit_Operations.Distillation_Column.Reb;\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 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(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 + "(Nc = " + str(comp_count)) + self.OM_data_init = self.OM_data_init + (",comp = {") + comp = str(addedcomp).strip('[').strip(']') + comp = comp.replace("'", "") + self.feedStages=str(self.feedStages).strip('[').strip(']') + self.feedStages = self.feedStages.replace("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},")+("noOfStages="+self.numStage+","+"noOfFeeds="+self.numFeeds+",feedStages="+"{"+self.feedStages+"}"+",condensor.condType="+"\""+self.condType+"\""+");\n") + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStm1.name+';\n' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStm2.name+';\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + self.OM_data_eqn = self.OM_data_eqn + ('connect('+self.name+'.'+'condensor_duty'+','+ self.EngStm1.name+'.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect('+self.name+'.reboiler_duty'+', '+self.EngStm2.name+'.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect('+self.name+'.distillate'+", "+self.OutputStms[0].name+'.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect('+self.name+'.bottoms'+", "+self.OutputStms[1].name+'.inlet);\n') + for i in range(len(self.InputStms)): + self.OM_data_eqn = self.OM_data_eqn + ('connect('+self.InputStms[i].name+'.outlet'+", "+self.name+'.feed['+str(i+1)+']);\n') + self.OM_data_eqn = self.OM_data_eqn + (self.OutputStms[1].name+'.'+'totMolFlow[1] = '+str(self.OutputStms[1].Prop['totMolFlo[1]'])+';\n') + if self.mode=="refluxRatio": + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+str(self.mode)+'='+ str(self.modeVal) + ';\n') + else: + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.condensor.'+self.mode+'='+ str(self.modeVal) + ';\n') + + self.OM_data_eqn = self.OM_data_eqn + self.name +'.reboiler.P='+self.rebP+';\n' + self.OM_data_eqn = self.OM_data_eqn + self.name +'.condensor.P='+self.condP+';\n' + return self.OM_data_eqn + diff --git a/OMChem/EngStm.py b/OMChem/EngStm.py new file mode 100644 index 0000000..c02a5d5 --- /dev/null +++ b/OMChem/EngStm.py @@ -0,0 +1,18 @@ + +class EngStm(): + + def __init__(self,name = 'Engstm'): + self.name = name + self.type = 'EngStm' + self.OM_data_init = '' + self.OM_data_eqn = '' + + + def OM_Flowsheet_Init(self,addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.name+';\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self,addedcomp): + self.OM_data_eqn='' + return self.OM_data_eqn diff --git a/OMChem/Flash.py b/OMChem/Flash.py new file mode 100644 index 0000000..165849a --- /dev/null +++ b/OMChem/Flash.py @@ -0,0 +1,55 @@ +class Flash(): + counter = 1 + def __init__(self,name='Flash'): + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + self.type = 'flash' + 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 + + def modesList(self): + return [] + + def paramgetter(self,mode=None): + dict = {"thermoPackage":None} + return dict + def paramsetter(self,dict): + self.thermoPackage = dict['thermoPackage'] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + ("model fls"+str(self.count)+"\n") + self.OM_data_init = self.OM_data_init + ("extends Simulator.Unit_Operations.Flash;\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 fls"+str(self.count)+";\n") + comp_count = len(addedcomp) + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("});\n") + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + comp_count = len(addedcomp) + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.feed' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.vapor,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.liquid,' + self.OutputStms[1].name + '.inlet);\n') + return self.OM_data_eqn
\ No newline at end of file diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py new file mode 100644 index 0000000..2e7b098 --- /dev/null +++ b/OMChem/Flowsheet.py @@ -0,0 +1,306 @@ +import os +import csv +from subprocess import Popen, PIPE +import pandas as pd + +class Flowsheet(): + def __init__(self): + self.sim_name = 'Simulator' + self.sim_method = '' + self.unit_operations = [] + self.data = [] + self.compounds = [] + self.interface = '' + self.omc_path = None + 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') + self.result_data = [] + self.stdout=None + self.stderr=None + + def get_omc_path(self,msg): + 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: + msg.parent().parent().parent().container.disableInterfaceforSimulation(False) + msg.append("<span style=\"color:red\"><b>Installation Error : </b>The OpenModelica compiler is missing in the System path please install it.</span>") + print("The OpenModelica compiler is missing in the System path please install it" ) + raise + + def add_unit_operations(self,unitop): + self.unit_operations.append(unitop) + + def remove_unit_operations(self,unitop): + self.unit_operations.remove(unitop) + + def add_compound_list(self,C): + self.compounds = C + + def send_for_simulation_Eqn(self,msg): + self.result_data = [] + self.omc_path = self.get_omc_path(msg) + #print(self.omc_path) + + if self.sim_method == 'Eqn': + simpath = self.eqn_mos_path + os.chdir(self.sim_dir_path) + + self.process = Popen([self.omc_path, '-s',simpath], stdout=PIPE, stderr=PIPE) + self.stdout, self.stderr = self.process.communicate() + + os.chdir(self.root_dir) + if ('timeSimulation = 0.0,\n' in self.stdout.decode("utf-8")): + self.result_data = [] + else: + csvpath = os.path.join(self.sim_dir_path,'Flowsheet_res.csv') + with open (csvpath,'r') as resultFile: + self.result_data = [] + csvreader = csv.reader(resultFile,delimiter=',') + for row in csvreader: + self.result_data.append(row) + + def send_for_simulation_SM(self,unitop): + self.result_data = [] + self.omc_path = self.get_omc_path() + os.chdir(self.sim_dir_path) + self.process = Popen([self.omc_path, '-s',unitop.name,'.mos'], stdout=PIPE, stderr=PIPE) + stdout, stderr = self.process.communicate() + # print("############### StdOut ################") + # print(stdout) + self.result_data = [] + #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.result_data.append(row) + self.ext_data() + + def ext_data(self): + for unit in self.unit_operations: + if unit[0].type == 'MaterialStream': + for key, value in unit[0].Prop.items(): + property_name = unit[0].name + '.' + key + if property_name in self.result_data[0]: + ind = self.result_data[0].index(property_name) + resultval = str(self.result_data[-1][ind]) + unit[0].Prop[key] = resultval + + def simulate_EQN(self,msg): + self.data = [] + self.sim_method = 'Eqn' + self.data.append("model Flowsheet\n") + + tempCompounds = self.compounds + for c in tempCompounds: + CompName = c + CompName = CompName.replace(" ", "") + CompName = CompName.replace("-", "") + CompName = CompName.replace(",", "") + CompName = CompName.replace("1", "One") + CompName = CompName.replace("2", "Two") + CompName = CompName.replace("3", "Three") + CompName = CompName.replace("4", "Four") + CompName = CompName.replace("5", "Five") + self.data.append("parameter database." + CompName +' '+ CompName + "; \n") + tempCompounds[tempCompounds.index(c)] = CompName + + self.data.append("parameter Integer Nc = " + str(len(tempCompounds)) + ";\n") + self.data.append("parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] = {" + + str(tempCompounds).strip('[').strip(']').replace("'", "") + "};\n") + + for unitop in self.unit_operations: + if unitop.type != 'MaterialStream': + self.data.append(unitop.OM_Flowsheet_Initialize()) + else: + self.data.append(unitop.OM_Flowsheet_Initialize(self.compounds)) + + self.data.append("equation\n") + + self.outlist = [] + self.stm = ['MaterialStream','EngStm'] + for unitop in self.unit_operations: + if unitop.type not in self.stm: + for j in unitop.output_stms.values(): + self.outlist.append(j) + + for unitop in self.unit_operations: + if unitop not in self.outlist: + if unitop.type == 'MaterialStream': + self.data.append(unitop.OM_Flowsheet_Equation(self.compounds,'Eqn')) + else: + self.data.append(unitop.OM_Flowsheet_Equation()) + else: + pass + with open(self.Flomo_path, 'w') as txtfile: + for d in self.data: + txtfile.write(str(d)) + txtfile.write('end Flowsheet;\n') + #print(self.eqn_mos_path) + with open(self.eqn_mos_path, 'w') as mosFile: + mosFile.write('loadModel(Modelica);\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') + + self.send_for_simulation_Eqn(msg) + + def simulate_SM(self,ip,op): + self.sim_method = 'SM' + self.data = [] + self.result_data = [] + self.unit = [] + self.csvlist = [] + + for i in ip: + common = ip[i] + + for k,v in op.items(): + if(set(v) & set(common)): + if((i in self.unit) and (k in self.unit)): + pass + elif(i in self.unit): + self.unit.insert(self.unit.index(i),k) + elif(k in self.unit): + self.unit.append(i) + else: + self.unit.append(k) + self.unit.append(i) + + for unitop in self.unit: + os.chdir(self.root_dir) + self.data = [] + if unitop.type not in ['MaterialStream','EngStm']: + inpstms = unitop.input_stms + outstms = unitop.output_stms + + try: + engstms = unitop.EngStms + except: + engstms = None + + self.data.append("model "+unitop.name.lower()+'\n') + + for c in self.compounds: + c = c.title() + lcase = c.lower() + self.data.append("parameter Simulator.Files.Chemsep_Database." + c +' '+ c + "; \n") + + self.data.append(unitop.OM_Flowsheet_Initialize()) + + if type(outstms) is list: + for stm in outstms: + self.data.append(stm.OM_Flowsheet_Initialize()) + else: + self.data.append(outstms.OM_Flowsheet_Initialize()) + + if engstms: + self.data.append(engstms.OM_Flowsheet_Initialize()) + + if type(inpstms) is list: + for stm in inpstms: + self.data.append(stm.OM_Flowsheet_Initialize()) + else: + self.data.append(inpstms.OM_Flowsheet_Initialize()) + + self.data.append('equation\n') + self.data.append(unitop.OM_Flowsheet_Equation()) + + if type(inpstms) is list: + for stm in inpstms: + self.data.append(stm.OM_Flowsheet_Equation()) + else: + self.data.append(inpstms.OM_Flowsheet_Equation()) + + 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.omc_path = self.get_omc_path() + os.chdir(self.sim_dir_path) + sim = os.path.join(self.sim_dir_path,unitop.name.lower()+'.mos') + self.process = Popen([self.omc_path, '-s',sim], stdout=PIPE, stderr=PIPE) + self.stdout, self.stderr = self.process.communicate() + os.chdir(self.root_dir) + + # 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.result_data.append(row) + + os.chdir(self.root_dir) + if type(inpstms) is list: + for stm in inpstms: + for key,value in stm.Prop.items(): + property_name = stm.name + '.' + key + if property_name in self.result_data[0]: + ind = self.result_data[0].index(property_name) + resultval = str(self.result_data[-1][ind]) + stm.Prop[key] = resultval + else: + for key, value in inpstms.Prop.items(): + property_name = inpstms.name + '.' + key + if property_name in self.result_data[0]: + ind = self.result_data[0].index(property_name) + resultval = str(self.result_data[-1][ind]) + inpstms.Prop[key] = resultval + + if type(outstms) is list: + for stm in outstms: + for key, value in stm.Prop.items(): + property_name = stm.name + '.' + key + if property_name in self.result_data[0]: + ind = self.result_data[0].index(property_name) + resultval = str(self.result_data[-1][ind]) + stm.Prop[key] = resultval + else: + for key, value in outstms.Prop.items(): + property_name = outstms.name + '.' + key + if property_name in self.result_data[0]: + ind = self.result_data[0].index(property_name) + resultval = str(self.result_data[-1][ind]) + outstms.Prop[key] = resultval + + 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.result_data.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.result_data.append(row) diff --git a/OMChem/Heater.py b/OMChem/Heater.py new file mode 100644 index 0000000..a24253d --- /dev/null +++ b/OMChem/Heater.py @@ -0,0 +1,75 @@ +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.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + self.EngStms = EngStm(name='EngStm'+name) + self.type = 'Heater' + self.mode = None + self.modeVal = None + + self.Prop = { + 'pressDrop':None, + 'eff':None, + 'outT':None, + 'tempInc':None, + '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 + + def modesList(self): + return ["heatAdd","outT","outVapPhasMolFrac","tempInc","enFlo"] + + def paramgetter(self,mode="heatAdd"): + self.mode = mode + dict = {"PressureDrop":None,"eff":None,self.mode:None} + return dict + + def paramsetter(self,dict): + + self.PressureDrop = dict['PressureDrop'] + self.eff = dict['eff'] + self.modeVal = dict[self.mode] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + 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 + "(Nc = " + 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 + ("},") + self.OM_data_init = self.OM_data_init + 'pressDrop = ' + str(self.PressureDrop) +',' + self.OM_data_init = self.OM_data_init + 'eff = ' + str(self.eff) + ');\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,' + self.name + '.energy);\n') + + if(self.mode =="enFlo"): + self.OM_data_eqn = self.OM_data_eqn + (self.EngStms.name+'.'+self.mode+'='+ self.modeVal + ';\n') + else: + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + return self.OM_data_eqn diff --git a/OMChem/Mixer.py b/OMChem/Mixer.py new file mode 100644 index 0000000..c726cdc --- /dev/null +++ b/OMChem/Mixer.py @@ -0,0 +1,58 @@ +class Mixer(): + counter = 1 # + def __init__(self,name='Mixer',NOI=5,Pcal = 'Inlet_Average'): + self.NOI = NOI + self.Pcal = Pcal + 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) + + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},") + self.OM_data_init = self.OM_data_init + ("outPress = \""+self.Pcal+"\",NI=" + str(self.NOI) + ");\n") + return self.OM_data_init + + def connect(self,InputStms = [],OutputStms = None): + self.NOI=len(InputStms) + self.InputStms = InputStms + self.OutputStms = OutputStms + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + comp_count = len(addedcomp) + strcount = 1 + for strm in self.InputStms: + self.OM_data_eqn = self.OM_data_eqn + ( + 'connect(' + strm.name + '.outlet,' + self.name + '.inlet[' + str(strcount) + ']);\n') + 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 new file mode 100644 index 0000000..e9b9149 --- /dev/null +++ b/OMChem/Pump.py @@ -0,0 +1,62 @@ +from OMChem.EngStm import EngStm +class Pump(): + counter = 1 + def __init__(self,name='Pump',eff = None): + self.eff = eff + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + self.EngStms = EngStm(name='EngStm'+name) + 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 + self.OutputStms = OutputStms + + def modesList(self): + return ["pressInc","outP","reqPow","enFlo"] + + def paramgetter(self,mode="pressInc"): + self.mode = mode + dict = {"eff":None,self.mode:None} + return dict + + def paramsetter(self,dict): + self.eff = dict['eff'] + self.modeVal = dict[self.mode] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + 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 + "(Nc = " + 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 + ("},") + self.OM_data_init = self.OM_data_init + 'eff = ' + str(self.eff) + ');\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,' + self.name + '.energy);\n') + + if(self.mode =="enFlo"): + self.OM_data_eqn = self.OM_data_eqn + (self.EngStms.name+'.'+self.mode+'='+ self.modeVal + ';\n') + else: + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + return self.OM_data_eqn diff --git a/OMChem/ShortcutColumn.py b/OMChem/ShortcutColumn.py new file mode 100644 index 0000000..60d9d1b --- /dev/null +++ b/OMChem/ShortcutColumn.py @@ -0,0 +1,86 @@ +from OMChem.EngStm import EngStm +class ShortcutColumn(): + 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 + 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 = 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 [] + + def paramgetter(self,mode=None): + dict = { "HKey" : None,"LKey" :None,"HKeyMolFrac":None,"LKeyMolFrac":None,"condType":None,"thermoPackage":None,"condP":None,"rebP":None,"actR":None} + return dict + + def paramsetter(self,dict): + self.HKey = dict["HKey"] + self.LKey = dict["LKey"] + self.HKeyMolFrac = dict["HKeyMolFrac"] + self.LKeyMolFrac=dict["LKeyMolFrac"] + self.condP=dict["condP"] + self.rebP=dict["rebP"] + self.actR=dict["actR"] + self.condType=dict["condType"] + self.thermoPackage=dict["thermoPackage"] + def connect(self,InputStms = None,OutputStms = None): + self.InputStms = InputStms + self.OutputStms = OutputStms + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + ("model sc"+str(self.count)+"\n") + self.OM_data_init = self.OM_data_init + ("extends Simulator.Unit_Operations.Shortcut_Column;\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 sc"+str(self.count)+";\n") + comp_count = len(addedcomp) + 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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},") + self.OM_data_init = self.OM_data_init + 'condType = ' + "\""+self.condType+"\""+',' + self.OM_data_init = self.OM_data_init + 'HKey = ' + str(self.HKey) +',' + self.OM_data_init = self.OM_data_init + 'LKey = ' + str(self.LKey) + ');\n' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStm1.name+';\n' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStm2.name+';\n' + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.reboiler_duty,' +self.EngStm1.name +'.outlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStm2.name+'.inlet,' + self.name + '.condenser_duty);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.distillate,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.bottoms,' + self.OutputStms[1].name + '.inlet);\n') + + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.feed);\n') + self.OM_data_eqn = self.OM_data_eqn + self.name +'.rebP = ' + self.rebP + ';\n' + self.OM_data_eqn = self.OM_data_eqn + self.name +'.condP = ' + self.condP + ';\n' + self.OM_data_eqn = self.OM_data_eqn + self.name +'.mixMolFrac[2,'+self.name+'.LKey]='+self.LKeyMolFrac+ ';\n' + self.OM_data_eqn = self.OM_data_eqn + self.name +'.mixMolFrac[3,'+self.name+'.HKey]='+self.HKeyMolFrac+ ';\n' + self.OM_data_eqn = self.OM_data_eqn + self.name +'.actR=' + self.actR + ';\n' + return self.OM_data_eqn
\ No newline at end of file diff --git a/OMChem/Splitter.py b/OMChem/Splitter.py new file mode 100644 index 0000000..98d41ab --- /dev/null +++ b/OMChem/Splitter.py @@ -0,0 +1,61 @@ + +import json +class Splitter(): + counter = 1 + def __init__(self,name='Splitter',NOO=5,calcType = 'Molar_Flow',specval = [50,50]): + self.NOO = NOO + self.calcType = calcType + self.name = name + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + 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): + dict = {"NOO":None} + return dict + def paramsetter(self,dict): + self.NOI = dict["NOO"] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + comp_count = len(addedcomp) + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},") + self.OM_data_init = self.OM_data_init + ("calcType = \""+self.calcType+"\",NO=" + str(self.NOO) + ");\n") + return self.OM_data_init + + def connect(self,InputStms = None,OutputStms = []): + self.NOO=len(OutputStms) + self.InputStms = InputStms + self.OutputStms = OutputStms + + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + comp_count = len(addedcomp) + strcount = 1 + #print("Output#########",self.OutputStms) + for strm in self.OutputStms: + self.OM_data_eqn = self.OM_data_eqn + ( + 'connect(' + strm.name + '.inlet,' + self.name + '.outlet[' + str(strcount) + ']);\n') + strcount += 1 + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.inlet,' + self.InputStms[0].name + '.outlet);\n') + self.OM_data_eqn = self.OM_data_eqn + self.name +'.' +'specVal =' + self.specval +';\n' + return self.OM_data_eqn diff --git a/OMChem/Valve.py b/OMChem/Valve.py new file mode 100644 index 0000000..05fa55f --- /dev/null +++ b/OMChem/Valve.py @@ -0,0 +1,58 @@ +class Valve(): + counter = 1 + def __init__(self,name='Valve'): + self.mode = None + self.modeVal = None + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + self.type = 'Valve' + + self.Prop = { + '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"] + + def paramgetter(self,mode="pressDrop"): + self.mode = mode + dict = {self.mode:None} + return dict + + def paramsetter(self,dict): + + self.modeVal = dict[self.mode] + + def connect(self,InputStms = None,OutputStms = None): + self.InputStms = InputStms + self.OutputStms = OutputStms + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + comp_count = len(addedcomp) + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("});\n") + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + return self.OM_data_eqn
\ No newline at end of file diff --git a/OMChem/__init__.py b/OMChem/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/OMChem/__init__.py diff --git a/OMChem/adiabatic_comp.py b/OMChem/adiabatic_comp.py new file mode 100644 index 0000000..bda0476 --- /dev/null +++ b/OMChem/adiabatic_comp.py @@ -0,0 +1,67 @@ +from OMChem.EngStm import EngStm +class AdiabaticCompressor(): + counter = 1 + def __init__(self,name='AdiabaticCompressor', eff = None): + self.eff = eff + self.name = name + str(AdiabaticCompressor.counter) + + self.OM_data_eqn = '' + self.OM_data_init = '' + self.InputStms = None + self.OutputStms = None + self.EngStms = EngStm(name='EngStm'+self.name) + 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 + AdiabaticCompressor.counter += 1 + + def getname(self): + return self.name + + def connect(self,InputStms = None,OutputStms = None): + self.InputStms = InputStms + self.OutputStms = OutputStms + + def modesList(self): + return ["pressInc","outP","reqPow"] + + def paramgetter(self,mode="pressInc"): + self.mode = mode + dict = {"eff":None,self.mode:None,"thermoPackage":None} + return dict + + def paramsetter(self,dict): + self.eff = dict['eff'] + self.modeVal = dict[self.mode] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStms.name+';\n' + self.OM_data_init = self.OM_data_init + ("model adiaComp"+str(self.count)+"\n") + self.OM_data_init = self.OM_data_init + ("extends Simulator.Unit_Operations.Adiabatic_Compressor;\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 adiaComp"+str(self.count)+";\n") + comp_count = len(addedcomp) + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},")+("eff="+self.eff+");\n") + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,' + self.name + '.energy);\n') + + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + + return self.OM_data_eqn + diff --git a/OMChem/adiabatic_exp.py b/OMChem/adiabatic_exp.py new file mode 100644 index 0000000..48381fa --- /dev/null +++ b/OMChem/adiabatic_exp.py @@ -0,0 +1,67 @@ +from OMChem.EngStm import EngStm +class AdiabaticExpander(): + counter = 1 + def __init__(self,name='AdiabaticExpander', eff = None): + self.eff = eff + 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 = 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 + AdiabaticExpander.counter += 1 + + def getname(self): + return self.name + + def connect(self,InputStms = None,OutputStms = None): + self.InputStms = InputStms + self.OutputStms = OutputStms + + def modesList(self): + return ["pressDrop","outP","genPow"] + + def paramgetter(self,mode="pressDrop"): + self.mode = mode + dict = {"eff":None,self.mode:None,"thermoPackage":None} + return dict + + def paramsetter(self,dict): + self.eff = dict['eff'] + self.modeVal = dict[self.mode] + + def OM_Flowsheet_Init(self, addedcomp): + self.OM_data_init = '' + self.OM_data_init = self.OM_data_init + 'Simulator.Streams.Energy_Stream '+self.EngStms.name+';\n' + self.OM_data_init = self.OM_data_init + ("model adiaComp"+str(self.count)+"\n") + self.OM_data_init = self.OM_data_init + ("extends Simulator.Unit_Operations.Adiabatic_Expander;\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 adiaComp"+str(self.count)+";\n") + comp_count = len(addedcomp) + self.OM_data_init = self.OM_data_init + ( + "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("'", "") + self.OM_data_init = self.OM_data_init + comp + ("},")+("eff="+self.eff+");\n") + return self.OM_data_init + + def OM_Flowsheet_Eqn(self, addedcomp): + self.OM_data_eqn = '' + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.InputStms[0].name + '.outlet,' + self.name + '.inlet' + ');\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.name + '.outlet,' + self.OutputStms[0].name + '.inlet);\n') + self.OM_data_eqn = self.OM_data_eqn + ('connect(' + self.EngStms.name + '.outlet,' + self.name + '.energy);\n') + + self.OM_data_eqn = self.OM_data_eqn + (self.name+'.'+self.mode+'='+ self.modeVal + ';\n') + + return self.OM_data_eqn + diff --git a/OMChem/setup.py b/OMChem/setup.py new file mode 100644 index 0000000..037da1c --- /dev/null +++ b/OMChem/setup.py @@ -0,0 +1,54 @@ +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + +from subprocess import call +import sys +import os +# Python 3.3 offers shutil.which() +from distutils import spawn + +def warningOrError(errorOnFailure, msg): + if errorOnFailure: + raise Exception(msg) + else: + print(msg) + +def generateIDL(): + errorOnFailure = not os.path.exists(os.path.join(os.path.dirname(__file__), 'OMPythonIDL', '__init__.py')) + try: + omhome = os.path.split(os.path.split(os.path.realpath(spawn.find_executable("omc")))[0])[0] + except: + omhome = None + omhome = omhome or os.environ.get('OPENMODELICAHOME') + + if omhome is None: + warningOrError(errorOnFailure, "Failed to find OPENMODELICAHOME (searched for environment variable as well as the omc executable)") + return + idl = os.path.join(omhome,"share","omc","omc_communication.idl") + if not os.path.exists(idl): + warningOrError(errorOnFailure, "Path not found: %s" % idl) + return + + if 0 is not call(["omniidl","-bpython","-Wbglobal=_OMCIDL","-Wbpackage=OMPythonIDL",idl]): + warningOrError(errorOnFailure, "omniidl command failed") + return + print("Generated OMPythonIDL files") +generateIDL() + +setup(name='OMPython', + version='2.0.7', + description='OpenModelica-Python API Interface', + author='Anand Kalaiarasi Ganeson', + author_email='ganan642@student.liu.se', + maintainer='Adeel Asghar', + maintainer_email='adeel.asghar@liu.se', + license="BSD, OSMC-PL 1.2, GPL (user's choice)", + url='http://openmodelica.org/', + packages=['OMPython', 'OMPython.OMParser', 'OMPythonIDL', 'OMPythonIDL._OMCIDL', 'OMPythonIDL._OMCIDL__POA'], + install_requires=[ + # 'omniORB', # Required, but not part of pypi + 'pyparsing' + ] +) |