Commit graph

10 commits

Author SHA1 Message Date
Robert C. Helling
741099bdbb Show correct gas density in CCR mode
When collecting the data for the infobox, we have
already computed the current partial pressures of the
breathing gas taking into accoutn the divemode. Use
those rather than fractions (which for CCR mode are
those of diluent) to compute the gas density.

Reported-by: Pietro Tranquillini <p.tranquillini@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2022-11-08 10:43:47 -08:00
Robert C. Helling
41258647d2 Don't access gasmix.o2.fraction
Air is a special gas that does not contain oxygen according
to gasmix.o2.fraction. If you want to use the fo2, you
need to use get_o2() to treat this special case correctly.

This fixes a bug when setting the MND of a gas containing
21% oxygen when o2 is considered not narcotic.

Reported-by: Christoph Gruen <gruen.christoph@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-10-01 08:50:36 -07:00
Berthold Stoeger
2a966ac2a9 Cleanup: replace macro by inline function in gas-model.c
Replace a macro calculating a degree-three polynomial by an
inline function.

Moreover, calculate the powers 1, 2 and 3 of the pressure inside
the function. The compiler will be smart enough to optimize this
to the same code. The only important thing is to write "x*x*x*coeff"
instead of "coeff*x*x*x". The compiler can't optimize the latter
because ... wonderful floating point semantics.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 15:22:09 -07:00
Linus Torvalds
a8b1c86139 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 <torvalds@linux-foundation.org>
2019-08-08 09:07:48 +02:00
Berthold Stoeger
ce065968f0 Cleanup: remove bogus inline modifier
gas_density() was declared extern in the header and defined inline
in the translation unit. I didn't even realize that this oxymoron
is valid. Remove inline and an Java-style function definition.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Robert C. Helling
bb6ceba4ac Compute and display gas density
This appears to be critical for work of breathing so it might be
worthwhile to compute. So far only in infobox.

For background, see

https://www.youtube.com/watch?v=QBajM3xmOtc

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:52:04 -07:00
Dirk Hohndel
b368ecd5aa Add SPDX header to remaining core files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Robert C. Helling
7725842383 Use real gas compressibility in planner
Modify formluas for gas use to take into account the
compressibility correction for real gases. This introduces
also the inverse formula to compute the pressure for a given
amount of gas.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-01-16 03:17:40 -08:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/gas-model.c (Browse further)