power flow balance constraint using LINOPY

73 views
Skip to first unread message

Juan Manuel Home Ortiz

unread,
Nov 16, 2023, 4:58:06 PM11/16/23
to pypsa
Hi, I would like to define a power flow balance constraint using Linopy. I am unsure how to deal with indexes.
The constraint is:

PG[i] + sum {(j,i) in B} P[j,i] - sum {(i,j) in B} P[i,j]  = L[i]; forall(i in N)

Where:

Var: PG # power generated.

Var P # Power flow through branches

Param: L # load

For example:

Set: B = [[1,2], [2,3], [2,4]] # BRANCHES

Set: N = [1, 2, 3, 4] # NODES

 

The expected set of constraints is:

PG_[1] - P_[1,2] = L_[1]                                 for [i=1]
PG_[2] + P_[1,2] - P_[2,3] - P_[2,4] = L_[2]   for [i=2]
PG_[3] + P_[2,3] = L_[3]                                for [i=3]
PG_[4] + P_[2,4] = L_[4]                                for [i=4]


In Python, I tried this:

N = pd.Index(N_,name='N') # N_ = [1,2,3,4]

B = pd.Index(B_, name='B') # B_  = [[1,2], [2,3], [2,4]]

PG = m.add_variables(lower = 0, coords=[N], name=PG)

P  = m.add_variables(coords=[B], name='P')

L = xr.DataArray(L, coords=[N], name="L")

P_Balance = m.add_constraints(PG + P.sum(dims=['Linhas'])  == L)

 

unfortunately,  P.sum(dims=['Linhas']) includes all the branches.

Any suggestion?


Best regards,
Juan











Reply all
Reply to author
Forward
0 new messages