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

Add min_upstream_level and max_downstream_level to Pump and Outlet #1792

Merged
merged 6 commits into from
Sep 3, 2024

Conversation

visr
Copy link
Member

@visr visr commented Sep 3, 2024

Fixes #1771, the remaining part after #1788 was merged. I split out #1789 as a separate issue, though in this PR a lot of the preparatory work is already done (all changes related to TabulatedRatingCurve).

This is breaking due to #1791 because of adding new optional columns.
It is also breaking that TabulatedRatingCurve and Pump now only support one outflow edge. As far as I know this wasn't used anywhere though. We cannot easily support that anymore since we now look at downstream levels. Users should instead use separate Pumps or TabulatedRatingCurves, which can share the same upstream Basin, but go to different downstream nodes.

I decided to start the reduction factors for reaching these limits from 2 centimeters away. There was one existing level based reduction factor, the level difference in the Outlet, which I also adjusted from 10 to 2 centimeter. I feel like 10 centimeter would be too much in areas where the level is controlled up to centimeter accuracies.

@visr visr added the breaking A change that breaks existing models label Sep 3, 2024
@Huite
Copy link
Contributor

Huite commented Sep 3, 2024

I decided to start the reduction factors for reaching these limits from 2 centimeters away. There was one existing level based reduction factor, the level difference in the Outlet, which I also adjusted from 10 to 2 centimeter. I feel like 10 centimeter would be too much in areas where the level is controlled up to centimeter accuracies.

This seems like something a user might want to control. 2 centimeter is probably a reasonable default, but why not make this part of the structure?

FWIW, mf6 uses auto_flow_reduce, which is still a bit vague, but something like that.

@visr
Copy link
Member Author

visr commented Sep 3, 2024

Yeah we may need to support that at some point, but not in this PR. We could either set it as a global setting in the TOML, or per node in the database.

Copy link
Collaborator

@SouthEndMusic SouthEndMusic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, but overall looking good


set_flow!(graph, inflow_edge, q, du)
_, src_level = get_level(p, inflow_id, t, du)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we don't ever use the first output of get_level, might be worth a refactor. I'm also not sure why you compare src_level to nothing, as the second output of get_level is always a number.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also isnothing looks a bit nicer to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I refactored get_level to return only a number, which I set to -Inf for Terminal to avoid reduction factors based on downstream level checks.

q *= reduction_factor(src_level - min_upstream_level, 0.02)
end

if dst_level !== nothing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I also see that comparing against nothing this way was already in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to check nothing with the new get_level.

- $Q$ is the realized Outlet flow rate.
- $Q_\text{set}$ is the Outlet's target `flow_rate`.
- $Q_{\min}$ and $Q_{\max}$ are the Outlet `min_flow_rate` and `max_flow_rate`.
- $\phi$ is the reduction factor, which smoothly reduces flow based on all of these criteria:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still be in favor of writing say

$$ Q = \mathrm{clamp}(\Phi Q_\text{set}, Q_{\min}, Q_{\max}) $$

and then

$$ \Phi = \phi(\ldots)\phi(\ldots)\phi(\ldots)\phi(\ldots) $$

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle the text is precise and with links to the reduction factor curious users can determine the exact equations. Though perhaps we can make the mathematical notation more complete besides the text.

- $Q$ is the realized Pump flow rate.
- $Q_\text{set}$ is the Pump's target `flow_rate`.
- $Q_{\min}$ and $Q_{\max}$ are the Pump `min_flow_rate` and `max_flow_rate`.
- $\phi$ is the reduction factor, which smoothly reduces flow based on all of these criteria:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@visr visr merged commit 77ba85a into main Sep 3, 2024
24 of 27 checks passed
@visr visr deleted the min-max branch September 3, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A change that breaks existing models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding min_upstream_level and max_downstream_level to Pump and Outlet
3 participants