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!
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();
/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')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')INFO:linopy.model: Solve problem using Gurobi solverINFO:linopy.model:Solver options:
- log_to_console: FalseINFO:linopy.io: Writing time: 0.04sSet parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-1oh_x3ej.lpReading time = 0.00 secondsobj: 11 rows, 5 columns, 16 nonzerosSet parameter LogToConsole to value 0INFO: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: 2INFO: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!
n.loads_t.pn.loads_t.p
Out[3]:
| name | Frankfurt | Frankfurt heat |
|---|---|---|
| snapshot | ||
| now | 5.0 | 3.0 |
In [4]:
Copied!
n.links_t.p0n.links_t.p0
Out[4]:
| name | OCGT | CHP |
|---|---|---|
| snapshot | ||
| now | 5.0 | 10.0 |
In [5]:
Copied!
n.links_t.p1n.links_t.p1
Out[5]:
| name | OCGT | CHP |
|---|---|---|
| snapshot | ||
| now | -2.0 | -3.0 |
In [6]:
Copied!
n.links_t.p2n.links_t.p2
Out[6]:
| name | OCGT | CHP |
|---|---|---|
| snapshot | ||
| now | 0.0 | -3.0 |
2026-11-05
2020-02-28