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

Add update_subgrid_level to BMI functions #986

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions core/src/bmi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ function BMI.update_until(model::Model, time)::Model
return model
end

function BMI.update_subgrid_level(model::Model)::Model
update_subgrid_level!(model.integrator)
return model
end
Huite marked this conversation as resolved.
Show resolved Hide resolved

function BMI.get_value_ptr(model::Model, name::AbstractString)
if name == "volume"
model.integrator.u.storage
Expand Down
11 changes: 11 additions & 0 deletions python/ribasim_api/tests/test_bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def test_update_until(libribasim, basic, tmp_path):
assert actual_time == pytest.approx(expected_time)


def test_update_subgrid_level(libribasim, basic, tmp_path):
basic.write(tmp_path / "ribasim.toml")
config_file = str(tmp_path / "ribasim.toml")
libribasim.initialize(config_file)
libribasim.update_subgrid_level()
level = libribasim.get_value_ptr("subgrid_level")
# The subgrid levels are initialized with NaN.
# After calling update, they should have regular values.
assert np.isfinite(level).all()


def test_get_var_type(libribasim, basic, tmp_path):
basic.write(tmp_path / "ribasim.toml")
config_file = str(tmp_path / "ribasim.toml")
Expand Down
11 changes: 10 additions & 1 deletion python/ribasim_testmodels/ribasim_testmodels/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ def basic_model() -> ribasim.Model:
state = pd.DataFrame(
data={"node_id": static["node_id"], "level": 0.04471158417652035}
)
basin = ribasim.Basin(profile=profile, static=static, state=state)
# This is a 1:1 translation.
subgrid = pd.DataFrame(
data={
"node_id": profile["node_id"],
"subgrid_id": profile["node_id"],
"basin_level": profile["level"],
"subgrid_level": profile["level"],
}
)
basin = ribasim.Basin(profile=profile, static=static, state=state, subgrid=subgrid)

# Setup linear resistance:
linear_resistance = ribasim.LinearResistance(
Expand Down
Loading