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

Support soft flow constraints #1199

Merged
merged 1 commit 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,5 +1,5 @@
water_link,water_node_from,water_node_to,water_link_flow_transport_time_hours
Water_Link_12,Water_Node_1,Water_Node_2,0
Water_Link_23,Water_Node_2,Water_Node_3,0
Water_Link_34,Water_Node_3,Water_Node_4,0
Water_Link_45,Water_Node_4,Water_Node_5,0
water_link,water_node_from,water_node_to,water_link_flow_transport_time_hours,allow_water_link_min_flow_violation,min_flow_violation_penalty_cost,allow_water_link_max_flow_violation,max_flow_violation_penalty_cost
Water_Link_12,Water_Node_1,Water_Node_2,0,,,,
Water_Link_23,Water_Node_2,Water_Node_3,0,,,,
Water_Link_34,Water_Node_3,Water_Node_4,0,,,,
Water_Link_45,Water_Node_4,Water_Node_5,0,,,,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
water_link,water_node_from,water_node_to,water_link_flow_transport_time_hours
Water_Link_12,Water_Node_1,Water_Node_2,1
Water_Link_23,Water_Node_2,Water_Node_3,2
Water_Link_34,Water_Node_3,Water_Node_4,1
Water_Link_45,Water_Node_4,Water_Node_5,2
water_link,water_node_from,water_node_to,water_link_flow_transport_time_hours,allow_water_link_min_flow_violation,min_flow_violation_penalty_cost,allow_water_link_max_flow_violation,max_flow_violation_penalty_cost
Water_Link_12,Water_Node_1,Water_Node_2,1,,,,
Water_Link_23,Water_Node_2,Water_Node_3,2,,,,
Water_Link_34,Water_Node_3,Water_Node_4,1,,,,
Water_Link_45,Water_Node_4,Water_Node_5,2,,,,
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
water_system_balancing_type,theoretical_power_coefficient,allow_lin_hrz_first_tmp_flow_slack,allow_lin_hrz_first_tmp_flow_slack_tuning_cost
day,84.7,0,0
water_system_balancing_type,theoretical_power_coefficient
day,84.7
38 changes: 21 additions & 17 deletions db/db_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,9 @@ CREATE TABLE subscenarios_system_water_system_params
DROP TABLE IF EXISTS inputs_system_water_system_params;
CREATE TABLE inputs_system_water_system_params
(
water_system_params_scenario_id INTEGER PRIMARY KEY,
water_system_balancing_type TEXT,
theoretical_power_coefficient FLOAT,
allow_lin_hrz_first_tmp_flow_slack FLOAT,
allow_lin_hrz_first_tmp_flow_slack_tuning_cost FLOAT,
water_system_params_scenario_id INTEGER PRIMARY KEY,
water_system_balancing_type TEXT,
theoretical_power_coefficient FLOAT,
FOREIGN KEY (water_system_params_scenario_id) REFERENCES
subscenarios_system_water_system_params (water_system_params_scenario_id)
);
Expand All @@ -1083,6 +1081,10 @@ CREATE TABLE inputs_geography_water_network
water_node_from TEXT,
water_node_to TEXT,
water_link_flow_transport_time_hours FLOAT,
allow_water_link_min_flow_violation INTEGER,
min_flow_violation_penalty_cost FLOAT,
allow_water_link_max_flow_violation INTEGER,
max_flow_violation_penalty_cost FLOAT,
PRIMARY KEY (water_network_scenario_id, water_link),
FOREIGN KEY (water_network_scenario_id) REFERENCES
subscenarios_geography_water_network (water_network_scenario_id)
Expand Down Expand Up @@ -6694,17 +6696,18 @@ DROP TABLE IF EXISTS results_system_ra;
DROP TABLE IF EXISTS results_system_water_link_timepoint;
CREATE TABLE results_system_water_link_timepoint
(
scenario_id INTEGER,
weather_iteration INTEGER,
hydro_iteration INTEGER,
availability_iteration INTEGER,
subproblem_id INTEGER,
stage_id INTEGER,
water_link VARCHAR(32),
departure_timepoint INTEGER,
arrival_timepoint INTEGER,
water_flow_vol_per_sec FLOAT,
water_flow_slack_used_vol_per_sec FLOAT,
scenario_id INTEGER,
weather_iteration INTEGER,
hydro_iteration INTEGER,
availability_iteration INTEGER,
subproblem_id INTEGER,
stage_id INTEGER,
water_link VARCHAR(32),
departure_timepoint INTEGER,
arrival_timepoint INTEGER,
water_flow_vol_per_sec FLOAT,
water_flow_min_violation_vol_per_sec FLOAT,
water_flow_max_violation_vol_per_sec FLOAT,
PRIMARY KEY (scenario_id, weather_iteration, hydro_iteration,
availability_iteration, subproblem_id, stage_id, water_link,
departure_timepoint)
Expand Down Expand Up @@ -6812,7 +6815,8 @@ CREATE TABLE results_system_costs
Total_Carbon_Credit_Costs FLOAT,
Total_Peak_Deviation_Monthly_Demand_Charge_Cost FLOAT,
Total_Policy_Target_Balance_Penalty_Costs FLOAT,
Total_Flow_Constraint_Slack_Tuning_Cost FLOAT,
Total_Min_Flow_Violation_Penalty_Cost FLOAT,
Total_Max_Flow_Violation_Penalty_Cost FLOAT,
PRIMARY KEY (scenario_id, weather_iteration, hydro_iteration,
availability_iteration, subproblem_id, stage_id)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
water_link water_node_from water_node_to water_link_flow_transport_time_hours
Water_Link_12 Water_Node_1 Water_Node_2 0.0
Water_Link_23 Water_Node_2 Water_Node_3 0.0
Water_Link_34 Water_Node_3 Water_Node_4 0.0
Water_Link_45 Water_Node_4 Water_Node_5 0.0
water_link water_node_from water_node_to water_link_flow_transport_time_hours allow_water_link_min_flow_violation min_flow_violation_penalty_cost allow_water_link_max_flow_violation max_flow_violation_penalty_cost
Water_Link_12 Water_Node_1 Water_Node_2 0.0 . . . .
Water_Link_23 Water_Node_2 Water_Node_3 0.0 . . . .
Water_Link_34 Water_Node_3 Water_Node_4 0.0 . . . .
Water_Link_45 Water_Node_4 Water_Node_5 0.0 . . . .
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
water_system_balancing_type theoretical_power_coefficient allow_lin_hrz_first_tmp_flow_slack allow_lin_hrz_first_tmp_flow_slack_tuning_cost
day 84.7 0.0 0.0
water_system_balancing_type theoretical_power_coefficient
day 84.7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##### SUMMARY RESULTS FOR SCENARIO *hydro_system_exog_elev* #####

### CAPACITY RESULTS ###

### OPERATIONAL RESULTS ###

--> Energy Production <--
Annual Energy (MWh) % Total Power
load_zone period technology
Zone1 2026 Hydro_Water 798,513.42 100.00
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
optimal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
water_link water_node_from water_node_to water_link_flow_transport_time_hours
Water_Link_12 Water_Node_1 Water_Node_2 1.0
Water_Link_23 Water_Node_2 Water_Node_3 2.0
Water_Link_34 Water_Node_3 Water_Node_4 1.0
Water_Link_45 Water_Node_4 Water_Node_5 2.0
water_link water_node_from water_node_to water_link_flow_transport_time_hours allow_water_link_min_flow_violation min_flow_violation_penalty_cost allow_water_link_max_flow_violation max_flow_violation_penalty_cost
Water_Link_12 Water_Node_1 Water_Node_2 1.0 . . . .
Water_Link_23 Water_Node_2 Water_Node_3 2.0 . . . .
Water_Link_34 Water_Node_3 Water_Node_4 1.0 . . . .
Water_Link_45 Water_Node_4 Water_Node_5 2.0 . . . .
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
water_system_balancing_type theoretical_power_coefficient allow_lin_hrz_first_tmp_flow_slack allow_lin_hrz_first_tmp_flow_slack_tuning_cost
day 84.7 0.0 0.0
water_system_balancing_type theoretical_power_coefficient
day 84.7
4 changes: 2 additions & 2 deletions gridpath/auxiliary/module_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def all_modules_list():
"objective.system.reliability.local_capacity"
".aggregate_local_capacity_violation_penalties",
"objective.system.aggregate_market_revenue_and_costs",
"objective.system.water.aggregate_flow_constraint_slack_use_tuning_costs",
"objective.system.water.aggregate_flow_violation_penalty_costs",
"objective.max_npv",
]
return all_modules
Expand Down Expand Up @@ -492,7 +492,7 @@ def optional_modules_list():
"system.water.water_node_balance",
"system.water.water_flows",
"system.water.powerhouses",
"objective.system.water.aggregate_flow_constraint_slack_use_tuning_costs",
"objective.system.water.aggregate_flow_violation_penalty_costs",
],
"tuning": [
"project.operations.tuning_costs",
Expand Down
34 changes: 30 additions & 4 deletions gridpath/geography/water_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Param,
NonNegativeReals,
Any,
Boolean,
)

from gridpath.auxiliary.db_interface import directories_to_db_values
Expand Down Expand Up @@ -91,6 +92,18 @@ def add_model_components(
m.water_link_flow_transport_time_hours = Param(
m.WATER_LINKS, within=NonNegativeReals, default=0
)
m.allow_water_link_min_flow_violation = Param(
m.WATER_LINKS, within=Boolean, default=0
)
m.min_flow_violation_penalty_cost = Param(
m.WATER_LINKS, within=NonNegativeReals, default=0
)
m.allow_water_link_max_flow_violation = Param(
m.WATER_LINKS, within=Boolean, default=0
)
m.max_flow_violation_penalty_cost = Param(
m.WATER_LINKS, within=NonNegativeReals, default=0
)


def load_model_data(
Expand Down Expand Up @@ -120,6 +133,10 @@ def load_model_data(
m.water_node_from,
m.water_node_to,
m.water_link_flow_transport_time_hours,
m.allow_water_link_min_flow_violation,
m.min_flow_violation_penalty_cost,
m.allow_water_link_max_flow_violation,
m.max_flow_violation_penalty_cost,
),
)

Expand All @@ -145,7 +162,11 @@ def get_inputs_from_database(
c = conn.cursor()
water_links = c.execute(
f"""SELECT water_link, water_node_from, water_node_to,
water_link_flow_transport_time_hours
water_link_flow_transport_time_hours,
allow_water_link_min_flow_violation,
min_flow_violation_penalty_cost,
allow_water_link_max_flow_violation,
max_flow_violation_penalty_cost
FROM inputs_geography_water_network
WHERE water_network_scenario_id = {subscenarios.WATER_NETWORK_SCENARIO_ID};
"""
Expand Down Expand Up @@ -210,7 +231,7 @@ def write_model_inputs(
weather_iteration, hydro_iteration, availability_iteration, subproblem, stage
)

carbon_cap_zone = get_inputs_from_database(
water_network = get_inputs_from_database(
scenario_id,
subscenarios,
db_weather_iteration,
Expand Down Expand Up @@ -244,8 +265,13 @@ def write_model_inputs(
"water_node_from",
"water_node_to",
"water_link_flow_transport_time_hours",
"allow_water_link_min_flow_violation",
"min_flow_violation_penalty_cost",
"allow_water_link_max_flow_violation",
"max_flow_violation_penalty_cost",
]
)

for row in carbon_cap_zone:
writer.writerow(row)
for row in water_network:
replace_nulls = ["." if i is None else i for i in row]
writer.writerow(replace_nulls)

This file was deleted.

Loading
Loading