2019-06-04 11:52:48 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef GAS_H
|
|
|
|
#define GAS_H
|
|
|
|
|
2020-10-25 10:36:44 +00:00
|
|
|
#include "divemode.h"
|
2019-06-04 11:52:48 +00:00
|
|
|
#include "units.h"
|
|
|
|
|
2024-07-02 10:38:36 +00:00
|
|
|
#include <string>
|
|
|
|
|
2020-10-02 17:40:42 +00:00
|
|
|
enum gas_component { N2, HE, O2 };
|
|
|
|
|
2019-06-04 11:52:48 +00:00
|
|
|
// o2 == 0 && he == 0 -> air
|
|
|
|
// o2 < 0 -> invalid
|
|
|
|
struct gasmix {
|
|
|
|
fraction_t o2;
|
|
|
|
fraction_t he;
|
2024-07-02 10:38:36 +00:00
|
|
|
std::string name() const;
|
2019-06-04 11:52:48 +00:00
|
|
|
};
|
2024-09-01 19:48:31 +00:00
|
|
|
static const struct gasmix gasmix_invalid = { { .permille = -1 }, { .permille = -1 } };
|
2024-09-03 15:04:48 +00:00
|
|
|
static const struct gasmix gasmix_air = { 0_percent, 0_percent };
|
2019-06-04 11:52:48 +00:00
|
|
|
|
2020-11-23 18:19:21 +00:00
|
|
|
enum gastype {
|
|
|
|
GASTYPE_AIR,
|
|
|
|
GASTYPE_NITROX,
|
|
|
|
GASTYPE_HYPOXIC_TRIMIX,
|
|
|
|
GASTYPE_NORMOXIC_TRIMIX,
|
|
|
|
GASTYPE_HYPEROXIC_TRIMIX,
|
|
|
|
GASTYPE_OXYGEN,
|
|
|
|
GASTYPE_COUNT
|
|
|
|
};
|
|
|
|
|
2019-06-04 11:52:48 +00:00
|
|
|
struct icd_data { // This structure provides communication between function isobaric_counterdiffusion() and the calling software.
|
|
|
|
int dN2; // The change in fraction (permille) of nitrogen during the change
|
|
|
|
int dHe; // The change in fraction (permille) of helium during the change
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool isobaric_counterdiffusion(struct gasmix oldgasmix, struct gasmix newgasmix, struct icd_data *results);
|
|
|
|
|
|
|
|
extern double gas_compressibility_factor(struct gasmix gas, double bar);
|
|
|
|
extern double isothermal_pressure(struct gasmix gas, double p1, int volume1, int volume2);
|
|
|
|
extern int same_gasmix(struct gasmix a, struct gasmix b);
|
|
|
|
|
2021-10-01 13:50:21 +00:00
|
|
|
static inline int get_o2(const struct gasmix mix)
|
2019-06-04 11:52:48 +00:00
|
|
|
{
|
|
|
|
return mix.o2.permille ?: O2_IN_AIR;
|
|
|
|
}
|
|
|
|
|
2021-10-01 13:50:21 +00:00
|
|
|
static inline int get_he(const struct gasmix mix)
|
2019-06-04 11:52:48 +00:00
|
|
|
{
|
|
|
|
return mix.he.permille;
|
|
|
|
}
|
|
|
|
|
2020-10-02 17:58:36 +00:00
|
|
|
static inline int get_n2(struct gasmix mix)
|
|
|
|
{
|
|
|
|
return 1000 - get_o2(mix) - get_he(mix);
|
|
|
|
}
|
|
|
|
|
2021-03-11 22:27:13 +00:00
|
|
|
int pscr_o2(const double amb_pressure, struct gasmix mix);
|
|
|
|
|
2019-06-04 11:52:48 +00:00
|
|
|
struct gas_pressures {
|
2024-05-03 16:51:03 +00:00
|
|
|
double o2 = 0.0, n2 = 0.0, he = 0.0;
|
2019-06-04 11:52:48 +00:00
|
|
|
};
|
|
|
|
|
2024-05-28 19:31:11 +00:00
|
|
|
extern void sanitize_gasmix(struct gasmix &mix);
|
2019-06-04 11:52:48 +00:00
|
|
|
extern int gasmix_distance(struct gasmix a, struct gasmix b);
|
2020-10-02 17:58:36 +00:00
|
|
|
extern fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_component component);
|
2024-05-05 04:54:30 +00:00
|
|
|
extern gas_pressures fill_pressures(double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype);
|
2019-06-04 11:52:48 +00:00
|
|
|
|
|
|
|
extern bool gasmix_is_air(struct gasmix gasmix);
|
2021-01-01 00:30:13 +00:00
|
|
|
extern bool gasmix_is_invalid(struct gasmix mix);
|
2020-11-23 18:19:21 +00:00
|
|
|
extern enum gastype gasmix_to_type(struct gasmix mix);
|
|
|
|
extern const char *gastype_name(enum gastype type);
|
2021-10-01 13:50:21 +00:00
|
|
|
extern fraction_t make_fraction(int f);
|
2019-06-04 11:52:48 +00:00
|
|
|
|
|
|
|
#endif
|