Skip to content

Commit

Permalink
Test Integrating discontinuous flow (#1499)
Browse files Browse the repository at this point in the history
Fixes #1498.
  • Loading branch information
SouthEndMusic authored May 24, 2024
1 parent a45d8c8 commit c0879ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function create_callbacks(
push!(callbacks, integrating_flows_cb)

tstops = get_tstops(basin.time.time, starttime)
basin_cb = PresetTimeCallback(tstops, update_basin; save_positions = (false, false))
basin_cb = PresetTimeCallback(tstops, update_basin!; save_positions = (false, false))
push!(callbacks, basin_cb)

tstops = get_tstops(tabulated_rating_curve.time.time, starttime)
Expand Down Expand Up @@ -426,7 +426,7 @@ function save_subgrid_level(u, t, integrator)
end

"Load updates from 'Basin / time' into the parameters"
function update_basin(integrator)::Nothing
function update_basin!(integrator)::Nothing
(; p, u) = integrator
(; basin) = p
(; storage) = u
Expand Down
24 changes: 24 additions & 0 deletions core/test/time_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,27 @@ end
basin_table.precipitation .≈ time_table.fixed_area .* time_table.precipitation,
)
end

@testitem "Integrate over discontinuity" begin
import BasicModelInterface as BMI
using Ribasim: get_tmp

toml_path = normpath(@__DIR__, "../../generated_testmodels/level_demand/ribasim.toml")
@test ispath(toml_path)
day = 86400.0

saveat = 20day
config = Ribasim.Config(
toml_path;
solver_saveat = saveat,
solver_dt = 5day,
solver_algorithm = "Euler",
)
model = Ribasim.Model(config)
starting_precipitation =
get_tmp(model.integrator.p.basin.vertical_flux, 0).precipitation[1]
BMI.update_until(model, saveat)
mean_precipitation = only(model.saved.vertical_flux.saveval).precipitation[1]
# Given that precipitation stops after 15 of the 20 days
@test mean_precipitation 3 / 4 * starting_precipitation
end

0 comments on commit c0879ca

Please sign in to comment.