CoolProp Plot in Julia

How to reproduce this example in Julia:
propane (R-290)

import CoolProp
from CoolProp.Plots import PropertyPlot
plot = PropertyPlot('R290', 'ph')
plot.calc_isolines()
plot.show()

You could try using PyCall.

1 Like

I managed to install in julia 1.5.4 CoolProp.jl

Julia>using CoolProp
[ Info: Precompiling CoolProp [e084ae63-2819-5025-826e-f8e611a84251]

Julia>PropsSI("n-Butane", "rhomolar_critical")
08:46:54->>3922.769612987809

Julia>saturation_ancillary("R410A","I",1,"T", 300)
08:48:38->>0.004877519938463291

Julia>PropsSI("T","P",101325.0,"Q",0.0,"Water")
08:55:35->>373.1242958476844

Julia>PropsSI("T","P",101325.0,"Q",0.0,"Water")
08:56:51->>373.1242958476844

Julia>PropsSI("D", "T", 298.15, "P", 100e5, "CO2")
08:59:15->>817.6273812375758

Using PyCall will I be able to get the graphics? I have searched the Internet for an example developed in Julia. But without results !!!

Julia>ENV["PYCALL_JL_RUNTIME_PYTHON"] = Sys.which("python")
Julia>using PyCall
Julia>pyimport("sys").executable
Julia>@pyimport CoolProp.CoolProp as CP
Julia>mu_w= CP.PropsSI("V","T",273.15+22.0,"P",100,"H2O") # mu [Pa.s], T [K], P [kPa]
15:07:53->>9.613300658014403e-6

So far I have advanced with the installation of CoolProp in Python and make it run within the Julia 1.5.4 environment
Could you guide me to achieve the graphic part of the example shown above

ph_plot = CPP.PropertyPlot("R290", "ph")
ph_plot.calc_isolines();
ph_plot.show()

Julia>ph_plot = CPP.PropertyPlot("R290", "ph")
15:38:19->>PyObject <CoolProp.Plots.Plots.PropertyPlot object at 
With the command, I get a lot of alerts:
Julia>ph_plot.calc_isolines()
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 5554182.916463, -1395.183008 with index (241,): unable to solve 1phase PY flash with Tmin=86.0392, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5194289616 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 5944686.491989, -1395.183008 with index (242,): unable to solve 1phase PY flash with Tmin=86.0754, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5168139473 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 6362645.598741, -1395.183008 with index (243,): unable to solve 1phase PY flash with Tmin=86.1141, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5139955242 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 6809990.580620, -1395.183008 with index (244,): unable to solve 1phase PY flash with Tmin=86.1556, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5109566397 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 7288787.500172, -1395.183008 with index (245,): unable to solve 1phase PY flash with Tmin=86.1999, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [-61.5215 J/mol/K] is below the minimum value of -61.5076786622 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3451904.204494,
6393.882263 with index (234,): unable to solve 1phase PY flash with Tmin=358.414, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 238.143838756 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3694600.736910,
6393.882263 with index (235,): unable to solve 1phase PY flash with Tmin=362.14,
Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 237.549744409 J/mol/K

                                           #*** 
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:608: UserWarning: Please use "calc_sat_range" to calculate saturation and isoquality lines. Input ranges are discarded.

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Plots.py:217: UserWarning: Detected an incomplete phase envelope, fixing
it numerically.
  warnings.warn("Detected an incomplete phase envelope, fixing it numerically.")

I haven’t heard of CoolProps, but if there is a Julia version of it, you presumably don’t need to use PyCall. The reason for suggesting that was probably that you didn’t at first mention that there exists a CoolProps.jl. Without a Julia version or wrapper you would need PyCall.

If you need a Julia plotting library, there are several to choose from, perhaps the most widely used is Plots.jl.

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3451904.204494,
6393.882263 with index (234,): unable to solve 1phase PY flash with Tmin=358.414, Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 238.143838756 J/mol/K
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:655: UserWarning: An error occurred for inputs 3694600.736910,
6393.882263 with index (235,): unable to solve 1phase PY flash with Tmin=362.14,
Tmax=975 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [281.942 J/mol/K] is above the maximum value of 237.549744409 J/mol/K

                                           #*** 
  warnings.warn(
C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Common.py:608: UserWarning: Please use "calc_sat_range" to calculate saturation and isoquality lines. Input ranges are discarded.

C:\Users\hermesr\AppData\Local\Programs\Python\Python38\lib\site-packages\CoolProp\Plots\Plots.py:217: UserWarning: Detected an incomplete phase envelope, fixing
it numerically.
  warnings.warn("Detected an incomplete phase envelope, fixing it numerically.")

I read about the CoolProp.jl package
And I could not install it by following the instructions in the package.
I only got through the “GitHub Desktop”
I show the successful installation:

 [e084ae63] CoolProp v0.0.0 `C:\Users\hermesr\Documents\GitHub\CoolProp.jl#master`

above I show the use of the package
But I have not found help from the package that shows the use of it and handling of the graphics, isolines …
Please could you guide me to achieve the graph shown in Python Plotting

Unfortunately, I know nothing about CoolProps or how to plot with it. But what do you mean by this:

?
Did you install it inside Julia, or some other way? You should install it using the Julia package manager, Pkg. If the installation instructions don’t work, then perhaps you can contact the package author (of the Julia wrapper) in the github repository, by opening an issue.

Yes, I install it inside Julia

In the following line of code I receive the following alert:

@pyimport CoolProp.CoolProp as CP
@pyimport CoolProp.Plots as CPP #StateContainer

T0 = 300.000; p0 = 200000.000; h0 = 112745.749; s0 = 393.035;
cycle_states = CPP.StateContainer()
cycle_states[1,"H"] = h0
ERROR: MethodError: no method matching setindex!(::PyObject, ::Float64, ::Int64,
::String)
Closest candidates are:
  setindex!(::PyObject, ::Any, ::Integer) at deprecated.jl:70
  setindex!(::PyObject, ::Any, ::Integer, ::Integer) at deprecated.jl:70
  setindex!(::PyObject, ::Any, ::Integer...) at deprecated.jl:70
  ...
Stacktrace:
 [1] top-level scope at REPL[197]:1

the original code from Python is the following:

In [3]: from CoolProp.Plots import StateContainer

In [4]: T0 = 300.000; p0 = 200000.000; h0 = 112745.749; s0 = 393.035

In [5]: cycle_states = StateContainer()

In [6]: cycle_states[0,'H'] = h0

how to write correctly in Julia this line of code. !!!

Solution
https://stackoverflow.com/a/66911000/8409550

1 Like

How to achieve the following command: print (cycle states). I have tried @pycall (cycle_states)
ERROR: ArgumentError: Usage: @pycall func (args …) :: T;
get! (cycle_states)
ERROR: MethodError: no method matching get! (:: PyObject)
print(cycle states)
PyObject <CoolProp.Plots.SimpleCycles.StateContainer object at 0x0000000007E70AF0>