Skip to content

Commit

Permalink
Precompute basin bottoms for Manningresistance
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed May 8, 2024
1 parent ad544bb commit 715fffd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions core/src/parameter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ struct ManningResistance <: AbstractParameterNode
manning_n::Vector{Float64}
profile_width::Vector{Float64}
profile_slope::Vector{Float64}
upstream_bottom::Vector{Float64}
downstream_bottom::Vector{Float64}
control_mapping::Dict{Tuple{NodeID, String}, NamedTuple}
end

Expand Down
15 changes: 12 additions & 3 deletions core/src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ function TabulatedRatingCurve(
)
end

function ManningResistance(db::DB, config::Config, graph::MetaGraph)::ManningResistance
function ManningResistance(
db::DB,
config::Config,
graph::MetaGraph,
basin::Basin,
)::ManningResistance
static = load_structvector(db, config, ManningResistanceStaticV1)
parsed_parameters, valid =
parse_static_and_time(db, config, "ManningResistance"; static)
Expand All @@ -347,6 +352,8 @@ function ManningResistance(db::DB, config::Config, graph::MetaGraph)::ManningRes
end

node_id = NodeID.(NodeType.ManningResistance, parsed_parameters.node_id)
upstream_bottom = basin_bottom.(Ref(basin), inflow_id.(Ref(graph), node_id))
downstream_bottom = basin_bottom.(Ref(basin), outflow_id.(Ref(graph), node_id))

return ManningResistance(
node_id,
Expand All @@ -357,6 +364,8 @@ function ManningResistance(db::DB, config::Config, graph::MetaGraph)::ManningRes
parsed_parameters.manning_n,
parsed_parameters.profile_width,
parsed_parameters.profile_slope,
[bottom[2] for bottom in upstream_bottom],
[bottom[2] for bottom in downstream_bottom],
parsed_parameters.control_mapping,
)
end
Expand Down Expand Up @@ -1071,8 +1080,9 @@ function Parameters(db::DB, config::Config)::Parameters
error("Invalid number of connections for certain node types.")
end

basin = Basin(db, config, graph, chunk_sizes)
linear_resistance = LinearResistance(db, config, graph)
manning_resistance = ManningResistance(db, config, graph)
manning_resistance = ManningResistance(db, config, graph, basin)
tabulated_rating_curve = TabulatedRatingCurve(db, config, graph)
fractional_flow = FractionalFlow(db, config, graph)
level_boundary = LevelBoundary(db, config)
Expand All @@ -1086,7 +1096,6 @@ function Parameters(db::DB, config::Config)::Parameters
level_demand = LevelDemand(db, config)
flow_demand = FlowDemand(db, config)

basin = Basin(db, config, graph, chunk_sizes)
subgrid_level = Subgrid(db, config, basin)

p = Parameters(
Expand Down
16 changes: 12 additions & 4 deletions core/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,16 @@ function formulate_flow!(
t::Number,
)::Nothing
(; basin, graph) = p
(; node_id, active, length, manning_n, profile_width, profile_slope) =
manning_resistance
(;
node_id,
active,
length,
manning_n,
profile_width,
profile_slope,
upstream_bottom,
downstream_bottom,
) = manning_resistance
for (i, id) in enumerate(node_id)
inflow_edge = manning_resistance.inflow_edge[i]
outflow_edge = manning_resistance.outflow_edge[i]
Expand All @@ -465,8 +473,8 @@ function formulate_flow!(

_, h_a = get_level(p, inflow_id, t; storage)
_, h_b = get_level(p, outflow_id, t; storage)
_, bottom_a = basin_bottom(basin, inflow_id)
_, bottom_b = basin_bottom(basin, outflow_id)
bottom_a = upstream_bottom[i]
bottom_b = downstream_bottom[i]
slope = profile_slope[i]
width = profile_width[i]
n = manning_n[i]
Expand Down

0 comments on commit 715fffd

Please sign in to comment.