Skip to content

Commit

Permalink
Attempt at #1084
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Mar 26, 2024
1 parent bf0dfe0 commit 6ab85b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ function BMI.get_value_ptr(model::Model, name::AbstractString)
model.integrator.u.storage
elseif name == "basin.level"
get_tmp(model.integrator.p.basin.current_level, 0)
elseif name == "basin.infiltration"
elseif name == "basin.infiltration_instantaneous"
get_tmp(model.integrator.p.basin.vertical_flux, 0).infiltration
elseif name == "basin.drainage"
elseif name == "basin.drainage_instantaneous"
get_tmp(model.integrator.p.basin.vertical_flux, 0).drainage
elseif name == "basin.infiltration_integrated"
model.integrator.p.basin.vertical_flux_bmi.infiltration
elseif name == "basin.drainage_integrated"
model.integrator.p.basin.vertical_flux_bmi.drainage
elseif name == "basin.subgrid_level"
model.integrator.p.subgrid.level
elseif name == "user_demand.demand"
Expand Down
4 changes: 3 additions & 1 deletion core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ function integrate_flows!(u, t, integrator)::Nothing
(; p, dt) = integrator
(; graph, user_demand, basin) = p
(; flow, flow_dict, flow_prev, flow_integrated) = graph[]
(; vertical_flux, vertical_flux_prev, vertical_flux_integrated) = basin
(; vertical_flux, vertical_flux_prev, vertical_flux_integrated, vertical_flux_bmi) =
basin
flow = get_tmp(flow, 0)
vertical_flux = get_tmp(vertical_flux, 0)
if !isempty(flow_prev) && isnan(flow_prev[1])
Expand All @@ -121,6 +122,7 @@ function integrate_flows!(u, t, integrator)::Nothing

@. flow_integrated += 0.5 * (flow + flow_prev) * dt
@. vertical_flux_integrated += 0.5 * (vertical_flux + vertical_flux_prev) * dt
@. vertical_flux_bmi += 0.5 * (vertical_flux + vertical_flux_prev) * dt

for (i, id) in enumerate(user_demand.node_id)
src_id = inflow_id(graph, id)
Expand Down
3 changes: 3 additions & 0 deletions core/src/parameter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct Basin{T, C, V1, V2, V3} <: AbstractParameterNode
vertical_flux::V2
vertical_flux_prev::V3
vertical_flux_integrated::V3
vertical_flux_bmi::V3
# Cache this to avoid recomputation
current_level::T
current_area::T
Expand All @@ -176,6 +177,7 @@ struct Basin{T, C, V1, V2, V3} <: AbstractParameterNode
vertical_flux::V2,
vertical_flux_prev::V3,
vertical_flux_integrated,
vertical_flux_bmi,
current_level::T,
current_area::T,
area,
Expand All @@ -192,6 +194,7 @@ struct Basin{T, C, V1, V2, V3} <: AbstractParameterNode
vertical_flux,
vertical_flux_prev,
vertical_flux_integrated,
vertical_flux_bmi,
current_level,
current_area,
area,
Expand Down
2 changes: 2 additions & 0 deletions core/src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ function Basin(db::DB, config::Config, chunk_sizes::Vector{Int})::Basin
)
vertical_flux_prev = zero(vertical_flux)
vertical_flux_integrated = zero(vertical_flux)
vertical_flux_bmi = zero(vertical_flux)

if config.solver.autodiff
current_level = DiffCache(current_level, chunk_sizes)
Expand All @@ -530,6 +531,7 @@ function Basin(db::DB, config::Config, chunk_sizes::Vector{Int})::Basin
vertical_flux,
vertical_flux_prev,
vertical_flux_integrated,
vertical_flux_bmi,
current_level,
current_area,
area,
Expand Down

0 comments on commit 6ab85b3

Please sign in to comment.