Skip to content

Commit ef20a81

Browse files
committed
Add the min_per_tech module
1 parent ce5ce12 commit ef20a81

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
This module allows defining a constraint that specifies a minimum buildout for a certain type of gen_tech.
3+
4+
The advantage of this module is that it stills allows switch to decide where to place
5+
the specified technology.
6+
"""
7+
import os
8+
9+
from pyomo.environ import *
10+
11+
from switch_model.reporting import write_table
12+
13+
14+
def define_components(mod):
15+
mod.GEN_TECH_PER_PERIOD = Set(
16+
initialize=lambda m: m.GENERATION_TECHNOLOGIES * m.PERIODS, dimen=2
17+
)
18+
19+
mod.minimum_capacity_mw = Param(
20+
mod.GEN_TECH_PER_PERIOD, within=NonNegativeReals, default=0
21+
)
22+
23+
mod.GenCapacityPerTech = Expression(
24+
mod.GEN_TECH_PER_PERIOD,
25+
rule=lambda m, tech, p: sum(
26+
m.GenCapacity[g, p] for g in m.GENS_BY_TECHNOLOGY[tech]
27+
),
28+
)
29+
30+
mod.Enforce_Minimum_Capacity_Per_Tech = Constraint(
31+
mod.GEN_TECH_PER_PERIOD,
32+
rule=lambda m, tech, p: Constraint.Skip
33+
if m.minimum_capacity_mw[tech, p] == 0
34+
else m.GenCapacityPerTech[tech, p] >= m.minimum_capacity_mw[tech, p],
35+
)
36+
37+
38+
def load_inputs(mod, switch_data, inputs_dir):
39+
"""
40+
Expected input file:
41+
42+
min_per_tech.csv with the following format:
43+
gen_tech,period,minimum_capacity_mw
44+
Nuclear,2040,10
45+
"""
46+
switch_data.load_aug(
47+
filename=os.path.join(inputs_dir, "min_per_tech.csv"),
48+
param=mod.minimum_capacity_mw,
49+
auto_select=True,
50+
# We want this module to run even if we don't specify a constraint so we still get the useful outputs
51+
optional=True,
52+
)
53+
54+
55+
def post_solve(mod, outdir):
56+
write_table(
57+
mod,
58+
mod.GEN_TECH_PER_PERIOD,
59+
output_file=os.path.join(outdir, "gen_cap_per_tech.csv"),
60+
headings=("gen_tech", "period", "gen_capacity", "minimum_capacity_mw"),
61+
values=lambda m, tech, p: (
62+
tech,
63+
p,
64+
m.GenCapacityPerTech[tech, p],
65+
m.minimum_capacity_mw[tech, p],
66+
),
67+
)

switch_model/wecc/get_inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def write_csv(data: Iterable[List], fname, headers: List[str], log=True):
6868
"switch_model.transmission.transport.dispatch",
6969
"switch_model.policies.carbon_policies",
7070
"switch_model.policies.rps_unbundled",
71+
"switch_model.policies.min_per_tech", # Always include since it provides useful outputs even when unused
7172
# "switch_model.reporting.basic_exports_wecc",
7273
]
7374

0 commit comments

Comments
 (0)