Skip to content

Commit

Permalink
Revert "UPD: JuMP v1.23.2 - new NL interface"
Browse files Browse the repository at this point in the history
This reverts commit a827107.
  • Loading branch information
pseudocubic committed Sep 23, 2024
1 parent a827107 commit 4f5f0b2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

- 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
Expand Down
14 changes: 7 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerModelsProtection"
uuid = "719c1aef-945b-435a-a240-4c2992e5e0df"
authors = ["Art Barnes", "Jose Tabarez"]
version = "0.7.0"
version = "0.6.0"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand All @@ -18,12 +18,12 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Graphs = "1.9"
InfrastructureModels = "0.7.8"
Ipopt = "1"
JuMP = "1.23.2"
PowerModels = "0.21"
PowerModelsDistribution = "0.16"
Graphs = "1.4.1, 1.6, 1.7, 1.8, 1.9"
InfrastructureModels = "0.7.3"
Ipopt = "0.9, 1.0.2"
JuMP = "0.22, 0.23, 1"
PowerModels = "0.19.1"
PowerModelsDistribution = "~0.13.3, 0.14, 0.15"
julia = "1.6"

[extras]
Expand Down
16 changes: 8 additions & 8 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.@constraint(pm.model, sum(cr[a] for a in bus_arcs)
JuMP.@NLconstraint(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.@constraint(pm.model, sum(ci[a] for a in bus_arcs)
JuMP.@NLconstraint(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
Expand All @@ -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.@constraint(pm.model, sum(cr[a] for a in bus_arcs)
JuMP.@NLconstraint(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.@constraint(pm.model, sum(ci[a] for a in bus_arcs)
JuMP.@NLconstraint(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
Expand Down Expand Up @@ -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.@constraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns)
JuMP.@NLconstraint(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)
==
Expand All @@ -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.@constraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns)
JuMP.@NLconstraint(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)
==
Expand All @@ -196,15 +196,15 @@ function constraint_mc_fault_current_balance(pm::_PMD.AbstractUnbalancedIVRModel
- cfi[t] # faults
)
else
JuMP.@constraint(pm.model, sum(cr[a][t] for (a, conns) in bus_arcs if t in conns)
JuMP.@NLconstraint(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)
==
sum(crg[g][t] for (g, conns) in bus_gens if t in conns)
- 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.@constraint(pm.model, sum(ci[a][t] for (a, conns) in bus_arcs if t in conns)
JuMP.@NLconstraint(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)
==
Expand Down
24 changes: 12 additions & 12 deletions src/core/constraint_inverter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.@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)
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)

else
z = _PMD.var(pm, nw)[:z_gfli] = JuMP.@variable(pm.model,
Expand All @@ -347,10 +347,10 @@ function constraint_mc_pq_inverter(pm::_PMD.AbstractUnbalancedIVRModel, nw::Int,
)

for (idx,c) in enumerate(connections)
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])
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])
end
end
end
Expand Down Expand Up @@ -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.@constraint(pm.model, (crg[c]^2 + cig[c]^2 - cmax^2)*z[c] >= 0.0)
JuMP.@NLconstraint(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]))
Expand Down Expand Up @@ -429,8 +429,8 @@ function constraint_mc_grid_formimg_inverter_impedance(pm::_PMD.AbstractUnbalanc

for (idx,c) in enumerate(cnds)
# current limits
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)
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)

# setpoint voltage mag
JuMP.@constraint(pm.model, vrstar[c]^2 + vistar[c]^2 <= vm[idx] * (1+z[c]))
Expand Down Expand Up @@ -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.@constraint(pm.model, (crg[c]^2 + cig[c]^2 - imax[c]^2)*z[c] >= 0.0)
JuMP.@NLconstraint(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])
Expand Down
4 changes: 2 additions & 2 deletions src/core/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.@expression(pm.model, vr * crg + vi * cig)
qg[i] = JuMP.@expression(pm.model, vi * crg - vr * cig)
pg[i] = JuMP.@NLexpression(pm.model, vr * crg + vi * cig)
qg[i] = JuMP.@NLexpression(pm.model, vi * crg - vr * cig)
end

_PM.var(pm, nw)[:pg] = pg
Expand Down

0 comments on commit 4f5f0b2

Please sign in to comment.