Skip to content

Commit

Permalink
Refactor SimpleReservoir and Lake structs
Browse files Browse the repository at this point in the history
  • Loading branch information
verseve committed Nov 12, 2024
1 parent f42907a commit 089b2c2
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 242 deletions.
44 changes: 22 additions & 22 deletions src/flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ function update!(sf::SurfaceFlowRiver, network, doy)
# because of possible iterations set reservoir and lake inflow and total outflow at
# start to zero, the total sum of inflow and outflow at each sub time step is calculated
if !isnothing(reservoir)
reservoir.inflow .= 0.0
reservoir.totaloutflow .= 0.0
reservoir.actevap .= 0.0
reservoir.boundary_conditions.inflow .= 0.0
reservoir.variables.totaloutflow .= 0.0
reservoir.variables.actevap .= 0.0
end
if !isnothing(lake)
lake.inflow .= 0.0
lake.totaloutflow .= 0.0
lake.actevap .= 0.0
lake.boundary_conditions.inflow .= 0.0
lake.variables.totaloutflow .= 0.0
lake.variables.actevap .= 0.0
end

dt, its = stable_timestep(sf)
Expand Down Expand Up @@ -376,7 +376,7 @@ function update!(sf::SurfaceFlowRiver, network, doy)
n_downstream = length(downstream_nodes)
if n_downstream == 1
j = only(downstream_nodes)
qin[j] = reservoir.outflow[i]
qin[j] = reservoir.variables.outflow[i]
elseif n_downstream == 0
error(
"""A reservoir without a downstream river node is not supported.
Expand All @@ -397,7 +397,7 @@ function update!(sf::SurfaceFlowRiver, network, doy)
n_downstream = length(downstream_nodes)
if n_downstream == 1
j = only(downstream_nodes)
qin[j] = lake.outflow[i]
qin[j] = lake.variables.outflow[i]
elseif n_downstream == 0
error(
"""A lake without a downstream river node is not supported.
Expand Down Expand Up @@ -1108,7 +1108,7 @@ function shallowwater_river_update!(sw::ShallowWaterRiver, network, dt, doy, upd

q_in = get_inflow_waterbody(sw, links_at_node.src[i])
update!(reservoir, v, q_in + inflow_wb[i], dt)
river_v.q[i] = reservoir.outflow[v]
river_v.q[i] = reservoir.variables.outflow[v]
river_v.q_av[i] += river_v.q[i] * dt
end
(; lake, lake_index, inflow_wb) = sw.boundary_conditions
Expand All @@ -1117,7 +1117,7 @@ function shallowwater_river_update!(sw::ShallowWaterRiver, network, dt, doy, upd

q_in = get_inflow_waterbody(sw, links_at_node.src[i])
update!(lake, v, q_in + inflow_wb[i], doy, dt)
river_v.q[i] = lake.outflow[v]
river_v.q[i] = lake.variables.outflow[v]
river_v.q_av[i] += river_v.q[i] * dt
end
if update_h
Expand Down Expand Up @@ -1173,14 +1173,14 @@ end
function update!(sw::ShallowWaterRiver{T}, network, doy; update_h = true) where {T}
(; reservoir, lake) = sw.boundary_conditions
if !isnothing(reservoir)
reservoir.inflow .= 0.0
reservoir.totaloutflow .= 0.0
reservoir.actevap .= 0.0
reservoir.boundary_conditions.inflow .= 0.0
reservoir.variables.totaloutflow .= 0.0
reservoir.variables.actevap .= 0.0
end
if !isnothing(lake)
lake.inflow .= 0.0
lake.totaloutflow .= 0.0
lake.actevap .= 0.0
lake.boundary_conditions.inflow .= 0.0
lake.variables.totaloutflow .= 0.0
lake.variables.actevap .= 0.0
end
if !isnothing(sw.floodplain)
sw.floodplain.variables.q_av .= 0.0
Expand Down Expand Up @@ -1485,14 +1485,14 @@ function update!(
(; reservoir, lake) = swr.boundary_conditions

if !isnothing(reservoir)
reservoir.inflow .= 0.0
reservoir.totaloutflow .= 0.0
reservoir.actevap .= 0.0
reservoir.boundary_conditions.inflow .= 0.0
reservoir.variables.totaloutflow .= 0.0
reservoir.variables.actevap .= 0.0
end
if !isnothing(lake)
lake.inflow .= 0.0
lake.totaloutflow .= 0.0
lake.actevap .= 0.0
lake.boundary_conditions.inflow .= 0.0
lake.variables.totaloutflow .= 0.0
lake.variables.actevap .= 0.0
end
swr.variables.q_av .= 0.0
swr.variables.h_av .= 0.0
Expand Down
8 changes: 4 additions & 4 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ end
function get_param_res(model)
return Dict(
symbols"vertical.atmospheric_forcing.precipitation" =>
model.lateral.river.boundary_conditions.reservoir.precipitation,
model.lateral.river.boundary_conditions.reservoir.boundary_conditions.precipitation,
symbols"vertical.atmospheric_forcing.potential_evaporation" =>
model.lateral.river.boundary_conditions.reservoir.evaporation,
model.lateral.river.boundary_conditions.reservoir.boundary_conditions.evaporation,
)
end

function get_param_lake(model)
return Dict(
symbols"vertical.atmospheric_forcing.precipitation" =>
model.lateral.river.boundary_conditions.lake.precipitation,
model.lateral.river.boundary_conditions.lake.boundary_conditions.precipitation,
symbols"vertical.atmospheric_forcing.potential_evaporation" =>
model.lateral.river.boundary_conditions.lake.evaporation,
model.lateral.river.boundary_conditions.lake.boundary_conditions.evaporation,
)
end

Expand Down
Loading

0 comments on commit 089b2c2

Please sign in to comment.