usnistgov / REFPROP-wrappers

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

Equation of State Switching is not working #509

Closed S-Middleton closed 6 months ago

S-Middleton commented 1 year ago

I'm using the python wrapper ctREFPROP. I'm been looking for ways to compare different equations of states but I've run into this problem where the Peng-Robinson equation of state will not activate or deactivate in response to the PREOSdll function call. I'm working on a much larger code but the following illustrates my problem just fine and is taken from another issue.

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

root = os.environ['RPPREFIX']
RP = REFPROPFunctionLibrary(root)
RP.SETPATHdll(root)
RP.FLAGSdll("Cache", 3)

def props(inputs):
    usePR, hOut, key1, val1, key2, val2, hFld, z = inputs
    if usePR:
        RP.PREOSdll(2)  # 2 Use Peng-Robinson equation for all calculations
    else:
        RP.PREOSdll(0)
    RP.SETFLUIDSdll(hFld)
    hIn = key1+key2
    return RP.REFPROPdll('', hIn, hOut, RP.MASS_BASE_SI, 0, 1, val1, val2, z).Output[0]

string = 'REFPROP::NITROGEN[0.80]&HYDROGEN[0.20]'

components = string.split("::")[1].split('&')
fluid_names = [x[0: x.find('[')] for x in components]
fractions = [float(x[x.find('[') + 1: x.find(']')]) for x in components]
hFld = ";".join(fluid_names)

samples_1 = [True, 'H', 'P', 1011620, 'T', 373.15, hFld, fractions]
samples_2 = [False, 'H', 'P', 1011620, 'T', 373.15, hFld, fractions]

print(props(samples_1))
print(props(samples_2))

This is what it prints out for me:

468310.40330816555 468310.40330816555

Also, given that the first run is supposed to use Peng-Robinson and the second run is supposed to use the default model, I'd expect that this would of provided a different answer. I encounter the same lack of action when using FLAGSdll("PR", 2). Along these same lines, is there a general method to determine which equation is applied at a given time. As querying:

    for i in range(len(z)):
        out = RP.REFPROPdll('', 'TP', 'DOI_EOS(' + str(i + 1) + ')', RP.MASS_BASE_SI, 0, 1, val1, val2, z)
        print("Mixture: {}, Equation of state applied ({}): DOI: {}".format(hFld, i, out[2]))

Doesn't provide a different DOI in cases when I am seemingly able to change the EOS: For example, using the SETMODdll function to change to change hcomp="PRT". Has the PREOSdll function been made no longer functional?

ianhbell commented 1 year ago

Please note the docs: https://refprop-docs.readthedocs.io/en/latest/DLL/legacy.html#f/_/PREOSdll

Thus, the call to PREOSdll should be AFTER the call to SETFLUIDSdll