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!
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);
/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!
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!
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!
n.optimize();n.optimize();
/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')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')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')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')INFO:linopy.model: Solve problem using Gurobi solverINFO:linopy.model:Solver options:
- log_to_console: FalseINFO:linopy.io: Writing time: 0.08sSet 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-409jzqo_.lpReading time = 0.00 secondsobj: 46 rows, 22 columns, 69 nonzerosSet parameter LogToConsole to value 0INFO: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: 2INFO: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!
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]:
| p | e | |
|---|---|---|
| snapshot | ||
| 2025-01-01 00:00:00 | 20.000 | 4.377 |
| 2025-01-01 01:00:00 | 4.333 | 0.000 |
| 2025-01-01 02:00:00 | -13.423 | 13.423 |
| 2025-01-01 03:00:00 | -11.334 | 24.623 |
In [7]:
Copied!
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]:
| p0 | p1 | |
|---|---|---|
| snapshot | ||
| 2025-01-01 00:00:00 | 0.000 | -0.000 |
| 2025-01-01 01:00:00 | 5.222 | -15.667 |
| 2025-01-01 02:00:00 | 10.445 | -33.423 |
| 2025-01-01 03:00:00 | 10.445 | -31.334 |
2026-08-14
2020-02-28