Post · 5 min read· pp. 306–311

Heat Pumps and Thermal Storage

In this example, a heat demand is supplied by a wind turbine in combination with a heat pump and a water tank that stores hot water with a standing loss.

In [2]:

Copied! diagram

ipynb
import pandas as pd

import pypsa

n = pypsa.Network()
n.set_snapshots(pd.date_range("2025-01-01 00:00", "2025-01-01 03:00", freq="h"))

n.add("Bus", "power", carrier="AC")
n.add("Bus", "heat", carrier="heat")

n.add(
    "Generator",
    "wind turbine",
    bus="power",
    carrier="wind",
    p_nom_extendable=True,
    p_max_pu=[0.0, 0.2, 0.7, 0.4],
    capital_cost=500,
)

n.add("Load", "heat demand", bus="heat", p_set=20);

import pandas as pd import pypsa n = pypsa.Network() n.set_snapshots(pd.date_range("2025-01-01 00:00", "2025-01-01 03:00", freq="h")) n.add("Bus", "power", carrier="AC") n.add("Bus", "heat", carrier="heat") n.add( "Generator", "wind turbine", bus="power", carrier="wind", p_nom_extendable=True, p_max_pu=[0.0, 0.2, 0.7, 0.4], capital_cost=500, ) n.add("Load", "heat demand", bus="heat", p_set=20);

text
/tmp/ipykernel_8357/1312632822.py:5: 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()

The heat pump has time-varying efficiency (i.e. its coefficient of performance, COP) due to changing ambient temperatures.

In [3]:

Copied! diagram

ipynb
n.add(
    "Link",
    "heat pump",
    bus0="power",
    bus1="heat",
    efficiency=[2.5, 3.0, 3.2, 3.0],
    capital_cost=1000,
    p_nom_extendable=True,
);

n.add( "Link", "heat pump", bus0="power", bus1="heat", efficiency=[2.5, 3.0, 3.2, 3.0], capital_cost=1000, p_nom_extendable=True, );

The hot water tank has a standing loss of 1% of its state of charge per hour.

In [4]:

Copied! diagram

ipynb
n.add(
    "Store",
    "water tank",
    bus="heat",
    e_cyclic=True,
    e_nom=100,
    standing_loss=0.01,
);

n.add( "Store", "water tank", bus="heat", e_cyclic=True, e_nom=100, standing_loss=0.01, );

The wind turbine and the heat pump can be sized by the optimisation, while the water tank has a fixed size of 100 MWh.

In [5]:

Copied! diagram

ipynb
n.optimize();

n.optimize();

text
/tmp/ipykernel_8357/1450685117.py:1: 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(['power', 'heat'], dtype='object', name='name')
text
WARNING:pypsa.consistency:The following generators have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['wind turbine'], 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(['heat pump'], dtype='object', name='name')
text
WARNING:pypsa.consistency:The following stores have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['water tank'], 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.08s
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-409jzqo_.lp
text
Reading time = 0.00 seconds
text
obj: 46 rows, 22 columns, 69 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 22 primals, 54 duals
Objective: 2.35e+04
Solver: gurobi
Runtime: 0.00s
Dual bound: 2.35e+04
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-fix-p-lower, Store-fix-p-upper, Store-fix-p_store-lower, Store-fix-p_store-upper, Store-energy_balance were not assigned to the network.

In [6]:

Copied! diagram

ipynb
pd.DataFrame({attr: n.stores_t[attr]["water tank"] for attr in ["p", "e"]}).round(3)

pd.DataFrame({attr: n.stores_t[attr]["water tank"] for attr in ["p", "e"]}).round(3)

Out[6]:

pe
snapshot
2025-01-01 00:00:0020.0004.377
2025-01-01 01:00:004.3330.000
2025-01-01 02:00:00-13.42313.423
2025-01-01 03:00:00-11.33424.623

In [7]:

Copied! diagram

ipynb
pd.DataFrame({attr: n.links_t[attr]["heat pump"] for attr in ["p0", "p1"]}).round(3)

pd.DataFrame({attr: n.links_t[attr]["heat pump"] for attr in ["p0", "p1"]}).round(3)

Out[7]:

p0p1
snapshot
2025-01-01 00:00:000.000-0.000
2025-01-01 01:00:005.222-15.667
2025-01-01 02:00:0010.445-33.423
2025-01-01 03:00:0010.445-31.334

diagram 2026-08-14

diagram 2020-02-28