diff --git a/CHANGELOG.md b/CHANGELOG.md index 551df27..8b99290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - none +## v0.7.0 + +- Upgrade to new JuMP NL interface (v1.23.2+) + ## v0.6.0 - Fixed solver and removed the z-matrix to handle larger problems diff --git a/Project.toml b/Project.toml index 4228bf4..7352280 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PowerModelsProtection" uuid = "719c1aef-945b-435a-a240-4c2992e5e0df" authors = ["Art Barnes", "Jose Tabarez"] -version = "0.6.0" +version = "0.7.0" [deps] Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" @@ -18,13 +18,13 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] -Graphs = "1.4.1, 1.6, 1.7, 1.8, 1.9" -InfrastructureModels = "0.7.3" -Ipopt = "0.9, 1.0.2" +Graphs = "1.9" +InfrastructureModels = "0.7.8" +Ipopt = "1" JSON = "0.21" -JuMP = "0.22, 0.23, 1" -PowerModels = "0.19.1" -PowerModelsDistribution = "~0.13.3, 0.14, 0.15" +JuMP = "1.23.2" +PowerModels = "0.21" +PowerModelsDistribution = "0.16" julia = "1.6" [extras] diff --git a/src/core/constraint.jl b/src/core/constraint.jl index 820b1c8..9fc8262 100644 --- a/src/core/constraint.jl +++ b/src/core/constraint.jl @@ -58,12 +58,12 @@ function constraint_current_balance(pm::_PM.AbstractIVRModel, n::Int, i::Int, bu crg = _PM.var(pm, n, :crg) cig = _PM.var(pm, n, :cig) - JuMP.@NLconstraint(pm.model, sum(cr[a] for a in bus_arcs) + JuMP.@constraint(pm.model, sum(cr[a] for a in bus_arcs) == sum(crg[g] for g in bus_gens) - sum(gs for gs in values(bus_gs)) * vr + sum(bs for bs in values(bus_bs)) * vi ) - JuMP.@NLconstraint(pm.model, sum(ci[a] for a in bus_arcs) + JuMP.@constraint(pm.model, sum(ci[a] for a in bus_arcs) == sum(cig[g] for g in bus_gens) - sum(gs for gs in values(bus_gs)) * vi - sum(bs for bs in values(bus_bs)) * vr @@ -89,13 +89,13 @@ function constraint_fault_current_balance(pm::_PM.AbstractIVRModel, n::Int, i::I cfr = _PM.var(pm, n, :cfr_bus, i) cfi = _PM.var(pm, n, :cfi_bus, i) - JuMP.@NLconstraint(pm.model, sum(cr[a] for a in bus_arcs) + JuMP.@constraint(pm.model, sum(cr[a] for a in bus_arcs) == sum(crg[g] for g in bus_gens) - sum(gs for gs in values(bus_gs)) * vr + sum(bs for bs in values(bus_bs)) * vi - cfr ) - JuMP.@NLconstraint(pm.model, sum(ci[a] for a in bus_arcs) + JuMP.@constraint(pm.model, sum(ci[a] for a in bus_arcs) == sum(cig[g] for g in bus_gens) - sum(gs for gs in values(bus_gs)) * vi - sum(bs for bs in values(bus_bs)) * vr @@ -177,7 +177,7 @@ function constraint_mc_fault_current_balance(pm::_PMD.AbstractUnbalancedIVRModel for (idx, t) in ungrounded_terminals if t in fault_conns - JuMP.@NLconstraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns) + JuMP.@constraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns) + sum(crsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(crt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == @@ -186,7 +186,7 @@ function constraint_mc_fault_current_balance(pm::_PMD.AbstractUnbalancedIVRModel - sum( Gt[idx,jdx]*vr[u] -Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) # shunts - cfr[t] # faults ) - JuMP.@NLconstraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns) + JuMP.@constraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns) + sum(cisw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(cit[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == @@ -196,7 +196,7 @@ function constraint_mc_fault_current_balance(pm::_PMD.AbstractUnbalancedIVRModel - cfi[t] # faults ) else - JuMP.@NLconstraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns) + JuMP.@constraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns) + sum(crsw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(crt[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == @@ -204,7 +204,7 @@ function constraint_mc_fault_current_balance(pm::_PMD.AbstractUnbalancedIVRModel - sum(crs[s][t] for (s, conns) in bus_storage if t in conns) - sum( Gt[idx,jdx]*vr[u] -Bt[idx,jdx]*vi[u] for (jdx,u) in ungrounded_terminals) # shunts ) - JuMP.@NLconstraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns) + JuMP.@constraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns) + sum(cisw[a_sw][t] for (a_sw, conns) in bus_arcs_sw if t in conns) + sum(cit[a_trans][t] for (a_trans, conns) in bus_arcs_trans if t in conns) == diff --git a/src/core/constraint_inverter.jl b/src/core/constraint_inverter.jl index 416498d..8e15cce 100644 --- a/src/core/constraint_inverter.jl +++ b/src/core/constraint_inverter.jl @@ -320,10 +320,10 @@ function constraint_mc_pq_inverter(pm::_PMD.AbstractUnbalancedIVRModel, nw::Int, JuMP.@constraint(pm.model, (1/3)*vr[1] + ar*vr[2] - ai*vi[2] + a2r*vr[3] - a2i*vi[3] == vr_pos) JuMP.@constraint(pm.model, (1/3)*vi[1] + ar*vi[2] + ai*vr[2] + a2r*vi[3] + a2i*vr[3] == vi_pos) - JuMP.@NLconstraint(pm.model, imax[1]^2 - crg_pos^2 - cig_pos^2 >= 0.0) - JuMP.@NLconstraint(pm.model, (imax[1]^2 - crg_pos^2 - cig_pos^2)*z <= 0.0) - JuMP.@NLconstraint(pm.model, vr_pos*crg_pos + vi_pos*cig_pos == pg[1] - pg_int*z) - JuMP.@NLconstraint(pm.model, vi_pos*crg_pos - vr_pos*cig_pos == 0.0) + JuMP.@constraint(pm.model, imax[1]^2 - crg_pos^2 - cig_pos^2 >= 0.0) + JuMP.@constraint(pm.model, (imax[1]^2 - crg_pos^2 - cig_pos^2)*z <= 0.0) + JuMP.@constraint(pm.model, vr_pos*crg_pos + vi_pos*cig_pos == pg[1] - pg_int*z) + JuMP.@constraint(pm.model, vi_pos*crg_pos - vr_pos*cig_pos == 0.0) else z = _PMD.var(pm, nw)[:z_gfli] = JuMP.@variable(pm.model, @@ -347,10 +347,10 @@ function constraint_mc_pq_inverter(pm::_PMD.AbstractUnbalancedIVRModel, nw::Int, ) for (idx,c) in enumerate(connections) - JuMP.@NLconstraint(pm.model, imax[idx]^2 - crg[c]^2 - cig[c]^2 >= 0.0) - JuMP.@NLconstraint(pm.model, m*(imax[idx]^2 - crg[c]^2 - cig[c]^2)*z[c] <= 0.0) - JuMP.@NLconstraint(pm.model, vr[c]*crg[c] + vi[c]*cig[c] == pg[idx]-z[c]*pg_int[c]) - JuMP.@NLconstraint(pm.model, vi[c]*crg[c] - vr[c]*cig[c] == qg[idx]-z[c]*qg_int[c]) + JuMP.@constraint(pm.model, imax[idx]^2 - crg[c]^2 - cig[c]^2 >= 0.0) + JuMP.@constraint(pm.model, m*(imax[idx]^2 - crg[c]^2 - cig[c]^2)*z[c] <= 0.0) + JuMP.@constraint(pm.model, vr[c]*crg[c] + vi[c]*cig[c] == pg[idx]-z[c]*pg_int[c]) + JuMP.@constraint(pm.model, vi[c]*crg[c] - vr[c]*cig[c] == qg[idx]-z[c]*qg_int[c]) end end end @@ -381,7 +381,7 @@ function constraint_mc_grid_forming_inverter(pm::_PMD.AbstractUnbalancedIVRModel # current limits # z = 1 -> invert in in current limiting mode JuMP.@constraint(pm.model, crg[c]^2 + cig[c]^2 <= cmax^2) - JuMP.@NLconstraint(pm.model, (crg[c]^2 + cig[c]^2 - cmax^2)*z[c] >= 0.0) + JuMP.@constraint(pm.model, (crg[c]^2 + cig[c]^2 - cmax^2)*z[c] >= 0.0) # terminal voltage mag JuMP.@constraint(pm.model, vr[c]^2 + vi[c]^2 <= vm[idx] * (1+z[c])) @@ -429,8 +429,8 @@ function constraint_mc_grid_formimg_inverter_impedance(pm::_PMD.AbstractUnbalanc for (idx,c) in enumerate(cnds) # current limits - JuMP.@NLconstraint(pm.model, crg[c]^2 + cig[c]^2 <= cmax[c]^2) - JuMP.@NLconstraint(pm.model, m*(cmax[c]^2 - crg[c]^2 - cig[c]^2)*z[c] <= 0.0) + JuMP.@constraint(pm.model, crg[c]^2 + cig[c]^2 <= cmax[c]^2) + JuMP.@constraint(pm.model, m*(cmax[c]^2 - crg[c]^2 - cig[c]^2)*z[c] <= 0.0) # setpoint voltage mag JuMP.@constraint(pm.model, vrstar[c]^2 + vistar[c]^2 <= vm[idx] * (1+z[c])) @@ -482,7 +482,7 @@ function constraint_mc_grid_formimg_inverter_virtual_impedance(pm::_PMD.Abstract for (idx,c) in enumerate(connections) JuMP.@constraint(pm.model, crg[c]^2 + cig[c]^2 <= imax[c]^2) - JuMP.@NLconstraint(pm.model, (crg[c]^2 + cig[c]^2 - imax[c]^2)*z[c] >= 0.0) + JuMP.@constraint(pm.model, (crg[c]^2 + cig[c]^2 - imax[c]^2)*z[c] >= 0.0) JuMP.@constraint(pm.model, vrstar[c]^2 + vistar[c]^2 >= vm[idx] * (1-z[c])) JuMP.@constraint(pm.model, vrstar[c]^2 + vistar[c]^2 <= vm[idx]) diff --git a/src/core/variable.jl b/src/core/variable.jl index 54daf29..5cb75f1 100644 --- a/src/core/variable.jl +++ b/src/core/variable.jl @@ -44,8 +44,8 @@ function variable_gen(pm::_PM.AbstractIVRModel; nw::Int=nw_id_default, bounded:: JuMP.set_upper_bound(cig, cmax) end - pg[i] = JuMP.@NLexpression(pm.model, vr * crg + vi * cig) - qg[i] = JuMP.@NLexpression(pm.model, vi * crg - vr * cig) + pg[i] = JuMP.@expression(pm.model, vr * crg + vi * cig) + qg[i] = JuMP.@expression(pm.model, vi * crg - vr * cig) end _PM.var(pm, nw)[:pg] = pg