Phases in javascript coolprop

125 views
Skip to first unread message

Bart de Waal

unread,
Aug 27, 2021, 5:28:51 AM8/27/21
to coolprop-users
Hi,

I'm using the javascript/wasm version of coolprop.

Whenever I need a phase, I get a number.
Is it possible to change these to text using the javascript/wasm version?
Or even better, is there somewhere in the documentation where all phases are listed with the associated number? I would hope this is stable between versions.

I tried to find this in the documentation, but I couldn't find a listing or a function that works with the wasm library I found.

Kind Regards,

Bart de Waal

Ian Bell

unread,
Aug 30, 2021, 12:38:54 PM8/30/21
to coolpro...@googlegroups.com
There is the PhaseSI function, also methods for programmatic lookup of phase enumerated values

--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coolprop-users/61ddee0a-3f08-465c-8732-289c15e8bad8n%40googlegroups.com.

Ian Bell

unread,
Aug 30, 2021, 4:59:32 PM8/30/21
to coolpro...@googlegroups.com
Like these ones:

import CoolProp
print(CoolProp.CoolProp.get_phase_index('phase_gas'))
print(CoolProp.CoolProp.get_phase_index('phase_liquid'))
print(CoolProp.CoolProp.get_phase_index('phase_supercritical_gas'))

yielding

5
0
2

You should not rely on the values staying fixed, rather you should look up the enumerated values at the beginning of your script.

David Contreras

unread,
Dec 17, 2021, 11:09:42 AM12/17/21
to coolprop-users
I had to do some reverse engineering and found the following corresponding values.

const phases = ["liquid", "supercritical","supercritical_gas", "supercritical_liquid","critical_point","gas", "twophase",
"unknown", "not_imposed"]

Then made some function like this to convert the number to the correct string.

function phaseSI(prop1, value1, prop2, value2, fluid){
return phases[Module.PropsSI('Phase', prop1, value1, prop2, value2, fluid)]
}

Ian Bell

unread,
Dec 18, 2021, 11:36:05 AM12/18/21
to coolpro...@googlegroups.com
Did you see the code I posted above? That is how you should approach it.  The numerical codes are not guaranteed to be stable.

--
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-user...@googlegroups.com.

David Contreras

unread,
Dec 19, 2021, 1:08:25 PM12/19/21
to coolprop-users
I did validate with this python code:

import CoolProp as cp

phases =  ["liquid", "supercritical","supercritical_gas", "supercritical_liquid","critical_point","gas", "twophase",
               "unknown", "not_imposed"]

for phase in phases:
  print(cp.CoolProp.get_phase_index('phase_'+phase))
And this was the result:
0 1 2 3 4 5 6 7 8

Maybe a better way could be to have phases as a dictionary instead of a list.
phases = {0:"liquid", 1:"supercritical", 2:"supercritical_gas", 3:"supercritical_liquid", 4:"critical_point", 5:"gas", 6:"twophase",
               7:"unknown", 8:"not_imposed"}

Ian Bell

unread,
Dec 19, 2021, 7:17:46 PM12/19/21
to coolpro...@googlegroups.com
You might want to consider adding an accessor to get_global_param_string to get the list of phases like is done for parameters: https://github.com/CoolProp/CoolProp/blob/71a82276ffd1d19bc886b0377b9838468ef0ace2/src/CoolProp.cpp#L989

David Contreras

unread,
Dec 30, 2021, 5:16:15 PM12/30/21
to coolprop-users
Hi, I recently made an example function that works with units.

Please take a look.

Ian Bell

unread,
Dec 30, 2021, 6:57:29 PM12/30/21
to coolpro...@googlegroups.com
Nice work! Want to add a link to the main page?

David Contreras

unread,
Dec 31, 2021, 8:20:49 PM12/31/21
to coolprop-users
Yes, that would be nice!

Naveed Ullah

unread,
Jan 3, 2022, 12:20:15 AM1/3/22
to coolpro...@googlegroups.com
Hi Mr Ian Bell
I'm master student and new to coolprop user
can you help me resolving the problem regarding attached errors
image.png

Ian Bell

unread,
Jan 3, 2022, 5:12:59 AM1/3/22
to coolpro...@googlegroups.com
This is not the place to ask this question.   Please create a new thread,  or open an issue on github. 

Reply all
Reply to author
Forward
0 new messages