Note

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

# Wind Turbine combined with Heat Pump and Water Tank

In this example the 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.

```
[1]:
```

```
import pypsa
import pandas as pd
from pyomo.environ import Constraint
```

```
[2]:
```

```
network = pypsa.Network()
network.set_snapshots(pd.date_range("2016-01-01 00:00", "2016-01-01 03:00", freq="H"))
network.add("Bus", "0", carrier="AC")
network.add("Bus", "0 heat", carrier="heat")
network.add("Carrier", "wind")
network.add("Carrier", "heat")
network.add(
"Generator",
"wind turbine",
bus="0",
carrier="wind",
p_nom_extendable=True,
p_max_pu=[0.0, 0.2, 0.7, 0.4],
capital_cost=500,
)
network.add("Load", "heat demand", bus="0 heat", p_set=20.0)
# NB: Heat pump has changing efficiency (properly the Coefficient of Performance, COP)
# due to changing ambient temperature
network.add(
"Link",
"heat pump",
bus0="0",
bus1="0 heat",
efficiency=[2.5, 3.0, 3.2, 3.0],
capital_cost=1000,
p_nom_extendable=True,
)
network.add(
"Store",
"water tank",
bus="0 heat",
e_cyclic=True,
e_nom_extendable=True,
standing_loss=0.01,
)
```

```
[3]:
```

```
network.lopf(network.snapshots)
```

```
WARNING:pypsa.components:Solving optimisation problem with pyomo.In PyPSA version 0.21 the default will change to ``n.lopf(pyomo=False)``.Explicitly set ``n.lopf(pyomo=True)`` to retain current behaviour.
INFO:pypsa.opf:Performed preliminary steps
INFO:pypsa.opf:Building pyomo model using `kirchhoff` formulation
INFO:pypsa.opf:Solving model using glpk
INFO:pypsa.opf:Optimization successful
```

```
# ==========================================================
# = Solver Results =
# ==========================================================
# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: unknown
Lower bound: 23500.5858249914
Upper bound: 23500.5858249914
Number of objectives: 1
Number of constraints: 37
Number of variables: 20
Number of nonzeros: 64
Sense: minimize
# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
Termination condition: optimal
Statistics:
Branch and bound:
Number of bounded subproblems: 0
Number of created subproblems: 0
Error rc: 0
Time: 0.0026044845581054688
# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
number of solutions displayed: 0
```

```
[3]:
```

```
(<SolverStatus.ok: 'ok'>, <TerminationCondition.optimal: 'optimal'>)
```

```
[4]:
```

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

```
[4]:
```

p | e | |
---|---|---|

snapshot | ||

2016-01-01 00:00:00 | 20.000000 | 4.376710 |

2016-01-01 01:00:00 | 4.332943 | 0.000000 |

2016-01-01 02:00:00 | -13.423055 | 13.423055 |

2016-01-01 03:00:00 | -11.334114 | 24.622939 |

```
[5]:
```

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

```
[5]:
```

p0 | p1 | |
---|---|---|

snapshot | ||

2016-01-01 00:00:00 | 0.000000 | -0.000000 |

2016-01-01 01:00:00 | 5.222352 | -15.667057 |

2016-01-01 02:00:00 | 10.444705 | -33.423055 |

2016-01-01 03:00:00 | 10.444705 | -31.334114 |

```
[6]:
```

```
network.stores.loc[["water tank"]].T
```

```
[6]:
```

Store | water tank |
---|---|

attribute | |

bus | 0 heat |

type | |

carrier | heat |

e_nom | 0.0 |

e_nom_extendable | True |

e_nom_min | 0.0 |

e_nom_max | inf |

e_min_pu | 0.0 |

e_max_pu | 1.0 |

e_initial | 0.0 |

e_initial_per_period | False |

e_cyclic | True |

e_cyclic_per_period | True |

p_set | 0.0 |

q_set | 0.0 |

sign | 1.0 |

marginal_cost | 0.0 |

capital_cost | 0.0 |

standing_loss | 0.01 |

build_year | 0 |

lifetime | inf |

e_nom_opt | 24.622939 |

```
[7]:
```

```
network.generators.loc[["wind turbine"]].T
```

```
[7]:
```

Generator | wind turbine |
---|---|

attribute | |

bus | 0 |

control | Slack |

type | |

p_nom | 0.0 |

p_nom_extendable | True |

p_nom_min | 0.0 |

p_nom_max | inf |

p_min_pu | 0.0 |

p_max_pu | 1.0 |

p_set | 0.0 |

q_set | 0.0 |

sign | 1.0 |

carrier | wind |

marginal_cost | 0.0 |

build_year | 0 |

lifetime | inf |

capital_cost | 500.0 |

efficiency | 1.0 |

committable | False |

start_up_cost | 0.0 |

shut_down_cost | 0.0 |

min_up_time | 0 |

min_down_time | 0 |

up_time_before | 1 |

down_time_before | 0 |

ramp_limit_up | NaN |

ramp_limit_down | NaN |

ramp_limit_start_up | 1.0 |

ramp_limit_shut_down | 1.0 |

p_nom_opt | 26.111762 |