Skip to content

Commit

Permalink
Add reset_cumulatives!
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Oct 3, 2024
1 parent 60cbc38 commit 5fb5c1d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,35 @@ function update_subgrid_level(model::Model)::Model
update_subgrid_level!(model.integrator)
return model
end

function reset_cumulatives!(integrator)::Nothing
(; u, p, t) = integrator

# Update the storage0 to the current storage
# such that the current storage is correct.
current_storage = p.basin.current_storage[parent(u)]
formulate_storages!(current_storage, u, u, p, t)
p.basin.storage0 .= current_storage

# Reset the cumulative states
u.tabulated_rating_curve .= 0.0
u.pump .= 0.0
u.outlet .= 0.0
u.user_demand_inflow .= 0.0
u.user_demand_outflow .= 0.0
u.linear_resistance .= 0.0
u.manning_resistance .= 0.0
u.evaporation .= 0.0
u.infiltration .= 0.0

# Reset the exact cumulative parameters
p.basin.cumulative_precipitation .= 0.0
p.basin.cumulative_drainage .= 0.0
p.basin.cumulative_drainage .= 0.0
p.flow_boundary.cumulative_flow .= 0.0

# Allow the solver to handle the discontinuity
u_modified!(integrator, true)

return nothing
end

0 comments on commit 5fb5c1d

Please sign in to comment.