Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extrapolating the LinearInterpolation #279

Closed
7 tasks done
visr opened this issue Jun 6, 2023 · 2 comments · Fixed by #1486
Closed
7 tasks done

Extrapolating the LinearInterpolation #279

visr opened this issue Jun 6, 2023 · 2 comments · Fixed by #1486
Labels
validation Related to model validation

Comments

@visr
Copy link
Member

visr commented Jun 6, 2023

We use the LinearInterpolation from DataInterpolations for Q(h), A(S) and h(S) relations, the last two provided by users as A(h) once #225 is fixed.

It's important to control the extrapolation behavior, e.g. what happens if h is below the lowest h in the table, or above the largest. We currently have the default behavior of LinearInterpolation, which is linear based on the slope of the last segment. Visually:

image

I think the linear extrapolation on the high end is fine, since generally the trend continues there, rather than stop. On the low end however we have a different situation, where we should keep it constant instead. So I think this is desired:

image

There is no direct option for this in DataInterpolations, but it can be achieved by prepending an entry in the table, using prevfloat on the input, and the same output to get a horizontal segment.

Q(h)

A(S) and h(S), provided by a user as A(h)

The interpolation input, level, gets sorted. We currently don't enforce that the interpolation output, Q or A, are increasing (or staying constant). In most cases you want this, but it's possible to image scenarios where you don't. A bit contrived, but:

image

A decreasing surface water area is possible if you think about fishbowl or cave like profiles. And for Q(h) naturally this typically won't happen, but it could be of interest if you want to encode steering behavior without separate control rules.

  • Since it is quite rare, and in most cases a decreasing Q or A is a user error, I think we should start enforcing this. If there is a need for it in the future, we could add config options to enable decreasing Q or A, to allow the user to say, I know what I'm doing, don't get in my way.

  • For Q(h) a single row is probably fine, but for A(h) we need at least two, where the h is increasing, otherwise you cannot have storage.

@github-project-automation github-project-automation bot moved this to To do in Ribasim Jun 6, 2023
SouthEndMusic pushed a commit that referenced this issue Jun 14, 2023
Fixes #225

This removes the need to provide the storage for a profile. We can
calculate it ourselves by integrating over A(h) to get A(S) and h(S).

First this updates the test models to a correct storage in the profile.
Then we calculate the profile and get the same results. Then we remove
the storage from the schemas and docs.

I hoped this would help with #80 but based on the plot I added there it
doesn't seem to. This does not yet add all the validation and
extrapolation for lookup tables as described in #279, that can be done
separately.
@SouthEndMusic
Copy link
Collaborator

In a basin profile table there should never be the same level twice, it might be good to validate this.

visr added a commit that referenced this issue Jun 19, 2023
I have implemented the physical interpolation (as proposed in
#225). I have not checked
whether this implementation is exactly what we want for extrapolation
(#279), but this
implementation assumes that the storage is 0 at the lowest level and
does linear extrapolation of the area as a function of the level based
on the last 2 values.

This does not solve the problem of high oscillating flows produced by
the ManningResistance node as hoped
(#80). I think the problem
there is that the calculated flows are way to large, and therefore the
equilibrium is overshooted at every time step.

I cannot wrap my head around the current ManningResistance
implementation. I understand that flow occurs due to a difference in
level, but I do not understand why that means that all the water comes
in motion, not just the bit at the top (which is why I find
LinearResistance more intuitive). Is anyone familiar with a
ManningResistance being used for flow that can go both directions, or is
it only used for flow that goes one direction due to gravity? In that
last case I understand better why all water is in motion.

Also, the current implementation assumes the presence of a lot of water
in the channel itself, which fluctuates with the level in the upstream
basin with no regard for (local) water preservation (by which I do not
mean that the ManningResistance node is not preserving but it is less
physical).

---------

Co-authored-by: Bart de Koning <[email protected]>
Co-authored-by: Martijn Visser <[email protected]>
@visr visr added the validation Related to model validation label Jun 30, 2023
@SnippenE SnippenE added the needs-refinement Issues that are too large and need refinement label Feb 22, 2024
@visr visr removed the needs-refinement Issues that are too large and need refinement label Feb 22, 2024
@visr visr removed their assignment Feb 22, 2024
@gijsber
Copy link
Contributor

gijsber commented Feb 22, 2024

problem also experienced by @Fati-Mon

visr added a commit that referenced this issue May 21, 2024
Fixes a part of #279.

The four checks added here are:

- At least two datapoints are needed.
- The `flow_rate` must start at 0.
- The `level` cannot be repeated.
- The `flow_rate` cannot decrease with increasing `level`.

And additionally we now ensure that flow rates are kept at 0 for levels
below the minimum.

~~I should still check the docs, they may need some updating.~~ The
other part of #279 is best done in a separate PR as it relates to the
Basin / profile table.

---------

Co-authored-by: Bart de Koning <[email protected]>
SouthEndMusic pushed a commit that referenced this issue May 21, 2024
Fixes #279.
Follow up of #1469.

Most rules were already in place, this just adds a bit more validation.
I moved the validation out of the constructor to be more in line with
the other validation taking place.
@github-project-automation github-project-automation bot moved this from To do to ✅ Done in Ribasim May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validation Related to model validation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants