Skip to content

Commit

Permalink
move geometry to parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hboisgon committed Dec 4, 2024
1 parent 6b62c34 commit 03c57b0
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 99 deletions.
4 changes: 2 additions & 2 deletions src/erosion.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@with_kw struct SoilLoss{RE, OFE, SE, T}
hydrometeo_forcing::HydrometeoForcing
geometry::LandGeometry
geometry::LandParameters
rainfall_erosion::RE
overland_flow_erosion::OFE
soil_erosion::SE
Expand All @@ -10,7 +10,7 @@ function SoilLoss(nc, config, inds)
n = length(inds)

hydrometeo_forcing = HydrometeoForcing(n)
geometry = LandGeometry(nc, config, inds)
geometry = LandParameters(nc, config, inds)

# Rainfall erosion
rainfallerosionmodel = get(config.model, "rainfall_erosion", "answers")::String
Expand Down
2 changes: 1 addition & 1 deletion src/erosion/overland_flow_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function update_boundary_conditions!(
return nothing
end

function update!(model::OverlandFlowErosionAnswersModel, geometry::LandGeometry, ts)
function update!(model::OverlandFlowErosionAnswersModel, geometry::LandParameters, ts)
(; q) = model.boundary_conditions
(; usle_k, usle_c, answers_k) = model.parameters
(; amount) = model.variables
Expand Down
4 changes: 2 additions & 2 deletions src/erosion/rainfall_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function update_boundary_conditions!(
@. waterlevel = model.boundary_conditions.waterlevel_land
end

function update!(model::RainfallErosionEurosemModel, geometry::LandGeometry, ts)
function update!(model::RainfallErosionEurosemModel, geometry::LandParameters, ts)
(; precipitation, interception, waterlevel) = model.boundary_conditions
(;
soil_detachability,
Expand Down Expand Up @@ -221,7 +221,7 @@ function update_boundary_conditions!(
@. precipitation = hydrometeo_forcing.precipitation
end

function update!(model::RainfallErosionAnswersModel, geometry::LandGeometry, ts)
function update!(model::RainfallErosionAnswersModel, geometry::LandParameters, ts)
(; precipitation) = model.boundary_conditions
(; usle_k, usle_c) = model.parameters
(; amount) = model.variables
Expand Down
2 changes: 1 addition & 1 deletion src/erosion/river_erosion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function update_boundary_conditions!(
@. waterlevel = waterlevel_river
end

function update!(model::RiverErosionJulianTorresModel, geometry::RiverGeometry, ts)
function update!(model::RiverErosionJulianTorresModel, geometry::RiverParameters, ts)
(; waterlevel) = model.boundary_conditions
(; d50) = model.parameters
(; bed, bank) = model.variables
Expand Down
79 changes: 0 additions & 79 deletions src/geometry.jl

This file was deleted.

82 changes: 82 additions & 0 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,86 @@ function VegetationParameters(nc, config, inds)
)
end
return vegetation_parameter_set
end

@get_units @grid_loc @with_kw struct LandParameters{T}
# cell area [m^2]
area::Vector{T} | "m^2"
# drain width [m]
width::Vector{T} | "m"
# drain slope
slope::Vector{T} | "-"
end

function LandParameters(nc, config, inds)
# read x, y coordinates and calculate cell length [m]
y_nc = read_y_axis(nc)
x_nc = read_x_axis(nc)
y = permutedims(repeat(y_nc; outer = (1, length(x_nc))))[inds]
cellength = abs(mean(diff(x_nc)))

sizeinmetres = get(config.model, "sizeinmetres", false)::Bool
xl, yl = cell_lengths(y, cellength, sizeinmetres)
area = xl .* yl
ldd = ncread(nc, config, "ldd"; optional = false, sel = inds, allow_missing = true)
drain_width = map(detdrainwidth, ldd, xl, yl)
landslope = ncread(
nc,
config,
"vertical.land_parameter_set.slope";
optional = false,
sel = inds,
type = Float,
)
clamp!(landslope, 0.00001, Inf)

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

@get_units @grid_loc @with_kw struct RiverParameters{T}
# river width [m]
width::Vector{T} | "m"
# river length
length::Vector{T} | "m"
# slope
slope::Vector{T} | "-"
end

function RiverParameters(nc, config, inds)
riverwidth = ncread(
nc,
config,
"lateral.river_parameter_set.width";
optional = false,
sel = inds,
type = Float,
)
riverlength = ncread(
nc,
config,
"lateral.river_parameter_set.length";
optional = false,
sel = inds,
type = Float,
)
riverslope = ncread(
nc,
config,
"lateral.river_parameter_set.slope";
optional = false,
sel = inds,
type = Float,
)
minimum(riverlength) > 0 || error("river length must be positive on river cells")
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,
)
return river_parameter_set
end
8 changes: 4 additions & 4 deletions src/sediment_flux.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Overland flow ###
@get_units @grid_loc @with_kw struct OverlandFlowSediment{TT, SF, TR, T}
hydrometeo_forcing::HydrometeoForcing
geometry::LandGeometry
geometry::LandParameters
transport_capacity::TT
sediment_flux::SF
to_river::TR
Expand All @@ -12,7 +12,7 @@ end
function OverlandFlowSediment(nc, config, inds, waterbodies, rivers)
n = length(inds)
hydrometeo_forcing = HydrometeoForcing(n)
geometry = LandGeometry(nc, config, inds)
geometry = LandParameters(nc, config, inds)
# Check what transport capacity equation will be used
do_river = get(config.model, "runrivermodel", false)::Bool
# Overland flow transport capacity method: ["yalinpart", "govers", "yalin"]
Expand Down Expand Up @@ -80,7 +80,7 @@ end
### River ###
@get_units @grid_loc @with_kw struct RiverSediment{TTR, ER, SFR, CR, T}
hydrometeo_forcing::HydrometeoForcing
geometry::RiverGeometry
geometry::RiverParameters
transport_capacity::TTR
potential_erosion::ER
sediment_flux::SFR
Expand All @@ -91,7 +91,7 @@ end
function RiverSediment(nc, config, inds, waterbodies)
n = length(inds)
hydrometeo_forcing = HydrometeoForcing(n)
geometry = RiverGeometry(nc, config, inds)
geometry = RiverParameters(nc, config, inds)

# Check what transport capacity equation will be used
# River flow transport capacity method: ["bagnold", "engelund", "yang", "kodatie", "molinas"]
Expand Down
4 changes: 2 additions & 2 deletions src/sediment_transport/river_transport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ end
function update!(
model::SedimentRiverTransportModel,
network,
geometry::RiverGeometry,
geometry::RiverParameters,
waterbodies,
ts,
)
Expand Down Expand Up @@ -952,7 +952,7 @@ function update_boundary_conditions!(
@. gravel = sediment_flux_model.variables.gravel
end

function update!(model::SedimentConcentrationsRiverModel, geometry::RiverGeometry, ts)
function update!(model::SedimentConcentrationsRiverModel, geometry::RiverParameters, ts)
(; 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
12 changes: 6 additions & 6 deletions src/sediment_transport/transport_capacity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ end

function update!(
model::TransportCapacityYalinDifferentiationModel,
geometry::LandGeometry,
geometry::LandParameters,
waterbodies,
rivers,
ts,
Expand Down Expand Up @@ -520,7 +520,7 @@ function TransportCapacityBagnoldModel(nc, config, inds)
return model
end

function update!(model::TransportCapacityBagnoldModel, geometry::RiverGeometry, ts)
function update!(model::TransportCapacityBagnoldModel, geometry::RiverParameters, ts)
(; q, waterlevel) = model.boundary_conditions
(; c_bagnold, e_bagnold) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -561,7 +561,7 @@ function TransportCapacityEngelundModel(nc, config, inds)
return model
end

function update!(model::TransportCapacityEngelundModel, geometry::RiverGeometry, ts)
function update!(model::TransportCapacityEngelundModel, geometry::RiverParameters, ts)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -655,7 +655,7 @@ function TransportCapacityKodatieModel(nc, config, inds)
return model
end

function update!(model::TransportCapacityKodatieModel, geometry::RiverGeometry, ts)
function update!(model::TransportCapacityKodatieModel, geometry::RiverParameters, ts)
(; q, waterlevel) = model.boundary_conditions
(; a_kodatie, b_kodatie, c_kodatie, d_kodatie) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -697,7 +697,7 @@ function TransportCapacityYangModel(nc, config, inds)
return model
end

function update!(model::TransportCapacityYangModel, geometry::RiverGeometry, ts)
function update!(model::TransportCapacityYangModel, geometry::RiverParameters, ts)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down Expand Up @@ -737,7 +737,7 @@ function TransportCapacityMolinasModel(nc, config, inds)
return model
end

function update!(model::TransportCapacityMolinasModel, geometry::RiverGeometry, ts)
function update!(model::TransportCapacityMolinasModel, geometry::RiverParameters, ts)
(; q, waterlevel) = model.boundary_conditions
(; density, d50) = model.parameters
(; amount) = model.variables
Expand Down
4 changes: 2 additions & 2 deletions test/sediment_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ waterlevel_land = "levKinL"
#interception = "int"
q_land = "runL"

[input.vertical.geometry]
[input.vertical.land_parameter_set]
slope = "Slope"

[input.vertical.rainfall_erosion.parameters]
Expand Down Expand Up @@ -122,7 +122,7 @@ dm_lagg = "dm_lagg"
waterlevel_river = "h"
q_river = "q"

[input.lateral.river.geometry]
[input.lateral.river_parameter_set]
length = "wflow_riverlength"
slope = "RiverSlope"
width = "wflow_riverwidth"
Expand Down

0 comments on commit 03c57b0

Please sign in to comment.