mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix ATM-vs-bar confusion
SAC should be calculated in relationship to surface pressure, not "1 bar". I also realize that we have a few other cases where we do the same mistake: the partial pressure calculations do things like po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive); which is wrong as well - the partial pressure is also relative to standard atmospheric pressures. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
92bbed3304
commit
e58f54cac1
4 changed files with 16 additions and 6 deletions
10
dive.h
10
dive.h
|
@ -223,6 +223,11 @@ static inline double bar_to_atm(double bar)
|
||||||
return bar / SURFACE_PRESSURE * 1000;
|
return bar / SURFACE_PRESSURE * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double mbar_to_atm(int mbar)
|
||||||
|
{
|
||||||
|
return (double) mbar / SURFACE_PRESSURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Volume in mliter of a cylinder at pressure 'p' */
|
/* Volume in mliter of a cylinder at pressure 'p' */
|
||||||
extern int gas_volume(cylinder_t *cyl, pressure_t p);
|
extern int gas_volume(cylinder_t *cyl, pressure_t p);
|
||||||
extern int wet_volume(double cuft, pressure_t p);
|
extern int wet_volume(double cuft, pressure_t p);
|
||||||
|
@ -450,6 +455,11 @@ static inline int depth_to_mbar(int depth, struct dive *dive)
|
||||||
return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
|
return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double depth_to_atm(int depth, struct dive *dive)
|
||||||
|
{
|
||||||
|
return mbar_to_atm(depth_to_mbar(depth, dive));
|
||||||
|
}
|
||||||
|
|
||||||
/* for the inverse calculation we use just the relative pressure
|
/* for the inverse calculation we use just the relative pressure
|
||||||
* (that's the one that some dive computers like the Uemis Zurich
|
* (that's the one that some dive computers like the Uemis Zurich
|
||||||
* provide - for the other models that do this libdivecomputer has to
|
* provide - for the other models that do this libdivecomputer has to
|
||||||
|
|
|
@ -221,7 +221,7 @@ static int calculate_otu(struct dive *dive)
|
||||||
po2 = sample->po2;
|
po2 = sample->po2;
|
||||||
} else {
|
} else {
|
||||||
int o2 = active_o2(dive, dc, sample->time);
|
int o2 = active_o2(dive, dc, sample->time);
|
||||||
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
|
po2 = o2 * depth_to_atm(sample->depth.mm, dive);
|
||||||
}
|
}
|
||||||
if (po2 >= 500)
|
if (po2 >= 500)
|
||||||
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
|
otu += pow((po2 - 500) / 1000.0, 0.83) * t / 30.0;
|
||||||
|
@ -285,7 +285,7 @@ static int calculate_cns(struct dive *dive)
|
||||||
po2 = sample->po2;
|
po2 = sample->po2;
|
||||||
} else {
|
} else {
|
||||||
int o2 = active_o2(dive, dc, sample->time);
|
int o2 = active_o2(dive, dc, sample->time);
|
||||||
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);
|
po2 = o2 / depth_to_atm(sample->depth.mm, dive);
|
||||||
}
|
}
|
||||||
/* Find what table-row we should calculate % for */
|
/* Find what table-row we should calculate % for */
|
||||||
for (j = 1; j < sizeof(cns_table)/(sizeof(int) * 3); j++)
|
for (j = 1; j < sizeof(cns_table)/(sizeof(int) * 3); j++)
|
||||||
|
@ -338,7 +338,7 @@ static int calculate_sac(struct dive *dive)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Mean pressure in ATM (SAC calculations are in atm*l/min) */
|
/* Mean pressure in ATM (SAC calculations are in atm*l/min) */
|
||||||
pressure = (double) depth_to_mbar(meandepth, dive) / SURFACE_PRESSURE;
|
pressure = depth_to_atm(meandepth, dive);
|
||||||
sac = airuse / pressure * 60 / duration;
|
sac = airuse / pressure * 60 / duration;
|
||||||
|
|
||||||
/* milliliters per minute.. */
|
/* milliliters per minute.. */
|
||||||
|
|
|
@ -226,7 +226,7 @@ static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, str
|
||||||
|
|
||||||
/* Mean pressure in ATM */
|
/* Mean pressure in ATM */
|
||||||
depth = (entry1->depth + entry2->depth) / 2;
|
depth = (entry1->depth + entry2->depth) / 2;
|
||||||
atm = (double) depth_to_mbar(depth, dive) / SURFACE_PRESSURE;
|
atm = depth_to_atm(depth, dive);
|
||||||
|
|
||||||
cyl = dive->cylinder + index;
|
cyl = dive->cylinder + index;
|
||||||
|
|
||||||
|
|
|
@ -475,7 +475,7 @@ void MainTab::updateDiveInfo(int dive)
|
||||||
volume_t sac;
|
volume_t sac;
|
||||||
QString SACs;
|
QString SACs;
|
||||||
if (mean[0] && duration[0]) {
|
if (mean[0] && duration[0]) {
|
||||||
sac.mliter = gases[0].mliter * 1000.0 / (depth_to_mbar(mean[0], d) * duration[0] / 60.0);
|
sac.mliter = gases[0].mliter / (depth_to_atm(mean[0], d) * duration[0] / 60.0);
|
||||||
SACs = get_volume_string(sac, true).append(tr("/min"));
|
SACs = get_volume_string(sac, true).append(tr("/min"));
|
||||||
} else {
|
} else {
|
||||||
SACs = QString(tr("unknown"));
|
SACs = QString(tr("unknown"));
|
||||||
|
@ -483,7 +483,7 @@ void MainTab::updateDiveInfo(int dive)
|
||||||
for(int i=1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
|
for(int i=1; i < MAX_CYLINDERS && gases[i].mliter != 0; i++) {
|
||||||
volumes.append("\n" + get_volume_string(gases[i], true));
|
volumes.append("\n" + get_volume_string(gases[i], true));
|
||||||
if (duration[i]) {
|
if (duration[i]) {
|
||||||
sac.mliter = gases[i].mliter * 1000.0 / (depth_to_mbar(mean[i], d) * duration[i] / 60);
|
sac.mliter = gases[i].mliter / (depth_to_atm(mean[i], d) * duration[i] / 60);
|
||||||
SACs.append("\n" + get_volume_string(sac, true).append(tr("/min")));
|
SACs.append("\n" + get_volume_string(sac, true).append(tr("/min")));
|
||||||
} else {
|
} else {
|
||||||
SACs.append("\n");
|
SACs.append("\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue