def __init__(self, initScript=None): """Init the flash Init Info: nuLiqphases = 2 nuStreamsIn = 2 """ super(LLStage, self).__init__(initScript) # Create a separator self.innerFlash = innerFlash = Flash.SimpleFlash() self.AddUnitOperation(innerFlash, FLASH) # Create a balance self.innerMixer = innerMixer = Balance.BalanceOp() self.AddUnitOperation(innerMixer, MIX) # Initialize params self.InitializeParameters() # Share the ports directly self.ports_mat_OUT = innerFlash.ports_mat_OUT self.ports_mat_IN = innerMixer.ports_mat_IN # Connect the balance to the separator self.ConnectPorts(MIX, OUT_PORT + str(0), FLASH, IN_PORT)
def PropertiesHandling(): print("""Init PropertiesHandling ++++++++++++++++++++++++++++++""") thAdmin = ThermoAdmin.ThermoAdmin() providers = thAdmin.GetAvThermoProviderNames() print("Thermo providers: ", providers, "\n") if len(providers) < 1: print("Error") return 0 thermo = thAdmin.AddPkgFromName(providers[0], "thCase1", "Peng-Robinson") thAdmin.AddCompound(providers[0], "thCase1", "METHANE") thAdmin.AddCompound(providers[0], "thCase1", "PROPANE") parentFlowsh = Flowsheet.Flowsheet() parentFlowsh.SetThermoAdmin(thAdmin) parentFlowsh.SetThermo(thermo) commonProps = thAdmin.GetCommonPropertyNames(providers[0]) print("Initial common properties: ", commonProps, "\n") suppProps = thAdmin.GetPropertyNames(providers[0]) print("Supported properties: ", suppProps, "\n") flash = Flash.SimpleFlash() parentFlowsh.AddUnitOperation(flash, "myFlash1") portsIn = flash.GetPortNames(MAT | IN) comps = [0.25, 0.25] flash.SetCompositionValues(portsIn[0], comps) flash.GetPort(portsIn[0]).SetPropValue(T_VAR, 273.15, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(P_VAR, 101.325, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(MOLEFLOW_VAR, 10.0, FIXED_V) print("A separator was added, now let's request Viscosity from one of its ports") parentFlowsh.Solve() visc = flash.GetPropValue(portsIn[0], VISCOSITY_VAR) print("Viscosity value = ", visc, ". It is None, because it ain't there :) \n") commonProps = list(commonProps) commonProps.append('Viscosity') print("Now lets set the following as commonProps", commonProps, "\n") # thAdmin.SetCommonPropertyNames(providers[0], commonProps) thAdmin.SetCommonPropertyNames(providers[0], suppProps) commonProps = thAdmin.GetCommonPropertyNames(providers[0]) print("These are the new common properties: ", commonProps, "\n") print("Let's solve again and get viscosity again") flash.GetPort(portsIn[0]).SetPropValue(T_VAR, 300.15, FIXED_V) parentFlowsh.Solve() visc = flash.GetPropValue(portsIn[0], VISCOSITY_VAR) print("Viscosity value = ", visc, "\n") parentFlowsh.CleanUp() thAdmin.CleanUp() print("""PropertiesHandling ++++++++++++++++++++++++++++++""")
def TestSimpleFlash2LPhase(): print("""Init SimpleFlash2LPhase ++++++++++++++++++++++++++++++""") # Set Thermo pkgName = "Peng-Robinson" cmpNames = ("PROPANE", "n-BUTANE", "ISOBUTANE", "n-PENTANE", "WATER") thAdmin = ThermoAdmin.ThermoAdmin() providers = thAdmin.GetAvThermoProviderNames() provider = providers[0] # Should be Virt Mat thCase = 'myTh' thermo = thAdmin.AddPkgFromName(provider, thCase, pkgName) for i in cmpNames: thAdmin.AddCompound(provider, thCase, i) # Load vals flash = Flash.SimpleFlash() flash.SetThermoAdmin(thAdmin) flash.SetThermo(thermo) flash.SetParameterValue(NULIQPH_PAR, 2) # Should be NULIQPH_PAR cmps = flash.GetCompoundNames() print('Cmps: ', cmps) portsIn = flash.GetPortNames(MAT | IN) print('Names Ports In: ', portsIn) portsOut = flash.GetPortNames(MAT | OUT) print('Names Ports Out: ', portsOut) flash.SetCompositionValue(portsIn[0], "PROPANE", 0.20) flash.SetCompositionValue(portsIn[0], "n-BUTANE", 0.20) flash.SetCompositionValue(portsIn[0], "ISOBUTANE", 0.20) flash.SetCompositionValue(portsIn[0], "n-PENTANE", 0.20) flash.SetCompositionValue(portsIn[0], "WATER", 0.20) flash.GetPort(portsIn[0]).SetPropValue(T_VAR, 273.15, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(P_VAR, 101.325, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(MOLEFLOW_VAR, 10.0, FIXED_V) print('Return value from Solve()', flash.Solve()) print('') # Print some info in for i in portsIn: comp = flash.GetCompositionValues(i) print('Composition of port in "', i, '":') for j in range(len(comp)): print('fraction of ', cmpNames[j], ': ', comp[j]) print('') print('Some props of port in "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') # Print some info out for i in portsOut: comp = flash.GetCompositionValues(i) print('Composition of port out "', i, '":') for j in range(len(comp)): print('fraction of ', cmpNames[j], ': ', comp[j]) print('') print('Some props of port out "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') print("""Finished SimpleFlash2LPhase ++++++++++++++++++++++++++++++""") flash.CleanUp() thAdmin.CleanUp()
def TestRecycle2(): print("""Init TestRecycle2 ++++++++++++++++++++++++++++++""") # Set Thermo pkgName = "Peng-Robinson" # cmpNames = ("n-HEPTANE", "BENZENE", "TRIETHYLENE GLYCOL") cmpNames = ("PROPANE", "n-BUTANE", "ISOBUTANE", "n-NONANE") thAdmin = ThermoAdmin.ThermoAdmin() providers = thAdmin.GetAvThermoProviderNames() provider = providers[0] # Should be Virt Mat thCase = 'myTh' thermo = thAdmin.AddPkgFromName(provider, thCase, pkgName) for i in cmpNames: thAdmin.AddCompound(provider, thCase, i) # Create a flowsheet to contain all the units flsheet = Flowsheet.Flowsheet() flsheet.SetThermoAdmin(thAdmin) flsheet.SetThermo(thermo) flsheet.SetParameterValue(NULIQPH_PAR, 1) # SetStream stream = Stream.Stream_Material() flsheet.AddUnitOperation(stream, 'Feed') portsIn = stream.GetPortNames(MAT | IN) # I know in advance there's only one port in stream.SetCompositionValue(portsIn[0], "PROPANE", 0.25) stream.SetCompositionValue(portsIn[0], "n-BUTANE", 0.25) stream.SetCompositionValue(portsIn[0], "ISOBUTANE", 0.25) stream.SetCompositionValue(portsIn[0], "n-NONANE", 0.25) stream.GetPort(portsIn[0]).SetPropValue(T_VAR, 360.15, FIXED_V) stream.GetPort(portsIn[0]).SetPropValue(P_VAR, 715.0, FIXED_V) recycle = Stream.Stream_Material() flsheet.AddUnitOperation(recycle, 'Recycle') portsIn = recycle.GetPortNames(MAT | IN) # I know in advance there's only one port in # Set a mixer mixer = Mixer.Mixer() flsheet.AddUnitOperation(mixer, 'Mixer') mixer.SetParameterValue(NUSTIN_PAR, 2) flsheet.ConnectPorts('Feed', 'Out', 'Mixer', 'In0') flsheet.ConnectPorts('Recycle', 'Out', 'Mixer', 'In1') # Set mixed Stream mixed = Stream.Stream_Material() flsheet.AddUnitOperation(mixed, 'Mixed') fixedGuess = FIXED_V | ESTIMATED_V portsIn = mixed.GetPortNames(MAT | IN) # Set Flash UO flash = Flash.SimpleFlash() flsheet.AddUnitOperation(flash, 'Flash') # to start, just guess same as feed flash.SetCompositionValue(portsIn[0], "PROPANE", 0.25, fixedGuess) flash.SetCompositionValue(portsIn[0], "n-BUTANE", 0.25, fixedGuess) flash.SetCompositionValue(portsIn[0], "ISOBUTANE", 0.25, fixedGuess) flash.SetCompositionValue(portsIn[0], "n-NONANE", 0.25, fixedGuess) flash.GetPort(portsIn[0]).SetPropValue(T_VAR, 360.15, fixedGuess) flsheet.ConnectPorts('Mixer', 'Out', 'Mixed', 'In') flsheet.ConnectPorts('Mixed', 'Out', 'Flash', 'In') # Set a splitter splitter = Split.Splitter() flsheet.AddUnitOperation(splitter, 'Splitter') splitter.SetParameterValue(NUSTOUT_PAR, 2) flsheet.ConnectPorts('Flash', 'Liq0', 'Splitter', 'In') splitter.GetPort('Out1').SetPropValue(MOLEFLOW_VAR, 200.0, FIXED_V) splitter.GetPort('Out1').SetPropValue(P_VAR, 715.0, FIXED_V) flash.GetPort('Vap').SetPropValue(MOLEFLOW_VAR, 1652.682, FIXED_V) # close recycle flsheet.ConnectPorts('Splitter', 'Out1', 'Recycle', 'In') # add balance to back calculate flow bal = Balance.BalanceOp() flsheet.AddUnitOperation(bal, 'Balance') bal.SetParameterValue(NUSTIN_PAR + Balance.S_MAT, 2) bal.SetParameterValue(NUSTOUT_PAR + Balance.S_MAT, 1) bal.SetParameterValue('BalanceType', Balance.MOLE_BALANCE) flsheet.ConnectPorts('Balance', 'In1', 'Flash', 'Vap') flsheet.ConnectPorts('Balance', 'In0', 'Splitter', 'Out0') flsheet.ConnectPorts('Balance', 'Out0', 'Feed', 'In') flsheet.Solve() print('***************') cmps = splitter.GetCompositionValues('Out0') for j in range(len(cmps)): print('fraction of ', cmpNames[j], ': ', cmps[j]) print('***************') print('Some properties of splitter Out0') print(T_VAR, ': ', splitter.GetPropValue('Out0', T_VAR)) print(P_VAR, ': ', splitter.GetPropValue('Out0', P_VAR)) print(H_VAR, ': ', splitter.GetPropValue('Out0', H_VAR)) print(MOLEFLOW_VAR, ': ', splitter.GetPropValue('Out0', MOLEFLOW_VAR)) print('Some properties of mixed Out') print(T_VAR, ': ', mixed.GetPropValue('Out', T_VAR)) print(P_VAR, ': ', mixed.GetPropValue('Out', P_VAR)) print(H_VAR, ': ', mixed.GetPropValue('Out', H_VAR)) print(MOLEFLOW_VAR, ': ', mixed.GetPropValue('Out', MOLEFLOW_VAR)) print('Some properties of stream Out') print(T_VAR, ': ', stream.GetPropValue('Out', T_VAR)) print(P_VAR, ': ', stream.GetPropValue('Out', P_VAR)) print(H_VAR, ': ', stream.GetPropValue('Out', H_VAR)) print(MOLEFLOW_VAR, ': ', stream.GetPropValue('Out', MOLEFLOW_VAR)) print('****reset pressure***') # stream.GetPort(portsIn[0]).SetPropValue(P_VAR, 800.0, FIXED_V) stream.GetPort(portsIn[0]).SetPropValue(T_VAR, 400.0, FIXED_V) flsheet.Solve() print('*************** splitter out1') cmps = splitter.GetCompositionValues('Out0') for j in range(len(cmps)): print('fraction of ', cmpNames[j], ': ', cmps[j]) print('***************') print('Some properties of splitter Out0') print(T_VAR, ': ', splitter.GetPropValue('Out0', T_VAR)) print(P_VAR, ': ', splitter.GetPropValue('Out0', P_VAR)) print(H_VAR, ': ', splitter.GetPropValue('Out0', H_VAR)) print(MOLEFLOW_VAR, ': ', splitter.GetPropValue('Out0', MOLEFLOW_VAR)) print("""Finished TestRecycle2 ++++++++++++++++++++++++++++++""") flsheet.CleanUp() thAdmin.CleanUp()
def TestFlowsh2(): import numpy as np np.seterr(all='raise') print("""Init Flowsh2 ++++++++++++++++++++++++++++++""") # Set Thermo pkgName = "Peng-Robinson" cmpNames = ("PROPANE", "n-BUTANE", "ISOBUTANE", "n-PENTANE") thAdmin = ThermoAdmin.ThermoAdmin() providers = thAdmin.GetAvThermoProviderNames() provider = providers[0] # Should be Virt Mat thCase = 'myTh' thermo = thAdmin.AddPkgFromName(provider, thCase, pkgName) for i in cmpNames: thAdmin.AddCompound(provider, thCase, i) # SetStream stream = Stream.Stream_Material() stream2 = Stream.Stream_Material() mixer = Mixer.Mixer() flash = Flash.SimpleFlash() # Add all the units to a flowsheet and connect them flsheet = Flowsheet.Flowsheet() flsheet.AddUnitOperation(flash, 'myFlash1') flsheet.AddUnitOperation(stream, 'myStream1') flsheet.AddUnitOperation(stream2, 'myStream2') flsheet.AddUnitOperation(mixer, 'myMixer') flsheet.SetParameterValue(NULIQPH_PAR, 1) flsheet.SetThermoAdmin(thAdmin) flsheet.SetThermo(thermo) portsIn = stream.GetPortNames(MAT | IN) # I know in advance there's only one port in stream.SetCompositionValue(portsIn[0], "PROPANE", 0.5) stream.SetCompositionValue(portsIn[0], "n-BUTANE", 0.5) stream.SetCompositionValue(portsIn[0], "ISOBUTANE", 0.0) stream.SetCompositionValue(portsIn[0], "n-PENTANE", 0.0) stream.GetPort(portsIn[0]).SetPropValue(T_VAR, 460.15, FIXED_V) stream.GetPort(portsIn[0]).SetPropValue(P_VAR, 715.0, FIXED_V) stream.GetPort(portsIn[0]).SetPropValue(MOLEFLOW_VAR, 3000.0, FIXED_V) # stream.Solve() --- Could be done, but not yet # Set second Stream portsIn = stream2.GetPortNames(MAT | IN) # I know in advance there's only one port in stream2.SetCompositionValue(portsIn[0], "PROPANE", 0.0) stream2.SetCompositionValue(portsIn[0], "n-BUTANE", 0.0) stream2.SetCompositionValue(portsIn[0], "ISOBUTANE", 0.5) stream2.SetCompositionValue(portsIn[0], "n-PENTANE", 0.5) stream2.GetPort(portsIn[0]).SetPropValue(T_VAR, 200.15, FIXED_V) stream2.GetPort(portsIn[0]).SetPropValue(P_VAR, 715.0, FIXED_V) stream2.GetPort(portsIn[0]).SetPropValue(MOLEFLOW_VAR, 3000.0, FIXED_V) # stream.Solve() --- Could be done, but not yet # Set a mixer mixer.SetParameterValue(NUSTIN_PAR, 2) # Set Flash UO # I already know the names of the ports uOpNameOut = 'myStream1' portNameOut = 'Out' uOpNameIn = 'myMixer' portNameIn = 'In0' print('conn', flsheet.ConnectPorts(uOpNameOut, portNameOut, uOpNameIn, portNameIn)) uOpNameOut = 'myStream2' portNameOut = 'Out' uOpNameIn = 'myMixer' portNameIn = 'In1' print('conn2', flsheet.ConnectPorts(uOpNameOut, portNameOut, uOpNameIn, portNameIn)) uOpNameOut = 'myMixer' portNameOut = 'Out' uOpNameIn = 'myFlash1' portNameIn = 'In' print('conn3', flsheet.ConnectPorts(uOpNameOut, portNameOut, uOpNameIn, portNameIn)) flsheet.Solve() portsIn = flash.GetPortNames(MAT | IN) portsOut = flash.GetPortNames(MAT | OUT) # Print some info in for i in portsIn: comp = flash.GetCompositionValues(i) print('Composition of port in "', i, '":') for j in range(len(comp)): print('fraction of ', cmpNames[j], ': ', comp[j]) print('') print('Some props of flash port in "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') # Print some info out for i in portsOut: comp = flash.GetCompositionValues(i) print('Composition of flash port out "', i, '":') for j in range(len(comp)): print('fraction of ', cmpNames[j], ': ', comp[j]) print('') print('Some props of flash port out "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') print("""Now lets add two cmps and delete one ++++++++++++++++++++++++++++++""") thAdmin.AddCompound(provider, thCase, 'n-HEXANE') thAdmin.AddCompound(provider, thCase, 'n-DODECANE') thAdmin.DeleteCompound(provider, thCase, 'n-PENTANE') portsIn = stream.GetPortNames(MAT | IN) stream.SetCompositionValue(portsIn[0], 'n-HEXANE', 0.25) stream.SetCompositionValue(portsIn[0], 'n-DODECANE', 0.25) portsIn = stream.GetPortNames(MAT | IN) stream2.SetCompositionValue(portsIn[0], 'n-HEXANE', 0.3) stream2.SetCompositionValue(portsIn[0], 'n-DODECANE', 0.2) flsheet.Solve() cmps = flash.GetCompoundNames() portsIn = flash.GetPortNames(MAT | IN) portsOut = flash.GetPortNames(MAT | OUT) # Print some info in for i in portsIn: comp = flash.GetCompositionValues(i) print('Composition of flash port in "', i, '":') for j in range(len(comp)): print('fraction of ', cmps[j], ': ', comp[j]) print('') print('Some props of flash port in "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') # Print some info out for i in portsOut: comp = flash.GetCompositionValues(i) print('Composition of flash port out "', i, '":') for j in range(len(comp)): print('fraction of ', cmps[j], ': ', comp[j]) print('') print('Some props of flash port out "', i, '":') print(T_VAR, ': ', flash.GetPropValue(i, T_VAR)) print(H_VAR, ': ', flash.GetPropValue(i, H_VAR)) print(MOLEFLOW_VAR, ': ', flash.GetPropValue(i, MOLEFLOW_VAR)) print('') print("""Finished Flowsh2 ++++++++++++++++++++++++++++++""") flsheet.CleanUp() thAdmin.CleanUp()
def TestThAdminSaveLoad(): print("""Init ThAdminSaveLoad ++++++++++++++++++++++++++++++""") # Set Thermo pkgName = "Peng-Robinson" cmpNames = ("PROPANE", "n-BUTANE", "ISOBUTANE", "n-PENTANE") thAdmin = ThermoAdmin.ThermoAdmin() # saveInfo = thAdmin.GetSaveInfo() # print "saveInfo before doing anything: ", saveInfo, "\n" providers = thAdmin.GetAvThermoProviderNames() provider = providers[0] # Should be Virt Mat thCase = "thCase1" thermo = thAdmin.AddPkgFromName(provider, thCase, pkgName) for i in cmpNames: thAdmin.AddCompound(provider, thCase, i) parentFlowsh = Flowsheet.Flowsheet() parentFlowsh.SetThermoAdmin(thAdmin) parentFlowsh.SetThermo(thermo) flash = Flash.SimpleFlash() parentFlowsh.AddUnitOperation(flash, "myFlash1") portsIn = flash.GetPortNames(MAT | IN) comps = [0.25, 0.25, 0.25, 0.25] flash.SetCompositionValues(portsIn[0], comps) flash.GetPort(portsIn[0]).SetPropValue(T_VAR, 273.15, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(P_VAR, 101.325, FIXED_V) flash.GetPort(portsIn[0]).SetPropValue(MOLEFLOW_VAR, 10.0, FIXED_V) fout = open('myTemp.out', 'w') pickle.dump(parentFlowsh, fout) fout.close() thAdmin.CleanUp() parentFlowsh.CleanUp() del thAdmin del parentFlowsh del flash fout = open('myTemp.out', 'r') parentFlowsh = pickle.load(fout) fout.close() thAdmin = parentFlowsh.GetThermoAdmin() flash = parentFlowsh.GetChildUO("myFlash1") os.remove('myTemp.out') parentFlowsh.Solve() print("Just saved an loaded a flowsheet with a separator. Now solve.. \n") h = flash.GetPropValue('Vap', H_VAR) print("H value = ", h) thCases = thAdmin.GetAvThCaseNames(provider) print("Th cases:", thCases) propPkg = thAdmin.GetPropPkgString(provider, thCases[0]) print("Prop pkg for", str(thCases[0]), ":", propPkg) cmps = thAdmin.GetSelectedCompoundNames(provider, thCases[0]) print("Compounds for", str(thCases[0]), ":", cmps, "\n") parentFlowsh.CleanUp() thAdmin.CleanUp() print("""Finished ThAdminSaveLoad ++++++++++++++++++++++++++++++""")