Advanced Thermodynamics

advancedthermo.com

Thermodynamic properties of natural gas mixtures containing helium - Part 9b

15 May 2022 (First published 1 October 2022)

This is Part 9b of a series.

In Part 9a, I reported that the Julia package Clapeyron.jl did not have a flash procedure implemented. Recently, I was contacted by one of the package authors to inform me that a flash algorithm has been added; the focus of this post will be to check its performance against my flash benchmarks for mixtures containing methane and helium.

The first step is to obtain the latest version of the package (at the time of writing this is 0.3.6):


  ] add https://github.com/ypaul21/Clapeyron.jl#master
The author was generous enough to give me an example to try:

  using Clapeyron
  model = GERG2008(["helium","nitrogen"])
  (x,n,G) = tp_flash(model,2e6,90,[0.5,0.5])
the output of which agreed with their supplied values:

  ([0.9616497782871675 0.038350221712832484; 0.09980808558719821 0.9001919144128017], 
   [0.44653730380779205 0.01780773519709112; 0.05346269619220795 0.4821922648029089], 
   -2.010398635641377)

I tried using the following code to run the flash against the benchmarks:


using Clapeyron
using CSV

model = Clapeyron.GERG2008(["methane","helium"])
file = "test\\flash_benchmark_GERG2008_methane+helium.csv"
for row in CSV.File(file)
    z = [row.z1, 1-row.z1]
    (x,ϕ,G) = Clapeyron.tp_flash(model,row.p*1e3,row.T,z)
    if (abs(x[1,1]-row.x1)>2.e-6 && abs(x[2,1]-row.x1)>2.e-6) || 
       (abs(x[2,1]-row.y1)>2.e-6 && abs(x[1,1]-row.y1)>2.e-6)
        @info row
    end
end
but this seems to hit an infinite loop. The documentation of tp_flash indicates that the method being used is named DETPFlash. Its documentation begins:

  DETPFlash(;
      numphases = 2;
      max_steps = 1e4*(numphases-1),
      population_size =20,
      time_limit = Inf,
      verbose = false, 
      logspace = false
  )
so it should be possible to set a limit on the time like so (indicated in bold):

for row in CSV.File(file)
    z = [row.z1, 1-row.z1]
    (x,ϕ,G) = Clapeyron.tp_flash(model,row.p*1e3,row.T,z,DETPFlash(time_limit=4))
    if (abs(x[1,1]-row.x1)>2.e-6 && abs(x[2,1]-row.x1)>2.e-6) || 
       (abs(x[2,1]-row.y1)>2.e-6 && abs(x[1,1]-row.y1)>2.e-6)
        @info row
    end
end
The result from this loop is that points 6, 7, 9, 13, 15, 20, 24, 28, 31, 38, 48 and 49 do not agree with the benchmarks: that's 12 cases out of 56. In the course of trying other settings and getting other outputs I ran a loop similar to the above several times and found that — due to randomness in the solver — some of the points listed would occasionally pass, while others from the benchmark set would occassionally fail, with the number of failures staying between about 10 and 14.

I observe no common feature to all of the failure cases: several of them appear to be returning a phase composition that is essentially pure methane or pure helium; some of the failure cases are reaching the allotted time limit (even when increased to 10 seconds) but so are some of the successful cases.

As noted above, some cases are timing out after 10 seconds. However, even those that terminate on their own are taking more than 1 second, with some exceeding 6 seconds. For comparison, my flash algorithm can return in under 4 milliseconds. The speed of the calculations is an issue, especially if the results are incorrect about 25 % of the time.

Discussion

Overall, the flash algorithm in Clapeyron.jl is unreliable and slow when applied to mixtures of methane and helium modelled with the GERG-2008 EOS. As I have detailed in this series, helium presents unique challenges for the flash so it is possible that the algorithm performs better on other systems. I have not spent any time trying to debug the failures I observed. However, if some additional information had been returned from the flash it could have facilitated that effort, e.g.:

Also, it is possible other solver options are available in the package that are more robust or faster. If so, they should be mentioned in the documentation. I expect to send these observations to the developers soon so hopefully future versions of the package address these shortcomings.

References

[1] Kunz and Wagner, J. Chem. Eng. Data, 2012, 57, 3032 (link to publisher)

[2] Span et al., TREND. Thermodynamic Reference and Engineering Data 4.0. Lehrstuhl für Thermodynamik, Ruhr-Universität Bochum, 2019

Go to Home How to cite this page Permalink to this page