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

Fix looped subnetwork #965

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions python/ribasim_testmodels/ribasim_testmodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import ribasim_testmodels
from ribasim_testmodels.allocation import (
allocation_example_model,
# looped_subnetwork_model,
fractional_flow_subnetwork_model,
looped_subnetwork_model,
minimal_subnetwork_model,
subnetwork_model,
user_model,
Expand Down Expand Up @@ -82,9 +82,7 @@
"subnetwork_model",
"minimal_subnetwork_model",
"fractional_flow_subnetwork_model",
# Disable until this issue is resolved:
# https://github.com/Deltares/Ribasim/issues/692
# "looped_subnetwork_model",
"looped_subnetwork_model",
]

# provide a mapping from model name to its constructor, so we can iterate over all models
Expand Down
19 changes: 13 additions & 6 deletions python/ribasim_testmodels/ribasim_testmodels/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,15 @@ def looped_subnetwork_model():
dtype=np.int64,
)
lines = node.geometry_from_connectivity(from_id, to_id)
allocation_network_id = len(from_id) * [None]
allocation_network_id[0] = 1
edge = ribasim.Edge(
df=gpd.GeoDataFrame(
data={
"from_node_id": from_id,
"to_node_id": to_id,
"edge_type": len(from_id) * ["flow"],
"allocation_network_id": allocation_network_id,
},
geometry=lines,
crs="EPSG:28992",
Expand All @@ -454,21 +457,21 @@ def looped_subnetwork_model():
}
)

state = pd.DataFrame(data={"node_id": [2, 7, 9, 15, 17, 21], "level": 1.0})
state = pd.DataFrame(data={"node_id": [2, 7, 9, 11, 15, 17, 21], "level": 1.0})

basin = ribasim.Basin(profile=profile, static=static, state=state)

# Setup the flow boundary:
flow_boundary = ribasim.FlowBoundary(
static=pd.DataFrame(data={"node_id": [5], "flow_rate": [4.5]})
static=pd.DataFrame(data={"node_id": [5], "flow_rate": [4.5e-3]})
)

# Setup the users:
user = ribasim.User(
static=pd.DataFrame(
data={
"node_id": [1, 12, 18, 20, 24],
"demand": 1.0,
"demand": 1.0e-3,
"return_factor": 0.9,
"min_level": 0.9,
"priority": [2, 1, 3, 3, 2],
Expand All @@ -481,16 +484,16 @@ def looped_subnetwork_model():
static=pd.DataFrame(
data={
"node_id": [6, 16],
"flow_rate": 4.0,
"max_flow_rate": 4.0,
"flow_rate": 4.0e-3,
"max_flow_rate": 4.0e-3,
}
)
)

# Setup the outlets:
outlet = ribasim.Outlet(
static=pd.DataFrame(
data={"node_id": [3, 8, 10, 22], "flow_rate": 3.0, "max_flow_rate": 3.0}
data={"node_id": [3, 8, 10, 22], "flow_rate": 3.0e-3, "max_flow_rate": 3.0}
)
)

Expand All @@ -514,6 +517,9 @@ def looped_subnetwork_model():
)
)

# Setup allocation:
allocation = ribasim.Allocation(use_allocation=True, timestep=86400)

model = ribasim.Model(
network=ribasim.Network(node=node, edge=edge),
basin=basin,
Expand All @@ -523,6 +529,7 @@ def looped_subnetwork_model():
outlet=outlet,
tabulated_rating_curve=rating_curve,
terminal=terminal,
allocation=allocation,
starttime="2020-01-01 00:00:00",
endtime="2021-01-01 00:00:00",
)
Expand Down
Loading