Skip to content

Commit

Permalink
Reformulate target releases in terms of average flow (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamileva authored Jan 15, 2025
1 parent 40b10d3 commit 10966d8
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hydro_iteration,balancing_type,horizon,reservoir_target_release
hydro_iteration,balancing_type,horizon,reservoir_target_release_avg_flow_volunit_per_sec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hydro_iteration,balancing_type,horizon,reservoir_target_release
hydro_iteration,balancing_type,horizon,reservoir_target_release_avg_flow_volunit_per_sec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hydro_iteration,balancing_type,horizon,reservoir_target_release
hydro_iteration,balancing_type,horizon,reservoir_target_release_avg_flow_volunit_per_sec
12 changes: 6 additions & 6 deletions db/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1219,12 +1219,12 @@ CREATE TABLE subscenarios_system_water_node_reservoirs_target_releases
DROP TABLE IF EXISTS inputs_system_water_node_reservoirs_target_releases;
CREATE TABLE inputs_system_water_node_reservoirs_target_releases
(
water_node TEXT,
target_release_scenario_id INTEGER,
hydro_iteration INTEGER DEFAULT 0 NOT NULL,
balancing_type TEXT,
horizon INTEGER,
reservoir_target_release DECIMAL,
water_node TEXT,
target_release_scenario_id INTEGER,
hydro_iteration INTEGER DEFAULT 0 NOT NULL,
balancing_type TEXT,
horizon INTEGER,
reservoir_target_release_avg_flow_volunit_per_sec DECIMAL,
PRIMARY KEY (water_node, target_release_scenario_id, hydro_iteration,
balancing_type, horizon),
FOREIGN KEY (water_node, target_release_scenario_id) REFERENCES
Expand Down
32 changes: 18 additions & 14 deletions gridpath/system/water/reservoirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def add_model_components(
)

# Release targets
m.reservoir_target_release = Param(
m.reservoir_target_release_avg_flow_volunit_per_sec = Param(
m.WATER_NODE_RESERVOIR_BT_HRZS_WITH_TOTAL_RELEASE_REQUIREMENTS,
within=NonNegativeReals,
)
Expand Down Expand Up @@ -210,14 +210,13 @@ def reservoir_storage_max_bound_constraint_rule(mod, r, tmp):
# Target releases
def reservoir_target_release_constraint_rule(mod, wn, bt, hrz):
""" """
return (
sum(
mod.Gross_Reservoir_Release_Rate_Vol_Per_Sec[wn, tmp]
* 3600
* mod.hrs_in_tmp[tmp]
for tmp in mod.TMPS_BY_BLN_TYPE_HRZ[bt, hrz]
)
== mod.reservoir_target_release[wn, bt, hrz]
return sum(
mod.Gross_Reservoir_Release_Rate_Vol_Per_Sec[wn, tmp] * mod.hrs_in_tmp[tmp]
for tmp in mod.TMPS_BY_BLN_TYPE_HRZ[bt, hrz]
) == sum(
mod.reservoir_target_release_avg_flow_volunit_per_sec[wn, bt, hrz]
* mod.hrs_in_tmp[tmp]
for tmp in mod.TMPS_BY_BLN_TYPE_HRZ[bt, hrz]
)

m.Water_Node_Target_Release_Constraint = Constraint(
Expand Down Expand Up @@ -328,14 +327,14 @@ def load_model_data(
subproblem,
stage,
"inputs",
"reservoir_target_releases.tab",
"reservoir_target_release_avg_flow_volunit_per_secs.tab",
)

if os.path.exists(rel_fname):
data_portal.load(
filename=rel_fname,
index=m.WATER_NODE_RESERVOIR_BT_HRZS_WITH_TOTAL_RELEASE_REQUIREMENTS,
param=m.reservoir_target_release,
param=m.reservoir_target_release_avg_flow_volunit_per_sec,
)

# TODO: refactor
Expand Down Expand Up @@ -441,7 +440,7 @@ def get_inputs_from_database(

c2 = conn.cursor()
target_releases = c2.execute(
f"""SELECT water_node, balancing_type, horizon, reservoir_target_release
f"""SELECT water_node, balancing_type, horizon, reservoir_target_release_avg_flow_volunit_per_sec
FROM inputs_system_water_node_reservoirs_target_releases
WHERE (water_node, target_release_scenario_id)
IN (SELECT water_node, target_release_scenario_id
Expand Down Expand Up @@ -597,7 +596,7 @@ def write_model_inputs(
subproblem,
stage,
"inputs",
"reservoir_target_releases.tab",
"reservoir_target_release_avg_flow_volunit_per_secs.tab",
),
"w",
newline="",
Expand All @@ -606,7 +605,12 @@ def write_model_inputs(

# Write header
writer.writerow(
["reservoir", "balancing_type", "horizon", "reservoir_target_release"]
[
"reservoir",
"balancing_type",
"horizon",
"reservoir_target_release_avg_flow_volunit_per_sec",
]
)

for row in target_releases_list:
Expand Down
6 changes: 4 additions & 2 deletions tests/system/water/test_water_reservoirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ def test_data_loaded_correctly(self):
}
self.assertDictEqual(expected_te, actual_te)

# Param: reservoir_target_release
# Param: reservoir_target_release_avg_flow_volunit_per_sec
expected_rt = {
("Water_Node_1", "day", 202001): 200,
("Water_Node_2", "day", 202001): 200,
("Water_Node_3", "day", 202001): 200,
}
actual_rt = {
(r, bt, hrz): instance.reservoir_target_release[r, bt, hrz]
(r, bt, hrz): instance.reservoir_target_release_avg_flow_volunit_per_sec[
r, bt, hrz
]
for (
r,
bt,
Expand Down

0 comments on commit 10966d8

Please sign in to comment.