mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
5e9ee9febb
commit
41258647d2
8 changed files with 9280 additions and 9276 deletions
|
|
@ -86,7 +86,9 @@ double isothermal_pressure(struct gasmix gas, double p1, int volume1, int volume
|
|||
|
||||
double gas_density(struct gasmix gas, int pressure)
|
||||
{
|
||||
int density = gas.he.permille * HE_DENSITY + gas.o2.permille * O2_DENSITY + (1000 - gas.he.permille - gas.o2.permille) * N2_DENSITY;
|
||||
int fo2 = get_o2(gas);
|
||||
int fhe = get_he(gas);
|
||||
int density = fhe * HE_DENSITY + fo2 * O2_DENSITY + (1000 - fhe - fo2) * N2_DENSITY;
|
||||
|
||||
return density * (double) pressure / gas_compressibility_factor(gas, pressure / 1000.0) / SURFACE_PRESSURE / 1000000.0;
|
||||
}
|
||||
|
|
|
|||
22
core/gas.c
22
core/gas.c
|
|
@ -33,15 +33,15 @@ int same_gasmix(struct gasmix a, struct gasmix b)
|
|||
return 0;
|
||||
if (gasmix_is_air(a) && gasmix_is_air(b))
|
||||
return 1;
|
||||
return a.o2.permille == b.o2.permille && a.he.permille == b.he.permille;
|
||||
return get_o2(a) == get_o2(b) && get_he(a) == get_he(b);
|
||||
}
|
||||
|
||||
void sanitize_gasmix(struct gasmix *mix)
|
||||
{
|
||||
unsigned int o2, he;
|
||||
|
||||
o2 = mix->o2.permille;
|
||||
he = mix->he.permille;
|
||||
o2 = get_o2(*mix);
|
||||
he = get_he(*mix);
|
||||
|
||||
/* Regular air: leave empty */
|
||||
if (!he) {
|
||||
|
|
@ -74,12 +74,12 @@ int gasmix_distance(struct gasmix a, struct gasmix b)
|
|||
|
||||
bool gasmix_is_air(struct gasmix gasmix)
|
||||
{
|
||||
int o2 = gasmix.o2.permille;
|
||||
int he = gasmix.he.permille;
|
||||
int o2 = get_o2(gasmix);
|
||||
int he = get_he(gasmix);
|
||||
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
||||
}
|
||||
|
||||
static fraction_t make_fraction(int i)
|
||||
fraction_t make_fraction(int i)
|
||||
{
|
||||
fraction_t res;
|
||||
res.permille = i;
|
||||
|
|
@ -152,13 +152,13 @@ enum gastype gasmix_to_type(struct gasmix mix)
|
|||
{
|
||||
if (gasmix_is_air(mix))
|
||||
return GASTYPE_AIR;
|
||||
if (mix.o2.permille >= 980)
|
||||
if (get_o2(mix) >= 980)
|
||||
return GASTYPE_OXYGEN;
|
||||
if (mix.he.permille == 0)
|
||||
return mix.o2.permille >= 230 ? GASTYPE_NITROX : GASTYPE_AIR;
|
||||
if (mix.o2.permille <= 180)
|
||||
if (get_he(mix) == 0)
|
||||
return get_o2(mix) >= 230 ? GASTYPE_NITROX : GASTYPE_AIR;
|
||||
if (get_o2(mix) <= 180)
|
||||
return GASTYPE_HYPOXIC_TRIMIX;
|
||||
return mix.o2.permille <= 230 ? GASTYPE_NORMOXIC_TRIMIX : GASTYPE_HYPEROXIC_TRIMIX;
|
||||
return get_o2(mix) <= 230 ? GASTYPE_NORMOXIC_TRIMIX : GASTYPE_HYPEROXIC_TRIMIX;
|
||||
}
|
||||
|
||||
static const char *gastype_names[] = {
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ extern double isothermal_pressure(struct gasmix gas, double p1, int volume1, int
|
|||
extern double gas_density(struct gasmix gas, int pressure);
|
||||
extern int same_gasmix(struct gasmix a, struct gasmix b);
|
||||
|
||||
static inline int get_o2(struct gasmix mix)
|
||||
static inline int get_o2(const struct gasmix mix)
|
||||
{
|
||||
return mix.o2.permille ?: O2_IN_AIR;
|
||||
}
|
||||
|
||||
static inline int get_he(struct gasmix mix)
|
||||
static inline int get_he(const struct gasmix mix)
|
||||
{
|
||||
return mix.he.permille;
|
||||
}
|
||||
|
|
@ -74,6 +74,7 @@ extern bool gasmix_is_air(struct gasmix gasmix);
|
|||
extern bool gasmix_is_invalid(struct gasmix mix);
|
||||
extern enum gastype gasmix_to_type(struct gasmix mix);
|
||||
extern const char *gastype_name(enum gastype type);
|
||||
extern fraction_t make_fraction(int f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue