Deltares / Ribasim

Water resources modeling
https://ribasim.org/
MIT License
39 stars 5 forks source link

Investigate weirdness in basin profile interpolation #1551

Closed SouthEndMusic closed 3 months ago

SouthEndMusic commented 3 months ago

See https://github.com/Deltares/Ribasim/pull/1543#issuecomment-2163718293. The introduction of SmoothInterpolation reveiled some weirdness in the basin interpolation.

SouthEndMusic commented 3 months ago

The problem was probably with floating point errors. Calculating the level from the storage involves solving an equation of this form:

$$ \frac{1}{2}\frac{\Delta A}{\Delta t}(\ell-\ell_0)^2 + A_0(\ell-\ell_0) - (S-S_0) = 0. $$

The quadratic formula to solve this equation behaves poorly in the case that $\frac{\Delta A}{\Delta t}$ is small, as there is the transition between quadratic and linear behavior. What the new code does differently from the old code is that the threshold for when the area interpolation is considered constant is higher:

https://github.com/SouthEndMusic/SmoothInterpolation.jl/blob/8f31fd90176f969a68a9fdf9b134507857d689f4/src/cache.jl#L16

Note that this new threshold is just empirically determined.