Skip to content

Commit

Permalink
Fix manning test
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Sep 4, 2024
1 parent 0f48062 commit ecabcbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion core/src/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ function check_water_balance_error(u, t, integrator)::Nothing
end

if errors
error("Too large water balance error(s) detected.")
error(
"Too large water balance error(s) detected. Consider lowering solver tolerances or reducing shocks in the model.",
)
end
return nothing
end
Expand Down
8 changes: 4 additions & 4 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,21 +479,21 @@ end

toml_path = normpath(@__DIR__, "../../generated_testmodels/backwater/ribasim.toml")
@test ispath(toml_path)
config = Ribasim.Config(toml_path; solver_water_balance_error_reltol = Inf)
model = Ribasim.run(config)
model = Ribasim.run(toml_path)
@test successful_retcode(model)

u = model.integrator.sol.u[end]
p = model.integrator.p
manning_n = first(p.manning_resistance.manning_n)
h_actual = p.basin.current_level[parent(u)][1:50]
x = collect(10.0:20.0:990.0)
h_expected = standard_step_method(x, 5.0, 1.0, 0.04, h_actual[end], 1.0e-6)
h_expected = standard_step_method(x, 5.0, 1.0, manning_n, h_actual[end], 1.0e-6)

# We test with a somewhat arbitrary difference of 0.01 m. There are some
# numerical choices to make in terms of what the representative friction
# slope is. See e.g.:
# https://www.hec.usace.army.mil/confluence/rasdocs/ras1dtechref/latest/theoretical-basis-for-one-dimensional-and-two-dimensional-hydrodynamic-calculations/1d-steady-flow-water-surface-profiles/friction-loss-evaluation
@test all(isapprox.(h_expected, h_actual; atol = 0.02))
@test all(isapprox.(h_expected, h_actual; atol = 0.04))
# Test for conservation of mass, flow at the beginning == flow at the end
n_self_loops = length(p.graph[].flow_dict)
@test Ribasim.get_flow(
Expand Down
4 changes: 2 additions & 2 deletions python/ribasim_testmodels/ribasim_testmodels/backwater.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def backwater_model():
[
manning_resistance.Static(
length=[20.0],
manning_n=[0.04],
manning_n=[0.09],
profile_width=[1.0],
profile_slope=[0.0],
)
Expand All @@ -69,7 +69,7 @@ def backwater_model():

model.basin.add(
Node(102, Point(1010.0, 0.0)),
[basin.State(level=[2.0]), basin.Profile(level=[0.0, 1.0], area=1e20)],
[basin.State(level=[2.0]), basin.Profile(level=[0.0, 1.0], area=1e10)],
)
model.edge.add(
model.manning_resistance[101],
Expand Down

0 comments on commit ecabcbd

Please sign in to comment.