Deltares / Ribasim

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

`ManningResistance` causes unexpected oscillations #1743

Closed SouthEndMusic closed 3 months ago

SouthEndMusic commented 3 months ago

In the basic model, the levels of the basins around the ManningResistance look like this with saveat = 0:

plot

These oscillations are damped by setting k = 100.0 in formulate_flow! for the ManningResistance:

plot

@Huite do you think that's a valid change? It relaxes the approximation of the absolute value function.

visr commented 3 months ago

Oh nice find. To add some context, the basic model has only static parameters, so we expect just smoothly going to a dynamic equilibrium like in the lower figure. There is a constant inflow on the upstream side, so that level should be slightly higher the whole time.

SouthEndMusic commented 3 months ago

It would be nice if we had a more structural solution than parameter fiddling, though. I think the problem (still) is that the flow is too sensitive to head difference changes around a head difference of 0.

Huite commented 3 months ago

@Huite do you think that's a valid change? It relaxes the approximation of the absolute value function

It's currently k=1000.0 right? I haven't looked at atan enough to know in at which $\Delta h$ it starts to make a difference.

Don't we use a quadratic sigmoid somewhere else? That has the upside of being cheaper to compute and is more explicit in when it's "turned" on.

SouthEndMusic commented 3 months ago

Not sure what a quadratic signmoid is or what this means:

... and is more explicit in when it's "turned" on.

What we want is to limit $\frac{\text{d}Q}{\text{d}\Delta h}$ which is essentially the inverse of the resistance used in LinearResistance. So we could make that an optional parameter which we enforce in the ManningResistance formulation (I would have to look into what's the best way to do that).

Huite commented 3 months ago

I don't think it's a proper term, I mean something like this, more in general for reduction factors:

image

In our case, the Sf isn't naturally bounded (0, 1), so you specify when the (linear reduction) starts. But to get smooth gradients you adjust the function a bit, $\Omega$ control when you start adjusting. For linear relationship you'd only use $\Omega$.

And what I mean with "turning on/off", basically this (for arctan):

image

SouthEndMusic commented 3 months ago

I see, but our problem here is of a different nature (I think). We're not looking at smooth transitions to 0, we're looking at bounding a derivative. The manning resistance behaves like $\text{sign}(\Delta h)\sqrt{|\Delta h|}$:

image

which is bad around $0$.

SouthEndMusic commented 3 months ago

Suggestion:

https://www.desmos.com/calculator/g6xogkegp5

Here you can set a threshold below which the curve is modified to prevent the derivative going to $\infty$.