Skip to content

Commit ce1967d

Browse files
committed
Add the min_per_tech module
1 parent c50b40a commit ce1967d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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,
17+
dimen=2
18+
)
19+
20+
mod.minimum_capacity_mw = Param(
21+
mod.GEN_TECH_PER_PERIOD,
22+
within=NonNegativeReals,
23+
default=0
24+
)
25+
26+
mod.GenCapacityPerTech = Expression(
27+
mod.GEN_TECH_PER_PERIOD,
28+
rule=lambda m, tech, p: sum(m.GenCapacity[g, p] for g in m.GENS_BY_TECHNOLOGY[tech])
29+
)
30+
31+
mod.Enforce_Minimum_Capacity_Per_Tech = Constraint(
32+
mod.GEN_TECH_PER_PERIOD,
33+
rule=lambda m, tech, p:
34+
Constraint.Skip if m.minimum_capacity_mw[tech, p] == 0 else m.GenCapacityPerTech[tech, p] >=
35+
m.minimum_capacity_mw[tech, p]
36+
)
37+
38+
39+
def load_inputs(mod, switch_data, inputs_dir):
40+
"""
41+
Expected input file:
42+
43+
min_per_tech.csv with the following format:
44+
gen_tech,period,minimum_capacity_mw
45+
Nuclear,2040,10
46+
"""
47+
switch_data.load_aug(
48+
filename=os.path.join(inputs_dir, "min_per_tech.csv"),
49+
param=mod.minimum_capacity_mw,
50+
auto_select=True,
51+
# We want this module to run even if we don't specify a constraint so we still get the useful outputs
52+
optional=True
53+
)
54+
55+
56+
def post_solve(mod, outdir):
57+
write_table(
58+
mod,
59+
mod.GEN_TECH_PER_PERIOD,
60+
output_file=os.path.join(outdir, "gen_cap_per_tech.csv"),
61+
headings=("gen_tech", "period", "gen_capacity", "minimum_capacity_mw"),
62+
values=lambda m, tech, p: (tech, p, m.GenCapacityPerTech[tech, p], m.minimum_capacity_mw[tech, p])
63+
)

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)