simplify pipe retrofitting constraint
This commit is contained in:
parent
a4dab4306b
commit
cfdec7e56d
@ -12,6 +12,7 @@ import numpy as np
|
||||
|
||||
from add_existing_baseyear import add_build_year_to_new_assets
|
||||
from helper import override_component_attrs
|
||||
from solve_network import basename
|
||||
|
||||
|
||||
def add_brownfield(n, n_p, year):
|
||||
@ -79,8 +80,23 @@ def add_brownfield(n, n_p, year):
|
||||
# deal with gas network
|
||||
pipe_carrier = ['gas pipeline']
|
||||
if snakemake.config["sector"]['H2_retrofit']:
|
||||
# drop capacities of previous year to avoid duplicating
|
||||
to_drop = n.links.carrier.isin(pipe_carrier) & (n.links.build_year!=year)
|
||||
n.mremove("Link", n.links.loc[to_drop].index)
|
||||
|
||||
# subtract the already retrofitted from today's gas grid capacity
|
||||
h2_retrofitted_fixed_i = n.links[(n.links.carrier=='H2 pipeline retrofitted') & (n.links.build_year!=year)].index
|
||||
gas_pipes_i = n.links[n.links.carrier.isin(pipe_carrier)].index
|
||||
CH4_per_H2 = 1 / snakemake.config["sector"]["H2_retrofit_capacity_per_CH4"]
|
||||
fr = "H2 pipeline retrofitted"
|
||||
to = "gas pipeline"
|
||||
# today's pipe capacity
|
||||
pipe_capacity = n.links.loc[gas_pipes_i, 'p_nom']
|
||||
# already retrofitted capacity from gas -> H2
|
||||
already_retrofitted = (n.links.loc[h2_retrofitted_fixed_i, 'p_nom']
|
||||
.rename(lambda x: basename(x).replace(fr, to)).groupby(level=0).sum())
|
||||
remaining_capacity = pipe_capacity - CH4_per_H2 * already_retrofitted.reindex(index=pipe_capacity.index).fillna(0)
|
||||
n.links.loc[gas_pipes_i, "p_nom"] = remaining_capacity
|
||||
else:
|
||||
new_pipes = n.links.carrier.isin(pipe_carrier) & (n.links.build_year==year)
|
||||
n.links.loc[new_pipes, "p_nom"] = 0.
|
||||
|
@ -193,7 +193,6 @@ def add_pipe_retrofit_constraint(n):
|
||||
|
||||
gas_pipes_i = n.links.query("carrier == 'gas pipeline' and p_nom_extendable").index
|
||||
h2_retrofitted_i = n.links.query("carrier == 'H2 pipeline retrofitted' and p_nom_extendable").index
|
||||
h2_retrofitted_fixed_i = n.links.query("carrier == 'H2 pipeline retrofitted' and not p_nom_extendable").index
|
||||
|
||||
if h2_retrofitted_i.empty or gas_pipes_i.empty: return
|
||||
|
||||
@ -204,9 +203,6 @@ def add_pipe_retrofit_constraint(n):
|
||||
to = "gas pipeline"
|
||||
|
||||
pipe_capacity = n.links.loc[gas_pipes_i, 'p_nom'].rename(basename)
|
||||
already_retrofitted = (n.links.loc[h2_retrofitted_fixed_i, 'p_nom']
|
||||
.rename(lambda x: basename(x).replace(fr, to)).groupby(level=0).sum())
|
||||
remaining_capacity = pipe_capacity - CH4_per_H2 * already_retrofitted.reindex(index=pipe_capacity.index).fillna(0)
|
||||
|
||||
lhs = linexpr(
|
||||
(CH4_per_H2, link_p_nom.loc[h2_retrofitted_i].rename(index=lambda x: x.replace(fr, to))),
|
||||
@ -214,7 +210,7 @@ def add_pipe_retrofit_constraint(n):
|
||||
)
|
||||
|
||||
lhs.rename(basename, inplace=True)
|
||||
define_constraints(n, lhs, "=", remaining_capacity, 'Link', 'pipe_retrofit')
|
||||
define_constraints(n, lhs, "=", pipe_capacity, 'Link', 'pipe_retrofit')
|
||||
|
||||
|
||||
def add_co2_sequestration_limit(n, sns):
|
||||
|
Loading…
Reference in New Issue
Block a user