Skip to content

Commit

Permalink
[FIX] Fix call of opf when passing the old pypower format
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonUlm committed Aug 28, 2024
1 parent be0f2cf commit 12e4369
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pandapower/pypower/idx_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@
CZD = 14 # coefficient of constant impedance load at rated voltage in range [0,1]
SL_FAC = 15

bus_cols = 16
bus_cols = 17
16 changes: 0 additions & 16 deletions pandapower/pypower/opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from time import perf_counter

from numpy import zeros, c_, shape
from pandapower.pypower.idx_brch import MU_ANGMAX
from pandapower.pypower.idx_bus import MU_VMIN
from pandapower.pypower.idx_gen import MU_QMIN

from pandapower.pypower.opf_args import opf_args2
from pandapower.pypower.opf_execute import opf_execute
Expand Down Expand Up @@ -152,19 +149,6 @@ def opf(ppc, ppopt):
## process input arguments
ppc, ppopt = opf_args2(ppc, ppopt)

## add zero columns to bus, gen, branch for multipliers, etc if needed
nb = shape(ppc['bus'])[0] ## number of buses
nl = shape(ppc['branch'])[0] ## number of branches
ng = shape(ppc['gen'])[0] ## number of dispatchable injections
if shape(ppc['bus'])[1] < MU_VMIN + 1:
ppc['bus'] = c_[ppc['bus'], zeros((nb, MU_VMIN + 1 - shape(ppc['bus'])[1]))]

if shape(ppc['gen'])[1] < MU_QMIN + 1:
ppc['gen'] = c_[ppc['gen'], zeros((ng, MU_QMIN + 1 - shape(ppc['gen'])[1]))]

if shape(ppc['branch'])[1] < MU_ANGMAX + 1:
ppc['branch'] = c_[ppc['branch'], zeros((nl, MU_ANGMAX + 1 - shape(ppc['branch'])[1]))]

##----- convert to internal numbering, remove out-of-service stuff -----
# ppc = ext2int(ppc)

Expand Down
18 changes: 17 additions & 1 deletion pandapower/pypower/opf_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

from sys import stderr

from numpy import array
from numpy import array, c_, shape, zeros
from scipy.sparse import issparse

from pandapower.pypower._compat import PY2
from pandapower.pypower.idx_brch import branch_cols
from pandapower.pypower.idx_bus import bus_cols
from pandapower.pypower.idx_gen import gen_cols
from pandapower.pypower.ppoption import ppoption
#from pandapower.pypower.loadcase import loadcase

Expand All @@ -19,6 +22,16 @@
basestring = str


def _add_zero_columns(bus, gen, branch):
"""Add zero columns to bus, gen, branch for multipliers, etc. if needed
"""
bus = c_[bus, zeros((shape(bus)[0], bus_cols - shape(bus)[1]))]
gen = c_[gen, zeros((shape(gen)[0], gen_cols - shape(gen)[1]))]
branch = c_[branch, zeros((shape(branch)[0], branch_cols - shape(branch)[1]))]

return bus, gen, branch


def opf_args(ppc, ppopt):
"""Parses and initializes OPF input arguments.
Expand Down Expand Up @@ -151,6 +164,9 @@ def opf_args(ppc, ppopt):
if ppopt == None or len(ppopt) == 0:
ppopt = ppoption()

# add zero columns to bus, gen, branch for multipliers, etc. if needed
bus, gen, branch = _add_zero_columns(bus, gen, branch)

return baseMVA, bus, gen, branch, gencost, Au, lbu, ubu, \
ppopt, N, fparm, H, Cw, z0, zl, zu, userfcn, areas

Expand Down

0 comments on commit 12e4369

Please sign in to comment.