Large negative pressures

Linus Torvalds torvalds at linux-foundation.org
Wed Aug 7 11:21:04 PDT 2019


On Wed, Aug 7, 2019 at 10:31 AM Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> The planner does most things in floating point, so maybe that's what
> goes on - doing the math in FP and then assigning to an integer.

Ahhah! Caught it.

I hacked up a special version of "ssrf_double_to_int()" that does
range verification, and made all our lrint() cases use that.

Lookie here, we've calculated some crazy cylinder pressure in
update_cylinder_pressure() and are trying to assigned it to
"delta_p.mbar":

        if (cyl->type.size.mliter) {
                delta_p.mbar = lrint(gas_used.mliter * 1000.0 /
cyl->type.size.mliter * gas_compressibility_factor(cyl->gasmix,
cyl->end.mbar / 1000.0));
                cyl->end.mbar -= delta_p.mbar;
        }

and the value it has is nonsensical (30 billion mbar?)

And the reason turns out to be

(gdb) p gas_used.mliter
$1 = 73086
(gdb) p cyl->type.size.mliter
$2 = 11094
(gdb) p gas_compressibility_factor(cyl->gasmix, cyl->end.mbar / 1000.0)
$3 = 4679328.4598676935

and that odd gas compressibility value is because the planner has
already gotten to a crazy cylinder pressures:

(gdb) p cyl->gasmix
$4 = {o2 = {permille = 0}, he = {permille = 0}}
(gdb) p cyl->end.mbar
$5 = -133241985

and our gas_compressibility_factor() thing gives insane results for
insane values.

Garbage in, even more garbage out.

Anyway, I think the planner needs to just realize that it can't use
negative cylinder pressures and then do math on those.

But with this pull request at least you don't get the crazy overflows
due to insane negative pressures:

    https://github.com/Subsurface-divelog/subsurface/pull/2214

and while it doesn't fix the real underlying fundamental problem, the
fact that it no longer uses insane values to create insane
compressibility factors at least means that you are going to have to
work a lot harder to get to the true overflow range (ie cylinder
pressures in the millions or bars).

I'll leave the actual real planner bug to somebody else.

               Linus


More information about the subsurface mailing list