diff --git a/core/src/callback.jl b/core/src/callback.jl index 761d89526..215bdace9 100644 --- a/core/src/callback.jl +++ b/core/src/callback.jl @@ -93,7 +93,7 @@ function create_callbacks( end """ -Integrate flows over timesteps +Integrate flows over the last timestep """ function integrate_flows!(u, t, integrator)::Nothing (; p, dt) = integrator @@ -422,7 +422,8 @@ function set_control_params!(p::Parameters, node_id::NodeID, control_state::Stri end end -"Copy the current flow to the SavedValues" +"Compute the average flows over the last saveat interval and write +them to SavedValues" function save_flow(u, t, integrator) (; dt, p) = integrator (; graph) = p diff --git a/core/src/model.jl b/core/src/model.jl index ffd8b00fe..81c8f337f 100644 --- a/core/src/model.jl +++ b/core/src/model.jl @@ -155,7 +155,7 @@ function Model(config::Config)::Model end "Get all saved times in seconds since start" -tstops(model::Model)::Vector{Float64} = model.integrator.sol.t +tsaves(model::Model)::Vector{Float64} = model.integrator.sol.t "Get all saved times as a Vector{DateTime}" function datetimes(model::Model)::Vector{DateTime} diff --git a/core/src/write.jl b/core/src/write.jl index 0dcafa59a..9c7b39610 100644 --- a/core/src/write.jl +++ b/core/src/write.jl @@ -64,7 +64,7 @@ function get_storages_and_levels( (; sol, p) = integrator node_id = p.basin.node_id.values::Vector{NodeID} - tsteps = datetime_since.(tstops(model), config.starttime) + tsteps = datetime_since.(tsaves(model), config.starttime) storage = hcat([collect(u_.storage) for u_ in sol.u]...) level = zero(storage) diff --git a/core/test/allocation_test.jl b/core/test/allocation_test.jl index c6b407464..dd361397e 100644 --- a/core/test/allocation_test.jl +++ b/core/test/allocation_test.jl @@ -341,7 +341,7 @@ end model = Ribasim.run(toml_path) storage = Ribasim.get_storages_and_levels(model).storage[1, :] - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) p = model.integrator.p (; user_demand, graph, allocation, basin, level_demand) = p diff --git a/core/test/control_test.jl b/core/test/control_test.jl index a4d916707..ae572e45e 100644 --- a/core/test/control_test.jl +++ b/core/test/control_test.jl @@ -32,7 +32,7 @@ ["off", "active", "on", "off", "inactive"] level = Ribasim.get_storages_and_levels(model).level - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) # Control times t_1 = discrete_control.record.time[3] @@ -56,7 +56,7 @@ end Δt = discrete_control.look_ahead[1] - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) t_control = discrete_control.record.time[2] t_control_index = searchsortedfirst(t, t_control) @@ -80,7 +80,7 @@ end Δt = discrete_control.look_ahead[1] - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) t_control = discrete_control.record.time[2] t_control_index = searchsortedfirst(t, t_control) @@ -100,7 +100,7 @@ end (; basin, pid_control, flow_boundary) = p level = Ribasim.get_storages_and_levels(model).level[1, :] - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) target_itp = pid_control.target[1] t_target_change = target_itp.t[2] @@ -161,7 +161,7 @@ end (; discrete_control) = p (; record, greater_than) = discrete_control level = Ribasim.get_storages_and_levels(model).level[1, :] - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) t_none_1 = discrete_control.record.time[2] t_in = discrete_control.record.time[3] @@ -192,7 +192,7 @@ end p = model.integrator.p (; discrete_control, pid_control) = p - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) level = Ribasim.get_storages_and_levels(model).level[1, :] target_high = diff --git a/core/test/run_models_test.jl b/core/test/run_models_test.jl index 3d96f5cb1..4d3fd0ae6 100644 --- a/core/test/run_models_test.jl +++ b/core/test/run_models_test.jl @@ -4,7 +4,7 @@ using Tables.DataAPI: nrow using Dates: DateTime import Arrow - using Ribasim: get_tstops, tstops + using Ribasim: get_tstops, tsaves toml_path = normpath(@__DIR__, "../../generated_testmodels/trivial/ribasim.toml") @test ispath(toml_path) @@ -84,7 +84,7 @@ end @testset "Results size" begin - nsaved = length(tstops(model)) + nsaved = length(tsaves(model)) @test nsaved > 10 # t0 has no flow, 2 flow edges and 2 boundary condition flows @test nrow(flow) == (nsaved - 1) * 4 @@ -189,7 +189,7 @@ end @test all(isconcretetype, fieldtypes(typeof(p))) @test successful_retcode(model) - @test allunique(Ribasim.tstops(model)) + @test allunique(Ribasim.tsaves(model)) @test model.integrator.sol.u[end] ≈ Float32[519.8817, 519.8798, 339.3959, 1418.4331] skip = Sys.isapple() atol = 1.5 @@ -366,7 +366,7 @@ end # No outlet flow when upstream level is below minimum crest level @test all(@. outlet_flow.flow_rate[t <= t_min_crest_level] == 0) - t = Ribasim.tstops(model) + t = Ribasim.tsaves(model) t_maximum_level = level.t[2] level_basin = Ribasim.get_storages_and_levels(model).level[:]