Biomass, synthetic fuels and carbon management

Note

You can download this example as a Jupyter notebook or start it in interactive mode.

Biomass, synthetic fuels and carbon management#

In this example we show how to manage different biomass stocks with different potentials and costs, synthetic fuel production, direct air capture (DAC) and carbon capture and usage/sequestration/cycling (CCU/S/C).

Demand for electricity and diesel transport have to be met from various biomass sources, natural gas with possibility for carbon capture, electrolysis for hydrogen production, direct air capture of CO2, and diesel synthesis via Fischer-Tropsch.

The system has to reach a target of net negative emissions over the period.

All numbers/costs/efficiencies are fictitious to allow easy analysis.

[1]:
import matplotlib.pyplot as plt

import pypsa
[2]:
n = pypsa.Network()
n.set_snapshots(range(10))

Add a constant electrical load

[3]:
n.add("Bus", "bus")
n.add("Load", "load", bus="bus", p_set=1.0)

Add a constant demand for transport

[4]:
n.add("Bus", "transport")
n.add("Load", "transport", bus="transport", p_set=1.0)


n.add("Bus", "diesel")


n.add("Store", "diesel", bus="diesel", e_cyclic=True, e_nom=1000.0)

Add a bus for Hydrogen storage.

[5]:
n.add("Bus", "hydrogen")

n.add("Store", "hydrogen", bus="hydrogen", e_cyclic=True, e_nom=1000.0)

# n.add("Load","hydrogen",
#      bus="hydrogen",
#      p_set=1.)

n.add("Link", "electrolysis", p_nom=2.0, efficiency=0.8, bus0="bus", bus1="hydrogen")

Allow production of diesel from H2 and CO2 using Fischer-Tropsch

[6]:
n.add(
    "Link",
    "FT",
    p_nom=4,
    bus0="hydrogen",
    bus1="diesel",
    bus2="co2 stored",
    efficiency=1.0,
    efficiency2=-1,
)

# minus sign because opposite to how fossil fuels used:
# CH4 burning puts CH4 down, atmosphere up
n.add("Carrier", "co2", co2_emissions=-1.0)

# this tracks CO2 in the atmosphere
n.add("Bus", "co2 atmosphere", carrier="co2")

# NB: can also be negative
n.add("Store", "co2 atmosphere", e_nom=1000, e_min_pu=-1, bus="co2 atmosphere")

# this tracks CO2 stored, e.g. underground
n.add("Bus", "co2 stored")

# NB: can also be negative
n.add("Store", "co2 stored", e_nom=1000, e_min_pu=-1, bus="co2 stored")
WARNING:pypsa.components:The bus name `co2 stored` given for bus2 of Link `FT` does not appear in network.buses

Direct air capture consumes electricity to take CO2 from the air to the underground store

[7]:
n.add(
    "Link",
    "DAC",
    bus0="bus",
    bus1="co2 stored",
    bus2="co2 atmosphere",
    efficiency=1,
    efficiency2=-1,
    p_nom=5.0,
)

Meet transport with diesel

[8]:
n.add(
    "Link",
    "diesel car",
    bus0="diesel",
    bus1="transport",
    bus2="co2 atmosphere",
    efficiency=1.0,
    efficiency2=1.0,
    p_nom=2.0,
)

n.add("Bus", "gas")

n.add("Store", "gas", e_initial=50, e_nom=50, marginal_cost=20, bus="gas")

n.add(
    "Link",
    "OCGT",
    bus0="gas",
    bus1="bus",
    bus2="co2 atmosphere",
    p_nom_extendable=True,
    efficiency=0.5,
    efficiency2=1,
)


n.add(
    "Link",
    "OCGT+CCS",
    bus0="gas",
    bus1="bus",
    bus2="co2 stored",
    bus3="co2 atmosphere",
    p_nom_extendable=True,
    efficiency=0.4,
    efficiency2=0.9,
    efficiency3=0.1,
)

Add a cheap and a expensive biomass generator.

[9]:
biomass_marginal_cost = [20.0, 50.0]
biomass_stored = [40.0, 15.0]

for i in range(2):
    n.add("Bus", "biomass" + str(i))

    n.add(
        "Store",
        "biomass" + str(i),
        bus="biomass" + str(i),
        e_nom_extendable=True,
        marginal_cost=biomass_marginal_cost[i],
        e_nom=biomass_stored[i],
        e_initial=biomass_stored[i],
    )

    # simultaneously empties and refills co2 atmosphere
    n.add(
        "Link",
        "biomass" + str(i),
        bus0="biomass" + str(i),
        bus1="bus",
        p_nom_extendable=True,
        efficiency=0.5,
    )

    n.add(
        "Link",
        "biomass+CCS" + str(i),
        bus0="biomass" + str(i),
        bus1="bus",
        bus2="co2 stored",
        bus3="co2 atmosphere",
        p_nom_extendable=True,
        efficiency=0.4,
        efficiency2=1.0,
        efficiency3=-1,
    )


# can go to -50, but at some point can't generate enough electricity for DAC and demand
target = -50

Add a global CO\(_2\) constraint.

[10]:
n.add(
    "GlobalConstraint",
    "co2_limit",
    sense="<=",
    carrier_attribute="co2_emissions",
    constant=target,
)
[11]:
n.optimize();
WARNING:pypsa.consistency:The following stores have carriers which are not defined:
Index(['diesel', 'hydrogen', 'co2 stored', 'gas', 'biomass0', 'biomass1'], dtype='object', name='Store')
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['bus', 'transport', 'diesel', 'hydrogen', 'co2 stored', 'gas',
       'biomass0', 'biomass1'],
      dtype='object', name='Bus')
WARNING:pypsa.consistency:The following links have carriers which are not defined:
Index(['electrolysis', 'FT', 'DAC', 'diesel car', 'OCGT', 'OCGT+CCS',
       'biomass0', 'biomass+CCS0', 'biomass1', 'biomass+CCS1'],
      dtype='object', name='Link')
WARNING:pypsa.consistency:Encountered nan's in static data for columns ['efficiency3', 'efficiency2'] of component 'Link'.
WARNING:pypsa.consistency:The following stores have carriers which are not defined:
Index(['diesel', 'hydrogen', 'co2 stored', 'gas', 'biomass0', 'biomass1'], dtype='object', name='Store')
WARNING:pypsa.consistency:The following buses have carriers which are not defined:
Index(['bus', 'transport', 'diesel', 'hydrogen', 'co2 stored', 'gas',
       'biomass0', 'biomass1'],
      dtype='object', name='Bus')
WARNING:pypsa.consistency:The following links have carriers which are not defined:
Index(['electrolysis', 'FT', 'DAC', 'diesel car', 'OCGT', 'OCGT+CCS',
       'biomass0', 'biomass+CCS0', 'biomass1', 'biomass+CCS1'],
      dtype='object', name='Link')
WARNING:pypsa.consistency:Encountered nan's in static data for columns ['efficiency3', 'efficiency2'] of component 'Link'.
INFO:linopy.model: Solve problem using Highs solver
INFO:linopy.io: Writing time: 0.07s
INFO:linopy.solvers:Log file at /tmp/highs.log
INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 248 primals, 509 duals
Objective: 1.92e+03
Solver model: available
Solver message: optimal

INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Link-fix-p-lower, Link-fix-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-ext-e-lower, Store-ext-e-upper, Store-energy_balance were not assigned to the network.
Running HiGHS 1.7.2 (git hash: 184e327): Copyright (c) 2024 HiGHS under MIT licence terms
Coefficient ranges:
  Matrix [1e-01, 1e+00]
  Cost   [2e+01, 5e+01]
  Bound  [0e+00, 0e+00]
  RHS    [1e+00, 1e+03]
Presolving model
135 rows, 215 cols, 515 nonzeros  0s
80 rows, 160 cols, 405 nonzeros  0s
55 rows, 135 cols, 355 nonzeros  0s
53 rows, 133 cols, 351 nonzeros  0s
Presolve : Reductions: rows 53(-456); columns 133(-115); elements 351(-653)
Solving the presolved LP
Using EKK dual simplex solver - serial
  Iteration        Objective     Infeasibilities num(sum)
          0    -4.9998168098e+01 Ph1: 1(1); Du: 1(49.9982) 0s
         80     1.9166666667e+03 Pr: 0(0); Du: 0(1.7053e-13) 0s
Solving the original LP from the solution after postsolve
Model   status      : Optimal
Simplex   iterations: 80
Objective value     :  1.9166666667e+03
HiGHS run time      :          0.00
Writing the solution to /tmp/linopy-solve-ycn9yefo.sol

How do the different stores in the system behave?

[12]:
n.stores_t.e.plot(figsize=(9, 7), lw=3)
plt.tight_layout()
../_images/examples_biomass-synthetic-fuels-carbon-management_21_0.png

Let’s have a look at the production

[13]:
n.links_t.p0[["biomass+CCS0", "biomass+CCS1", "OCGT+CCS", "DAC"]].plot(
    subplots=True, figsize=(9, 7)
)
plt.tight_layout()
../_images/examples_biomass-synthetic-fuels-carbon-management_23_0.png

At all times, the amount of carbon is constant!

[14]:
n.stores_t.e[["co2 stored", "co2 atmosphere", "gas", "diesel"]].sum(axis=1)
[14]:
snapshot
0    50.0
1    50.0
2    50.0
3    50.0
4    50.0
5    50.0
6    50.0
7    50.0
8    50.0
9    50.0
dtype: float64