[PATCH 2/2] gas model: replace Redlich-Kwong with least-square quintic

Linus Torvalds torvalds at linux-foundation.org
Wed Mar 2 19:15:32 PST 2016


On Wed, Mar 2, 2016 at 6:45 PM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> But having looked at the profiles, the "nosedive" happens closer to
> 450 bar (and only for oxygen at that).  And it may not be great at 400
> bar, but it's not a disaster.

Google is actually better at graphing this than wolfram alpha. Wolfram
has some low limit on the size of the cut-and-paste.

I pasted this nasty-ass expression into google:

 y = 1.0002556612420115-0.0003115084635183305*x+0.00000227808965401253*x^2+1.91596422989e-9*x^3-8.78421542e-12*x^4+6.77746e-15*x^5
     -0.21*(1.0002231211532653-0.0007471497056767194*x+0.00000200444854807816*x^2+2.91501995188e-9*x^3-4.48294663e-12*x^4-6.11529e-15*x^5)
     -0.79*(1.0001898816185364-0.00030793319362077315*x+0.00000327557417347714*x^2-1.93872574476e-9*x^3-2.7732353e-12*x^4-2.8921e-16*x^5)
from 0 to 500

which is the difference between our air polynomial (good to 500 bar)
and the linear combination of the oxygen and nitrogen polynomials
(each should be good to ~275 bar).

The thing actually looks *really* good. The difference is basically
less than 0.005 up to 200 bar.

Even up to 275 bar, the error is less than one percentage point. Now,
notice the difference between "one percent" and "one percentage
_point_".

At 275 bar, the real Z factor should be 1.087 according to Wikipedia.
The linear mixing gives us 1.078.

However, even that almost one percentage point difference turns out to
be not because the linear mixing doesn't work. Just taking the _air_
plots from baue.org shows that baue says 1.079 for air at 275.

So the linear mixing actually matches the baue air compressibility
factor almost exactly. It's just that baue.org and the Wikipedia
tables don't agree at 275 bar.

And then it starts growing, but at t 300 bar the difference is still
just 0.012. So it's one percentage point off: the proper Z factor
value for air is 1.108, and the "linear mixing" version is at 1.097.
That strikes me as "not perfect, but it's damn close to good".

At 400 bar, we're about 4 percentage points off, which is not great
(the real Z factor is 1.20, the linear mixing is at just 1.166).  I
suspect the linear mixing is still reasonably fine, and we're seeing
an effect of the curve fitting starting to fail more.

At 500 bar, the error is big. I still don't blame the linear mixing,
that's just the Oxygen curve that is way off at that point because the
last table point was 275 bar.

My takeaway from this:

 - the linear mixing seems to work very well at least for air.

 - it starts getting less precise at some point past 200 bar, but even
at 300 bar the error is arguably more due to the difference from
Wikipedia to Baue rather than anything else.

 - google is pretty good at graphing, and it's pretty easy to just
cut-and-paste your functions like the above.

Anyway, it all looks quite reasonable. I have very little reason to
believe that the code doesn't give us way more accuracy than anybody
will ever need.

                 Linus


More information about the subsurface mailing list