Skip to content

Commit

Permalink
fix to qloss and 3 issue. New objective added
Browse files Browse the repository at this point in the history
  • Loading branch information
jtabarez committed Nov 20, 2024
1 parent 673cb52 commit f760dd6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/PowerModelsGMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const _PMGMD = PowerModelsGMD
import JSON
import JuMP
import Memento
import Ipopt


# Suppressing information and warning messages:
const _LOGGER = Memento.getlogger(@__MODULE__)
Expand Down
2 changes: 1 addition & 1 deletion src/core/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function constraint_qloss_constant_ieff(pm::_PM.AbstractPowerModel, n::Int, k, i
==
# Use this if we implement piecewise K
# (pm.data["baseMVA"]) / branchMVA ) * (K * vm * ieff) / (3.0 * branchMVA)
(K * vm * ieff) / (3.0 * baseMVA)
(K * vm * ieff) / (3.0 * baseMVA) # need to change based on response
# K is per phase
)

Expand Down
17 changes: 17 additions & 0 deletions src/core/constraint_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,23 @@ function constraint_qloss(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default)
end


"CONSTRAINT: Calculation of qloss on a per edge basis"
function constraint_qloss_pu(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default)

branch = _PM.ref(pm, nw, :branch, k)

i = branch["hi_bus"]
j = branch["lo_bus"]

bus = _PM.ref(pm, nw, :bus, i)

K = calc_branch_K_pu(pm,k;nw=nw)

constraint_qloss_pu(pm, nw, k, i, j, K)

end


"CONSTRAINT: Calculation of qloss on a per edge basis where ieff is a constant"

function constraint_qloss_constant_ieff(pm::_PM.AbstractPowerModel, k; nw::Int=nw_id_default)
Expand Down
2 changes: 1 addition & 1 deletion src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function calc_branch_K_pu(pm::_PM.AbstractPowerModel, i; nw::Int=pm.cnw)
branch = _PM.ref(pm, nw, :branch, i)
ibase = calc_branch_ibase(pm,i;nw=nw)

return haskey(branch, "gmd_k") ? (branch["gmd_k"]) / (ibase) / 3 : 0.0
return haskey(branch, "gmd_k") ? (branch["gmd_k"]) / (ibase) : 0.0 # waiting for response
end

"FUNCTION: calculate qloss returns MVA
Expand Down
10 changes: 6 additions & 4 deletions src/form/acp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ end

"CONSTRAINT: dc current on ungrounded gwye-gwye transformers"
function constraint_dc_current_mag_gwye_gwye_xf_3w(pm::_PM.AbstractACPModel, n::Int, k, kh, ih, jh)

Memento.debug(_LOGGER, "branch[$k]: hi_branch[$kh], 0.0")
ieff = _PM.var(pm, n, :i_dc_mag)[k]
ihi = _PM.var(pm, n, :dc)[(kh,ih,jh)]
Expand Down Expand Up @@ -94,17 +95,18 @@ end
# JuMP.@constraint(pm.model, qloss[(k,j,i)] == 0.0)
# end

"CONSTRAINT: qloss calculcated from dc current only"
function constraint_qloss(pm::_PM.AbstractACPModel, n::Int, k, i, j, baseMVA, K)
"CONSTRAINT: qloss calculcated for ac formulation single phase"
function constraint_qloss_pu(pm::_PM.AbstractACPModel, n::Int, k, i, j, K)
branch = _PM.ref(pm, n, :branch, k)

qloss = _PM.var(pm, n, :qloss)
vm = _PM.var(pm, n, :vm)[i]
ieff = _PM.var(pm, n, :i_dc_mag, k)

if branch["type"] == "xfmr"
JuMP.@constraint(pm.model,
qloss[(k,i,j)] == K / (3.0 * baseMVA) * ieff * vm
# qloss[(k,i,j)] == K / 3.0 * ieff * vm
qloss[(k,i,j)] == K * ieff * vm
)

else
Expand Down
17 changes: 11 additions & 6 deletions src/form/wr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ end

"CONSTRAINT: dc current on ungrounded gwye-delta transformers"
function constraint_dc_current_mag_gwye_delta_xf(pm::_PM.AbstractWRModel, n::Int, k, kh, ih, jh, ieff_max)

branch = _PM.ref(pm, n, :branch, k)
ieff = _PM.var(pm, n, :i_dc_mag)[k]
ihi = _PM.var(pm, n, :dc)[(kh,ih,jh)]

JuMP.@constraint(pm.model, ieff >= ihi)
JuMP.@constraint(pm.model, ieff >= -ihi)
if haskey(branch,"hi_3w_branch")
JuMP.@constraint(pm.model, ieff == 0.0)
else
JuMP.@constraint(pm.model, ieff >= ihi)
JuMP.@constraint(pm.model, ieff >= -ihi)
end

# TODO: use variable bounds for this
if !isnothing(ieff_max)
Expand Down Expand Up @@ -260,17 +264,18 @@ end


"""
CONSTRAINT: relaxed qloss calculcated from ac voltage and dc current
CONSTRAINT: relaxed qloss calculcated for ac formulation single phase
"""
function constraint_qloss(pm::_PM.AbstractWRModel, n::Int, k, i, j, baseMVA, K)
function constraint_qloss_pu(pm::_PM.AbstractWRModel, n::Int, k, i, j, K)
branch = _PM.ref(pm, n, :branch, k)

qloss = _PM.var(pm, n, :qloss)
vm = _PM.var(pm, n, :vm)[i]
ieff = _PM.var(pm, n, :i_dc_mag, k)

if branch["type"] == "xfmr"
scaled_relaxation_product(pm.model, K/(3.0 * baseMVA), ieff, vm, qloss[(k,i,j)])
# scaled_relaxation_product(pm.model, K/3.0, ieff, vm, qloss[(k,i,j)])
scaled_relaxation_product(pm.model, K, ieff, vm, qloss[(k,i,j)])
else
JuMP.@constraint(pm.model,
qloss[(k,i,j)] == 0.0
Expand Down
4 changes: 2 additions & 2 deletions src/prob/gmd_blocker_placement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function solve_blocker_placement(case, model_type::Type, optimizer; kwargs...)
],
solution_processors = [
solution_gmd!,
solution_gmd_qloss!,
# solution_gmd_qloss!,
],
kwargs...,
)
Expand Down Expand Up @@ -87,7 +87,7 @@ function build_blocker_placement(pm::_PM.AbstractPowerModel; kwargs...)
_PM.constraint_thermal_limit_from(pm, i)
_PM.constraint_thermal_limit_to(pm, i)

constraint_qloss(pm, i)
constraint_qloss_pu(pm, i)
constraint_dc_current_mag(pm, i)
end

Expand Down
2 changes: 1 addition & 1 deletion src/prob/gmd_bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function solve_bound_gmd_bus_v(case, model_type::Type, optimizer; kwargs...)
if length(conn) > 1
t = time()
for i in conn
bus = _case["gmd_bus"]["$i"]
bus = _case["gmd_bus"]["$i"]
if bus["sub"] == -1
kwargs[:setting]["gmd_bus"] = bus["index"]
kwargs[:setting]["max"] = true
Expand Down
5 changes: 3 additions & 2 deletions src/prob/gmd_mld.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function build_gmd_mld(pm::_PM.AbstractPowerModel; kwargs...)
_PM.constraint_thermal_limit_from(pm, i)
_PM.constraint_thermal_limit_to(pm, i)

constraint_qloss(pm, i)
constraint_qloss_pu(pm, i)
constraint_dc_current_mag(pm, i)
end

Expand All @@ -94,7 +94,8 @@ function build_gmd_mld(pm::_PM.AbstractPowerModel; kwargs...)
constraint_dc_ohms(pm, i)
end

_PM.objective_max_loadability(pm)
# _PM.objective_max_loadability(pm)
objective_max_loadability(pm)
end


Expand Down

0 comments on commit f760dd6

Please sign in to comment.