Skip to content

Commit

Permalink
Precalculate TabulatedRatingCurve inflow edge
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed May 7, 2024
1 parent b4f37e3 commit 1d4cbab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/src/parameter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ Type parameter C indicates the content backing the StructVector, which can be a
of Vectors or Arrow Primitives, and is added to avoid type instabilities.
node_id: node ID of the TabulatedRatingCurve node
inflow_id: node ID across the incoming flow edge
active: whether this node is active and thus contributes flows
tables: The current Q(h) relationships
time: The time table used for updating the tables
control_mapping: dictionary from (node_id, control_state) to Q(h) and/or active state
"""
struct TabulatedRatingCurve{C} <: AbstractParameterNode
node_id::Vector{NodeID}
inflow_id::Vector{NodeID}
active::BitVector
tables::Vector{ScalarInterpolation}
time::StructVector{TabulatedRatingCurveTimeV1, C, Int}
Expand Down
17 changes: 14 additions & 3 deletions core/src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ function LinearResistance(db::DB, config::Config, graph::MetaGraph)::LinearResis
)
end

function TabulatedRatingCurve(db::DB, config::Config)::TabulatedRatingCurve
function TabulatedRatingCurve(
db::DB,
config::Config,
graph::MetaGraph,
)::TabulatedRatingCurve
static = load_structvector(db, config, TabulatedRatingCurveStaticV1)
time = load_structvector(db, config, TabulatedRatingCurveTimeV1)

Expand Down Expand Up @@ -322,7 +326,14 @@ function TabulatedRatingCurve(db::DB, config::Config)::TabulatedRatingCurve
error("Errors occurred when parsing TabulatedRatingCurve data.")
end

return TabulatedRatingCurve(node_ids, active, interpolations, time, control_mapping)
return TabulatedRatingCurve(
node_ids,
inflow_id.(Ref(graph), node_ids),
active,
interpolations,
time,
control_mapping,
)
end

function ManningResistance(db::DB, config::Config, graph::MetaGraph)::ManningResistance
Expand Down Expand Up @@ -1061,7 +1072,7 @@ function Parameters(db::DB, config::Config)::Parameters

linear_resistance = LinearResistance(db, config, graph)
manning_resistance = ManningResistance(db, config, graph)
tabulated_rating_curve = TabulatedRatingCurve(db, config)
tabulated_rating_curve = TabulatedRatingCurve(db, config, graph)
fractional_flow = FractionalFlow(db, config, graph)
level_boundary = LevelBoundary(db, config)
flow_boundary = FlowBoundary(db, config)
Expand Down
5 changes: 3 additions & 2 deletions core/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ function formulate_flow!(
t::Number,
)::Nothing
(; basin, graph) = p
(; node_id, active, tables) = tabulated_rating_curve
(; node_id, active, tables, inflow_id) = tabulated_rating_curve

for (i, id) in enumerate(node_id)
upstream_basin_id = inflow_id(graph, id)
upstream_basin_id = inflow_id[i]
downstream_ids = outflow_ids(graph, id)

if active[i]
Expand Down

0 comments on commit 1d4cbab

Please sign in to comment.