From a8b1c86139fe03c838e54a0940f878d5da6d57ae Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 7 Aug 2019 11:12:06 -0700 Subject: Limit gas compressibility argument range to halfway sane values The curve fitting for our gas compressibility was only done in the sane range of 0-500 bar, which is what a scuba cylinder can reasonably be expected to perhaps have. But the planner ends up happily using negative cylinder pressures when you run out of gas, and then the compressibility gives nonsensical results. That's clearly a planner bug, but the nonsensical gas compressibility values made it harder to see what could be wrong. So we just clamp the inpot range to the range we have verified against experimental data. If you try to get compressibility for negative pressures, you get the compressibility for an ideal and imaginary gas. And if you try to get compressibility for pressures over 500 bar, we'll just assume that it's 500 bar. Signed-off-by: Linus Torvalds --- core/gas-model.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/gas-model.c b/core/gas-model.c index 79dbd2ded..4dccdf6b3 100644 --- a/core/gas-model.c +++ b/core/gas-model.c @@ -47,6 +47,14 @@ double gas_compressibility_factor(struct gasmix gas, double bar) double x1, x2, x3; double Z; + /* + * The curve fitting range is only [0,500] bar. + * Anything else is way out of range for cylinder + * pressures. + */ + if (bar < 0) bar = 0; + if (bar > 500) bar = 500; + o2 = get_o2(gas); he = get_he(gas); -- cgit v1.2.3-70-g09d2