TopoToolbox / libtopotoolbox

A C library for the analysis of digital elevation models.
https://topotoolbox.github.io/libtopotoolbox/
GNU General Public License v3.0
0 stars 3 forks source link

excesstopography: Fix numerical error in eikonal solver #54

Closed wkearn closed 1 week ago

wkearn commented 1 week ago

Fixes #53

This bug turns out to result from numerical issues when applying the eikonal solver, especially when the elevations are large and the slopes are small. You end up taking the square root of a negative number and the resulting proposal is NaN, which is never accepted and so the infinite elevations are left in the DEM. Modifying the eikonal solution formula seems to avoid these numerical problems even while still using single precision data.

A new test is added to test/excesstopography.cpp to verify this behavior. It does not directly test the eikonal solver, but instead tests the case from #53.