Skip to content

Commit

Permalink
fix failing gmd.jl tests from idc solution field name change
Browse files Browse the repository at this point in the history
  • Loading branch information
bluejuniper committed Oct 2, 2024
1 parent bf73bac commit d60f0e5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Memento = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
PowerModelsRestoration = "23adbb12-a187-11e9-26a2-eb4d4e6e68fb"
# PowerModelsRestoration = "23adbb12-a187-11e9-26a2-eb4d4e6e68fb"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

Expand All @@ -29,7 +29,7 @@ JSON = "~0.21"
JuMP = "~1.9"
Memento = "~1.0, ~1.1, ~1.2, ~1.3, ~1.4"
PowerModels = "~0.19"
PowerModelsRestoration = "~0.7"
# PowerModelsRestoration = "~0.7"
julia = "~1.6, ~1.7, ~1.8, ~1.10"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/PowerModelsGMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const _PMGMD = PowerModelsGMD
const _IM = InfrastructureModels
import PowerModels
const _PM = PowerModels
import PowerModelsRestoration
const _PMR = PowerModelsRestoration
# import PowerModelsRestoration
# const _PMR = PowerModelsRestoration


import PowerModels: pm_it_name, pm_it_sym, nw_ids, nws, ismultinetwork
Expand Down
62 changes: 31 additions & 31 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ function calc_ieff_current_mag_gwye_delta_xf(branch, case::Dict{String,Any}, sol
if haskey(branch,"hi_3w_branch")
return 0.0
else
if haskey(solution["gmd_branch"]["$khi"], "gmd_idc")
return abs(solution["gmd_branch"]["$khi"]["gmd_idc"])
if haskey(solution["gmd_branch"]["$khi"], "dcf")
return abs(solution["gmd_branch"]["$khi"]["dcf"])
else
Memento.warn(_LOGGER, "Gwye-delta transformers $k doesn't have high-side gmd_idc, skipping calculation of ieff")
Memento.warn(_LOGGER, "Gwye-delta transformers $k doesn't have high-side dcf, skipping calculation of ieff")
return 0.0
end
end
Expand All @@ -123,13 +123,13 @@ function calc_ieff_current_mag_gwye_gwye_xf(branch, case::Dict{String,Any}, solu
if khi == -1 || khi === nothing
Memento.warn(_LOGGER, "khi for gwye-gwye transformer $k is -1")
else
ihi = solution["gmd_branch"]["$khi"]["gmd_idc"]
ihi = solution["gmd_branch"]["$khi"]["dcf"]
end

if klo == -1 || klo === nothing
Memento.warn(_LOGGER, "klo for gwye-gwye transformer $k is -1")
else
ilo = solution["gmd_branch"]["$klo"]["gmd_idc"]
ilo = solution["gmd_branch"]["$klo"]["dcf"]
end

jfr = branch["f_bus"]
Expand Down Expand Up @@ -159,13 +159,13 @@ function calc_ieff_current_mag_gwye_gwye_auto_xf(branch, case::Dict{String,Any},
if ks == -1 || ks === nothing
Memento.warn(_LOGGER, "ks for autotransformer $k is -1")
else
is = solution["gmd_branch"]["$ks"]["gmd_idc"]
is = solution["gmd_branch"]["$ks"]["dcf"]
end

if kc == -1 || kc === nothing
Memento.warn(_LOGGER, "kc for autotransformer $k is -1")
else
ic = solution["gmd_branch"]["$kc"]["gmd_idc"]
ic = solution["gmd_branch"]["$kc"]["dcf"]
end

jfr = branch["f_bus"]
Expand All @@ -189,13 +189,13 @@ function calc_ieff_current_mag_gwye_gwye_auto_xf(branch, case::Dict{String,Any},
if ks == -1 || ks === nothing
Memento.warn(_LOGGER, "ks for autotransformer $k is -1")
else
is = solution["gmd_branch"]["$ks"]["gmd_idc"]
is = solution["gmd_branch"]["$ks"]["dcf"]
end

if kc == -1 || kc === nothing
Memento.warn(_LOGGER, "kc for autotransformer $k is -1")
else
ic = solution["gmd_branch"]["$kc"]["gmd_idc"]
ic = solution["gmd_branch"]["$kc"]["dcf"]
end

# ihi = -is
Expand Down Expand Up @@ -226,19 +226,19 @@ function calc_ieff_current_mag_3w_xf(branch, case::Dict{String,Any}, solution)
if khi == -1 || khi === nothing
Memento.warn(_LOGGER, "khi for three-winding transformer $k is -1")
else
ihi = solution["gmd_branch"]["$khi"]["gmd_idc"]
ihi = solution["gmd_branch"]["$khi"]["dcf"]
end

if klo == -1 || klo === nothing
Memento.warn(_LOGGER, "klo for three-winding transformer $k is -1")
else
ilo = solution["gmd_branch"]["$klo"]["gmd_idc"]
ilo = solution["gmd_branch"]["$klo"]["dcf"]
end

if kter == -1 || kter === nothing
Memento.warn(_LOGGER, "kter for three-winding transformer $k is -1")
else
iter = solution["gmd_branch"]["$ter"]["gmd_idc"]
iter = solution["gmd_branch"]["$ter"]["dcf"]
end

jfr = branch["source_id"][2]
Expand Down Expand Up @@ -308,7 +308,7 @@ function calc_ieff_current_mag_gwye_delta_xf(branch, case::Dict{Symbol,Any}, sol
Memento.warn(_LOGGER, "khi for gwye-delta transformer $k is -1")
return 0.0
else
return abs(solution["gmd_branch"]["$khi"]["gmd_idc"])
return abs(solution["gmd_branch"]["$khi"]["dcf"])
end

end
Expand All @@ -326,13 +326,13 @@ function calc_ieff_current_mag_gwye_gwye_xf(branch, case::Dict{Symbol,Any}, solu
if khi == -1 || khi === nothing
Memento.warn(_LOGGER, "khi for gwye-gwye transformer $k is -1")
else
ihi = solution["gmd_branch"]["$khi"]["gmd_idc"]
ihi = solution["gmd_branch"]["$khi"]["dcf"]
end

if klo == -1 || klo === nothing
Memento.warn(_LOGGER, "klo for gwye-gwye transformer $k is -1")
else
ilo = solution["gmd_branch"]["$klo"]["gmd_idc"]
ilo = solution["gmd_branch"]["$klo"]["dcf"]
end

jfr = branch["f_bus"]
Expand All @@ -357,13 +357,13 @@ function calc_ieff_current_mag_gwye_gwye_auto_xf(branch, case::Dict{Symbol,Any},
if ks == -1 || ks === nothing
Memento.warn(_LOGGER, "ks for autotransformer $k is -1")
else
is = solution["gmd_branch"]["$ks"]["gmd_idc"]
is = solution["gmd_branch"]["$ks"]["dcf"]
end

if kc == -1 || kc === nothing
Memento.warn(_LOGGER, "kc for autotransformer $k is -1")
else
ic = solution["gmd_branch"]["$kc"]["gmd_idc"]
ic = solution["gmd_branch"]["$kc"]["dcf"]
end

# ihi = -is
Expand Down Expand Up @@ -394,19 +394,19 @@ function calc_ieff_current_mag_3w_xf(branch, case::Dict{Symbol,Any}, solution)
if khi == -1 || khi === nothing
Memento.warn(_LOGGER, "khi for three-winding transformer $k is -1")
else
ihi = solution["gmd_branch"]["$khi"]["gmd_idc"]
ihi = solution["gmd_branch"]["$khi"]["dcf"]
end

if klo == -1 || klo === nothing
Memento.warn(_LOGGER, "klo for three-winding transformer $k is -1")
else
ilo = solution["gmd_branch"]["$klo"]["gmd_idc"]
ilo = solution["gmd_branch"]["$klo"]["dcf"]
end

if kter == -1 || kter === nothing
Memento.warn(_LOGGER, "kter for three-winding transformer $k is -1")
else
iter = solution["gmd_branch"]["$ter"]["gmd_idc"]
iter = solution["gmd_branch"]["$ter"]["dcf"]
end

jfr = branch["source_id"][2]
Expand All @@ -423,23 +423,23 @@ function calc_ieff_current_mag_3w_xf(branch, case::Dict{Symbol,Any}, solution)
end


function calc_dc_current_mag(branch, type, solution)
function calc_dc_current(branch, type, solution)
if type == "line"
return calc_dc_current_mag_line(branch, solution)
return calc_dc_current_line(branch, solution)

elseif type == "xfmr"
return calc_dc_current_mag_xfmr(branch, solution)
return calc_dc_current_xfmr(branch, solution)

else
return calc_dc_current_mag_sub(branch, solution)
return calc_dc_current_sub(branch, solution)

end

return 0.0
end


function calc_dc_current_mag_line(branch, solution)
function calc_dc_current_line(branch, solution)
nf = branch["f_bus"]
nt = branch["t_bus"]
g = 1 / branch["br_r"]
Expand All @@ -449,7 +449,7 @@ function calc_dc_current_mag_line(branch, solution)
end


function calc_dc_current_mag_xfmr(branch, solution)
function calc_dc_current_xfmr(branch, solution)
nf = branch["f_bus"]
nt = branch["t_bus"]
g = 1 / branch["br_r"]
Expand All @@ -459,7 +459,7 @@ function calc_dc_current_mag_xfmr(branch, solution)
end


function calc_dc_current_mag_sub(branch, solution)
function calc_dc_current_sub(branch, solution)
nf = branch["f_bus"]
nt = branch["t_bus"]
g = 1 / branch["br_r"]
Expand Down Expand Up @@ -804,7 +804,7 @@ function adjust_gmd_phasing!(result)

gmd_branches = result["solution"]["gmd_branch"]
for branch in values(gmd_branches)
branch["gmd_idc"] = branch["gmd_idc"] / 3
branch["dcf"] /= 3
end

return result
Expand All @@ -831,15 +831,15 @@ function add_gmd_data!(case::Dict{String,Any}, solution::Dict{String,<:Any}; dec

if br["type"] == "line"
k = "$(br["gmd_br"])"
br["gmd_idc"] = solution["gmd_branch"][k]["gmd_idc"]/3.0
br["dcf"] = solution["gmd_branch"][k]["dcf"]/3.0

else
if decoupled # TODO: add calculations from constraint_dc_current_mag

k = br["dc_brid_hi"]
# high-side gmd branch
br["gmd_idc"] = 0.0
br["ieff"] = abs(br["gmd_idc"])
br["dcf"] = 0.0
br["ieff"] = abs(br["dcf"])
br["qloss"] = calc_qloss(i, case, solution)

else
Expand Down
9 changes: 7 additions & 2 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,22 @@ function solution_gmd(v::Vector{Float64}, case::Dict{String,Any})
solution["gmd_bus"]["$bus"]["gmd_vdc"] = val
end

# TODO: check if calc_dc_current_mag is redundant with calc_ieff_current_mag
# Note: calc_dc_current (formely calc_dc_current_mag) is different from
# calc_ieff_current_mag as the latter is for ieff rather than idc
# and associated with branches rather than gmd_branches
for (n, branch) in case["gmd_branch"]
solution["gmd_branch"]["$n"] = Dict()
if haskey(branch, "parent_type") && branch["parent_type"] == "branch"
type = case["branch"]["$(branch["parent_index"])"]["type"]
solution["gmd_branch"]["$n"]["gmd_idc"] = calc_dc_current_mag(branch, type, solution)
idc = calc_dc_current(branch, type, solution)
solution["gmd_branch"]["$n"]["dcf"] = idc
solution["gmd_branch"]["$n"]["dcf"] = -idc
else
Memento.warn(_LOGGER, "Branch $n doesn't have parent_type, skipping")
end
end

# TODO:
solution["ieff"] = Dict{String,Any}()

for (n, branch) in case["branch"]
Expand Down
4 changes: 2 additions & 2 deletions test/gmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
@test isapprox(result["solution"]["ieff"]["25"], 19.075, rtol=1e-3)
@test isapprox(result["solution"]["ieff"]["29"], 17.183, rtol=1e-3)
@test isapprox(result["solution"]["ieff"]["30"], 17.183, rtol=1e-3)
println(result["solution"]["qloss"])
# println(result["solution"]["qloss"])
end
end
@testset "opt solve of gmd" begin
Expand Down Expand Up @@ -151,7 +151,7 @@
@test isapprox(result["solution"]["ieff"]["25"], 19.075, rtol=1e-3)
@test isapprox(result["solution"]["ieff"]["29"], 17.183, rtol=1e-3)
@test isapprox(result["solution"]["ieff"]["30"], 17.183, rtol=1e-3)
println(result["solution"]["qloss"])
# println(result["solution"]["qloss"])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ include("test_cases.jl")
include("gmd.jl")
# include("gmd_pf.jl")
# include("gmd_opf.jl")
include("gmd_mld.jl")
# include("gmd_mld.jl")
# include("gmd_ots.jl")
# include("gmd_blocker.jl")
include("parse.jl") # GIC parser
Expand Down

0 comments on commit d60f0e5

Please sign in to comment.