mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 22:53:23 +00:00
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>
This commit is contained in:
parent
e6d884cf26
commit
bb6ceba4ac
5 changed files with 17 additions and 2 deletions
|
@ -139,6 +139,8 @@ extern int units_to_sac(double volume);
|
||||||
extern int gas_volume(cylinder_t *cyl, pressure_t p);
|
extern int gas_volume(cylinder_t *cyl, pressure_t p);
|
||||||
extern double gas_compressibility_factor(struct gasmix *gas, double bar);
|
extern double gas_compressibility_factor(struct gasmix *gas, double bar);
|
||||||
extern double isothermal_pressure(struct gasmix *gas, double p1, int volume1, int volume2);
|
extern double isothermal_pressure(struct gasmix *gas, double p1, int volume1, int volume2);
|
||||||
|
extern double gas_density(struct gasmix *gas, int pressure);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static inline int get_o2(const struct gasmix *mix)
|
static inline int get_o2(const struct gasmix *mix)
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#define virial_m1(C, x1, x2, x3) (C[0]*x1+C[1]*x2+C[2]*x3)
|
#define virial_m1(C, x1, x2, x3) (C[0]*x1+C[1]*x2+C[2]*x3)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Z = pV/nRT
|
||||||
|
*
|
||||||
* Cubic virial least-square coefficients for O2/N2/He based on data from
|
* Cubic virial least-square coefficients for O2/N2/He based on data from
|
||||||
*
|
*
|
||||||
* PERRY’S CHEMICAL ENGINEERS’ HANDBOOK SEVENTH EDITION
|
* PERRY’S CHEMICAL ENGINEERS’ HANDBOOK SEVENTH EDITION
|
||||||
|
@ -73,3 +75,9 @@ double isothermal_pressure(struct gasmix *gas, double p1, int volume1, int volum
|
||||||
|
|
||||||
return p_ideal * gas_compressibility_factor(gas, p_ideal);
|
return p_ideal * gas_compressibility_factor(gas, p_ideal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline 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;
|
||||||
|
|
||||||
|
return density * (double) pressure / gas_compressibility_factor(gas, pressure / 1000.0) / SURFACE_PRESSURE / 1000000.0;
|
||||||
|
}
|
||||||
|
|
|
@ -1151,6 +1151,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
|
||||||
entry->pressures.n2 / amb_pressure * N2_DENSITY +
|
entry->pressures.n2 / amb_pressure * N2_DENSITY +
|
||||||
entry->pressures.he / amb_pressure * HE_DENSITY) /
|
entry->pressures.he / amb_pressure * HE_DENSITY) /
|
||||||
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000;
|
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000;
|
||||||
|
entry->density = gas_density(&dive->cylinder[cylinderindex].gasmix, depth_to_mbar(entry->depth, dive));
|
||||||
if (entry->mod < 0)
|
if (entry->mod < 0)
|
||||||
entry->mod = 0;
|
entry->mod = 0;
|
||||||
if (entry->ead < 0)
|
if (entry->ead < 0)
|
||||||
|
@ -1292,7 +1293,7 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
|
||||||
{
|
{
|
||||||
int pressurevalue, mod, ead, end, eadd;
|
int pressurevalue, mod, ead, end, eadd;
|
||||||
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
|
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
|
||||||
double depthvalue, tempvalue, speedvalue, sacvalue;
|
double depthvalue, tempvalue, speedvalue, sacvalue, density;
|
||||||
int decimals;
|
int decimals;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
|
|
||||||
|
@ -1327,15 +1328,18 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
|
||||||
put_format(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
|
put_format(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
|
||||||
}
|
}
|
||||||
eadd = lrint(get_depth_units(lrint(entry->eadd), NULL, &depth_unit));
|
eadd = lrint(get_depth_units(lrint(entry->eadd), NULL, &depth_unit));
|
||||||
|
|
||||||
if (prefs.ead) {
|
if (prefs.ead) {
|
||||||
switch (pi->dive_type) {
|
switch (pi->dive_type) {
|
||||||
case NITROX:
|
case NITROX:
|
||||||
ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
|
ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
|
||||||
put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s\n"), ead, depth_unit, eadd, depth_unit);
|
put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s\n"), ead, depth_unit, eadd, depth_unit);
|
||||||
|
put_format(b, translate("gettextFromC", "density: %.1fg/l\n"), entry->density);
|
||||||
break;
|
break;
|
||||||
case TRIMIX:
|
case TRIMIX:
|
||||||
end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
|
end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
|
||||||
put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s\n"), end, depth_unit, eadd, depth_unit);
|
put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s\n"), end, depth_unit, eadd, depth_unit);
|
||||||
|
put_format(b, translate("gettextFromC", "density: %.1fg/l\n"), entry->density);
|
||||||
break;
|
break;
|
||||||
case AIR:
|
case AIR:
|
||||||
case FREEDIVING:
|
case FREEDIVING:
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct plot_data {
|
||||||
int bearing;
|
int bearing;
|
||||||
double ambpressure;
|
double ambpressure;
|
||||||
double gfline;
|
double gfline;
|
||||||
|
double density;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ev_select {
|
struct ev_select {
|
||||||
|
|
|
@ -14,7 +14,7 @@ extern "C" {
|
||||||
#define O2_IN_AIR 209 // permille
|
#define O2_IN_AIR 209 // permille
|
||||||
#define N2_IN_AIR 781
|
#define N2_IN_AIR 781
|
||||||
#define O2_DENSITY 1429 // mg/Liter
|
#define O2_DENSITY 1429 // mg/Liter
|
||||||
#define N2_DENSITY 1251
|
#define N2_DENSITY 1165
|
||||||
#define HE_DENSITY 179
|
#define HE_DENSITY 179
|
||||||
#define SURFACE_PRESSURE 1013 // mbar
|
#define SURFACE_PRESSURE 1013 // mbar
|
||||||
#define SURFACE_PRESSURE_STRING "1013"
|
#define SURFACE_PRESSURE_STRING "1013"
|
||||||
|
|
Loading…
Add table
Reference in a new issue