Dear PyPSa Community,
I am trying to model a battery using storage unit, where whatever is being charged at time x, should maximum be completely discharged at e.g., time x+3.
but didn't work well with me. Here's a minimal example to reproduce my network
Also, when I create the model (n.optimize.create_model()) after the storage unit is added, I keep getting a ValueError: coordinate '_term' not present in all datasets.
Any thoughts on this are appreciated.
Best,
Anas
import pypsa
from pypsa.optimization.compat import get_var, linexpr, define_constraints
days=365
load=[39,37,36,35,34,33,32,33,
36,38,42,44,43,43,44,47,
50,51,50,48,47,47,43,40]*days
p_max_pu=[0,0,0,0,0.003,0.252,0.499,0.655,
0.735,0.761,0.734,0.651,0.504,
0.277,0.022,0,0,0,0,0,0,0,0,0]*days
n = pypsa.Network()
n.set_snapshots(range(len(load)))
n.add("Bus", "bus0")
n.add("Load", "load", bus="bus0", p_set=load)
n.add("Generator","bus0 RES",bus="bus0",
p_max_pu=p_max_pu,marginal_cost = 0.1,
capital_cost=68565,p_nom_extendable=True
)
n.add("Generator","bus0 CCGT",
bus="bus0",marginal_cost = 80,
capital_cost=94469,p_nom_extendable=True
)
n.add("StorageUnit","bus0 Battery",bus="bus0",
capital_cost=40000,p_nom_extendable=True
)
n.optimize.create_model()
var_d=get_var(n, "StorageUnit", "p_dispatch").loc[:, 'bus0 Battery']
var_s=get_var(n, "StorageUnit", "p_store").loc[:, 'bus0 Battery'].shift(snapshot=3)
lhs = linexpr((1, var_d))-linexpr((1, var_s))
rhs= 0
define_constraints(n, lhs, "=", rhs, 'StorageUnit', '3_hour')
n.lopf(solver_name='gurobi')
StorageUnit p_dispatch p_store
0 0.000000 0.000000
1 0.000000 0.000000
2 0.000000 7.427140
3 7.427140 0.000000
4 0.000000 0.000000
5 0.000000 0.000000
6 0.000000 0.000000
7 0.000000 9.004008
8 0.000000 11.134269
9 0.000000 10.801603
10 0.000000 5.070140
11 2.252505 0.000000
12 10.679359 0.000000
13 0.000000 12.093902
14 0.000000 0.837962
15 3.572860 0.000000
16 6.572860 0.000000
17 7.572860 0.000000
18 6.572860 0.000000
19 4.572860 0.000000
20 3.572860 0.000000
21 3.572860 0.000000
22 0.000000 0.000000
23 0.000000 0.000000