diff options
Diffstat (limited to 'OMChem/Flowsheet.py')
-rw-r--r-- | OMChem/Flowsheet.py | 68 |
1 files changed, 12 insertions, 56 deletions
diff --git a/OMChem/Flowsheet.py b/OMChem/Flowsheet.py index ab4d729..bc218c6 100644 --- a/OMChem/Flowsheet.py +++ b/OMChem/Flowsheet.py @@ -1,8 +1,6 @@ -# from OMPython import OMCSession import os import csv from subprocess import Popen, PIPE -#import subprocess import pandas as pd class Flowsheet(): @@ -14,8 +12,8 @@ class Flowsheet(): 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.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') @@ -63,28 +61,21 @@ class Flowsheet(): self.result_data = [] else: csvpath = os.path.join(self.sim_dir_path,'Flowsheet_res.csv') - print("csvPath",csvpath) with open (csvpath,'r') as resultFile: self.result_data = [] - print("opened") csvreader = csv.reader(resultFile,delimiter=',') for row in csvreader: - print("in reading csvreader") self.result_data.append(row) - print(self.result_data) def send_for_simulation_SM(self,unitop): self.result_data = [] self.omc_path = self.get_omc_path() os.chdir(self.sim_dir_path) - #os.system(self.omc_path + ' -s ' + unitop.name+'.mos') 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 ################") - print(stdout) + # print("############### StdOut ################") + # print(stdout) self.result_data = [] print('Simulating '+unitop.name+'...') csvpath = os.path.join(self.sim_dir_path,unitop.name+'_res.csv') @@ -102,14 +93,10 @@ class Flowsheet(): if property_name in self.result_data[0]: ind = self.result_data[0].index(property_name) resultval = str(self.result_data[-1][ind]) - #resultval = str(omc.sendExpression("val("+unit.name+ "." + value + ", 0.5)")) - print(resultval) unit[0].Prop[key] = resultval def simulate_EQN(self): self.data = [] - print("##################################################") - print("##################################################") self.sim_method = 'Eqn' self.data.append("model Flowsheet\n") @@ -124,7 +111,6 @@ class Flowsheet(): else: self.data.append(unitop.OM_Flowsheet_Initialize(self.compounds)) - self.data.append("equation\n") self.outlist = [] @@ -133,11 +119,9 @@ class Flowsheet(): if unitop.type not in self.stm: for j in unitop.output_stms: self.outlist.append(j) - print(j.name) 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: @@ -160,40 +144,27 @@ class Flowsheet(): self.send_for_simulation_Eqn() - def simulate_SM(self,ip,op): - print("ip op = ", ip, op) self.sim_method = 'SM' self.data = [] self.result_data = [] 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 MaterialStream***************") 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.root_dir) @@ -214,7 +185,6 @@ class Flowsheet(): lcase = c.lower() self.data.append("parameter Simulator.Files.Chemsep_Database." + ucase +' '+ ucase + "; \n") - print("##############compounds added") self.data.append(unitop.OM_Flowsheet_Initialize()) if type(outstms) is list: @@ -223,7 +193,6 @@ class Flowsheet(): else: self.data.append(outstms.OM_Flowsheet_Initialize()) - if engstms: self.data.append(engstms.OM_Flowsheet_Initialize()) @@ -234,18 +203,14 @@ class Flowsheet(): self.data.append(inpstms.OM_Flowsheet_Initialize()) self.data.append('equation\n') - print("##################equation") self.data.append(unitop.OM_Flowsheet_Equation()) if type(inpstms) is list: for stm in inpstms: - #stm.GetEquationValues() self.data.append(stm.OM_Flowsheet_Equation()) else: - #inpstms.GetEquationValues() 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') with open(unitmofile,'w') as unitFile: @@ -262,22 +227,18 @@ class Flowsheet(): mosFile.write("simulate("+unitop.name.lower()+", outputFormat=\"csv\", stopTime=1.0, numberOfIntervals=1);\n") print("Initiating simulation in Sequential Modular Mode") - #self.result_data = [] 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') 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) - print("############### StdOut ################") - print(self.stdout) - print("############### StdErr ################") - print(self.stderr) - print('Simulating '+unitop.name.lower()+'...') + + # 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) @@ -296,8 +257,6 @@ class Flowsheet(): ind = self.result_data[0].index(property_name) resultval = str(self.result_data[-1][ind]) stm.Prop[key] = resultval - #print("input",stm.Prop[key]) - else: for key, value in inpstms.Prop.items(): property_name = inpstms.name + '.' + key @@ -305,7 +264,6 @@ class Flowsheet(): ind = self.result_data[0].index(property_name) resultval = str(self.result_data[-1][ind]) inpstms.Prop[key] = resultval - #print("input",inpstms.Prop[key]) if type(outstms) is list: for stm in outstms: @@ -315,7 +273,6 @@ class Flowsheet(): ind = self.result_data[0].index(property_name) resultval = str(self.result_data[-1][ind]) stm.Prop[key] = resultval - print("output key:",key,"value:",stm.Prop[key]) else: for key, value in outstms.Prop.items(): property_name = outstms.name + '.' + key @@ -323,7 +280,6 @@ class Flowsheet(): ind = self.result_data[0].index(property_name) resultval = str(self.result_data[-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) |