Created
November 10, 2020 12:40
-
-
Save andr1976/1a2c86dfb8a00f8acd759590244c55ea to your computer and use it in GitHub Desktop.
Using DWSIM Standalone Thermodynamics Library in Python with Python.NET - Peng-Robinson
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import clr, array | |
| from System import String, Double, Array, Reflection, Exception | |
| dtlpath = "C:\\Users\name\\Folder\\" | |
| clr.AddReference(dtlpath + "DWSIM.Thermodynamics.StandaloneLibrary.dll") | |
| from DWSIM.Thermodynamics import Streams, PropertyPackages, CalculatorInterface | |
| from DWSIM.Interfaces.Enums import FlashCalculationType | |
| #from DWSIM.Thermodynamics.PropertyPackages.Auxiliary.FlashAlgorithms import * | |
| import CapeOpen | |
| dtlc = CalculatorInterface.Calculator() | |
| print(String.Format("DTL version: {0}", Reflection.Assembly.GetAssembly(dtlc.GetType()).GetName().Version)) | |
| print() | |
| dtlc.Initialize() | |
| #nrtl = PropertyPackages.NRTLPropertyPackage(True) | |
| pr = PropertyPackages.PengRobinsonPropertyPackage(True) | |
| dtlc.TransferCompounds(pr) | |
| T = 94+273.15 #K | |
| P = 25*101325.0 #Pa | |
| carray = Array[String](["Water", "Methane", "Propane", "Isobutane", "N-butane", "N-decane"]) | |
| comparray = Array[Double]([0.2, 0.2, 0.1, 0.1, 0.1, 0.3]) | |
| #result2 = dtlc.PTFlash(pr,3,P,T,carray,comparray) | |
| ms = dtlc.CreateMaterialStream(carray, comparray) | |
| print ("Calculating Material Stream Phase Equilibria and Properties at T = " + str(T) + " K and P = " + str(P) + " Pa") | |
| #print ("Mass Flow = 1000 kg/s") | |
| ms.SetPropertyPackage(pr) | |
| ms.SetPressure(P) | |
| ms.SetTemperature(T) | |
| ms.SetMolarFlow(1.0) # mol/s | |
| #nlvlle=NestedLoops #Immiscible | |
| #nlvlle.StabSearchCompIDs = String(r"Water") | |
| #nlvlle.StabSearchSeverity = 0 | |
| #ms.FlashAlgorithm = nlvlle | |
| ms.SetFlashSpec("PT") | |
| ms.Calculate() | |
| vapordensity = ms.GetPhase("Vapor").Properties.density | |
| print("Vapor Phase Density: " + str(vapordensity) + " kg/m3") | |
| print("Vapour molecular weight: " + str(ms.GetPhase("Vapor").Properties.molecularWeight)+ " kg/kmole") | |
| liquiddensity = ms.GetPhase("Liquid1").Properties.density | |
| print("Liquid1 Phase Density: " + str(liquiddensity) + " kg/m3") | |
| print("Liquid1 molecular weight: " + str(ms.GetPhase("Liquid1").Properties.molecularWeight) + " kg/kmole") | |
| liquid2density = ms.GetPhase("Liquid2").Properties.density | |
| print("Liquid 2 Phase Density: " + str(liquid2density) + " kg/m3") | |
| print("Liquid2 molecular weight: " + str(ms.GetPhase("Liquid2").Properties.molecularWeight) + " kg/kmole") | |
| for comp in ms.GetPhase("Overall").Compounds.Values: | |
| print(comp.ConstantProperties.Name + " Overall Molar Flow: " + str(comp.MolarFlow) + " mol/s") | |
| vaporflow = ms.GetPhase("Vapor").Properties.molarflow | |
| print("Vapor Phase Molar Flow: " + str(vaporflow) + " mol/s") | |
| liquidflow = ms.GetPhase("Liquid1").Properties.molarflow | |
| print("Liquid Phase Molar Flow: " + str(liquidflow) + " mol/s") | |
| liquid2flow = ms.GetPhase("Liquid2").Properties.molarflow | |
| print("Liquid Phase Molar Flow: " + str(liquid2flow) + " mol/s") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Anders!