Post · 4 min read· pp. 103–108

Backpressure CHP

This example demonstrates how to model a Combined Heat and Power (CHP) plant with a fixed heat-power ratio, assuming that the plant is operated in backpressure mode. For an example of a CHP plant with a more complicated heat-power feasible operational area, see the extraction-condensing CHP example. In this example, the CHP is modelled as a Link component with two output buses: one for electricity and one for heat. The CHP unit must be heat-following since there is no other supply of heat to the "Frankfurt heat" bus.

In [2]:

Copied! diagram

ipynb
import pypsa

n = pypsa.Network()

n.add("Bus", "Frankfurt", carrier="AC")
n.add("Load", "Frankfurt", bus="Frankfurt", p_set=5)

n.add("Bus", "Frankfurt heat", carrier="heat")
n.add("Load", "Frankfurt heat", bus="Frankfurt heat", p_set=3)

n.add("Bus", "Frankfurt gas", carrier="gas")
n.add("Generator", "Frankfurt gas", bus="Frankfurt gas", marginal_cost=100, p_nom=100)

n.add(
    "Link",
    "OCGT",
    bus0="Frankfurt gas",
    bus1="Frankfurt",
    p_nom_extendable=True,
    capital_cost=600,
    efficiency=0.4,  # electricity per unit of gas
)

n.add(
    "Link",
    "CHP",
    bus0="Frankfurt gas",
    bus1="Frankfurt",
    bus2="Frankfurt heat",
    p_nom_extendable=True,
    capital_cost=1400,
    efficiency=0.3,  # electricity per unit of gas
    efficiency2=0.3,  # heat per unit of gas
)

n.optimize();

import pypsa n = pypsa.Network() n.add("Bus", "Frankfurt", carrier="AC") n.add("Load", "Frankfurt", bus="Frankfurt", p_set=5) n.add("Bus", "Frankfurt heat", carrier="heat") n.add("Load", "Frankfurt heat", bus="Frankfurt heat", p_set=3) n.add("Bus", "Frankfurt gas", carrier="gas") n.add("Generator", "Frankfurt gas", bus="Frankfurt gas", marginal_cost=100, p_nom=100) n.add( "Link", "OCGT", bus0="Frankfurt gas", bus1="Frankfurt", p_nom_extendable=True, capital_cost=600, efficiency=0.4, # electricity per unit of gas ) n.add( "Link", "CHP", bus0="Frankfurt gas", bus1="Frankfurt", bus2="Frankfurt heat", p_nom_extendable=True, capital_cost=1400, efficiency=0.3, # electricity per unit of gas efficiency2=0.3, # heat per unit of gas ) n.optimize();

text
/tmp/ipykernel_2940/1890019209.py:3: PyPSA2Warning: pandas reads strings as `str` dtype since 3.0. PyPSA converts them back to object dtype on import, but keeps `str` from PyPSA 2.0 on. Set `pypsa.options.future.string_dtype` to True to opt in now or to False to keep the current behaviour.
  n = pypsa.Network()
/tmp/ipykernel_2940/1890019209.py:36: PyPSA2Warning: From PyPSA 2.0 on, the objective leaves out the capital costs of existing capacity on extendable assets, which improves LP conditioning. Pass `include_objective_constant` to `n.optimize` to choose per call. Set `pypsa.options.future.exclude_objective_constant` to True to opt in now or to False to keep the current behaviour.
  n.optimize();
WARNING:pypsa.consistency:The following buses have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['Frankfurt', 'Frankfurt heat', 'Frankfurt gas'], dtype='object', name='name')
text
WARNING:pypsa.consistency:The following links have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['OCGT', 'CHP'], dtype='object', name='name')
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.04s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-1oh_x3ej.lp
text
Reading time = 0.00 seconds
text
obj: 11 rows, 5 columns, 16 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 5 primals, 11 duals
Objective: 1.85e+04
Solver: gurobi
Runtime: 0.00s
Dual bound: 1.85e+04
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Link-ext-p-lower, Link-ext-p-upper were not assigned to the network.

In [3]:

Copied! diagram

ipynb
n.loads_t.p

n.loads_t.p

Out[3]:

nameFrankfurtFrankfurt heat
snapshot
now5.03.0

In [4]:

Copied! diagram

ipynb
n.links_t.p0

n.links_t.p0

Out[4]:

nameOCGTCHP
snapshot
now5.010.0

In [5]:

Copied! diagram

ipynb
n.links_t.p1

n.links_t.p1

Out[5]:

nameOCGTCHP
snapshot
now-2.0-3.0

In [6]:

Copied! diagram

ipynb
n.links_t.p2

n.links_t.p2

Out[6]:

nameOCGTCHP
snapshot
now0.0-3.0

diagram 2026-11-05

diagram 2020-02-28