Skip to content

Commit e3ae02b

Browse files
committed
Add (not yet working) test model
1 parent 80fbdf1 commit e3ae02b

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

core/src/allocation_optim.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ function apply_control_from_allocation!(
10331033
cache = node.flow_rate_cache[Float64[]] # TODO: Make non-allocating
10341034

10351035
for (id, c_type, link_in) in zip(node_id, control_type, inflow_link)
1036-
in_subnetwork = (graph[id].subnetwork_id != subnetwork_id)
1036+
in_subnetwork = (graph[id].subnetwork_id == subnetwork_id)
10371037
allocation_controlled = (c_type == ControlType.Allocation)
10381038
if in_subnetwork && allocation_controlled
10391039
cache[id.idx] = flow[link_in.link]

python/ribasim_testmodels/ribasim_testmodels/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import ribasim_testmodels
88
from ribasim_testmodels.allocation import (
9+
allocation_control_model,
910
allocation_example_model,
1011
allocation_training_model,
1112
bommelerwaard_model,
@@ -71,6 +72,7 @@
7172
from ribasim_testmodels.two_basin import two_basin_model
7273

7374
__all__ = [
75+
"allocation_control_model",
7476
"allocation_training_model",
7577
"allocation_example_model",
7678
"backwater_model",

python/ribasim_testmodels/ribasim_testmodels/allocation.py

+52-5
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def flow_demand_model() -> Model:
859859
return model
860860

861861

862-
def linear_resistance_demand_model():
862+
def linear_resistance_demand_model() -> Model:
863863
"""Small model with a FlowDemand for a node with a max flow rate."""
864864
model = Model(
865865
starttime="2020-01-01 00:00:00",
@@ -895,7 +895,7 @@ def linear_resistance_demand_model():
895895
return model
896896

897897

898-
def fair_distribution_model():
898+
def fair_distribution_model() -> Model:
899899
"""See the behavior of allocation with few restrictions within the graph."""
900900
model = Model(
901901
starttime="2020-01-01 00:00:00",
@@ -994,7 +994,7 @@ def fair_distribution_model():
994994
return model
995995

996996

997-
def allocation_training_model():
997+
def allocation_training_model() -> Model:
998998
model = Model(
999999
starttime="2022-01-01",
10001000
endtime="2023-01-01",
@@ -1173,7 +1173,7 @@ def allocation_training_model():
11731173
return model
11741174

11751175

1176-
def bommelerwaard_model():
1176+
def bommelerwaard_model() -> Model:
11771177
model = Model(
11781178
starttime="2016-01-01",
11791179
endtime="2016-03-31",
@@ -1368,7 +1368,7 @@ def get_node_data(node_id):
13681368
return model
13691369

13701370

1371-
def cyclic_demand_model():
1371+
def cyclic_demand_model() -> Model:
13721372
"""Create a model that has cyclic User- Flow- and LevelDemand."""
13731373
model = Model(
13741374
starttime="2020-01-01",
@@ -1442,3 +1442,50 @@ def cyclic_demand_model():
14421442
model.link.add(ud, bsn2)
14431443

14441444
return model
1445+
1446+
1447+
def allocation_control_model():
1448+
"""Create a model that has a pump controlled by allocation."""
1449+
model = Model(
1450+
starttime="2020-01-01",
1451+
endtime="2023-01-01",
1452+
crs="EPSG:28992",
1453+
allocation=Allocation(use_allocation=True),
1454+
)
1455+
1456+
lb = model.level_boundary.add(
1457+
Node(1, Point(0, 0), subnetwork_id=1), [level_boundary.Static(level=[1.0])]
1458+
)
1459+
1460+
out = model.outlet.add(
1461+
Node(2, Point(1, 0), subnetwork_id=1),
1462+
[outlet.Static(flow_rate=[0.0], control_state="Ribasim.allocation")],
1463+
)
1464+
1465+
bsn = model.basin.add(
1466+
Node(3, Point(2, 0), subnetwork_id=1),
1467+
[
1468+
basin.State(level=[1.0]),
1469+
basin.Profile(level=[0.0, 1.0], area=[100.0, 100.0]),
1470+
],
1471+
)
1472+
1473+
user = model.user_demand.add(
1474+
Node(4, Point(2, -1), subnetwork_id=1, cyclic_time=True),
1475+
[
1476+
user_demand.Time(
1477+
time=["2020-01-01", "2020-06-01", "2021-01-01"],
1478+
demand=[0.0, 10.0, 0.0],
1479+
return_factor=0.0,
1480+
min_level=-5.0,
1481+
demand_priority=1,
1482+
)
1483+
],
1484+
)
1485+
1486+
model.link.add(lb, out)
1487+
model.link.add(out, bsn)
1488+
model.link.add(bsn, user)
1489+
model.link.add(user, bsn)
1490+
1491+
return model

0 commit comments

Comments
 (0)