Skip to content

[Bug]: Plan dive uses salt water density by default, despite fresh water is selected #4829

@empl0

Description

@empl0

Description

When opening the "Log" -> "Plan dive" menu, the watertype fresh water with a density of 1,00 kg/l is selected. As long as this selection is not changed, all calculations are done with salt walter.

I was testing my own Buhlmann implementation against other implementations and stumbled upon a difference with Subsurface.
For testing purpose I got the current git master of Subsurface and added the following output to calculate_depth_to_mbarf in core/dive.cpp just before the return line.

std::cout << "calculate_depth_to_mbarf: depth=" << depth.mm << "mm, surface_pressure=" << surface_pressure.mbar << "mbar, salinity=" << salinity << "g/10l, specific_weight=" << specific_weight << "mbar/mm" << std::endl;

The salinity printed out is that of saltwater and is used in add_segment of core/deco.cpp.
When changing the water type in the gui to salt walter and back to fresh water, the correct salinity is used.

--- a/core/dive.cpp
+++ b/core/dive.cpp
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <memory>
+#include <iostream>
 #include "dive.h"
 #include "gettext.h"
 #include "subsurface-string.h"
@@ -2552,6 +2553,7 @@ static double calculate_depth_to_mbarf(depth_t depth, pressure_t surface_pressur
        if (salinity < 500)
                salinity += FRESHWATER_SALINITY;
        double specific_weight = salinity_to_specific_weight(salinity);
+       std::cout << "calculate_depth_to_mbarf: depth=" << depth.mm << "mm, surface_pressure=" << surface_pressure.mbar << "mbar, salinity=" << salinity << "g/10l, specific_weight=" << specific_weight << "mbar/mm" << std::endl;
        return surface_pressure.mbar + depth.mm * specific_weight;
 }

Subsurface Version

6.0.5621-dfx and git master @ 40a53ed

Platform(s)

Linux

Platform Version

Debian Testing (Forky)

Divecomputer Model

none

Steps to Reproduce

  1. Open "Log" -> "Plan dive"
  2. Do not change the water type!
  3. Calculate a long and deep dive (eg 40m, 30 min)
  4. Write down the deco
  5. Change the water type to "salt water" and back to "fresh water"
  6. Compare the deco from step 3 and step 5

Logs

Mentions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions