Skip to content

Commit

Permalink
fix gmd_opf_decoupled.jl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Mate committed Mar 31, 2021
1 parent a73d7d6 commit 35bca9d
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 130 deletions.
76 changes: 40 additions & 36 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export make_gmd_mixed_units, adjust_gmd_qloss, top_oil_rise, hotspot_rise, updat

"FUNCTION: add GMD data"
function add_gmd_data(case::Dict{String,Any}, solution::Dict{String,<:Any}; decoupled=false)
# NOTE: currently not being used


@assert !_IM.ismultinetwork(case)
@assert !haskey(case, "conductors")
Expand Down Expand Up @@ -58,41 +60,6 @@ gmd_not_pu = Set(["gmd_gs","gmd_e_field_mag"])
gmd_not_rad = Set(["gmd_e_field_dir"])


"FUNCTION: make GMD per unit"
function make_gmd_per_unit!(data::Dict{String,<:Any})

@assert !InfrastructureModels.ismultinetwork(case)
@assert !haskey(case, "conductors")

if !haskey(data, "GMDperUnit") || data["GMDperUnit"] == false
make_gmd_per_unit(data["baseMVA"], data)
data["GMDperUnit"] = true
end

end


"FUNCTION: make GMD per unit"
function make_gmd_per_unit!(mva_base::Number, data::Dict{String,<:Any})

@assert !InfrastructureModels.ismultinetwork(case)
@assert !haskey(case, "conductors")

# vb = 1e3*data["bus"][1]["base_kv"] # not sure h
# data["gmd_e_field_mag"] /= vb
# data["gmd_e_field_dir"] *= pi/180.0

for bus in data["bus"]
zb = bus["base_kv"]^2/mva_base

#println("bus: $(bus["index"]), zb: $zb, a(pu): $(bus["gmd_gs"])")
bus["gmd_gs"] *= zb
#println("-> a(pu): $(bus["gmd_gs"]) \n")
end

end




# === GENERAL FUNCTIONS === #
Expand Down Expand Up @@ -274,7 +241,7 @@ end



# === RESULT ADJUSTMENT AND CONVERSION === #
# === ADJUSTMENT AND CONVERSION === #


"FUNCTION: convert effective GIC to PowerWorld to-phase convention"
Expand Down Expand Up @@ -312,8 +279,45 @@ function adjust_gmd_qloss(case::Dict{String,Any}, solution::Dict{String,Any})
end


"FUNCTION: make GMD per unit"
function make_gmd_per_unit!(data::Dict{String,<:Any})
# FIX!

@assert !InfrastructureModels.ismultinetwork(case)
@assert !haskey(case, "conductors")

if !haskey(data, "GMDperUnit") || data["GMDperUnit"] == false
make_gmd_per_unit(data["baseMVA"], data)
data["GMDperUnit"] = true
end

end


"FUNCTION: make GMD per unit"
function make_gmd_per_unit!(mva_base::Number, data::Dict{String,<:Any})
# FIX!

@assert !InfrastructureModels.ismultinetwork(case)
@assert !haskey(case, "conductors")

# vb = 1e3*data["bus"][1]["base_kv"] # not sure h
# data["gmd_e_field_mag"] /= vb
# data["gmd_e_field_dir"] *= pi/180.0

for bus in data["bus"]
zb = bus["base_kv"]^2/mva_base

#println("bus: $(bus["index"]), zb: $zb, a(pu): $(bus["gmd_gs"])")
bus["gmd_gs"] *= zb
#println("-> a(pu): $(bus["gmd_gs"]) \n")
end

end

"FUNCTION: make GMD mixed units"
function make_gmd_mixed_units(solution::Dict{String,Any}, mva_base::Real)
# TODO: update code so all values are made to mixed unites instead of current per unit

rescale = x -> (x * mva_base)
rescale_dual = x -> (x / mva_base)
Expand Down
5 changes: 0 additions & 5 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ function solution_PM!(pm::_PM.AbstractPowerModel, solution::Dict{String,Any})
nws_data = Dict("0" => solution["it"][pm_it_name])
end

println("---ORIGINAL RESULT---")
println(nws_data)
println()
println()

# Bus
for (nw_id, nw_ref) in nws(pm)
for (n, nw_data) in nws_data
Expand Down
14 changes: 7 additions & 7 deletions test/gmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

dc_solution = result["solution"]

@test isapprox(dc_solution["gmd_bus"]["3"]["gmd_vdc"], -32.008063648310255, atol=0.1)
@test isapprox(dc_solution["gmd_bus"]["3"]["gmd_vdc"], -32.008063648310255, atol=1e-1)

@test isapprox(dc_solution["gmd_branch"]["2"]["gmd_idc"], 106.69354549436753, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["2"]["gmd_idc"], 106.69354549436753, atol=1e-1)

end

Expand All @@ -33,7 +33,7 @@

@test isapprox(dc_solution["gmd_bus"]["5"]["gmd_vdc"], -23.02219289879143, atol=1e-1)

@test isapprox(dc_solution["gmd_branch"]["3"]["gmd_idc"], -13.507237320660954, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["3"]["gmd_idc"], -13.507237320660954, atol=1e-1)

end

Expand All @@ -54,10 +54,10 @@
@test isapprox(dc_solution["gmd_bus"]["14"]["gmd_vdc"], 44.26301987818915, atol=1e-1)
@test isapprox(dc_solution["gmd_bus"]["17"]["gmd_vdc"], -40.6570388410749, atol=1e-1)

@test isapprox(dc_solution["gmd_branch"]["5"]["gmd_idc"], 140.6256703830644, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["13"]["gmd_idc"], 53.32820180462106, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["29"]["gmd_idc"], 177.05207951275656, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["35"]["gmd_idc"], -54.56937304382294, atol=1e1)
@test isapprox(dc_solution["gmd_branch"]["5"]["gmd_idc"], 140.6256703830644, atol=1e-1)
@test isapprox(dc_solution["gmd_branch"]["13"]["gmd_idc"], 53.32820180462106, atol=1e-1)
@test isapprox(dc_solution["gmd_branch"]["29"]["gmd_idc"], 177.05207951275656, atol=1e-1)
@test isapprox(dc_solution["gmd_branch"]["35"]["gmd_idc"], -54.56937304382294, atol=1e-1)

end

Expand Down
Loading

0 comments on commit 35bca9d

Please sign in to comment.