can I set the reference state when using REFPROP?

157 views
Skip to first unread message

Arjan van Mulukom

unread,
May 24, 2018, 10:12:57 AM5/24/18
to coolprop-users
I tried this in C# and in Python, in both cases did not manage to set the reference state.

Here's the python code to reproduce (I took the reference state example code from the CoolProp site).

If I take HEOS as the backend, As1 and As2 report different enthalpies, as expected since As2 now has NBP as the reference state:

HEOS 28796.289384 -390261.44371

If I use REFPROP, both enthalpies are the same, the NBP reference state is not set:

REFPROP 28796.2893841 28796.2893841

Am I doing something wrong?

Using REFPROP 9.1 and CoolProp 6.1.1.DEV

fluid = 'Water';
backend = 'REFPROP';

# This one doesn't see the change in reference state
AS1 = CoolProp.AbstractState(backend,fluid);

AS1.update(CoolProp.QT_INPUTS, 0, 280);

CoolProp.CoolProp.set_reference_state(backend + '::' + fluid,'NBP')

# This one gets the update in the reference state
AS2 = CoolProp.AbstractState(backend,fluid);

AS2.update(CoolProp.QT_INPUTS, 0, 280);

print backend, AS1.hmass(), AS2.hmass()



Ian Bell

unread,
May 26, 2018, 8:26:01 PM5/26/18
to coolpro...@googlegroups.com
Hmm...  That should work, and at one point, did.  But I suspect the problem is that the second call doesn't result in a call to setup because the state is the same, and therefore, the cached values are used. You could make this work by doing a call with another fluid in between to force a call to SETUPdll of REFPROP. 

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
Visit this group at https://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.

Ian Bell

unread,
May 28, 2018, 1:00:56 PM5/28/18
to coolpro...@googlegroups.com
Any luck with this?

To post to this group, send email to coolpro...@googlegroups.com.

Arjan van Mulukom

unread,
May 31, 2018, 1:38:45 AM5/31/18
to coolprop-users
No, no luck.

I don't think setting the reference state for REFPROP works at all.

This simple example should yield different values for different reference states, shouldn't it? But always returns the same value. It works for 'HEOS::D2O', not for 'REFPROP::D2O'.

import CoolProp.CoolProp as CP

# change the reference state here to IIR or DEF or ASH to see if the values change
ref = 'NBP'; # or ASH, IIR, DEF

CP.set_reference_state('REFPROP::D2O'ref);

# Should be zero (or very close to it)
print CP.PropsSI('H', 'T', 300, 'P', 1E5, 'REFPROP::D2O');


-313177.846288

Any luck with this?

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.

Ian Bell

unread,
Jun 12, 2018, 10:41:07 PM6/12/18
to coolpro...@googlegroups.com
What about if you call the setting of reference state method for the class?  REFPROP works in a "funny" way with setting reference states. I think the way it is handled in CoolProp is much cleaner.  And I have ideas to make it even cleaner.

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Henry Spindler

unread,
Jun 25, 2020, 5:20:43 PM6/25/20
to coolprop-users
I'm not sure what "calling the setting of reference state method for the class" means.


I'm having similar issues.  I would like to use the "Type 2" approach to change the reference state of a REFPROP fluid (see bottom of http://www.coolprop.org/apidoc/CoolProp.CoolProp.html):

CoolProp.CoolProp.set_reference_state(string FluidName*args)

Accepts one of two signatures:

Type #1 (A Python wrapper of CoolProp::set_reference_stateS()):

set_reference_state(FluidName,reference_state)

FluidName The name of the fluid param reference_state The reference state to use, one of


IIR
(h=200 kJ/kg, s=1 kJ/kg/K at 0C sat. liq.)
ASHRAE
(h=0,s=0 @ -40C sat liq)
NBP
(h=0,s=0 @ 1.0 bar sat liq.)

Type #2 (A Python wrapper of CoolProp::set_reference_stateD()):

set_reference_state(FluidName,T0,rho0,h0,s0)

FluidName The name of the fluid

T0 The temperature at the reference point [K]

rho0 The density at the reference point [kg/m^3]

h0 The enthalpy at the reference point [J/kg]

s0 The entropy at the reference point [J/kg]


Sample Code:
---------------------------------

from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
import CoolProp as CP

T= 25+273.15 #K
P= 1e5 #Pa

backend='HEOS'
fluid='CO2'

print("Use CoolProp:")
backend='HEOS'
print(f"Default Molar Enthalpy {CP.CoolProp.PropsSI('Hmolar', 'T', T, 'P', 1e5, backend+'::'+fluid):,.1f} J/mol")
Dmolar=CP.CoolProp.PropsSI("Dmolar", "T", T, "P", 1e5,  backend+'::'+fluid)
CP.CoolProp.set_reference_state(fluid, T, Dmolar, -393510,213.74) # fluid, T, D (mol/m^3), h (J/mol), s (J/mol/K)
print(f"Adjusted Molar Enthalpy {CP.CoolProp.PropsSI('Hmolar', 'T', T, 'P', 1e5,  backend+'::'+fluid):,.1f}, J/mol")

print()
print("Use REFPROP:")
backend='REFPROP'

print(f"Default Molar Enthalpy {CP.CoolProp.PropsSI('Hmolar', 'T', T, 'P', 1e5,  backend+'::'+fluid):,.1f} J/mol")
Dmolar=CP.CoolProp.PropsSI("Dmolar", "T", T, "P", 1e5, backend+'::'+fluid)
CP.CoolProp.set_reference_state("CO2", T, Dmolar, -393510,213.74) # fluid, T, D (mol/m^3), h (J/mol), s (J/mol/K)
print(f"Adjusted Molar Enthalpy {CP.CoolProp.PropsSI('Hmolar', 'T', T, 'P', 1e5,  backend+'::'+fluid):,.1f}, J/mol")
print()


CP.CoolProp.set_reference_state(backend+'::'+fluid, T, Dmolar, -393510,213.74) # fluid, T, D (mol/m^3), h (J/mol), s (J/mol/K)
print(f"Adjusted Molar Enthalpy {CP.CoolProp.PropsSI('Hmolar', 'T', T, 'P', 1e5,  backend+'::'+fluid):,.1f}, J/mol")
print()


----------------
First section runs fine; reference is changed.
Second section runs, but does not change reference state.
Third section fails with error:
RuntimeError: key [REFPROP::CO2] was not found in string_to_index_map in JSONFluidLibrary
How can this be properly addressed?

Finally, if you look up the description of CoolProp::set_reference_stateD(), it seems to expect molar inputs, rather than the mass-based inputs above.  Which is correct?

Thanks!




Ian Bell

unread,
Jun 28, 2020, 10:54:59 AM6/28/20
to coolpro...@googlegroups.com
The inputs for set_reference_stateD are indeed molar inputs, no idea how mass-inputs snuck in there.  As you can see from the C++ function:  https://github.com/CoolProp/CoolProp/blob/master/src/CoolProp.cpp#L949 .  Fixed in https://github.com/CoolProp/CoolProp/commit/e2b8d104b7bba71fc4dd77602c689ae0b502679f

The second approach is currently only supported for the internal backend, but not for REFPROP.  You are welcome to add that functionality with a pull request.

Jesse Gohl

unread,
Aug 21, 2024, 12:30:24 PM8/21/24
to coolprop-users

Am I misunderstanding how the `set_reference_state` method works or missing a step to use it correctly?

The example from the user's guide (http://www.coolprop.org/coolprop/HighLevelAPI.html#reference-states) works as expected (meaning I get the expected specific enthalpy of the specified reference state):


In [4]: CP_CP.set_reference_state('n-Propane', 'ASHRAE')

 

In [5]: CP_CP.PropsSI('H','T', 233.15, 'Q', 0, 'n-Propane')

Out[5]: -4.88073098973112e-12

 

In [6]: CP_CP.set_reference_state('n-Propane', 'DEF')

 

In [7]: CP_CP.PropsSI('H','T', 233.15, 'Q', 0, 'n-Propane')

Out[7]: 105123.27213761563


But if I use the REFPROP fluid I do not:

In [1]: import CoolProp.CoolProp as CP_CP

 

In [2]: CP_CP.set_reference_state('REFPROP::PROPANE', 'ASHRAE')

 

In [3]: CP_CP.PropsSI('H','T', 233.15, 'Q', 0, 'REFPROP::PROPANE')

Out[3]: 105123.38853908639


Can someone shed some light on what I'm doing wrong, or misunderstanding?


Thanks,

Jesse

Ian Bell

unread,
Aug 21, 2024, 6:00:49 PM8/21/24
to coolpro...@googlegroups.com
You need to use the low-level interface with REFPROP to set reference states: http://coolprop.org/coolprop/LowLevelAPI.html#reference-states

Jesse Gohl

unread,
Aug 22, 2024, 8:00:01 AM8/22/24
to coolprop-users
Hi Ian,

thanks for the response.  I tried the following but still don't get the expected result:

In [1]: import CoolProp

In [2]: CoolProp.CoolProp.set_reference_state('REFPROP::PROPANE', 'ASHRAE')

In [3]: AS4 = CoolProp.AbstractState('REFPROP','PROPANE')

In [4]: AS4.update(CoolProp.QT_INPUTS, 0, 233.15)

In [5]: AS4.hmass()
Out[5]: 105123.38853908639

But I've again confirmed it works if I replace REFPROP with HEOS:

In [6]: CoolProp.CoolProp.set_reference_state('HEOS::PROPANE', 'ASHRAE')

In [7]: AS2 = CoolProp.AbstractState('HEOS','PROPANE')

In [8]: AS2.update(CoolProp.QT_INPUTS, 0, 233.15)

In [9]: AS2.hmass()
Out[9]: -4.88073098973112e-12

Thanks,
Jesse

Ian Bell

unread,
Aug 22, 2024, 4:10:12 PM8/22/24
to coolpro...@googlegroups.com
I think maybe setting reference states doesn't work with REFPROP backend. That's a pity, but someone else will need to debug.

Jesse Gohl

unread,
Aug 22, 2024, 4:30:28 PM8/22/24
to coolprop-users
Ok, I understand.  Thanks for the confirmation.  Should I post a ticket on the GitHub issue tracker?

Thanks,
Jesse

Ian Bell

unread,
Aug 22, 2024, 8:51:43 PM8/22/24
to coolpro...@googlegroups.com
Yes, please do that. And try to find someone to look into fixing it.

Reply all
Reply to author
Forward
0 new messages