Skip to content

Commit

Permalink
Bring back formulate_flows!
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Sep 28, 2023
1 parent a6062a0 commit b3a8b33
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions core/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1075,19 +1075,6 @@ function formulate_flow!(
return nothing
end

function formulate_flow!(
node::AbstractParameterNode,
p::Parameters,
storage::AbstractVector,
t::Float64,
)::Nothing
node_type = nameof(typeof(node))
if !isa(node, Union{Basin, LevelBoundary, DiscreteControl, PidControl, Terminal})
error("'formulate_flow!' not defined for nodes of type $node_type.")
end
return nothing
end

function formulate!(
du::ComponentVector,
connectivity::Connectivity,
Expand All @@ -1109,6 +1096,30 @@ function formulate!(
return nothing
end

function formulate_flows!(p::Parameters, storage::AbstractVector, t::Float64)::Nothing
(;
linear_resistance,
manning_resistance,
tabulated_rating_curve,
flow_boundary,
pump,
outlet,
user,
fractional_flow,
) = p

formulate_flow!(linear_resistance, p, storage, t)
formulate_flow!(manning_resistance, p, storage, t)
formulate_flow!(tabulated_rating_curve, p, storage, t)
formulate_flow!(flow_boundary, p, storage, t)
formulate_flow!(pump, p, storage, t)
formulate_flow!(outlet, p, storage, t)
formulate_flow!(user, p, storage, t)

# FractionalFlow must be done last as it relies on formulated input flows
formulate_flow!(fractional_flow, p, storage, t)
end

"""
The right hand side function of the system of ODEs set up by Ribasim.
"""
Expand All @@ -1135,13 +1146,7 @@ function water_balance!(
formulate!(du, basin, storage)

# First formulate intermediate flows
for nodefield in nodefields(p)
if nodefield == :fractional_flow
continue
end
formulate_flow!(getfield(p, nodefield), p, storage, t)
end
formulate_flow!(p.fractional_flow, p, storage, t)
formulate_flows!(p, storage, t)

# Now formulate du
formulate!(du, connectivity, flow, basin)
Expand Down

0 comments on commit b3a8b33

Please sign in to comment.