commit 7efdc1db2fb1cf8c5819df4df488923d2e76981e
parent e4ea13764103f61767cfe520601ad24bf9a5e0b8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 20 Apr 2026 14:56:06 +0200
Upd to mitigate numerical issues when building a tree
When constructing a tree in which the polylines of the nodes must be
greater than the spectrum they represent, an offset must be added to the
vertices of the polylines to ensure this constraint between the
vertices, even if this constraint is already satisfied for the vertices.
In fact, the numerical uncertainty introduced by linear interpolation of
values between vertices can, in certain situations (for example, for
very sharp lines), result in a ka value lower than the actual spectral
value.
However, the offset added to the vertices of the polylines was too high:
specifically, the minimum between 1% of the vertex value and an
arbitrary absolute value of 1e-6. This latter adjustment was actually
too large and led to an overestimation of the polylines’ values, which
at the root could be by several orders of magnitude. Hence this update,
which now adds an offset at the vertex of the polyline solely relative
to the vertex value, i.e., its associated ka.
Diffstat:
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c
@@ -43,6 +43,15 @@ collapse_child_polylines
struct darray_vertex* scratch, /* Temporary buffer of vertices */
struct darray_vertex* vertices); /* List of polyline vertices */
+/* A multiplier to be applied to the calculated ka values in order to mitigate
+ * numerical issues related to ka interpolation in the case of a tree with an
+ * upper bound. This interpolation must ensure that the interpolated ka value is
+ * well above the actual ka value, which may not be the case due to numerical
+ * inaccuracies. Hence this constant, which defines a percentage of ka to be
+ * added to the calculated ka values to ensure that any interpolated value is
+ * well above the actual ka value. */
+#define KA_ADJUSTEMENT 1.01
+
/*******************************************************************************
* Helper functions
******************************************************************************/
@@ -387,7 +396,7 @@ merge_child_polylines
if(tree->args.mesh_type == SLN_MESH_UPPER) {
FOR_EACH(ivtx, vertices_range[0], vertices_range[1]+1/*inclusive bound*/) {
const double ka = vertices[ivtx].ka;
- vertices[ivtx].ka = (float)(ka + MMAX(ka*1e-2, 1e-6));
+ vertices[ivtx].ka = (float)(ka*KA_ADJUSTEMENT);
}
}
@@ -649,7 +658,7 @@ collapse_child_polylines
if(tree->args.mesh_type == SLN_MESH_UPPER) {
FOR_EACH(ivtx, vertices_range[0], vertices_range[1]+1/*inclusive bound*/) {
const double ka = vertices[ivtx].ka;
- vertices[ivtx].ka = (float)(ka + MMAX(ka*1e-2, 1e-6));
+ vertices[ivtx].ka = (float)(ka*KA_ADJUSTEMENT);
}
}