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

Calculate tracer concentrations internally #1849

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

evetion
Copy link
Member

@evetion evetion commented Sep 29, 2024

Fixes #1105

Very much a work in progress. Currently calculates the concentration of hardcoded tracers, using no user input from tables (although that stage has been set). Ever since the rework from Bart in #1819 I felt calculating tracers would be simple to implement.

This uses the intermediate flows from update_cumulative_flows to update the mass balance in all basins using straightforward addition/subtraction for each solver timestep. As such it should be more accurate than Delwaq (which uses the mean flows at the saveat interval). I do see some notable differences from Delwaq which needs investigating. Continuity tracer looks good though, so I'm slightly optimistic.

My initial attempt was to add this calculation to the save_flow callback, at the same time interval we export to Delwaq, but since this only does addition over large timesteps (whereas Delwaq does integration) the results were quite off (especially in the beginning, hitting negative concentrations). The end results looked similar to this approach. I also looked into adding this stuff instead to the water_balance! methods, but I'm out of my depth in how the RHS works (in terms of sciml, caches, etc.).

  • Generic parsing of user defined concentration input
  • Decide on either using interpolation for temporal input or update (discretely) via callback: update: Use discrete callback for updating concentrations
  • Hook up use_evaporation (and come up with a better name, evaporate_mass?)
  • Compare to Delwaq and explain differences (test smaller saveat timesteps)
  • Added missing UserDemandConcentration, enabling temperature or other discharges from such nodes.
  • edit: In new issue UserDemand should return mass, not swallow it.

@evetion
Copy link
Member Author

evetion commented Oct 2, 2024

This seems good to test with toy models now, everything is hooked up and running. HWS model runs fine. In testing the new testmodel I found I had to calculate inflows first and recalculate the concentration before outflows, otherwise the inflow/outflow could be reversed and result in negative mass.

The new testmodel switches a linear resistance on and off based on the concentration in the basin 🎉. However, I do see some weird effects, like consistent negative flows in both the turned off Linearresistance and Terminal, and the fact that the concentration goes much higher than the control should allow for. I guess I made an unrealistic model.

PS Is it correct that a linearresistance can be switched on/off based based on control, but that setting the resistance very high, or flow to 0 does not work?

@visr
Copy link
Member

visr commented Oct 3, 2024

PS Is it correct that a linearresistance can be switched on/off based based on control, but that setting the resistance very high, or flow to 0 does not work?

No that should also work.

@evetion
Copy link
Member Author

evetion commented Oct 10, 2024

So if you make a small toy model with huge flows and a control that acts like a pinball machine, results are bad (and at one time lead to a timeout (2h+) of the CI with the new tolerances). The current model can be improved for sure (probably by fixing the discrete control and introducing a levelboundary instead of the terminal, so the salt water is flushed better), but it now tests the different callbacks, and triggers the control correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add continuity tracer
2 participants