diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 110c10ed0..f03311e59 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 width. - Fixed use of absolute path for `path_forcing` in TOML file, which gave an error in Wflow v0.5.1. +- Fixed a crash when using glaciers. - When the surface flow width for overland flow is zero, the water level `h` of the kinematic wave should not be calculated, otherwise this results in `NaN` values. When the model is initialized from state files, `q` and `h` are set to zero for indices with a zero diff --git a/src/bmi.jl b/src/bmi.jl index 4647f0866..9140a3f22 100644 --- a/src/bmi.jl +++ b/src/bmi.jl @@ -62,14 +62,13 @@ end function BMI.update_until(model::Model, time::Float64) @unpack network, config = model - update_func = config.model.type == "sbm_gwf" ? update_sbm_gwf : update curtime = BMI.get_current_time(model) n_iter = Int(max(0, (time - curtime) / model.clock.Δt.value)) end_time = curtime + n_iter * config.timestepsecs @info "Updating model until $end_time." - for i = 1:n_iter + for _ = 1:n_iter load_dynamic_input!(model) - update_func(model) + update(model) end return model end diff --git a/src/hbv.jl b/src/hbv.jl index 29d4202ba..6c70bc71c 100644 --- a/src/hbv.jl +++ b/src/hbv.jl @@ -136,7 +136,7 @@ function update_after_snow(hbv::HBV, config) # Estimate the fraction of snow turned into ice (HBV-light). # Estimate glacier melt. - hbv.snow[i], snow2glacier, hbv.glacierstore[i], glaciermelt = glacier_hbv( + hbv.snow[i], _, hbv.glacierstore[i], glaciermelt = glacier_hbv( hbv.glacierfrac[i], hbv.glacierstore[i], hbv.snow[i], @@ -144,7 +144,7 @@ function update_after_snow(hbv::HBV, config) hbv.g_tt[i], hbv.g_cfmax[i], hbv.g_sifrac[i], - Δt, + hbv.Δt, ) # Convert to mm per grid cell and add to snowmelt glaciermelt = glaciermelt * hbv.glacierfrac[i] @@ -220,7 +220,7 @@ function update_after_snow(hbv::HBV, config) lowerzonestorage = lowerzonestorage - baseflow if external_qbase - directrunoffstorage = quickflow + seepage + real_quickflow + directrunoffstorage = quickflow + hbv_seepage + real_quickflow else directrunoffstorage = quickflow + baseflow + real_quickflow end diff --git a/src/io.jl b/src/io.jl index 83e19bff2..005fce877 100644 --- a/src/io.jl +++ b/src/io.jl @@ -77,10 +77,14 @@ Base.pop!(config::Config, key) = pop!(Dict(config), key) Base.pop!(config::Config, key, default) = pop!(Dict(config), key, default) Base.Dict(config::Config) = getfield(config, :dict) Base.pathof(config::Config) = getfield(config, :path) -Base.dirname(config::Config) = dirname(pathof(config)) Base.iterate(config::Config) = iterate(Dict(config)) Base.iterate(config::Config, state) = iterate(Dict(config), state) +function Base.dirname(config::Config) + path = pathof(config) + return path === nothing ? nothing : dirname(path) +end + function combined_path(config::Config, dir::AbstractString, path::AbstractString) tomldir = dirname(config) return normpath(tomldir, dir, path) diff --git a/src/sbm.jl b/src/sbm.jl index 8e3d7d2b4..149c54172 100644 --- a/src/sbm.jl +++ b/src/sbm.jl @@ -751,7 +751,7 @@ function update_until_recharge(sbm::SBM, config) # Estimate the fraction of snow turned into ice (HBV-light). # Estimate glacier melt. - snow, snow2glacier, glacierstore, glaciermelt = glacier_hbv( + snow, _, glacierstore, glaciermelt = glacier_hbv( sbm.glacierfrac[i], sbm.glacierstore[i], sbm.snow[i], @@ -759,7 +759,7 @@ function update_until_recharge(sbm::SBM, config) sbm.g_tt[i], sbm.g_cfmax[i], sbm.g_sifrac[i], - Second(sbm.Δt), + sbm.Δt, ) # Convert to mm per grid cell and add to snowmelt glaciermelt = glaciermelt * sbm.glacierfrac[i] @@ -835,7 +835,7 @@ function update_until_recharge(sbm::SBM, config) sbm.θₛ[i], sbm.θᵣ[i], ) - usld = setindex(usld, ustorelayerdepth, m) + usld = setindex(usld, ustorelayerdepth, 1) else for m = 1:n_usl l_sat = usl[m] * (sbm.θₛ[i] - sbm.θᵣ[i])