Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sediment model #463

Draft
wants to merge 9 commits into
base: v1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Wflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,28 @@ struct SedimentModel end # "sediment" type / sediment_model.jl
# prevent a large printout of model components and arrays
Base.show(io::IO, m::Model) = print(io, "model of type ", typeof(m))

include("forcing.jl")
include("geometry.jl")
include("horizontal_process.jl")
include("flow.jl")
include("water_demand.jl")
include("sbm.jl")
include("sediment.jl")
#include("sediment.jl")
include("reservoir_lake.jl")
include("sbm_model.jl")
include("erosion/erosion_process.jl")
include("erosion/rainfall_erosion.jl")
include("erosion/overland_flow_erosion.jl")
include("erosion/soil_erosion.jl")
include("erosion/river_erosion.jl")
include("sediment_transport/deposition.jl")
include("sediment_transport/transport_capacity_process.jl")
include("sediment_transport/transport_capacity.jl")
include("sediment_transport/overland_flow_transport.jl")
include("sediment_transport/land_to_river.jl")
include("sediment_transport/river_transport.jl")
include("erosion.jl")
include("sediment_flux.jl")
include("sediment_model.jl")
include("vertical_process.jl")
include("groundwater/connectivity.jl")
Expand Down
5 changes: 2 additions & 3 deletions src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,8 @@ exchange(::SBM, var) =
) ? 0 : 1
grid_location(::SBM, var) = var in (:n, :dt, :maxlayers) ? "none" : "node"

exchange(::Union{LandSediment, OverlandFlowSediment}, var) = var == :n ? 0 : 1
grid_location(::Union{LandSediment, OverlandFlowSediment}, var) =
var == :n ? "none" : "node"
exchange(::Union{SoilLoss, OverlandFlowSediment}, var) = var == :n ? 0 : 1
grid_location(::Union{SoilLoss, OverlandFlowSediment}, var) = var == :n ? "none" : "node"

exchange(::RiverSediment, var) = var in (:n, :dt) ? 0 : 1
grid_location(::RiverSediment, var) = var in (:n, :dt) ? "none" : "node"
Expand Down
74 changes: 74 additions & 0 deletions src/erosion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@get_units @with_kw struct SoilLoss{RE, OFE, SE, T}
hydrometeo_forcing::HydrometeoForcing | "-"
geometry::LandGeometry | "-"
rainfall_erosion::RE | "-"
overland_flow_erosion::OFE | "-"
soil_erosion::SE | "-"
end

function initialize_soil_loss(nc, config, inds)
n = length(inds)

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

# Rainfall erosion
rainfallerosionmodel = get(config.model, "rainfall_erosion", "answers")::String
if rainfallerosionmodel == "answers"
rainfall_erosion_model = RainfallErosionAnswersModel(nc, config, inds)
elseif rainfallerosionmodel == "eurosem"
rainfall_erosion_model = RainfallErosionEurosemModel(nc, config, inds)
else
error("Unknown rainfall erosion model: $rainfallerosionmodel")
end

# Overland flow erosion
overlandflowerosionmodel = get(config.model, "overland_flow_erosion", "answers")::String
if overlandflowerosionmodel == "answers"
overland_flow_erosion_model = OverlandFlowErosionAnswersModel(nc, config, inds)
else
error("Unknown overland flow erosion model: $overlandflowerosionmodel")
# overland_flow_erosion_model = NoOverlandFlowErosionModel()
end

# Total soil erosion and particle differentiation
soil_erosion_model = SoilErosionModel(nc, config, inds)

soil_loss = SoilLoss{
typeof(rainfall_erosion_model),
typeof(overland_flow_erosion_model),
typeof(soil_erosion_model),
Float,
}(;
hydrometeo_forcing = hydrometeo_forcing,
geometry = geometry,
rainfall_erosion = rainfall_erosion_model,
overland_flow_erosion = overland_flow_erosion_model,
soil_erosion = soil_erosion_model,
)
return soil_loss
end

function update!(model::SoilLoss, dt)
(;
hydrometeo_forcing,
geometry,
rainfall_erosion,
overland_flow_erosion,
soil_erosion,
) = model
# Convert dt to integer
ts = tosecond(dt)
#TODO add interception/canopygapfraction calculation here for eurosem
#need SBM refactor

# Rainfall erosion
update_boundary_conditions!(rainfall_erosion, hydrometeo_forcing)
update!(rainfall_erosion, geometry, ts)
# Overland flow erosion
update_boundary_conditions!(overland_flow_erosion, hydrometeo_forcing)
update!(overland_flow_erosion, geometry, ts)
# Total soil erosion and particle differentiation
update_boundary_conditions!(soil_erosion, rainfall_erosion, overland_flow_erosion)
update!(soil_erosion)
end
Loading
Loading