usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
193 stars 127 forks source link

Trouble with generating ouput in the desired units [REFPROP for Python] #486

Closed p-widi closed 1 year ago

p-widi commented 2 years ago

Hello,

I have a model (python) that relies on REFPROP to caclulate thermodynamic states of pure fluids & (not predefined) mixtures. Since I keep getting outputs that do not coincide with the respective outputs of the REFPROP GUI, I tried to build a small example that illustrates my problem.

I want the following units for inputs/outputs:

Input property combinations that are particularly important for my model: "TQ", "PQ", "PS", "HP" In my model, I tweeked the REFPROP flags in a way that REFPROP gives me some output. However, depending on the input properties this output can deviate a little or even a lot from the GUI output (GUI also set to NBP reference state).

For this example set the Flags so that, according to the REFPROP docs, I would yield output in the desired units. Unfortunately this results in NaN output (see below).

Am I doing something wrong? Did anybody experience similar problems? Any help is much appreciated!

import os
import numpy as np
import pandas as pd
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

mixture = ["hexane", "1BUTENE", .4]
mixture_str = ";".join(mixture[:2])

comp = 2
comp_molar = [mixture[2], 1.-mixture[2]]

os.environ['RPPREFIX'] = r'C:/Program Files (x86)/REFPROP'
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])
RP.SETREFdll("NBP", comp, comp_molar, -1, -1, -1, -1)  # -1 is placeholder
# print(RP.RPVersion())

T_1 = 309.1705 # [K]
q_1 = 1. # [kg/kg]

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

mixture_str = ";".join(mixture[:2])
hIn_loc = "TQ"
hOut_loc = "hs"
iUnits_loc = MASS_BASE_SI
iMass_loc = 2
iFlag_loc = 202
a_loc = T_1
b_loc = q_1
z_loc = comp_molar

print("REFPROP input parameters:", mixture_str, ",", hIn_loc, ",", hOut_loc, ",", iUnits_loc, ",", iMass_loc, ",", iFlag_loc, ",", a_loc, ",", b_loc, ",", z_loc)

RP_result = RP.REFPROPdll(hFld=mixture_str, hIn=hIn_loc, hOut=hOut_loc, iUnits=iUnits_loc, iMass=iMass_loc, iFlag=iFlag_loc, a=a_loc, b=b_loc, z=z_loc)
RP_output = RP_result.Output

print(RP_output)

The output of this script is:

REFPROP input parameters: hexane;1BUTENE , TQ , hs , 21 , 2 , 202 , 309.1705 , 1.0 , [0.4, 0.6] array('d', [-9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0, -9999990.0])

p-widi commented 2 years ago

EDIT:

I see in fact there are quite some people experiencing this bug. The recommendation by @ianhbell is to use molar input compositions - however, I am already doing that.

ianhbell commented 2 years ago

What is your ierr? It seems your mixture doesn't load properly.

p-widi commented 2 years ago

Thank you for commenting! In the meantime, I was able get the script working.

If I remember correctly, calling SETFLUIDSdll() previously to REFPROPdll() and setting "QMASS" in hOut did the trick.