Skip to content

Commit

Permalink
UPD: JuMP v1.23.2 - new NL interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudocubic committed Sep 23, 2024
1 parent a30825e commit 610b126
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.6.0"
version = "0.7.0"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand All @@ -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]
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.@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
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.@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
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.@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)
==
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.@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)
==
Expand All @@ -196,15 +196,15 @@ 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)
==
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.@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)
==
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.@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,
Expand All @@ -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
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.@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]))
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.@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]))
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.@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])
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.@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
Expand Down

2 comments on commit 610b126

@pseudocubic
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115772

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" 610b1265db140a589181c3fd1bdb1e7288b89d42
git push origin v0.7.0

Please sign in to comment.