Compare commits

...

2 commits

Author SHA1 Message Date
Robert C. Helling
dc6d0a46fe
Merge b7fc06892a into beb352d47c 2024-11-15 07:07:45 +00:00
Robert C. Helling
b7fc06892a Round MOD to lower depths
When computing the suggested switch depth for a gas,
we should take the next stop depth above the MOD, i.e.
round down. Otherwise we can produce MOD violation warnings.

We need, however, a bit of fudge as otherwise we do not
suggest to switch to o2 at 6m.

TestPlan uses the MOD to determine the depth to switch to
Tx21/35. This happens to be 65.378m. Therefore, switching
at 66m violates the MOD, the switch should be at 63m.
This then affects the gas usage.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2024-11-15 08:07:18 +01:00
2 changed files with 6 additions and 4 deletions

View file

@ -2457,7 +2457,9 @@ int dive::mbar_to_depth(int mbar) const
depth_t dive::gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const depth_t dive::gas_mod(struct gasmix mix, pressure_t po2_limit, int roundto) const
{ {
double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix)); double depth = (double) mbar_to_depth(po2_limit.mbar * 1000 / get_o2(mix));
return depth_t { .mm = int_cast<int>(depth / roundto) * roundto }; // Rounding should be towards lower=safer depths but we give a bit
// of fudge to all to switch to o2 at 6m. So from .9 we round up.
return depth_t { .mm = (int)(depth / roundto + 0.1) * roundto };
} }
/* Maximum narcotic depth rounded to multiples of roundto mm */ /* Maximum narcotic depth rounded to multiples of roundto mm */

View file

@ -865,17 +865,17 @@ void TestPlan::testVpmbMetricRepeat()
// check minimum gas result // check minimum gas result
dp = std::find_if(testPlan.dp.begin(), testPlan.dp.end(), [](auto &dp) { return dp.minimum_gas.mbar != 0; }); dp = std::find_if(testPlan.dp.begin(), testPlan.dp.end(), [](auto &dp) { return dp.minimum_gas.mbar != 0; });
QCOMPARE(lrint(dp == testPlan.dp.end() ? 0.0 : dp->minimum_gas.mbar / 1000.0), 80l); QCOMPARE(lrint(dp == testPlan.dp.end() ? 0.0 : dp->minimum_gas.mbar / 1000.0), 85l);
// print first ceiling // print first ceiling
printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001); printf("First ceiling %.1f m\n", dive.mbar_to_depth(test_deco_state.first_ceiling_pressure.mbar) * 0.001);
QVERIFY(dive.dcs[0].events.size() >= 3); QVERIFY(dive.dcs[0].events.size() >= 3);
// check first gas change to 21/35 at 66m // check first gas change to 21/35 at 63m
struct event *ev = &dive.dcs[0].events[0]; struct event *ev = &dive.dcs[0].events[0];
QVERIFY(ev != NULL); QVERIFY(ev != NULL);
QCOMPARE(ev->gas.index, 1); QCOMPARE(ev->gas.index, 1);
QCOMPARE(ev->gas.mix.o2.permille, 210); QCOMPARE(ev->gas.mix.o2.permille, 210);
QCOMPARE(ev->gas.mix.he.permille, 350); QCOMPARE(ev->gas.mix.he.permille, 350);
QCOMPARE(get_depth_at_time(&dive.dcs[0], ev->time.seconds), 66000); QCOMPARE(get_depth_at_time(&dive.dcs[0], ev->time.seconds), 63000);
// check second gas change to EAN50 at 21m // check second gas change to EAN50 at 21m
ev = &dive.dcs[0].events[1]; ev = &dive.dcs[0].events[1];
QCOMPARE(ev->gas.index, 2); QCOMPARE(ev->gas.index, 2);