wangye - 2024-03-20

Dear all

I can't run the following the example Daniel provided on (https://gist.github.com/DanWBR/3cb00f7ca112e6bbeca3e986890cef7f), and I get the following error:

Traceback (most recent call last):
  File "f:\C\04vb\testpy\testsDTL2.py", line 41, in <module>
    pval = dtlc.GetCompoundConstProp("Ethanol", prop)
System.NullReferenceException: Object reference not set to an instance of an object.
   在 DWSIM.Thermodynamics.Streams.MaterialStream.get_PropertyPackage()
   在 DWSIM.Thermodynamics.Streams.MaterialStream.GetCompoundConstant(Object props, Object compIds)
   在 DWSIM.Thermodynamics.CalculatorInterface.Calculator.GetCompoundConstProp(String compound, String prop)

Here is my code(modified from dtl_test.py ):

import pythoncom
pythoncom.CoInitialize()

import clr

from System.IO import Directory, Path, File
from System import String, Double, Array, Reflection, Exception

dtlpath = "F:\\C\\04vb\\testpy\\libs\\"

clr.AddReference(dtlpath + "DWSIM.Thermodynamics.StandaloneLibrary.dll")

from DWSIM.Thermodynamics import Streams, PropertyPackages, CalculatorInterface

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

compprops = dtlc.GetCompoundConstPropList()
print("Ethanol constant properties:\n")
for prop in compprops:
    pval = dtlc.GetCompoundConstProp("Ethanol", prop)
    print(prop + "\t" + pval)

print()

My OS: win11
Python version: 3.9
Pythonnet version:3.0.3
DTL version: 8.7.0.0

I would greatly appreciate your assistance in helping me resolve this issue.

Kind regards
wangye

 

Last edit: wangye 2024-03-21