Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dll inconsistent response #653

Open
hugo-cwp opened this issue Feb 6, 2024 · 4 comments
Open

dll inconsistent response #653

hugo-cwp opened this issue Feb 6, 2024 · 4 comments

Comments

@hugo-cwp
Copy link

hugo-cwp commented Feb 6, 2024

Description

When running RP.SETFLUIDSdll and RP.REFPROPdll I occasionally receive a -101 error. I resolved repeating the query for that case alone, which solves the issue (I have never received -101 twice in a row).

I am unsure about the reason for the error. At any rate it should not fail once and then work, in my opinion. Details below.

Workaround for RP.SETFLUIDSdll:

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary,get_default_DLL_extension,REFPROPInstance

RP_PATH = os.path.join(os.path.dirname(__file__), '..','resources','REFPROP')
extension=get_default_DLL_extension()
RP = REFPROPFunctionLibrary(RP_PATH,extension)
RP.SETPATHdll(RP_PATH)

loaded_fluids=[]

def check_fluid(fluid:str):
    fluid=fluid.upper()
    global loaded_fluids
    if fluid is None:
        raise ValueError('❌ No fluid specified')
    if fluid not in loaded_fluids:
        # check if fluid is known
        ierr=RP.SETFLUIDSdll(fluid.upper())
        if ierr != 0:
            if ierr == -101: # try again. For some reason trying twice does the trick
                ierr=RP.SETFLUIDSdll(fluid.upper())
            if ierr != 0:
                # throw error
                errmsg=RP.ERRMSGdll(ierr)
                raise ValueError(f'❌ Fluid {fluid} not found in REFPROP FLD files. Error code: {ierr}: {errmsg}')
        else:
            loaded_fluids.append(fluid)
            print(f'✅ Fluid {fluid} loaded in REFPROP')
            return True
    else:
        return True

Workaround for RP.REFPROPdll:

    def get_prop(self,RP_input:str,RP_output:str,a,b,units=0):
        property=0
        hFld=';'.join([key for key in self.species_dict])
        z=[self.species_dict[key] for key in self.species_dict]
        result=refprop_ops.RP.REFPROPdll(hFld,RP_input,RP_output,units,0,0,a,b,z)
        if result.ierr==-101:
            # retry, sometimes REFPROPdll fails
            result=refprop_ops.RP.REFPROPdll(hFld,RP_input,RP_output,units,0,0,a,b,z)

Steps to Reproduce

Use the functions defined above

Expected behavior: ierr = 0 first try

Actual behavior: ierr = 101 --> ierr = 0

Versions

REFPROP Version: 10.0
Operating System and Version: Windows 10.022631 and Linux
Access Method: Python

Additional Information

@ianhbell
Copy link
Contributor

ianhbell commented Feb 6, 2024

This is a bug in REFPROP. You should receive the same error message the second time too.

@hugo-cwp
Copy link
Author

Well I checked again and it's consistently returning -101 then 0. Can I still trust the result of my second query? Thanks

@ianhbell
Copy link
Contributor

No, it is a bug. You should in principle get -101 for the second call too.

@ianhbell ianhbell added the bug label May 31, 2024
@ianhbell ianhbell transferred this issue from usnistgov/REFPROP-wrappers May 31, 2024
@ianhbell
Copy link
Contributor

Can you give me an example that gives -101 for the error code? I can't reproduce on my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants