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

Reformulate target releases in terms of average flow #1200

Merged
merged 2 commits into from
Jan 15, 2025
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
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
Loading