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

Introduce custom TrapezoidIntegrationCallback to integrate flows and basin forcings #1468

Closed
wants to merge 13 commits into from
8 changes: 6 additions & 2 deletions core/src/Ribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ using DiffEqCallbacks:
PeriodicCallback,
PresetTimeCallback,
SavedValues,
SavingCallback
SavingCallback,
IntegratingCallback,
IntegratingSumCallback,
IntegrandValues,
IntegrandValuesSum
using EnumX: EnumX, @enumx
using ForwardDiff: pickchunksize
using Graphs:
Expand Down Expand Up @@ -63,7 +67,7 @@ using SciMLBase:
ODEFunction,
ODEProblem,
ODESolution,
VectorContinuousCallback,
DiscreteCallback,
get_proposed_dt
using SparseArrays: SparseMatrixCSC, spzeros
using SQLite: SQLite, DB, Query, esc_id
Expand Down
8 changes: 4 additions & 4 deletions core/src/allocation_optim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function set_initial_capacities_source!(
)::Nothing
(; problem) = allocation_model
(; graph, allocation) = p
(; mean_flows) = allocation
(; integrated_flow, integrated_flow_mapping) = allocation
(; subnetwork_id) = allocation_model
source_constraints = problem[:source]
main_network_source_edges = get_main_network_connections(p, subnetwork_id)
Expand All @@ -266,7 +266,7 @@ function set_initial_capacities_source!(
# If it is a source edge for this allocation problem
if edge ∉ main_network_source_edges
# Reset the source to the averaged flow over the last allocation period
source_capacity = mean_flows[edge][]
source_capacity = integrated_flow[integrated_flow_mapping[edge]]
JuMP.set_normalized_rhs(
source_constraints[edge],
# It is assumed that the allocation procedure does not have to be differentiated.
Expand Down Expand Up @@ -361,11 +361,11 @@ function get_basin_data(
(; graph, basin, level_demand, allocation) = p
(; vertical_flux) = basin
(; Δt_allocation) = allocation_model
(; mean_flows) = allocation
(; integrated_flow, integrated_flow_mapping) = allocation
@assert node_id.type == NodeType.Basin
vertical_flux = get_tmp(vertical_flux, 0)
_, basin_idx = id_index(basin.node_id, node_id)
influx = mean_flows[(node_id, node_id)][]
influx = integrated_flow[integrated_flow_mapping[node_id, node_id]]
_, basin_idx = id_index(basin.node_id, node_id)
storage_basin = u.storage[basin_idx]
control_inneighbors = inneighbor_labels_type(graph, node_id, EdgeType.control)
Expand Down
6 changes: 3 additions & 3 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ function BMI.get_value_ptr(model::Model, name::AbstractString)::AbstractVector{F
elseif name == "basin.drainage"
model.integrator.p.basin.vertical_flux_from_input.drainage
elseif name == "basin.infiltration_integrated"
model.integrator.p.basin.vertical_flux_bmi.infiltration
model.saved.integrated_bmi_data.infiltration
elseif name == "basin.drainage_integrated"
model.integrator.p.basin.vertical_flux_bmi.drainage
model.saved.integrated_bmi_data.drainage
elseif name == "basin.subgrid_level"
model.integrator.p.subgrid.level
elseif name == "user_demand.demand"
vec(model.integrator.p.user_demand.demand)
elseif name == "user_demand.realized"
model.integrator.p.user_demand.realized_bmi
model.saved.integrated_bmi_data.user_realized
else
error("Unknown variable $name")
end
Expand Down
Loading
Loading