Skip to content

Commit

Permalink
Renaming SurfaceFlow structs
Browse files Browse the repository at this point in the history
Refer to the kinematic wave method, more explicit and easier to distinquish from other river or overland flow methods.
  • Loading branch information
vers-w committed Nov 29, 2024
1 parent 92085a7 commit 7ba754a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
48 changes: 26 additions & 22 deletions src/routing/surface_kinwave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ function RiverFlowBC(n, reservoir, lake)
end

"River flow model using the kinematic wave method and the Manning flow equation"
@with_kw struct SurfaceFlowRiver{T, R, L, A} <: AbstractRiverFlowModel
@with_kw struct KinWaveRiverFlow{T, R, L, A} <: AbstractRiverFlowModel
timestepping::TimeStepping{T}
boundary_conditions::RiverFlowBC{T, R, L}
parameters::RiverFlowParameters{T}
variables::FlowVariables{T}
allocation::A # Water allocation
end

"Initialize river flow model `SurfaceFlowRiver`"
function SurfaceFlowRiver(
"Initialize river flow model `KinWaveRiverFlow`"
function KinWaveRiverFlow(
dataset,
config,
indices;
Expand All @@ -181,7 +181,7 @@ function SurfaceFlowRiver(
parameters = RiverFlowParameters(dataset, config, indices, river_length, river_width)
boundary_conditions = RiverFlowBC(n, reservoir, lake)

sf_river = SurfaceFlowRiver(;
sf_river = KinWaveRiverFlow(;
timestepping,
boundary_conditions,
parameters,
Expand Down Expand Up @@ -215,15 +215,15 @@ end
end

"Overland flow model using the kinematic wave method and the Manning flow equation"
@with_kw struct SurfaceFlowLand{T}
@with_kw struct KinWaveOverlandFlow{T}
timestepping::TimeStepping{T}
boundary_conditions::LandFlowBC{T}
parameters::ManningFlowParameters{T}
variables::LandFlowVariables{T}
end

"Initialize Overland flow model `SurfaceFlowLand`"
function SurfaceFlowLand(dataset, config, indices; slope, flow_length, flow_width)
"Initialize Overland flow model `KinWaveOverlandFlow`"
function KinWaveOverlandFlow(dataset, config, indices; slope, flow_length, flow_width)
mannings_n = ncread(
dataset,
config,
Expand All @@ -240,13 +240,14 @@ function SurfaceFlowLand(dataset, config, indices; slope, flow_length, flow_widt
variables = LandFlowVariables(; flow = FlowVariables(n), to_river = zeros(Float, n))
parameters = ManningFlowParameters(slope, mannings_n, flow_length, flow_width)
boundary_conditions = LandFlowBC(; inwater = zeros(Float, n))
sf_land = SurfaceFlowLand(; timestepping, boundary_conditions, variables, parameters)
sf_land =
KinWaveOverlandFlow(; timestepping, boundary_conditions, variables, parameters)

return sf_land
end

"Update overland flow model `SurfaceFlowLand` for a single timestep"
function surfaceflow_land_update!(model::SurfaceFlowLand, network, dt)
"Update overland flow model `KinWaveOverlandFlow` for a single timestep"
function surfaceflow_land_update!(model::KinWaveOverlandFlow, network, dt)
(;
order_of_subdomains,
order_subdomain,
Expand Down Expand Up @@ -305,10 +306,10 @@ function surfaceflow_land_update!(model::SurfaceFlowLand, network, dt)
end

"""
Update overland flow model `SurfaceFlowLand` for a single timestep `dt`. Timestepping within
Update overland flow model `KinWaveOverlandFlow` for a single timestep `dt`. Timestepping within
`dt` is either with a fixed timestep `dt_fixed` or adaptive.
"""
function update!(model::SurfaceFlowLand, network, dt)
function update!(model::KinWaveOverlandFlow, network, dt)
(; inwater) = model.boundary_conditions
(; alpha_term, mannings_n, slope, beta, alpha_pow, alpha, flow_width, flow_length) =
model.parameters
Expand Down Expand Up @@ -338,8 +339,8 @@ function update!(model::SurfaceFlowLand, network, dt)
return nothing
end

"Update river flow model `SurfaceFlowRiver` for a single timestep"
function surfaceflow_river_update!(model::SurfaceFlowRiver, network, doy, dt)
"Update river flow model `KinWaveRiverFlow` for a single timestep"
function surfaceflow_river_update!(model::KinWaveRiverFlow, network, doy, dt)
(;
graph,
order_of_subdomains,
Expand Down Expand Up @@ -439,10 +440,10 @@ function surfaceflow_river_update!(model::SurfaceFlowRiver, network, doy, dt)
end

"""
Update river flow model `SurfaceFlowRiver` for a single timestep `dt`. Timestepping within
Update river flow model `KinWaveRiverFlow` for a single timestep `dt`. Timestepping within
`dt` is either with a fixed timestep `dt_fixed` or adaptive.
"""
function update!(model::SurfaceFlowRiver, network, doy, dt)
function update!(model::KinWaveRiverFlow, network, doy, dt)
(; reservoir, lake, inwater) = model.boundary_conditions

(;
Expand Down Expand Up @@ -501,7 +502,10 @@ criterion. A quantile of the vector is computed based on probability `p` to remo
very low timestep sizes. Li et al. (1975) found that the nonlinear scheme is unconditonally
stable and that a wide range of dt/dx values can be used without loss of accuracy.
"""
function stable_timestep(model::S, p) where {S <: Union{SurfaceFlowLand, SurfaceFlowRiver}}
function stable_timestep(
model::S,
p,
) where {S <: Union{KinWaveOverlandFlow, KinWaveRiverFlow}}
(; q) = model.variables
(; alpha, beta, flow_length) = model.parameters
(; stable_timesteps) = model.timestepping
Expand Down Expand Up @@ -552,10 +556,10 @@ end

"""
Update boundary condition lateral inflow `inwater` of a kinematic wave overland flow model
`SurfaceFlowLand` for a single timestep.
`KinWaveOverlandFlow` for a single timestep.
"""
function update_lateral_inflow!(
model::SurfaceFlowLand,
model::KinWaveOverlandFlow,
external_models::NamedTuple,
area,
config,
Expand Down Expand Up @@ -603,11 +607,11 @@ end

# For the river kinematic wave, the variable `to_river` can be excluded, because this part
# is added to the river kinematic wave.
get_inflow_waterbody(::SurfaceFlowRiver, model::SurfaceFlowLand) = model.variables.q_av
get_inflow_waterbody(::SurfaceFlowRiver, model::LateralSSF) =
get_inflow_waterbody(::KinWaveRiverFlow, model::KinWaveOverlandFlow) = model.variables.q_av
get_inflow_waterbody(::KinWaveRiverFlow, model::LateralSSF) =
model.variables.ssf ./ tosecond(basetimestep)

# Exclude subsurface flow for other groundwater components than `LateralSSF`.
get_inflow_waterbody(::AbstractRiverFlowModel, model::GroundwaterFlow) =
model.flow.connectivity.ncell .* 0.0
get_inflow_waterbody(::SurfaceFlowRiver, model) = model.variables.to_river .* 0.0
get_inflow_waterbody(::KinWaveRiverFlow, model) = model.variables.to_river .* 0.0
2 changes: 1 addition & 1 deletion src/routing/surface_local_inertial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ end

# For local inertial river routing, `to_river` is included, as water body cells are excluded
# (boundary condition).
get_inflow_waterbody(::ShallowWaterRiver, model::SurfaceFlowLand) =
get_inflow_waterbody(::ShallowWaterRiver, model::KinWaveOverlandFlow) =
model.variables.q_av .+ model.variables.to_river
get_inflow_waterbody(::ShallowWaterRiver, model::LateralSSF) =
(model.variables.ssf .+ model.variables.to_river) ./ tosecond(basetimestep)
Expand Down
4 changes: 2 additions & 2 deletions src/sbm_gwf_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function initialize_sbm_gwf_model(config::Config)
end

if land_routing == "kinematic-wave"
overland_flow = SurfaceFlowLand(
overland_flow = KinWaveOverlandFlow(
dataset,
config,
indices;
Expand Down Expand Up @@ -193,7 +193,7 @@ function initialize_sbm_gwf_model(config::Config)
minimum(river_width) > 0 || error("river width must be positive on river cells")

if river_routing == "kinematic-wave"
river_flow = SurfaceFlowRiver(
river_flow = KinWaveRiverFlow(
dataset,
config,
inds_river;
Expand Down
4 changes: 2 additions & 2 deletions src/sbm_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function initialize_sbm_model(config::Config)
end

if land_routing == "kinematic-wave"
overland_flow = SurfaceFlowLand(
overland_flow = KinWaveOverlandFlow(
dataset,
config,
indices;
Expand Down Expand Up @@ -226,7 +226,7 @@ function initialize_sbm_model(config::Config)
minimum(river_length) > 0 || error("river length must be positive on river cells")
minimum(river_width) > 0 || error("river width must be positive on river cells")
if river_routing == "kinematic-wave"
river_flow = SurfaceFlowRiver(
river_flow = KinWaveRiverFlow(
dataset,
config,
inds_river;
Expand Down

0 comments on commit 7ba754a

Please sign in to comment.