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

Computational performance #411

Open
jowr opened this issue Jan 16, 2015 · 26 comments
Open

Computational performance #411

jowr opened this issue Jan 16, 2015 · 26 comments

Comments

@jowr
Copy link
Member

jowr commented Jan 16, 2015

I currently try to map the performance of the EOS solvers as f(D,T) and f(H,P) and it produces very interesting graphs. One thing that strikes me is that all fluids I have looked at exhibit a poor performance for subcooled liquid with T<Tcrit. Is that related to the guess values? There is also pressure band from pcrit<p<5*pcrit where performance is limited. The inflection points of the critical isotherm affect the behaviour as well. @ibell, have you ever looked into that? These plots could help us to improve performance even more in the future.

@jowr jowr added this to the 5.2 milestone Jan 16, 2015
@jowr
Copy link
Member Author

jowr commented Jan 16, 2015

CO2 f(H,P)

timecomp_hp_co2

CO2 f(D,T)

timecomp_dt_co2

@ibell
Copy link
Contributor

ibell commented Jan 17, 2015

Could you do the same with REFPROP? I'm curious to see how the speeds compare.

@ibell
Copy link
Contributor

ibell commented Feb 23, 2015

Very interesting results - makes me think that the solver for the melting line is the problem. When you are below the critical temp, D,T is very slow! This might actually be pretty easy to fix. @jowr , do you still have the code used to generate this figure? The performance in the subcooled liquid region is VERY bad.

@jowr
Copy link
Member Author

jowr commented Feb 23, 2015

Air f(rho,T) - CoolProp

timecomp-dt-heos-air pdf

Air f(rho,T) - REFPROP

timecomp-dt-refprop-air pdf

CO2 f(rho,T) - CoolProp

timecomp-dt-heos-co2 pdf

CO2 f(rho,T) - REFPROP

timecomp-dt-refprop-co2 pdf

Air f(h,p) - CoolProp

timecomp-hp-heos-air pdf

Air f(h,p) - REFPROP

timecomp-hp-refprop-air pdf

CO2 f(h,p) - CoolProp

timecomp-hp-heos-co2 pdf

CO2 f(h,p) - REFPROP

timecomp-hp-refprop-co2 pdf

@jowr
Copy link
Member Author

jowr commented Feb 23, 2015

I added the script to https://github.com/CoolProp/CoolProp/tree/master/dev/TTSE

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Ok, I now understand this issue. There is a clear problem for D,T inputs that I don't entirely understand how to fix. I was checking that if the density was more than 1.05 times the ancillary equation for saturated liquid density, it was liquid. As it turns out, because the liquid phase is very, very incompressible, 5% turns into a large pressure (the red line in the figure). Thus, all the slow points are places where it tries to do a saturation call.

import matplotlib.pyplot as plt, CoolProp, numpy as np
import time
import matplotlib.colors as colors

backend = 'HEOS'
fld = 'CO2'
Tt, Tmax = CoolProp.CoolProp.PropsSI('Ttriple', fld), CoolProp.CoolProp.PropsSI('Tmax', fld)
pt, pmax = CoolProp.CoolProp.PropsSI('ptriple', fld), CoolProp.CoolProp.PropsSI('pmax', fld)

Ts = np.linspace(Tt, CoolProp.CoolProp.PropsSI('Tcrit', fld))
ps = CoolProp.CoolProp.PropsSI('P','T',Ts,'Q',1,backend+'::'+fld)
plt.plot(Ts, ps, 'k')
rhos = CoolProp.CoolProp.PropsSI('D','T',Ts,'Q',0,backend+'::'+fld)
p2 = CoolProp.CoolProp.PropsSI('P','T',Ts,'D',1.05*rhos,backend+'::'+fld)
plt.plot(Ts, p2, 'r')

NT, Np = 50, 50
HEOS = CoolProp.AbstractState(backend, fld)
data = []
for T in np.linspace(Tt, Tmax, NT):
    for p in np.logspace(np.log10(pt*1.05), np.log10(pmax), Np):
        rho = CoolProp.CoolProp.PropsSI('D','T',T,'P',p,backend+'::'+fld)

        t1 = time.clock()
        N = 1000
        for i in range(N):
            HEOS.update(CoolProp.DmassT_INPUTS, rho, T)
            HEOS.p()
        t2 = time.clock()
        data.append((T, p, (t2-t1)/N))

T, p, times = zip(*data)

cNorm  = colors.LogNorm(vmin=1e-6, vmax=200e-6)
plt.scatter(T, p, c = times, cmap = plt.get_cmap('jet'), s = 20, lw = 0, norm = cNorm)
cb = plt.colorbar()
cb.set_label('time per call (s)')
plt.yscale('log')
plt.xlabel('T (K)')
plt.ylabel('p (Pa)')
plt.tight_layout()
plt.savefig(fld+'.png')
plt.show()

yields
co2

ibell added a commit that referenced this issue Apr 25, 2015
@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Well, that seems to have worked for D,T
co2

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

And now with P,H as inputs:

import matplotlib.pyplot as plt, CoolProp, numpy as np
import time
import matplotlib.colors as colors



backend = 'HEOS'
fld = 'CO2'
Tt, Tmax = CoolProp.CoolProp.PropsSI('Ttriple', fld), CoolProp.CoolProp.PropsSI('Tmax', fld)
pt, pmax = CoolProp.CoolProp.PropsSI('ptriple', fld), CoolProp.CoolProp.PropsSI('pmax', fld)

Ts = np.linspace(Tt, CoolProp.CoolProp.PropsSI('Tcrit', fld))
ps = CoolProp.CoolProp.PropsSI('P','T',Ts,'Q',1,backend+'::'+fld)
plt.plot(Ts, ps, 'k')
rhos = CoolProp.CoolProp.PropsSI('D','T',Ts,'Q',0,backend+'::'+fld)
p2 = CoolProp.CoolProp.PropsSI('P','T',Ts,'D',1.05*rhos,backend+'::'+fld)
plt.plot(Ts, p2, 'r')

NT, Np = 50, 50
HEOS = CoolProp.AbstractState(backend, fld)
data = []
for T in np.linspace(Tt, Tmax, NT):
    for p in np.logspace(np.log10(pt*1.0), np.log10(pmax), Np):
        try:
            h = CoolProp.CoolProp.PropsSI('H','T',T,'P',p,backend+'::'+fld)

            t1 = time.clock()
            N = 100
            for i in range(N):
                HEOS.update(CoolProp.HmassP_INPUTS, h, p)
                HEOS.p()
            t2 = time.clock()
            data.append((T, p, (t2-t1)/N*1e6))
        except:
            pass

T, p, times = zip(*data)

cNorm  = colors.Normalize(vmin=np.min(times), vmax=np.max(times))
plt.scatter(T, p, c = times, cmap = plt.get_cmap('jet'), s = 20, lw = 0, norm = cNorm)
cb = plt.colorbar()
cb.set_label('time per call ($\mu$s)')
plt.yscale('log')
plt.xlabel('T (K)')
plt.ylabel('p (Pa)')
plt.tight_layout()
plt.savefig(fld+'.png')
plt.show()

yields
co2

@jowr
Copy link
Member Author

jowr commented Apr 25, 2015

That looks good already, let us keep this issue around. Could be nice to get closer to REFPROP performance, which should be possible..

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Yeah that's why I was hoping you could run your script again so we can see since I can't run your script.

@jowr
Copy link
Member Author

jowr commented Apr 25, 2015

I thought, I fixed the script, but now there are some issues with CO2. You could try to run and see where it takes you.

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

I have tried, but I'm missing quite a lot of stuff, like jopy :)

On Sat, Apr 25, 2015 at 4:57 PM, Jorrit Wronski notifications@github.com
wrote:

I thought, I fixed the script, but now there are some issues with CO2. You
could try to run and see where it takes you.


Reply to this email directly or view it on GitHub
#411 (comment).

@jowr
Copy link
Member Author

jowr commented Apr 25, 2015

Have you tried the latest version? 20 minutes old ...

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Ah not since then, you mean T-S? I'm aware of that issue at least : #619

On Sat, Apr 25, 2015 at 5:04 PM, Jorrit Wronski notifications@github.com
wrote:

Have you tried the latest version? 20 minutes old ...


Reply to this email directly or view it on GitHub
#411 (comment).

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Hmm seems broken. I get a lot of errors like these:

-- HEOS::CO2        --
DT: D*(1000),T
(1000),DT_Tmax*(1000),DT_H*(1000),DT_P*(1000),DT_S*(1000),DT_HPS*(1000),DT_Tmax_V*(1),DT_H_V*(1),DT_P_V*(1),DT_S_V*(1),DT_HPS_V*(1),
HP: H (1000),P (1000),HP_Tmax*(1000),There was an error, dataset 000 from
HEOS::CO2.might be faulty:
unable to calculate melting line T(p) for polynomial_in_Theta curve for
p=6.27395e+009; bounds are 517950,8.22736e+008 Pa
There was an error, removing dataset 000 from HEOS::CO2.
The time data for HP_D is missing or faulty, cannot continue.

On Sat, Apr 25, 2015 at 5:05 PM, Ian Bell ian.h.bell@gmail.com wrote:

Ah not since then, you mean T-S? I'm aware of that issue at least : #619

On Sat, Apr 25, 2015 at 5:04 PM, Jorrit Wronski notifications@github.com
wrote:

Have you tried the latest version? 20 minutes old ...


Reply to this email directly or view it on GitHub
#411 (comment).

@jowr
Copy link
Member Author

jowr commented Apr 25, 2015

Yes, I get the same error. I am afraid that it comes from inside CoolProp because the error also occurred after I disabled the melting line in the plots. :(

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Argh. I think we are getting pretty close to REFPROP speed, but its
annoying to test because we can't just keep trying the same point because
REFPROP caches the last set of inputs/outputs.

On Sat, Apr 25, 2015 at 5:11 PM, Jorrit Wronski notifications@github.com
wrote:

Yes, I get the same error. I am afraid that it comes from inside CoolProp
because the error also occurred after I disabled the melting line in the
plots. :(


Reply to this email directly or view it on GitHub
#411 (comment).

@jowr
Copy link
Member Author

jowr commented Apr 25, 2015

Yes, that is why the script does not run a "best of X" configuration for the different points. I see what I can do about the script next month. It would be really nice to have a reliable method for mapping the performance, especially with inputs that require iteration like h,p.

@ibell
Copy link
Contributor

ibell commented Apr 25, 2015

Yeah, and that way we could triage and see what is most important to fix.

On Sat, Apr 25, 2015 at 5:17 PM, Jorrit Wronski notifications@github.com
wrote:

Yes, that is why the script does not run a "best of X" configuration for
the different points. I see what I can do about the script next month. It
would be really nice to have a reliable method for mapping the performance,
especially with inputs that require iteration like h,p.


Reply to this email directly or view it on GitHub
#411 (comment).

jowr pushed a commit that referenced this issue Apr 26, 2015
@jowr
Copy link
Member Author

jowr commented Apr 26, 2015

Very nice! The f(rho,T) calls improved significantly for CO2 (the script works now).

jowr pushed a commit that referenced this issue Apr 26, 2015
@jowr
Copy link
Member Author

jowr commented Apr 26, 2015

After revising the data for #624, I am tempted to say that the CO2 and water errors are caused by some change in CoolProp's intestines.

@jowr
Copy link
Member Author

jowr commented Apr 26, 2015

The HEOS backend for air still produces many exceptions, I left it out. For water, something is wrong with Tmin in the REFPROP wrapper. REFPROP keeps choking, I also imitted that.

For the other fluids, here are the latest results based on 50 000 data points with the very latest CoolProp:

CO2

timecomp-dt-heos-co2 pdf
timecomp-dt-refprop-co2 pdf
timecomp-hp-heos-co2 pdf
timecomp-hp-refprop-co2 pdf

n-pentane

timecomp-dt-heos-pentane pdf
timecomp-dt-refprop-pentane pdf
timecomp-hp-heos-pentane pdf
timecomp-hp-refprop-pentane pdf

R134a

timecomp-dt-heos-r134a pdf
timecomp-dt-refprop-r134a pdf
timecomp-hp-heos-r134a pdf
timecomp-hp-refprop-r134a pdf

@ibell
Copy link
Contributor

ibell commented Apr 26, 2015

Ok, let's go for a release of 5.1 once I finish the last few bugs today.
Anything else you can see blocking 5.1?

On Sun, Apr 26, 2015 at 5:20 PM, Jorrit Wronski notifications@github.com
wrote:

The HEOS backend for air still produces many exceptions, I left it out.
For water, something is wrong with Tmin in the REFPROP wrapper. REFPROP
keeps choking, I also imitted that.

For the other fluids, here are the latest results based on 50 000 data
points with the very latest CoolProp:
CO2

[image: timecomp-dt-heos-co2 pdf]
https://cloud.githubusercontent.com/assets/769593/7339799/763e4008-ec7b-11e4-95c3-f7f603006f2c.jpg
[image: timecomp-dt-refprop-co2 pdf]
https://cloud.githubusercontent.com/assets/769593/7339800/78b0f02e-ec7b-11e4-9c88-017d121c6fd9.jpg
[image: timecomp-hp-heos-co2 pdf]
https://cloud.githubusercontent.com/assets/769593/7339801/7b03632a-ec7b-11e4-8a9d-e5c403b862de.jpg
[image: timecomp-hp-refprop-co2 pdf]
https://cloud.githubusercontent.com/assets/769593/7339803/7cf85a8c-ec7b-11e4-8632-65a838788ff7.jpg
n-pentane

[image: timecomp-dt-heos-pentane pdf]
https://cloud.githubusercontent.com/assets/769593/7339805/845b3948-ec7b-11e4-8a0b-8592e3ab27a8.jpg
[image: timecomp-dt-refprop-pentane pdf]
https://cloud.githubusercontent.com/assets/769593/7339806/86834486-ec7b-11e4-938b-c19c479a8572.jpg
[image: timecomp-hp-heos-pentane pdf]
https://cloud.githubusercontent.com/assets/769593/7339807/88b2634a-ec7b-11e4-9f67-4211b5ed23fd.jpg
[image: timecomp-hp-refprop-pentane pdf]
https://cloud.githubusercontent.com/assets/769593/7339808/8a76b046-ec7b-11e4-8074-c2bd93c76529.jpg
R134a

[image: timecomp-dt-heos-r134a pdf]
https://cloud.githubusercontent.com/assets/769593/7339809/92473a16-ec7b-11e4-86f7-bbb7847d485e.jpg
[image: timecomp-dt-refprop-r134a pdf]
https://cloud.githubusercontent.com/assets/769593/7339811/93e34cca-ec7b-11e4-8cfb-32087211950a.jpg
[image: timecomp-hp-heos-r134a pdf]
https://cloud.githubusercontent.com/assets/769593/7339812/9596e770-ec7b-11e4-8687-361d753b154f.jpg
[image: timecomp-hp-refprop-r134a pdf]
https://cloud.githubusercontent.com/assets/769593/7339813/97161cba-ec7b-11e4-843e-596abc29ab53.jpg


Reply to this email directly or view it on GitHub
#411 (comment).

@jowr
Copy link
Member Author

jowr commented Apr 26, 2015

No, not if we take Modelica to 5.1.1.

@ibell
Copy link
Contributor

ibell commented Jul 13, 2015

More data:

import CoolProp
from CoolProp.CoolProp import PropsSI
import numpy as np
import matplotlib.pyplot as plt
import time

backend = 'HEOS'
fluid = 'Propane'
data = []
print backend
for _in1, _in2 in [('T','D'), ('T','P'), ('T','S'), ('D','H'), ('P','H'), ('P','S'), ('P','U'), ('H','S')]:

    in1 = CoolProp.CoolProp.get_parameter_index(_in1)
    in2 = CoolProp.CoolProp.get_parameter_index(_in2)

    AS = CoolProp.AbstractState(backend, fluid)
    AS.update(CoolProp.PT_INPUTS, 101325, 300)

    pair, v1, v2 = CoolProp.CoolProp.generate_update_pair(in1,AS.keyed_output(in1),in2,AS.keyed_output(in2))
    AS.update(pair, v1, v2)

    t1 = time.clock()
    for i in range(1000):
        #AS.keyed_output(CoolProp.iT_critical)
        AS.update(pair, v1, v2)
    t2 = time.clock()

    data.append(((t2-t1)*1000, _in1 + ' ' + _in2))

data = sorted(data)
for time, pair in data:
    print pair, time

yields

HEOS
T D 4.41872180948
T P 8.34120899537
P S 92.3349559562
T S 109.055104682
D H 114.226931957
P U 114.597296849
P H 114.960115595
H S 1330.00840037

@ibell
Copy link
Contributor

ibell commented Jan 18, 2016

See also updates to PY in 8e5930d

@ibell ibell modified the milestone: MinorRelease Oct 27, 2016
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