Skip to content

Commit

Permalink
use geometry again
Browse files Browse the repository at this point in the history
  • Loading branch information
hboisgon committed Dec 6, 2024
1 parent 2246a3d commit af9dd7a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@with_kw struct SoilLoss{RE, OFE, SE, T}
atmospheric_forcing::AtmosphericForcing{T}
hydrological_forcing::HydrologicalForcing{T}
geometry::LandParameters{T}
geometry::LandGeometry{T}
rainfall_erosion::RE
overland_flow_erosion::OFE
soil_erosion::SE
Expand All @@ -14,7 +14,7 @@ function SoilLoss(dataset, config, indices)

atmospheric_forcing = AtmosphericForcing(n)
hydrological_forcing = HydrologicalForcing(n)
geometry = LandParameters(dataset, config, indices)
geometry = LandGeometry(dataset, config, indices)

# Rainfall erosion
rainfallerosionmodel = get(config.model, "rainfall_erosion", "answers")::String
Expand Down
29 changes: 13 additions & 16 deletions src/groundwater/boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ end
# Do nothing for a confined aquifer: aquifer can always provide flux
check_flux(flux, aquifer::ConfinedAquifer, index::Int) = flux

@get_units @grid_loc @with_kw struct HyporheicParameters{T}
@get_units @grid_loc @with_kw struct RiverParameters{T}
infiltration_conductance::Vector{T} | "m2 d-1"
exfiltration_conductance::Vector{T} | "m2 d-1"
bottom::Vector{T} | "m"
end

@get_units @grid_loc @with_kw struct HyporheicVariables{T}
@get_units @grid_loc @with_kw struct RiverVariables{T}
stage::Vector{T} | "m"
flux::Vector{T} | "m3 d-1"
end

function HyporheicVariables(n)
variables = HyporheicVariables{Float}(; stage = fill(mv, n), flux = fill(mv, n))
function RiverVariables(n)
variables = RiverVariables{Float}(; stage = fill(mv, n), flux = fill(mv, n))
return variables
end

@get_units @grid_loc @with_kw struct Hyporheic{T} <: AquiferBoundaryCondition
parameters::HyporheicParameters{T}
variables::HyporheicVariables{T}
@get_units @grid_loc @with_kw struct River{T} <: AquiferBoundaryCondition
parameters::RiverParameters{T}
variables::RiverVariables{T}
index::Vector{Int} | "-"
end

function Hyporheic(dataset, config, indices, index)
function River(dataset, config, indices, index)
infiltration_conductance = ncread(
dataset,
config,
Expand All @@ -56,18 +56,15 @@ function Hyporheic(dataset, config, indices, index)
type = Float,
)

parameters = HyporheicParameters{Float}(
infiltration_conductance,
exfiltration_conductance,
bottom,
)
parameters =
RiverParameters{Float}(infiltration_conductance, exfiltration_conductance, bottom)
n = length(indices)
variables = HyporheicVariables(n)
river = Hyporheic(parameters, variables, index)
variables = RiverVariables(n)
river = River(parameters, variables, index)
return river
end

function flux!(Q, river::Hyporheic, aquifer)
function flux!(Q, river::River, aquifer)
for (i, index) in enumerate(river.index)
head = aquifer.variables.head[index]
stage = river.variables.stage[i]
Expand Down
21 changes: 11 additions & 10 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function VegetationParameters(dataset, config, indices)
return vegetation_parameter_set
end

@get_units @grid_loc @with_kw struct LandParameters{T}
"Struct to store land geometry parameters"
@get_units @grid_loc @with_kw struct LandGeometry{T}
# cell area [m^2]
area::Vector{T} | "m^2"
# drain width [m]
Expand All @@ -112,7 +113,8 @@ end
slope::Vector{T} | "-"
end

function LandParameters(nc, config, inds)
"Initialize land geometry parameters"
function LandGeometry(nc, config, inds)
# read x, y coordinates and calculate cell length [m]
y_nc = read_y_axis(nc)
x_nc = read_x_axis(nc)
Expand All @@ -135,11 +137,12 @@ function LandParameters(nc, config, inds)
clamp!(landslope, 0.00001, Inf)

land_parameter_set =
LandParameters{Float}(; area = area, width = drain_width, slope = landslope)
LandGeometry{Float}(; area = area, width = drain_width, slope = landslope)
return land_parameter_set
end

@get_units @grid_loc @with_kw struct RiverParameters{T}
"Struct to store river geometry parameters"
@get_units @grid_loc @with_kw struct RiverGeometry{T}
# river width [m]
width::Vector{T} | "m"
# river length
Expand All @@ -148,7 +151,8 @@ end
slope::Vector{T} | "-"
end

function RiverParameters(nc, config, inds)
"Initialize river geometry parameters"
function RiverGeometry(nc, config, inds)
riverwidth = ncread(
nc,
config,
Expand Down Expand Up @@ -177,10 +181,7 @@ function RiverParameters(nc, config, inds)
minimum(riverwidth) > 0 || error("river width must be positive on river cells")
clamp!(riverslope, 0.00001, Inf)

river_parameter_set = RiverParameters{Float}(;
width = riverwidth,
length = riverlength,
slope = riverslope,
)
river_parameter_set =
RiverGeometry{Float}(; width = riverwidth, length = riverlength, slope = riverslope)
return river_parameter_set
end
2 changes: 1 addition & 1 deletion src/sbm_gwf_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function initialize_sbm_gwf_model(config::Config)
)

# river boundary of unconfined aquifer
river = Hyporheic(dataset, config, inds_river, inds_land_map2river)
river = River(dataset, config, inds_river, inds_land_map2river)

# recharge boundary of unconfined aquifer
recharge = Recharge(
Expand Down
2 changes: 1 addition & 1 deletion src/sediment/erosion/overland_flow_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function update_boundary_conditions!(
end

"Update ANSWERS overland flow erosion model for a single timestep"
function update!(model::OverlandFlowErosionAnswersModel, geometry::LandParameters, dt)
function update!(model::OverlandFlowErosionAnswersModel, geometry::LandGeometry, dt)
(; q) = model.boundary_conditions
(; usle_k, usle_c, answers_k) = model.parameters
(; amount) = model.variables
Expand Down
4 changes: 2 additions & 2 deletions src/sediment/erosion/rainfall_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function update_boundary_conditions!(
end

"Update EUROSEM rainfall erosion model for a single timestep"
function update!(model::RainfallErosionEurosemModel, geometry::LandParameters, dt)
function update!(model::RainfallErosionEurosemModel, geometry::LandGeometry, dt)
(; precipitation, interception, waterlevel) = model.boundary_conditions
(;
soil_detachability,
Expand Down Expand Up @@ -237,7 +237,7 @@ function update_boundary_conditions!(
end

"Update ANSWERS rainfall erosion model for a single timestep"
function update!(model::RainfallErosionAnswersModel, geometry::LandParameters, dt)
function update!(model::RainfallErosionAnswersModel, geometry::LandGeometry, dt)
(; precipitation) = model.boundary_conditions
(; usle_k, usle_c) = model.parameters
(; amount) = model.variables
Expand Down
2 changes: 1 addition & 1 deletion src/sediment/erosion/river_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function update_boundary_conditions!(
end

"Update Julian and Torres river erosion model for a single timestep"
function update!(model::RiverErosionJulianTorresModel, geometry::RiverParameters, dt)
function update!(model::RiverErosionJulianTorresModel, geometry::RiverGeometry, dt)
(; waterlevel) = model.boundary_conditions
(; d50) = model.parameters
(; bed, bank) = model.variables
Expand Down
4 changes: 2 additions & 2 deletions src/sediment/sediment_transport/river_transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ end
function update!(
model::SedimentRiverTransportModel,
network,
geometry::RiverParameters,
geometry::RiverGeometry,
waterbodies,
dt,
)
Expand Down Expand Up @@ -968,7 +968,7 @@ function update_boundary_conditions!(
end

"Update river sediment concentrations model for a single timestep"
function update!(model::SedimentConcentrationsRiverModel, geometry::RiverParameters, dt)
function update!(model::SedimentConcentrationsRiverModel, geometry::RiverGeometry, dt)
(; q, waterlevel, clay, silt, sand, sagg, lagg, gravel) = model.boundary_conditions
(; dm_clay, dm_silt, dm_sand, dm_sagg, dm_lagg, dm_gravel) = model.parameters
(; total, suspended, bed) = model.variables
Expand Down
16 changes: 8 additions & 8 deletions src/sediment/sediment_transport/transport_capacity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ end
"Update Govers overland flow transport capacity model for a single timestep"
function update!(
model::TransportCapacityGoversModel,
geometry::LandParameters,
geometry::LandGeometry,
waterbodies,
rivers,
dt,
Expand Down Expand Up @@ -198,7 +198,7 @@ end
"Update Yalin overland flow transport capacity model for a single timestep"
function update!(
model::TransportCapacityYalinModel,
geometry::LandParameters,
geometry::LandGeometry,
waterbodies,
rivers,
dt,
Expand Down Expand Up @@ -362,7 +362,7 @@ end
"Update Yalin differentiated overland flow transport capacity model for a single timestep"
function update!(
model::TransportCapacityYalinDifferentiationModel,
geometry::LandParameters,
geometry::LandGeometry,
waterbodies,
rivers,
dt,
Expand Down Expand Up @@ -532,7 +532,7 @@ function TransportCapacityBagnoldModel(dataset, config, indices)
end

"Update Bagnold river transport capacity model for a single timestep"
function update!(model::TransportCapacityBagnoldModel, geometry::RiverParameters, dt)
function update!(model::TransportCapacityBagnoldModel, geometry::RiverGeometry, dt)
(; q, waterlevel) = model.boundary_conditions
(; c_bagnold, e_bagnold) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -575,7 +575,7 @@ function TransportCapacityEngelundModel(dataset, config, indices)
end

"Update Engelund and Hansen river transport capacity model for a single timestep"
function update!(model::TransportCapacityEngelundModel, geometry::RiverParameters, dt)
function update!(model::TransportCapacityEngelundModel, geometry::RiverGeometry, dt)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -673,7 +673,7 @@ function TransportCapacityKodatieModel(dataset, config, indices)
end

"Update Kodatie river transport capacity model for a single timestep"
function update!(model::TransportCapacityKodatieModel, geometry::RiverParameters, dt)
function update!(model::TransportCapacityKodatieModel, geometry::RiverGeometry, dt)
(; q, waterlevel) = model.boundary_conditions
(; a_kodatie, b_kodatie, c_kodatie, d_kodatie) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -717,7 +717,7 @@ function TransportCapacityYangModel(dataset, config, indices)
end

"Update Yang river transport capacity model for a single timestep"
function update!(model::TransportCapacityYangModel, geometry::RiverParameters, dt)
function update!(model::TransportCapacityYangModel, geometry::RiverGeometry, dt)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -759,7 +759,7 @@ function TransportCapacityMolinasModel(dataset, config, indices)
end

"Update Molinas and Wu river transport capacity model for a single timestep"
function update!(model::TransportCapacityMolinasModel, geometry::RiverParameters, dt)
function update!(model::TransportCapacityMolinasModel, geometry::RiverGeometry, dt)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down
8 changes: 4 additions & 4 deletions src/sediment_flux.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Sediment transport in overland flow model"
@get_units @grid_loc @with_kw struct OverlandFlowSediment{TT, SF, TR}
hydrological_forcing::HydrologicalForcing
geometry::LandParameters
geometry::LandGeometry
transport_capacity::TT
sediment_flux::SF
to_river::TR
Expand All @@ -13,7 +13,7 @@ end
function OverlandFlowSediment(dataset, config, indices, waterbodies, rivers)
n = length(indices)
hydrological_forcing = HydrologicalForcing(n)
geometry = LandParameters(dataset, config, indices)
geometry = LandGeometry(dataset, config, indices)
# Check what transport capacity equation will be used
do_river = get(config.model, "run_river_model", false)::Bool
# Overland flow transport capacity method: ["yalinpart", "govers", "yalin"]
Expand Down Expand Up @@ -79,7 +79,7 @@ end
"Sediment transport in river model"
@get_units @grid_loc @with_kw struct RiverSediment{TTR, ER, SFR, CR}
hydrological_forcing::HydrologicalForcing
geometry::RiverParameters
geometry::RiverGeometry
transport_capacity::TTR
potential_erosion::ER
sediment_flux::SFR
Expand All @@ -91,7 +91,7 @@ end
function RiverSediment(dataset, config, indices, waterbodies)
n = length(indices)
hydrological_forcing = HydrologicalForcing(n)
geometry = RiverParameters(dataset, config, indices)
geometry = RiverGeometry(dataset, config, indices)

# Check what transport capacity equation will be used
# River flow transport capacity method: ["bagnold", "engelund", "yang", "kodatie", "molinas"]
Expand Down
6 changes: 3 additions & 3 deletions test/groundwater.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ end
end

@testset "river" begin
parameters = Wflow.HyporheicParameters(;
parameters = Wflow.RiverParameters(;
infiltration_conductance = [100.0, 100.0],
exfiltration_conductance = [200.0, 200.0],
bottom = [1.0, 1.0],
)
variables = Wflow.HyporheicVariables(; stage = [2.0, 2.0], flux = [0.0, 0.0])
river = Wflow.Hyporheic(; parameters, variables, index = [1, 3])
variables = Wflow.RiverVariables(; stage = [2.0, 2.0], flux = [0.0, 0.0])
river = Wflow.River(; parameters, variables, index = [1, 3])
Q = zeros(3)
Wflow.flux!(Q, river, conf_aqf)
# infiltration, below bottom, flux is (stage - bottom) * inf_cond
Expand Down

0 comments on commit af9dd7a

Please sign in to comment.