usnistgov / REFPROP-issues

A repository solely used for reporting issues with NIST REFPROP
26 stars 13 forks source link

REFPROPdll changes composition in python wrapper. #644

Open Akwiatkowski-eng opened 1 year ago

Akwiatkowski-eng commented 1 year ago
import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])

MASS_BASE_SI = RP.GETENUMdll(0,"MASS BASE SI").iEnum
RP.FLAGSdll("PR", 2)

iMass = 1
iUnits = 21

composition_mix = [0.2, 0.8]
medium_mix = "R14 * R23"

composition_ref = [0.44, 0.52, 0.04]
medium_ref = "R125 * R143a * R134a"

p_H = 22.2*10**5
p_L = 1.39*10**5

T_H_in = 293 
T_C_in_guess = 273-40 
T_H_out = 273-35 

composition_ref_list = []
composition_mix_list = []

punkt_H_in = RP.REFPROPdll(medium_mix,"PT","H",iUnits,iMass,0,p_H,T_H_in,composition_mix)
print(punkt_H_in.z)
i_H_in = punkt_H_in.Output[0]
punkt_H_out = RP.REFPROPdll(medium_mix,"PT","H",iUnits,iMass,0,p_H,T_H_out,composition_mix)
print(punkt_H_out.z)

punkt_C_in = RP.REFPROPdll(medium_ref,"PT","H",iUnits,iMass,0,p_L,T_C_in_guess,composition_ref)
i_C_in = punkt_C_in.Output[0]
print(composition_ref)
print(punkt_C_in.z)

Description

Hello I noticed that REFPROPdll randomly changes mixture composition. It does not happen every single time, but I think the more times fucntion is called the more bugs occurs. I tried to debug it, but it the composition "z" is forwarded properly to the function, and the ctypes conversion also seems to be correct. It looks like something happens inside dll itself.

Steps to Reproduce

Please run the code and observe the printouts

Expected behavior: Composition used should not change

Actual behavior: Composition changes inside the function

Versions

REFPROP Version: [REFPROP dll version 10.0]
Operating System and Version: [Windows 10]
Access Method: Python via ctREFPROP]

Additional Information

Exemplary output: obraz

To "punkt_H_in" and "punkt_H_out" the same mixture and compositon is handed. However the output composition does not match in first case and it match in the second one.

Is there any solution or can it be somehow worked around? Thank you for your help. Adrian

Akwiatkowski-eng commented 1 year ago

It seems to be working properly when iMass flag is set to 2.

ianhbell commented 1 year ago

There are some bugs with mass-based composition. Always use mole compositions and things will work better.

Also, make sure you don't hard-code the iUnits

Akwiatkowski-eng commented 1 year ago

Thank you Ian. Could you please explain what you mean by "hard-coding the iUnits"?

ianhbell commented 1 year ago

You did iUnits = 21, you should only use values coming from GETENUMdll, we might change the enumerated values in the future.