Skip to content
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
21 changes: 8 additions & 13 deletions Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Wflow/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
PropertyDicts = "f8a19df8-e894-5f55-a973-672c1158cbca"
WflowSoil = "e4c7f7b8-5a3d-4e6f-9c1a-2b8d3f4e5a6c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Expand All @@ -43,12 +43,12 @@ Graphs = "1.4"
LoggingExtras = "0.4.6,0.5,1"
NCDatasets = "0.13.2, 0.14"
OrderedCollections = "1.8.1"
Parameters = "0.12"
Polyester = "0.7.10"
ProgressLogging = "0.1"
PropertyDicts = "0.2.1"
StaticArrays = "0.12,1.0"
Statistics = "1"
TOML = "1"
WflowSoil = "0.1"
TerminalLoggers = "0.1.5"
julia = "1.10"
32 changes: 29 additions & 3 deletions Wflow/src/Wflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ using LoggingExtras:
with_logger
using NCDatasets: NCDatasets, NCDataset, dimnames, dimsize, nomissing, defDim, defVar, path
using OrderedCollections: OrderedDict
using Parameters: @with_kw
using Polyester: @batch
using ProgressLogging: @progress
using PropertyDicts: PropertyDict
Expand All @@ -69,6 +68,35 @@ using Statistics: mean, median, quantile!, quantile
using TerminalLoggers
using TOML: TOML

import WflowSoil:
AbstractSoilModel,
bounded_power,
get_rootingdepth,
hydraulic_conductivity_at_depth,
KvExponential,
KvExponentialConstant,
KvLayered,
KvLayeredExponential,
lower_bound_drainable_porosity,
MISSING_VALUE,
number_of_active_layers,
pow,
SbmSoilBC,
SbmSoilDiagnosticVariables,
SbmSoilFluxes,
SbmSoilIntermediates,
SbmSoilModel,
SbmSoilParameters,
SbmSoilStates,
SbmSoilVariables,
scurve,
set_layerthickness,
threaded_foreach,
update_diagnostic_vars!,
update_soil_water_flow!,
VegetationParameters,
WflowSoil

const CFDataset = Union{NCDataset, NCDatasets.MFDataset}
const CFVariable_MF = Union{NCDatasets.CFVariable, NCDatasets.MFCFVariable}
const VERSION =
Expand Down Expand Up @@ -186,8 +214,6 @@ end
# prevent a large printout of model components and arrays
Base.show(io::IO, ::AbstractModel{T}) where {T} = print(io, "model of type ", T)

const MISSING_VALUE = Float64(NaN)

include("forcing.jl")
include("vegetation/parameters.jl")
include("vegetation/rainfall_interception.jl")
Expand Down
2 changes: 1 addition & 1 deletion Wflow/src/config_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ variable_name(var::InputEntry) =
isnothing(var.netcdf_variable_name) ? var.external_name : var.netcdf_variable_name

@kwdef mutable struct InputEntries <: AbstractConfigSection
dict::Dict{String, InputEntry} = Dict()
dict::Dict{String, InputEntry} = Dict{String, InputEntry}()
end

Base.haskey(input_entries::InputEntries, key) = haskey(input_entries.dict, key)
Expand Down
42 changes: 22 additions & 20 deletions Wflow/src/demand/water_demand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ struct NoAllocationRiverModel <: AbstractAllocationModel
end

"Struct to store non-irrigation water demand variables"
@with_kw struct NonIrrigationDemandVariables
@kwdef struct NonIrrigationDemandVariables
# return flow [m s⁻¹]
returnflow::Vector{Float64}
# return flow fraction [-]
returnflow_fraction::Vector{Float64}
end

"Struct to store prescribed water demand variables"
@with_kw struct PrescribedDemand
@kwdef struct PrescribedDemand
# gross water demand [m s⁻¹]
demand_gross::Vector{Float64}
# net water demand [m s⁻¹]
demand_net::Vector{Float64}
end

"Non-irrigation water demand model"
@with_kw struct NonIrrigationDemandModel <: AbstractDemandModel
@kwdef struct NonIrrigationDemandModel <: AbstractDemandModel
demand::PrescribedDemand
variables::NonIrrigationDemandVariables
end
Expand Down Expand Up @@ -77,21 +77,21 @@ function NonIrrigationDemandModel(
end

"Struct to store non-paddy irrigation model variables"
@with_kw struct NonPaddyVariables
@kwdef struct NonPaddyVariables
n::Int
demand_gross::Vector{Float64} = fill(MISSING_VALUE, n) # irrigation gross demand [m s⁻¹]
end

"Struct to store non-paddy irrigation model parameters"
@with_kw struct NonPaddyParameters
@kwdef struct NonPaddyParameters
irrigation_efficiency::Vector{Float64} # irrigation efficiency [-]
maximum_irrigation_rate::Vector{Float64} # maximum irrigation rate [m s⁻¹]
irrigation_areas::Vector{Bool} # irrigation areas [-]
irrigation_trigger::Vector{Bool} # irrigation on or off [-]
end

"Non-paddy (other crops than flooded rice) irrigation model"
@with_kw struct NonPaddyModel <: AbstractIrrigationModel
@kwdef struct NonPaddyModel <: AbstractIrrigationModel
n::Int
parameters::NonPaddyParameters
variables::NonPaddyVariables = NonPaddyVariables(; n)
Expand Down Expand Up @@ -168,7 +168,7 @@ function update_demand_gross!(
(; parameters, variables) = nonpaddy_model
(; irrigation_areas, irrigation_trigger, maximum_irrigation_rate) = parameters
(; demand_gross) = variables
(; n_unsatlayers) = soil_model.variables
(; n_unsatlayers) = soil_model.variables.diagnostic

for i in eachindex(irrigation_areas)
if irrigation_areas[i] && irrigation_trigger[i]
Expand Down Expand Up @@ -213,7 +213,9 @@ function water_demand_root_zone(soil_model::SbmSoilModel, i::Int, k::Int)
theta_fc,
brooks_corey_exponent,
) = soil_model.parameters
(; unsaturated_layer_thickness, unsaturated_layer_depth, h3) = soil_model.variables
(; unsaturated_layer_thickness) = soil_model.variables.diagnostic
(; unsaturated_layer_depth) = soil_model.variables.states
(; h3) = soil_model.variables.intermediates

rooting_depth = get_rootingdepth(soil_model)

Expand Down Expand Up @@ -249,7 +251,7 @@ function compute_demand_gross(
i::Int,
)
(; compacted_soil_area_fraction, infiltration_capacity_soil) = soil_model.parameters
(; f_infiltration_reduction) = soil_model.variables
(; f_infiltration_reduction) = soil_model.variables.intermediates
(; irrigation_efficiency, maximum_irrigation_rate) = nonpaddy_model.parameters

infiltration_capacity =
Expand All @@ -265,15 +267,15 @@ function compute_demand_gross(
end

"Struct to store paddy irrigation model variables"
@with_kw struct PaddyVariables
@kwdef struct PaddyVariables
n::Int
demand_gross::Vector{Float64} = fill(MISSING_VALUE, n) # irrigation gross demand [m s⁻¹]
h::Vector{Float64} = zeros(n) # actual water depth in rice field [m]
evaporation::Vector{Float64} = zeros(n) # evaporation rate [m s⁻¹]
end

"Struct to store paddy irrigation model parameters"
@with_kw struct PaddyParameters
@kwdef struct PaddyParameters
irrigation_efficiency::Vector{Float64} # irrigation efficiency [-]
maximum_irrigation_rate::Vector{Float64} # maximum irrigation rate [m s⁻¹]
irrigation_areas::Vector{Bool} # irrigation areas [-]
Expand All @@ -284,7 +286,7 @@ end
end

"PaddyModel (flooded rice) irrigation model"
@with_kw struct PaddyModel <: AbstractIrrigationModel
@kwdef struct PaddyModel <: AbstractIrrigationModel
n::Int
parameters::PaddyParameters
variables::PaddyVariables = PaddyVariables(; n)
Expand Down Expand Up @@ -456,7 +458,7 @@ end
update_demand_gross!(paddy_model::NoIrrigationPaddyModel, dt::Float64) = nothing

"Struct to store water demand model variables"
@with_kw struct DemandVariables
@kwdef struct DemandVariables
n::Int
irrigation_demand_gross::Vector{Float64} = zeros(n) # irrigation gross demand [m s⁻¹]
non_irrigation_demand_gross::Vector{Float64} = zeros(n) # non-irrigation gross demand [m s⁻¹]
Expand All @@ -466,7 +468,7 @@ update_demand_gross!(paddy_model::NoIrrigationPaddyModel, dt::Float64) = nothing
end

"Water demand model"
@with_kw struct DemandModel{
@kwdef struct DemandModel{
D <: AbstractDemandModel,
I <: AbstractDemandModel,
L <: AbstractDemandModel,
Expand All @@ -481,7 +483,7 @@ end
variables::DemandVariables
end

@with_kw struct NoDemandModel <: AbstractDemandModel
@kwdef struct NoDemandModel <: AbstractDemandModel
n::Int
domestic::NoNonIrrigationDemandModel = NoNonIrrigationDemandModel(n)
industry::NoNonIrrigationDemandModel = NoNonIrrigationDemandModel(n)
Expand Down Expand Up @@ -520,7 +522,7 @@ function DemandModel(dataset::NCDataset, config::Config, indices::Vector{Cartesi
end

"Struct to store river allocation model variables"
@with_kw struct AllocationRiverVariables
@kwdef struct AllocationRiverVariables
n::Int
actual_surfacewater_abstraction::Vector{Float64} = zeros(n) # actual surface water abstraction [m s⁻¹]
actual_surfacewater_abstraction_volume::Vector{Float64} = zeros(n) # actual surface water abstraction [m³ s⁻¹]
Expand All @@ -529,7 +531,7 @@ end
end

"River allocation model"
@with_kw struct AllocationRiverModel <: AbstractAllocationModel
@kwdef struct AllocationRiverModel <: AbstractAllocationModel
n::Int
variables::AllocationRiverVariables = AllocationRiverVariables(; n)
end
Expand All @@ -540,13 +542,13 @@ get_nonirrigation_returnflow(allocation_model::NoAllocationRiverModel) =
Zeros(allocation_model.n)

"Struct to store land allocation allocation model parameters"
@with_kw struct AllocationLandParameters
@kwdef struct AllocationLandParameters
fraction_surfacewater_used::Vector{Float64} # fraction surface water used [-]
areas::Vector{Int} # allocation areas [-]
end

"Struct to store land allocation model variables"
@with_kw struct AllocationLandVariables
@kwdef struct AllocationLandVariables
n::Int
# allocation from surface water [m s⁻¹]
surfacewater_allocation::Vector{Float64} = zeros(n)
Expand All @@ -569,7 +571,7 @@ end
end

"Land allocation model"
@with_kw struct AllocationLandModel <: AbstractAllocationModel
@kwdef struct AllocationLandModel <: AbstractAllocationModel
n::Int
parameters::AllocationLandParameters
variables::AllocationLandVariables = AllocationLandVariables(; n)
Expand Down
4 changes: 2 additions & 2 deletions Wflow/src/domain.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Struct to store (shared) land parameters"
@with_kw struct LandParameters
@kwdef struct LandParameters
# cell length x direction [m]
x_length::Vector{Float64} = Float64[]
# cell length y direction [m]
Expand Down Expand Up @@ -29,7 +29,7 @@
end

"Struct to store (shared) river parameters"
@with_kw struct RiverParameters
@kwdef struct RiverParameters
# river flow width [m]
flow_width::Vector{Float64} = Float64[]
# river flow length [m]
Expand Down
2 changes: 1 addition & 1 deletion Wflow/src/erosion.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Soil loss model"
@with_kw struct SoilLossModel{
@kwdef struct SoilLossModel{
RE <: AbstractRainfallErosionModel,
OFE <: AbstractOverlandFlowErosionModel,
SE <: AbstractSoilErosionModel,
Expand Down
4 changes: 2 additions & 2 deletions Wflow/src/forcing.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"Struct to store atmospheric forcing variables"
@with_kw struct AtmosphericForcing
@kwdef struct AtmosphericForcing
n::Int
# Precipitation [m s⁻¹]
precipitation::Vector{Float64} = fill(MISSING_VALUE, n)
Expand All @@ -10,7 +10,7 @@
end

"Struct to store hydrological forcing variables"
@with_kw struct HydrologicalForcing
@kwdef struct HydrologicalForcing
n::Int
# Rainfall interception by the vegetation [m s⁻¹]
interception::Vector{Float64} = fill(MISSING_VALUE, n)
Expand Down
8 changes: 4 additions & 4 deletions Wflow/src/glacier/glacier.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
abstract type AbstractGlacierModel end

"Struct for storing glacier model variables"
@with_kw struct GlacierVariables
@kwdef struct GlacierVariables
n::Int
# Water within the glacier [m]
glacier_store::Vector{Float64}
Expand All @@ -28,13 +28,13 @@ function GlacierVariables(
end

"Struct for storing boundary condition (snow storage from a snow model) of a glacier model"
@with_kw struct SnowStateBC
@kwdef struct SnowStateBC
# Snow storage [m]
snow_storage::Vector{Float64}
end

"Struct for storing glacier HBV model parameters"
@with_kw struct GlacierHbvParameters
@kwdef struct GlacierHbvParameters
# Threshold temperature for glacier melt [K]
temperature_threshold_melt::Vector{Float64}
# Degree-day factor [m K⁻¹ s⁻¹] for glacier
Expand All @@ -48,7 +48,7 @@ end
end

"Glacier HBV model"
@with_kw struct GlacierHbvModel <: AbstractGlacierModel
@kwdef struct GlacierHbvModel <: AbstractGlacierModel
boundary_conditions::SnowStateBC
parameters::GlacierHbvParameters
variables::GlacierVariables
Expand Down
Loading
Loading