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 co2 constraint #862

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions config/config.perfect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ scenario:
- 2p0-4380H-T-H-B-I-A-solar+p3-dist1
planning_horizons:
- 2020
- 2025
- 2030
- 2035
- 2040
- 2045
- 2050


Expand Down
2 changes: 1 addition & 1 deletion doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Upcoming Release

* New configuration option ``everywhere_powerplants`` to build conventional powerplants everywhere, irrespective of existing powerplants locations, in the network (https://github.com/PyPSA/pypsa-eur/pull/850).

* Remove option for wave energy as technology data is not maintained.
* Remove option for wave energy as technology data is not maintained.


PyPSA-Eur 0.9.0 (5th January 2024)
Expand Down
5 changes: 3 additions & 2 deletions scripts/prepare_sector_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ def add_co2limit(n, nyears=1.0, limit=0.0):
"CO2Limit",
carrier_attribute="co2_emissions",
sense="<=",
type="co2_atmosphere",
constant=co2_limit,
)

Expand Down Expand Up @@ -3606,8 +3607,8 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}):
configfiles="test/config.overnight.yaml",
simpl="",
opts="",
clusters="5",
ll="v1.5",
clusters="37",
ll="v1.0",
sector_opts="CO2L0-24H-T-H-B-I-A-solar+p3-dist1",
planning_horizons="2030",
)
Expand Down
35 changes: 30 additions & 5 deletions scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def add_co2_sequestration_limit(n, config, limit=200):


def add_carbon_constraint(n, snapshots):
glcs = n.global_constraints.query('type == "co2_limit"')
glcs = n.global_constraints.query('type == "co2_atmosphere"')
if glcs.empty:
return
for name, glc in glcs.iterrows():
Expand Down Expand Up @@ -795,6 +795,29 @@ def add_pipe_retrofit_constraint(n):
n.model.add_constraints(lhs == rhs, name="Link-pipe_retrofit")


def add_co2_atmosphere_constraint(n, snapshots):
glcs = n.global_constraints[n.global_constraints.type == "co2_atmosphere"]

if glcs.empty:
return
for name, glc in glcs.iterrows():
carattr = glc.carrier_attribute
emissions = n.carriers.query(f"{carattr} != 0")[carattr]

if emissions.empty:
continue

# stores
n.stores["carrier"] = n.stores.bus.map(n.buses.carrier)
stores = n.stores.query("carrier in @emissions.index and not e_cyclic")
if not stores.empty:
last_i = snapshots[-1]
lhs = n.model["Store-e"].loc[last_i, stores.index]
rhs = glc.constant

n.model.add_constraints(lhs <= rhs, name=f"GlobalConstraint-{name}")


def extra_functionality(n, snapshots):
"""
Collects supplementary constraints which will be passed to
Expand Down Expand Up @@ -837,6 +860,8 @@ def extra_functionality(n, snapshots):
add_carbon_constraint(n, snapshots)
add_carbon_budget_constraint(n, snapshots)
add_retrofit_gas_boiler_constraint(n, snapshots)
else:
add_co2_atmosphere_constraint(n, snapshots)

if snakemake.params.custom_extra_functionality:
source_path = snakemake.params.custom_extra_functionality
Expand Down Expand Up @@ -910,13 +935,13 @@ def solve_network(n, config, solving, opts="", **kwargs):
from _helpers import mock_snakemake

snakemake = mock_snakemake(
"solve_sector_network_perfect",
"solve_sector_network",
configfiles="../config/test/config.perfect.yaml",
simpl="",
opts="",
clusters="5",
ll="v1.5",
sector_opts="8760H-T-H-B-I-A-solar+p3-dist1",
clusters="37",
ll="v1.0",
sector_opts="CO2L0-1H-T-H-B-I-A-solar+p3-dist1",
planning_horizons="2030",
)
configure_logging(snakemake)
Expand Down
Loading