Skip to content

Commit

Permalink
set default min and max voltage in create functions for OPF 🐑
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Schaefer committed Oct 2, 2019
1 parent fcebcb0 commit f10639b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pandapower/build_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ def _build_bus_ppc(net, ppc):
if "max_vm_pu" in net.bus:
ppc["bus"][:n_bus, VMAX] = net["bus"].max_vm_pu.values
else:
ppc["bus"][:n_bus, VMAX] = 2 # changes of VMAX must be considered in check_opf_data
ppc["bus"][:n_bus, VMAX] = 2. # changes of VMAX must be considered in check_opf_data
if "min_vm_pu" in net.bus:
ppc["bus"][:n_bus, VMIN] = net["bus"].min_vm_pu.values
else:
ppc["bus"][:n_bus, VMIN] = 0 # changes of VMIN must be considered in check_opf_data
ppc["bus"][:n_bus, VMIN] = 0. # changes of VMIN must be considered in check_opf_data

if len(net.xward):
_fill_auxiliary_buses(net, ppc, bus_lookup, "xward", "bus", aux)
Expand Down
4 changes: 3 additions & 1 deletion pandapower/build_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def _check_gen_vm_limits(net, ppc, gen_buses, gen_is):
def _enforce_controllable_vm_pu_p_mw(net, ppc, gen_is, f, t):
delta = net["_options"]["delta"]
bus_lookup = net["_pd2ppc_lookups"]["bus"]
not_controllable = ~net["gen"]["controllable"].values[gen_is]
controllable = net["gen"]["controllable"].values[gen_is]
not_controllable = ~controllable.astype(bool)

# if there are some non controllable gens -> set vm_pu and p_mw fixed
if np.any(not_controllable):
bus = net["gen"]["bus"].values[not_controllable]
Expand Down
26 changes: 7 additions & 19 deletions pandapower/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,9 @@ def create_bus(net, vn_kv, name=None, index=None, geodata=None, type="b",
if coords is not None:
net["bus_geodata"].loc[index, "coords"] = coords

if not isnan(min_vm_pu):
if "min_vm_pu" not in net.bus.columns:
net.bus.loc[:, "min_vm_pu"] = pd.Series()

net.bus.loc[index, "min_vm_pu"] = float(min_vm_pu)

if not isnan(max_vm_pu):
if "max_vm_pu" not in net.bus.columns:
net.bus.loc[:, "max_vm_pu"] = pd.Series()

net.bus.loc[index, "max_vm_pu"] = float(max_vm_pu)
# column needed by OPF. 0. and 2. are the default maximum / minimum voltages
_create_column_and_set_value(net, index, min_vm_pu, "min_vm_pu", "bus", default_val=0.)
_create_column_and_set_value(net, index, max_vm_pu, "max_vm_pu", "bus", default_val=2.)

return index

Expand Down Expand Up @@ -967,12 +959,12 @@ def create_storage(net, bus, p_mw, max_e_mwh, q_mvar=0, sn_mva=nan, soc_percent=
return index


def _create_column_and_set_value(net, index, variable, column, element):
def _create_column_and_set_value(net, index, variable, column, element, default_val=None):
# if variable (e.g. p_mw) is not None and column (e.g. "p_mw") doesn't exist in element (e.g. "gen") table
# create this column and write the value of variable to the index of this element
if not isnan(variable):
if column not in net[element].columns:
net[element].loc[:, column] = pd.Series()
net[element].loc[:, column] = pd.Series(default_val)
net[element].at[index, column] = float(variable)
return net

Expand Down Expand Up @@ -1079,16 +1071,13 @@ def create_gen(net, bus, p_mw, vm_pu=1., sn_mva=nan, name=None, index=None, max_
net = _create_column_and_set_value(net, index, min_q_mvar, "min_q_mvar", "gen")
net = _create_column_and_set_value(net, index, max_q_mvar, "max_q_mvar", "gen")
# V limits for OPF if controllable == True
net = _create_column_and_set_value(net, index, max_vm_pu, "max_vm_pu", "gen")
net = _create_column_and_set_value(net, index, min_vm_pu, "min_vm_pu", "gen")

net = _create_column_and_set_value(net, index, max_vm_pu, "max_vm_pu", "gen", default_val=2.)
net = _create_column_and_set_value(net, index, min_vm_pu, "min_vm_pu", "gen", default_val=0.)

# Short circuit calculation limits
net = _create_column_and_set_value(net, index, vn_kv, "vn_kv", "gen")
net = _create_column_and_set_value(net, index, cos_phi, "cos_phi", "gen")



if not isnan(xdss_pu):
if "xdss_pu" not in net.gen.columns:
net.gen.loc[:, "xdss_pu"] = pd.Series()
Expand All @@ -1098,7 +1087,6 @@ def create_gen(net, bus, p_mw, vm_pu=1., sn_mva=nan, name=None, index=None, max_

net = _create_column_and_set_value(net, index, rdss_pu, "rdss_pu", "gen")


return index


Expand Down

0 comments on commit f10639b

Please sign in to comment.