commit 48735c862b79e2bdbb0bed222669593a4ba27ed5
parent f9afc2703152ceb05057d800d5ca6f4a48e4e17d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 2 Oct 2023 15:44:34 +0200
Mitigate an error during media recovery
Commit 7b6f77a has improved the scene_get_medium function by detecting
when the input position is inside an enclosure with multiple media and
then returns an unrecoverable error. However, this situation is quite
common when the path is close to a boundary: it may cross the boundary
due to numerical uncertainty and end up in such an enclosure.
Nevertheless, the simulation need not be stopped. Only the sampled
position should be rejected.
In this commit, we still detect this problematic situation, but we now
return a recoverable error and print a warning. Only if too many
positions are rejected will Stardis return an error, which will be the
case if a probe is positioned in an invalid enclosure.
Diffstat:
2 files changed, 6 insertions(+), 26 deletions(-)
diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h
@@ -1127,12 +1127,12 @@ XD(scene_get_medium)
}
if(enclosure->medium_id == ENCLOSURE_MULTI_MEDIA) {
- log_err
+ log_warn
(scn->dev,
"%s: invalid medium request at {%g, %g, %g}. "
"The position is located in an enclosure comprising several media.\n",
FUNC_NAME, P[0], P[1], DIM == 3 ? P[2] : 0);
- res = RES_BAD_ARG;
+ res = RES_BAD_OP;
goto error;
}
@@ -1148,43 +1148,23 @@ XD(scene_get_medium)
}
if(iprim >= nprims) {
+ log_warn(scn->dev, "%s: could not retrieve the medium at {%g, %g, %g}.\n",
+ FUNC_NAME, P[0], P[1], DIM == 3 ? P[2] : 0);
res = RES_BAD_OP;
goto error;
}
-#if DIM == 2
- if(iprim > 10 && iprim > (size_t)((double)nprims * 0.05)) {
- log_warn(scn->dev,
- "%s: performance issue. Up to %lu primitives were tested to define the "
- "current medium at {%g, %g}.\n",
- FUNC_NAME, (unsigned long)iprim, SPLIT2(P));
- }
-#else
if(iprim > 10 && iprim > (size_t)((double)nprims * 0.05)) {
log_warn(scn->dev,
"%s: performance issue. Up to %lu primitives were tested to define the "
"current medium at {%g, %g, %g}.\n",
- FUNC_NAME, (unsigned long)iprim, SPLIT3(P));
+ FUNC_NAME, (unsigned long)iprim, P[0], P[1], DIM == 3 ? P[2] : 0);
}
-#endif
exit:
*out_medium = medium;
return res;
error:
- {
- /* RES_BAD_OP means that this is a recoverable issue. In such case, print a
- * warning rather than an error. */
- void (*log_func)(const struct sdis_device*, const char*, ...) =
- (res == RES_BAD_OP ? log_warn : log_err);
-#if DIM == 2
- log_func(scn->dev, "%s: could not retrieve the medium at {%g, %g}.\n",
- FUNC_NAME, SPLIT2(pos));
-#else
- log_func(scn->dev, "%s: could not retrieve the medium at {%g, %g, %g}.\n",
- FUNC_NAME, SPLIT3(pos));
-#endif
- }
goto exit;
}
diff --git a/src/test_sdis_enclosure_limit_conditions.c b/src/test_sdis_enclosure_limit_conditions.c
@@ -221,7 +221,7 @@ solve_probe(struct sdis_scene* scn)
args.position[1] = 0.5;
args.position[2] = 0;
args.nrealisations = NREALISATIONS;
- CHK(sdis_solve_probe(scn, &args, &estimator) == RES_BAD_ARG);
+ CHK(sdis_solve_probe(scn, &args, &estimator) == RES_BAD_OP);
args.position[0] = 2;
args.position[1] = 0.5;