Skip to content

Commit

Permalink
Merge pull request #862 from PyPSA/reformulate-co2-constraint
Browse files Browse the repository at this point in the history
Reformulate co2 constraint
  • Loading branch information
fneum authored Jan 18, 2024
2 parents 6d2f2cc + b0e2365 commit dd1e07e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
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
5 changes: 5 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Upcoming Release

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

* Define global constraint for CO2 emissions on the final state of charge of the
CO2 atmosphere store. This gives a more sparse constraint that should improve
the performance of the solving process.

* Bugfix: Assure entering of code block which corrects Norwegian heat demand.

* Add warning when BEV availability weekly profile has negative values in `build_transport_demand`.
Expand All @@ -24,6 +28,7 @@ Upcoming Release

* Cluster residential and services heat buses by default. Can be disabled with ``cluster_heat_buses: false``.


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 @@ -797,6 +797,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 @@ -839,6 +862,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 @@ -912,13 +937,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

0 comments on commit dd1e07e

Please sign in to comment.