From e49279c977cad894bb6b882545b9fe2c82a2930f Mon Sep 17 00:00:00 2001 From: David M Fobes Date: Thu, 5 Sep 2019 08:07:21 -0600 Subject: [PATCH] REF: Ensure all PMD functions' phase loops are internal This refactor ensures that all variable and constraint functions internal to PowerModelsDistribution, e.g. those containing `_mc_`, have any loops over the phases internal to that function, instead of requiring an explicit loop inside the problem definition. Updates changelog Closes #81 Closes #61 Closes #152 --- CHANGELOG.md | 1 + src/core/constraint_template.jl | 222 +++++++++++++++++--------------- src/core/variable.jl | 20 ++- src/prob/debug.jl | 80 +++++++----- src/prob/mld.jl | 79 ++++++------ src/prob/opf.jl | 11 +- src/prob/opf_bctr.jl | 7 +- src/prob/opf_bf.jl | 2 - src/prob/opf_lm.jl | 13 +- src/prob/opf_oltc.jl | 9 +- src/prob/pf.jl | 31 ++--- src/prob/pf_lm.jl | 34 ++--- src/prob/test.jl | 20 ++- 13 files changed, 282 insertions(+), 247 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 734f39a8a..4249329b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ PowerModelsDistribution.jl Change Log =================================== ### staged +- Change internal variable and constraint functions to loop over phases internally (breaking) (#168) - Fix bug in OpenDSS parser on Lines where the connected phases are listed out of order (#167) - Add ability to "bank" single phase OpenDSS transformers into a single multiphase transformer (#166) - Add virtual line to sourcebus to model source impedance (#165) diff --git a/src/core/constraint_template.jl b/src/core/constraint_template.jl index 9bfda123e..dcf211e11 100644 --- a/src/core/constraint_template.jl +++ b/src/core/constraint_template.jl @@ -1,27 +1,29 @@ "" -function constraint_mc_power_balance_slack(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) - if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) - _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() - end - if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) - _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() - end +function constraint_mc_power_balance_slack(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + for cnd in _PMs.conductor_ids(pm) + if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) + _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() + end + if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) + _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) + bus = _PMs.ref(pm, nw, :bus, i) + bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) + bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) + bus_gens = _PMs.ref(pm, nw, :bus_gens, i) + bus_loads = _PMs.ref(pm, nw, :bus_loads, i) + bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) - bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) + bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) + bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) + bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) + bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) - constraint_mc_power_balance_slack(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + constraint_mc_power_balance_slack(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + end end @@ -40,7 +42,7 @@ end "ohms constraint for branches on the from-side" -function constraint_mc_ohms_yt_from(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) +function constraint_mc_ohms_yt_from(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) branch = _PMs.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] @@ -53,12 +55,14 @@ function constraint_mc_ohms_yt_from(pm::_PMs.AbstractPowerModel, i::Int; nw::Int b_fr = branch["b_fr"] tm = branch["tap"] - constraint_mc_ohms_yt_from(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) + for cnd in _PMs.conductor_ids(pm) + constraint_mc_ohms_yt_from(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) + end end "ohms constraint for branches on the to-side" -function constraint_mc_ohms_yt_to(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) +function constraint_mc_ohms_yt_to(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) branch = _PMs.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] @@ -71,12 +75,14 @@ function constraint_mc_ohms_yt_to(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=p b_to = branch["b_to"] tm = branch["tap"] - constraint_mc_ohms_yt_to(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) + for cnd in _PMs.conductor_ids(pm) + constraint_mc_ohms_yt_to(pm, nw, cnd, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) + end end "on/off ohms constraint for branches on the from-side" -function constraint_mc_ohms_yt_from_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) +function constraint_mc_ohms_yt_from_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) branch = _PMs.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] @@ -92,12 +98,14 @@ function constraint_mc_ohms_yt_from_on_off(pm::_PMs.AbstractPowerModel, i::Int; vad_min = [_PMs.ref(pm, nw, :off_angmin, c) for c in _PMs.conductor_ids(pm)] vad_max = [_PMs.ref(pm, nw, :off_angmax, c) for c in _PMs.conductor_ids(pm)] - constraint_mc_ohms_yt_from_on_off(pm, nw, cnd, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + for cnd in _PMs.conductor_ids(pm) + constraint_mc_ohms_yt_from_on_off(pm, nw, cnd, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + end end "on/off ohms constraint for branches on the from-side" -function constraint_mc_ohms_yt_to_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) +function constraint_mc_ohms_yt_to_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) branch = _PMs.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] @@ -113,7 +121,9 @@ function constraint_mc_ohms_yt_to_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw vad_min = [_PMs.ref(pm, nw, :off_angmin, c) for c in _PMs.conductor_ids(pm)] vad_max = [_PMs.ref(pm, nw, :off_angmax, c) for c in _PMs.conductor_ids(pm)] - constraint_mc_ohms_yt_to_on_off(pm, nw, cnd, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + for cnd in _PMs.conductor_ids(pm) + constraint_mc_ohms_yt_to_on_off(pm, nw, cnd, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + end end @@ -225,57 +235,61 @@ end "KCL including transformer arcs." -function constraint_mc_power_balance(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) - if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) - _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() - end - if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) - _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() - end +function constraint_mc_power_balance(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + for cnd in _PMs.conductor_ids(pm) + if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) + _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() + end + if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) + _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) + bus = _PMs.ref(pm, nw, :bus, i) + bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) + bus_gens = _PMs.ref(pm, nw, :bus_gens, i) + bus_loads = _PMs.ref(pm, nw, :bus_loads, i) + bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) + bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) - bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) - bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) + bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) + bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) + bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) + bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) - constraint_mc_power_balance(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + constraint_mc_power_balance(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + end end "KCL including transformer arcs and storage." -function constraint_mc_power_balance_storage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) - if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) - _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() - end - if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) - _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() - end +function constraint_mc_power_balance_storage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + for cnd in _PMs.conductor_ids(pm) + if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) + _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() + end + if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) + _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) - bus_storage = _PMs.ref(pm, nw, :bus_storage, i) + bus = _PMs.ref(pm, nw, :bus, i) + bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) + bus_gens = _PMs.ref(pm, nw, :bus_gens, i) + bus_loads = _PMs.ref(pm, nw, :bus_loads, i) + bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) + bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) + bus_storage = _PMs.ref(pm, nw, :bus_storage, i) - bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) - bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) + bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) + bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) + bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) + bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) - constraint_mc_power_balance_storage(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) + constraint_mc_power_balance_storage(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) + end end @@ -321,26 +335,28 @@ end "KCL including transformer arcs and load variables." -function constraint_mc_power_balance_load(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) - if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) - _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() - end - if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) - _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() - end +function constraint_mc_power_balance_load(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + for cnd in _PMs.conductor_ids(pm) + if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) + _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() + end + if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) + _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) + bus = _PMs.ref(pm, nw, :bus, i) + bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) + bus_gens = _PMs.ref(pm, nw, :bus_gens, i) + bus_loads = _PMs.ref(pm, nw, :bus_loads, i) + bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) + bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) + bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) + bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) - constraint_mc_power_balance_load(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_loads, bus_gs, bus_bs) + constraint_mc_power_balance_load(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_loads, bus_gs, bus_bs) + end end @@ -442,29 +458,31 @@ end "KCL for load shed problem with transformers" -function constraint_mc_power_balance_shed(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw, cnd::Int=pm.ccnd) - if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) - _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() - end - if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) - _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() - end +function constraint_mc_power_balance_shed(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + for cnd in _PMs.conductor_ids(pm) + if !haskey(_PMs.con(pm, nw, cnd), :kcl_p) + _PMs.con(pm, nw, cnd)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() + end + if !haskey(_PMs.con(pm, nw, cnd), :kcl_q) + _PMs.con(pm, nw, cnd)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) + bus = _PMs.ref(pm, nw, :bus, i) + bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) + bus_arcs_trans = _PMs.ref(pm, nw, :bus_arcs_trans, i) + bus_gens = _PMs.ref(pm, nw, :bus_gens, i) + bus_loads = _PMs.ref(pm, nw, :bus_loads, i) + bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) - bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) + bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd", cnd) for k in bus_loads) + bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd", cnd) for k in bus_loads) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) + bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs", cnd) for k in bus_shunts) + bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs", cnd) for k in bus_shunts) - constraint_mc_power_balance_shed(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + constraint_mc_power_balance_shed(pm, nw, cnd, i, bus_arcs, bus_arcs_dc, bus_arcs_trans, bus_gens, bus_pd, bus_qd, bus_gs, bus_bs) + end end diff --git a/src/core/variable.jl b/src/core/variable.jl index a88bcd236..aa6f82baf 100644 --- a/src/core/variable.jl +++ b/src/core/variable.jl @@ -114,8 +114,10 @@ end "generates variables for both `active` and `reactive` slack at each bus" function variable_mc_bus_power_slack(pm::_PMs.AbstractPowerModel; kwargs...) - variable_mc_active_bus_power_slack(pm; kwargs...) - variable_mc_reactive_bus_power_slack(pm; kwargs...) + for cnd in _PMs.conductor_ids(pm) + variable_mc_active_bus_power_slack(pm; cnd=cnd, kwargs...) + variable_mc_reactive_bus_power_slack(pm; cnd=cnd, kwargs...) + end end @@ -211,9 +213,11 @@ Create a dictionary with values of type Any for the load. Depending on the load model, this can be a parameter or a NLexpression. These will be inserted into KCL. """ -function variable_mc_load(pm::_PMs.AbstractPowerModel; nw=pm.cnw, cnd::Int=pm.ccnd, bounded=true) - _PMs.var(pm, nw, cnd)[:pd] = Dict{Int, Any}() - _PMs.var(pm, nw, cnd)[:qd] = Dict{Int, Any}() +function variable_mc_load(pm::_PMs.AbstractPowerModel; nw=pm.cnw, bounded=true) + for cnd in _PMs.conductor_ids(pm) + _PMs.var(pm, nw, cnd)[:pd] = Dict{Int, Any}() + _PMs.var(pm, nw, cnd)[:qd] = Dict{Int, Any}() + end end @@ -301,8 +305,10 @@ end "Create variables for `active` and `reactive` storage injection" function variable_mc_on_off_storage(pm::_PMs.AbstractPowerModel; kwargs...) - variabe_mc_on_off_storage_active(pm; kwargs...) - variable_mc_on_off_storage_reactive(pm; kwargs...) + for cnd in _PMs.conductor_ids(pm) + variabe_mc_on_off_storage_active(pm; cnd=cnd, kwargs...) + variable_mc_on_off_storage_reactive(pm; cnd=cnd, kwargs...) + end end diff --git a/src/prob/debug.jl b/src/prob/debug.jl index 7ebec5d22..a8d284c97 100644 --- a/src/prob/debug.jl +++ b/src/prob/debug.jl @@ -1,4 +1,4 @@ -# These problem formulations are used to debug Three Phase datasets +# These problem formulations are used to debug Distribution datasets # that do not converge using the standard formulations "" function run_mc_opf_pbs(data::Dict{String,Any}, model_type, solver; kwargs...) @@ -12,14 +12,28 @@ function run_mc_opf_pbs(file::String, model_type, solver; kwargs...) end +"" +function run_mc_pf_pbs(data::Dict{String,Any}, model_type, solver; kwargs...) + return _PMs.run_model(data, model_type, solver, post_mc_pf_pbs; multiconductor=true, ref_extensions=[ref_add_arcs_trans!], solution_builder=solution_pbs!, kwargs...) +end + + +"" +function run_mc_pf_pbs(file::String, model_type, solver; kwargs...) + return run_mc_pf_pbs(PowerModelsDistribution.parse_file(file), model_type, solver; kwargs...) +end + + "" function post_mc_opf_pbs(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm) + variable_mc_branch_flow(pm) variable_mc_trans_flow(pm) + variable_mc_bus_power_slack(pm) + for c in _PMs.conductor_ids(pm) - variable_mc_bus_power_slack(pm, cnd=c) _PMs.variable_generation(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end @@ -30,18 +44,20 @@ function post_mc_opf_pbs(pm::_PMs.AbstractPowerModel) constraint_mc_theta_ref(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_slack(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_slack(pm, i) end - for i in _PMs.ids(pm, :branch), c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + for i in _PMs.ids(pm, :branch) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i, cnd=c) + for c in _PMs.conductor_ids(pm) + _PMs.constraint_voltage_angle_difference(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) - _PMs.constraint_thermal_limit_to(pm, i, cnd=c) + _PMs.constraint_thermal_limit_from(pm, i, cnd=c) + _PMs.constraint_thermal_limit_to(pm, i, cnd=c) + end end for i in _PMs.ids(pm, :dcline), c in _PMs.conductor_ids(pm) @@ -52,26 +68,18 @@ function post_mc_opf_pbs(pm::_PMs.AbstractPowerModel) end -"" -function run_mc_pf_pbs(data::Dict{String,Any}, model_type, solver; kwargs...) - return _PMs.run_model(data, model_type, solver, post_mc_pf_pbs; multiconductor=true, ref_extensions=[ref_add_arcs_trans!], solution_builder=solution_pbs!, kwargs...) -end - - -"" -function run_mc_pf_pbs(file::String, model_type, solver; kwargs...) - return run_mc_pf_pbs(PowerModelsDistribution.parse_file(file), model_type, solver; kwargs...) -end "" function post_mc_pf_pbs(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm, bounded=false) + variable_mc_branch_flow(pm, bounded=false) variable_mc_trans_flow(pm, bounded=false) + variable_mc_bus_power_slack(pm) + for c in _PMs.conductor_ids(pm) - variable_mc_bus_power_slack(pm, cnd=c) _PMs.variable_generation(pm, bounded=false, cnd=c) _PMs.variable_dcline_flow(pm, bounded=false, cnd=c) end @@ -80,31 +88,33 @@ function post_mc_pf_pbs(pm::_PMs.AbstractPowerModel) for (i,bus) in _PMs.ref(pm, :ref_buses) constraint_mc_theta_ref(pm, i) - for c in _PMs.conductor_ids(pm) + for c in _PMs.conductor_ids(pm) @assert bus["bus_type"] == 3 _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) end end - for (i,bus) in _PMs.ref(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_slack(pm, i, cnd=c) - - # PV Bus Constraints - if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) - # this assumes inactive generators are filtered out of bus_gens - @assert bus["bus_type"] == 2 + for (i,bus) in _PMs.ref(pm, :bus) + constraint_mc_power_balance_slack(pm, i) - _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) - for j in _PMs.ref(pm, :bus_gens, i) - _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + for c in _PMs.conductor_ids(pm) + # PV Bus Constraints + if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) + # this assumes inactive generators are filtered out of bus_gens + @assert bus["bus_type"] == 2 + + _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) + for j in _PMs.ref(pm, :bus_gens, i) + _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + end end end end - for i in _PMs.ids(pm, :branch), c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + for i in _PMs.ids(pm, :branch) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) end for (i,dcline) in _PMs.ref(pm, :dcline), c in _PMs.conductor_ids(pm) diff --git a/src/prob/mld.jl b/src/prob/mld.jl index 07c5e39a9..148b4a90c 100644 --- a/src/prob/mld.jl +++ b/src/prob/mld.jl @@ -54,40 +54,41 @@ function post_mc_mld(pm::_PMs.AbstractPowerModel) variable_mc_indicator_bus_voltage(pm; relax=true) variable_mc_bus_voltage_on_off(pm) - variable_mc_trans_flow(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) variable_mc_indicator_generation(pm; relax=true) + + variable_mc_indicator_demand(pm; relax=true) + variable_mc_indicator_shunt(pm; relax=true) + for c in _PMs.conductor_ids(pm) _PMs.variable_generation_on_off(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_indicator_demand(pm; relax=true) - variable_mc_indicator_shunt(pm; relax=true) - constraint_mc_model_voltage(pm) for i in _PMs.ids(pm, :ref_buses) constraint_mc_theta_ref(pm, i) end + constraint_mc_bus_voltage_on_off(pm) for i in _PMs.ids(pm, :gen) _PMs.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_shed(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_shed(pm, i) end for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end @@ -110,35 +111,37 @@ function post_mc_mld_strg(pm::_PMs.AbstractPowerModel) variable_mc_indicator_bus_voltage(pm; relax=true) variable_mc_bus_voltage_on_off(pm) - variable_mc_trans_flow(pm) variable_mc_branch_flow(pm) - - variable_mc_storage(pm) + variable_mc_trans_flow(pm) variable_mc_indicator_generation(pm; relax=true) + + variable_mc_storage(pm) variable_mc_indicator_storage(pm; relax=true) + variable_mc_on_off_storage(pm) + + variable_mc_indicator_demand(pm; relax=true) + variable_mc_indicator_shunt(pm; relax=true) + for c in _PMs.conductor_ids(pm) _PMs.variable_generation_on_off(pm, cnd=c) - variable_mc_on_off_storage(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_indicator_demand(pm; relax=true) - variable_mc_indicator_shunt(pm; relax=true) - constraint_mc_model_voltage(pm) for i in _PMs.ids(pm, :ref_buses) constraint_mc_theta_ref(pm, i) end + constraint_mc_bus_voltage_on_off(pm) for i in _PMs.ids(pm, :gen) _PMs.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_shed(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_shed(pm, i) end for i in _PMs.ids(pm, :storage) @@ -151,10 +154,10 @@ function post_mc_mld_strg(pm::_PMs.AbstractPowerModel) end for i in _PMs.ids(pm, :branch) - for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) + for c in _PMs.conductor_ids(pm) _PMs.constraint_voltage_angle_difference(pm, i, cnd=c) _PMs.constraint_thermal_limit_from(pm, i, cnd=c) @@ -179,32 +182,34 @@ function post_mc_mld_bf(pm::_PMs.AbstractPowerModel) variable_mc_indicator_bus_voltage(pm; relax=true) variable_mc_bus_voltage_on_off(pm) + variable_mc_branch_current(pm) variable_mc_branch_flow(pm) variable_mc_trans_flow(pm) - variable_mc_branch_current(pm) variable_mc_indicator_generation(pm; relax=true) + + variable_mc_indicator_demand(pm; relax=true) + variable_mc_indicator_shunt(pm; relax=true) + for c in _PMs.conductor_ids(pm) _PMs.variable_generation_on_off(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_indicator_demand(pm; relax=true) - variable_mc_indicator_shunt(pm; relax=true) - constraint_mc_model_current(pm) for i in _PMs.ids(pm, :ref_buses) constraint_mc_theta_ref(pm, i) end + constraint_mc_bus_voltage_on_off(pm) for i in _PMs.ids(pm, :gen) _PMs.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_shed(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_shed(pm, i) end for i in _PMs.ids(pm, :branch) @@ -236,38 +241,40 @@ function post_mc_mld_uc(pm::_PMs.AbstractPowerModel) variable_mc_indicator_bus_voltage(pm; relax=false) variable_mc_bus_voltage_on_off(pm) - variable_mc_trans_flow(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) variable_mc_indicator_generation(pm; relax=false) + + variable_mc_indicator_demand(pm; relax=false) + variable_mc_indicator_shunt(pm; relax=false) + for c in _PMs.conductor_ids(pm) _PMs.variable_generation_on_off(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_indicator_demand(pm; relax=false) - variable_mc_indicator_shunt(pm; relax=false) - constraint_mc_model_voltage(pm) for i in _PMs.ids(pm, :ref_buses) constraint_mc_theta_ref(pm, i) end + constraint_mc_bus_voltage_on_off(pm) for i in _PMs.ids(pm, :gen) _PMs.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_shed(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_shed(pm, i) end for i in _PMs.ids(pm, :branch) - for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) + for c in _PMs.conductor_ids(pm) _PMs.constraint_voltage_angle_difference(pm, i, cnd=c) _PMs.constraint_thermal_limit_from(pm, i, cnd=c) diff --git a/src/prob/opf.jl b/src/prob/opf.jl index 0c2ecf120..2b8ea8ef9 100644 --- a/src/prob/opf.jl +++ b/src/prob/opf.jl @@ -20,12 +20,12 @@ end function post_mc_opf(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) for c in _PMs.conductor_ids(pm) _PMs.variable_generation(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_trans_flow(pm) constraint_mc_model_voltage(pm) @@ -33,17 +33,16 @@ function post_mc_opf(pm::_PMs.AbstractPowerModel) constraint_mc_theta_ref(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance(pm, i) end for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end diff --git a/src/prob/opf_bctr.jl b/src/prob/opf_bctr.jl index 19374b935..42aff374e 100644 --- a/src/prob/opf_bctr.jl +++ b/src/prob/opf_bctr.jl @@ -14,12 +14,12 @@ end function post_mc_opf_bctr(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) for c in _PMs.conductor_ids(pm) _PMs.variable_generation(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_trans_flow(pm) constraint_mc_model_voltage(pm) @@ -38,11 +38,10 @@ function post_mc_opf_bctr(pm::_PMs.AbstractPowerModel) for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end diff --git a/src/prob/opf_bf.jl b/src/prob/opf_bf.jl index 335ccbabe..9685c6650 100644 --- a/src/prob/opf_bf.jl +++ b/src/prob/opf_bf.jl @@ -35,9 +35,7 @@ function post_mc_opf_bf(pm::_PMs.AbstractPowerModel) for i in _PMs.ids(pm, :branch) constraint_mc_flow_losses(pm, i) - constraint_mc_model_voltage_magnitude_difference(pm, i) - constraint_mc_voltage_angle_difference(pm, i) for c in _PMs.conductor_ids(pm) diff --git a/src/prob/opf_lm.jl b/src/prob/opf_lm.jl index be907d953..2736b96ef 100644 --- a/src/prob/opf_lm.jl +++ b/src/prob/opf_lm.jl @@ -24,13 +24,13 @@ delta-connected and wye-connected function post_mc_opf_lm(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) + variable_mc_load(pm) for c in _PMs.conductor_ids(pm) _PMs.variable_generation(pm, cnd=c) - variable_mc_load(pm, cnd=c) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_trans_flow(pm) constraint_mc_model_voltage(pm) @@ -43,17 +43,16 @@ function post_mc_opf_lm(pm::_PMs.AbstractPowerModel) constraint_mc_load(pm, id) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_load(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_load(pm, i) end for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end diff --git a/src/prob/opf_oltc.jl b/src/prob/opf_oltc.jl index 4add283c7..1dd0798ce 100644 --- a/src/prob/opf_oltc.jl +++ b/src/prob/opf_oltc.jl @@ -34,17 +34,16 @@ function post_mc_opf_oltc(pm::_PMs.AbstractPowerModel) constraint_mc_theta_ref(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance(pm, i) end for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end diff --git a/src/prob/pf.jl b/src/prob/pf.jl index 3a1a35942..697ebc9e6 100644 --- a/src/prob/pf.jl +++ b/src/prob/pf.jl @@ -26,14 +26,13 @@ end function post_mc_pf(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm, bounded=false) variable_mc_branch_flow(pm, bounded=false) + variable_mc_trans_flow(pm, bounded=false) for c in _PMs.conductor_ids(pm) _PMs.variable_generation(pm, bounded=false, cnd=c) _PMs.variable_dcline_flow(pm, bounded=false, cnd=c) end - variable_mc_trans_flow(pm, bounded=false) - constraint_mc_model_voltage(pm) for (i,bus) in _PMs.ref(pm, :ref_buses) @@ -45,24 +44,26 @@ function post_mc_pf(pm::_PMs.AbstractPowerModel) end end - for (i,bus) in _PMs.ref(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance(pm, i, cnd=c) + for (i,bus) in _PMs.ref(pm, :bus) + constraint_mc_power_balance(pm, i) - # PV Bus Constraints - if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) - # this assumes inactive generators are filtered out of bus_gens - @assert bus["bus_type"] == 2 - - _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) - for j in _PMs.ref(pm, :bus_gens, i) - _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + for c in _PMs.conductor_ids(pm) + # PV Bus Constraints + if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) + # this assumes inactive generators are filtered out of bus_gens + @assert bus["bus_type"] == 2 + + _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) + for j in _PMs.ref(pm, :bus_gens, i) + _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + end end end end - for i in _PMs.ids(pm, :branch), c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + for i in _PMs.ids(pm, :branch) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) end for (i,dcline) in _PMs.ref(pm, :dcline), c in _PMs.conductor_ids(pm) diff --git a/src/prob/pf_lm.jl b/src/prob/pf_lm.jl index fc2b06fc1..dd0b8bf7f 100644 --- a/src/prob/pf_lm.jl +++ b/src/prob/pf_lm.jl @@ -26,15 +26,14 @@ end function post_mc_pf_lm(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm, bounded=false) variable_mc_branch_flow(pm, bounded=false) + variable_mc_trans_flow(pm, bounded=false) + variable_mc_load(pm, bounded=false) for c in _PMs.conductor_ids(pm) _PMs.variable_generation(pm, bounded=false, cnd=c) - variable_mc_load(pm, bounded=false, cnd=c) _PMs.variable_dcline_flow(pm, bounded=false, cnd=c) end - variable_mc_trans_flow(pm, bounded=false) - constraint_mc_model_voltage(pm) for (i,bus) in _PMs.ref(pm, :ref_buses) @@ -51,28 +50,29 @@ function post_mc_pf_lm(pm::_PMs.AbstractPowerModel) constraint_mc_load(pm, id) end - for (i,bus) in _PMs.ref(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_load(pm, i, cnd=c) - - # PV Bus Constraints - if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) - # this assumes inactive generators are filtered out of bus_gens - @assert bus["bus_type"] == 2 + for (i,bus) in _PMs.ref(pm, :bus) + constraint_mc_power_balance_load(pm, i) - _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) - for j in _PMs.ref(pm, :bus_gens, i) - _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + for c in _PMs.conductor_ids(pm) + # PV Bus Constraints + if length(_PMs.ref(pm, :bus_gens, i)) > 0 && !(i in _PMs.ids(pm,:ref_buses)) + # this assumes inactive generators are filtered out of bus_gens + @assert bus["bus_type"] == 2 + + _PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) + for j in _PMs.ref(pm, :bus_gens, i) + _PMs.constraint_active_gen_setpoint(pm, j, cnd=c) + end end end end - for i in _PMs.ids(pm, :branch), c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) + for i in _PMs.ids(pm, :branch) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) end for (i,dcline) in _PMs.ref(pm, :dcline), c in _PMs.conductor_ids(pm) - _PMs.constraint_active_dcline_setpoint(pm, i, cnd=c) f_bus = _PMs.ref(pm, :bus)[dcline["f_bus"]] diff --git a/src/prob/test.jl b/src/prob/test.jl index 6eb6d7a7c..3f1f03a87 100644 --- a/src/prob/test.jl +++ b/src/prob/test.jl @@ -21,6 +21,7 @@ end function post_mc_strg_opf(pm::_PMs.AbstractPowerModel) variable_mc_voltage(pm) variable_mc_branch_flow(pm) + variable_mc_trans_flow(pm) variable_mc_storage(pm) for c in _PMs.conductor_ids(pm) @@ -28,15 +29,14 @@ function post_mc_strg_opf(pm::_PMs.AbstractPowerModel) _PMs.variable_dcline_flow(pm, cnd=c) end - variable_mc_trans_flow(pm) constraint_mc_model_voltage(pm) for i in _PMs.ids(pm, :ref_buses) constraint_mc_theta_ref(pm, i) end - for i in _PMs.ids(pm, :bus), c in _PMs.conductor_ids(pm) - constraint_mc_power_balance_storage(pm, i, cnd=c) + for i in _PMs.ids(pm, :bus) + constraint_mc_power_balance_storage(pm, i) end for i in _PMs.ids(pm, :storage) @@ -50,11 +50,10 @@ function post_mc_strg_opf(pm::_PMs.AbstractPowerModel) for i in _PMs.ids(pm, :branch) constraint_mc_voltage_angle_difference(pm, i) + constraint_mc_ohms_yt_from(pm, i) + constraint_mc_ohms_yt_to(pm, i) for c in _PMs.conductor_ids(pm) - constraint_mc_ohms_yt_from(pm, i, cnd=c) - constraint_mc_ohms_yt_to(pm, i, cnd=c) - _PMs.constraint_thermal_limit_from(pm, i, cnd=c) _PMs.constraint_thermal_limit_to(pm, i, cnd=c) end @@ -90,6 +89,7 @@ end function post_mn_mc_strg_opf(pm::_PMs.AbstractPowerModel) for (n, network) in _PMs.nws(pm) variable_mc_voltage(pm, nw=n) + constraint_mc_model_voltage(pm, nw=n) variable_mc_branch_flow(pm, nw=n) variable_mc_storage(pm, nw=n) @@ -98,8 +98,6 @@ function post_mn_mc_strg_opf(pm::_PMs.AbstractPowerModel) _PMs.variable_dcline_flow(pm, cnd=c, nw=n) end - constraint_mc_model_voltage(pm, nw=n) - for i in _PMs.ids(pm, :ref_buses, nw=n) constraint_mc_theta_ref(pm, i, nw=n) end @@ -118,10 +116,10 @@ function post_mn_mc_strg_opf(pm::_PMs.AbstractPowerModel) end for i in _PMs.ids(pm, :branch, nw=n) - for c in _PMs.conductor_ids(pm, nw=n) - constraint_mc_ohms_yt_from(pm, i, cnd=c, nw=n) - constraint_mc_ohms_yt_to(pm, i, cnd=c, nw=n) + constraint_mc_ohms_yt_from(pm, i, nw=n) + constraint_mc_ohms_yt_to(pm, i, nw=n) + for c in _PMs.conductor_ids(pm, nw=n) _PMs.constraint_voltage_angle_difference(pm, i, cnd=c, nw=n) _PMs.constraint_thermal_limit_from(pm, i, cnd=c, nw=n)