Skip to content

Commit

Permalink
fix a few issues identified by JET
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Jan 25, 2022
1 parent b1f113e commit 877a505
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/hbv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ 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],
hbv.temperature[i],
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]
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/sbm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,15 @@ 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],
sbm.temperature[i],
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]
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 877a505

Please sign in to comment.