Created
November 6, 2020 20:02
-
-
Save DanWBR/4a803cf325ae89a2663d9cdd0e8a61a2 to your computer and use it in GitHub Desktop.
Using DWSIM Standalone Thermodynamics Library in Python with Python.NET (High-Level API + Material Stream calls)
This file contains 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.IO import Directory, Path, File | |
from System import String, Double, Array, Reflection, Exception | |
dtlpath = "C:\\Users\\Daniel\\Source\\Repos\\DanWBR\\dwsim6\\DistPackages\\DTL\\" | |
clr.AddReference(dtlpath + "DWSIM.Thermodynamics.StandaloneLibrary.dll") | |
from DWSIM.Thermodynamics import Streams, PropertyPackages, CalculatorInterface | |
from DWSIM.Interfaces.Enums import FlashCalculationType | |
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) | |
dtlc.TransferCompounds(nrtl) | |
T = 355.0 #K | |
P = 101325.0 #Pa | |
carray = Array[String](["Water", "Ethanol"]) | |
comparray = Array[Double]([0.5, 0.5]) | |
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, Water Molar Fraction = 0.5, Ethanol Molar Fraction = 0.5") | |
ms.SetPropertyPackage(nrtl) | |
ms.SetPressure(P) | |
ms.SetTemperature(T) | |
ms.SetMassFlow(1000.0) # kg/s | |
ms.SetFlashSpec("PT") | |
ms.Calculate() | |
print() | |
vaporflow = ms.GetPhase("Vapor").Properties.massflow | |
print("Vapor Phase Mass Flow: " + str(vaporflow) + " kg/s") | |
vapordensity = ms.GetPhase("Vapor").Properties.density | |
print("Vapor Phase Density: " + str(vapordensity) + " kg/m3") | |
print() | |
liquidflow = ms.GetPhase("Liquid1").Properties.massflow | |
print("Liquid Phase Mass Flow: " + str(liquidflow) + " kg/s") | |
liquiddensity = ms.GetPhase("Liquid1").Properties.density | |
print("Liquid Phase Density: " + str(liquiddensity) + " kg/m3") | |
print() | |
for comp in ms.GetPhase("Overall").Compounds.Values: | |
print(comp.ConstantProperties.Name + " Overall Molar Flow: " + str(comp.MolarFlow) + " mol/s") | |
print() | |
for comp in ms.GetPhase("Vapor").Compounds.Values: | |
print(comp.ConstantProperties.Name + " Molar Flow in Vapor Phase: " + str(comp.MolarFlow) + " mol/s") | |
print() | |
for comp in ms.GetPhase("Liquid1").Compounds.Values: | |
print(comp.ConstantProperties.Name + " Molar Flow in Liquid Phase: " + str(comp.MolarFlow) + " mol/s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: