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

Total Water Storage #327

Merged
merged 9 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions docs/src/model_docs/params_vertical.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ specific_leaf = "Sl"
| **`leaf_area_index`** | leaf area index | m``^2`` m``{-2}`` | - |
| `waterlevel_land` | water level land | mm | - |
| `waterlevel_river` | water level river | mm | - |
| `total_storage` | total water storage (excluding floodplains) | mm | - |
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved


## [HBV](@id params_hbv)
Expand Down
35 changes: 35 additions & 0 deletions src/sbm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
waterlevel_land::Vector{T} | "mm"
# Water level river [mm]
waterlevel_river::Vector{T} | "mm"
# Total water storage (excluding floodplain volume) [mm]
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved
total_storage::Vector{T} | "mm"

function SBM{T,N,M}(args...) where {T,N,M}
equal_size_vectors(args)
Expand Down Expand Up @@ -597,6 +599,7 @@ function initialize_sbm(nc, config, riverfrac, inds)
leaf_area_index = fill(mv, n),
waterlevel_land = fill(mv, n),
waterlevel_river = zeros(Float, n), #set to zero to account for cells outside river domain
total_storage = zeros(Float, n) # Set the total water storage from initialized values
)

return sbm
Expand Down Expand Up @@ -1049,3 +1052,35 @@ function update_after_subsurfaceflow(sbm::SBM, zi, exfiltsatwater)
sbm.zi[i] = zi[i]
end
end

function update_total_water_storage(sbm::SBM, rnet, rrouting, lrouting)
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved

# Set the total storage to zero
fill!(sbm.total_storage, 0)

# Burn the river routing values
sbm.total_storage[rnet] = (
rrouting.h_av .* sbm.riverfrac[rnet] * 0.001 # convert to mm
verseve marked this conversation as resolved.
Show resolved Hide resolved
)

# Chunk the data for parallel computing
threaded_foreach(1:sbm.n, basesize=1000) do i

# Cumulate per vertical type
# Maybe re-categorize in the future
# Unique are those that are not always present
unique = sbm.glacierstore[i] * sbm.glacierfrac[i]
verseve marked this conversation as resolved.
Show resolved Hide resolved
surface = (
sbm.snow[i] + sbm.snowwater[i] + sbm.canopystorage[i]
)
sub_surfuce = sbm.ustoredepth[i] + sbm.satwaterdepth[i]
verseve marked this conversation as resolved.
Show resolved Hide resolved
lateral = (
lrouting.h_av[i] * (1 - sbm.riverfrac[i]) * 0.001 # convert to mm
)

# Add everything to the total water storage
sbm.total_storage[i] += (
unique + surface + sub_surfuce + lateral
)
end
end
17 changes: 17 additions & 0 deletions src/sbm_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ function update(model::Model{N,L,V,R,W,T}) where {N,L,V,R,W,T<:SbmModel}
# update lateral subsurface flow domain (kinematic wave)
update(lateral.subsurface, network.land, network.frac_toriver)
model = update_after_subsurfaceflow(model)
model = update_total_water_storage(model)
end

"""
Expand Down Expand Up @@ -438,6 +439,22 @@ function update_after_subsurfaceflow(
return model
end

function update_total_water_storage(
JoostBuitink marked this conversation as resolved.
Show resolved Hide resolved
model::Model{N,L,V,R,W,T},
) where {N,L,V,R,W,T<:SbmModel}
@unpack lateral, vertical, network, clock, config = model

# Update the total water storage based on vertical states
# TODO Maybe look at routing in the near future
update_total_water_storage(
verseve marked this conversation as resolved.
Show resolved Hide resolved
vertical,
network.index_river,
lateral.river,
lateral.land,
)
return model
end

function set_states(model::Model{N,L,V,R,W,T}) where {N,L,V,R,W,T<:SbmModel}
@unpack lateral, vertical, network, config = model

Expand Down
6 changes: 3 additions & 3 deletions test/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ tomlpath = joinpath(@__DIR__, "sbm_config.toml")

@testset "model information functions" begin
@test BMI.get_component_name(model) == "sbm"
@test BMI.get_input_item_count(model) == 183
@test BMI.get_output_item_count(model) == 183
@test BMI.get_input_var_names(model)[[1, 5, 150, 174]] == [
@test BMI.get_input_item_count(model) == 184
@test BMI.get_output_item_count(model) == 184
@test BMI.get_input_var_names(model)[[1, 5, 151, 175]] == [
"vertical.nlayers",
"vertical.θᵣ",
"lateral.river.sl",
Expand Down
4 changes: 4 additions & 0 deletions test/run_sbm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ end
@test sbm.runoff[50063] == 0.0
@test sbm.soilevap[50063] == 0.0
@test sbm.snow[5] ≈ 3.592840840467347f0
@test sbm.total_storage[50063] ≈ 559.70849973344f0
@test sbm.total_storage[429] ≈ 583.9800667536956f0 # river cell
end

# run the second timestep
Expand All @@ -92,6 +94,8 @@ model = Wflow.run_timestep(model)
@test sbm.runoff[50063] == 0.0
@test sbm.soilevap[50063] ≈ 0.006358004660566856f0
@test sbm.snow[5] ≈ 3.667748983774868f0
@test sbm.total_storage[50063] ≈ 559.7935411649405f0
@test sbm.total_storage[429] ≈ 589.7026699582976f0 # river cell
end

@testset "subsurface flow" begin
Expand Down
Loading