From 24b8fff438be1b325356ca2d4f8bd1242f3c432b Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Mon, 16 Dec 2024 13:26:10 +0100 Subject: [PATCH] update_subgrid_level! --- core/src/callback.jl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/callback.jl b/core/src/callback.jl index 467e71060..4e2440210 100644 --- a/core/src/callback.jl +++ b/core/src/callback.jl @@ -671,12 +671,23 @@ function apply_parameter_update!(parameter_update)::Nothing end function update_subgrid_level!(integrator)::Nothing - (; p) = integrator + (; p, t) = integrator du = get_du(integrator) basin_level = p.basin.current_properties.current_level[parent(du)] subgrid = integrator.p.subgrid - for (i, (index, interp)) in enumerate(zip(subgrid.basin_index, subgrid.interpolations)) - subgrid.level[i] = interp(basin_level[index]) + + i = 0 + # First update the all the subgrids with static h(h) relations + for (index, hh_itp) in zip(subgrid.basin_index, subgrid.interpolations) + i += 1 + subgrid.level[i] = hh_itp(basin_level[index]) + end + # Then update the subgrids with dynamic h(h) relations + for (index, lookup) in zip(subgrid.basin_index_time, current_interpolation_index) + i += 1 + itp_index = lookup(t) + hh_itp = subgrid.interpolations_time[itp_index] + subgrid.level[i] = hh_itp(basin_level[index]) end end