Skip to content

Commit

Permalink
FIX: Line lengths and units (#113)
Browse files Browse the repository at this point in the history
Fixes bug with mismatched line lengths where lengths were not getting
converted correctly. Adds unit test.
  • Loading branch information
pseudocubic authored Jan 7, 2019
1 parent 648746a commit 848b6e9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ThreePhasePowerModels.jl Change Log
===================================

### Staged
- nothing
- Minor fix to OpenDSS line parsing (length units mismatch with linecode)

### v0.1.4
- Update to PowerModels v0.9
Expand Down
19 changes: 13 additions & 6 deletions src/io/opendss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,19 @@ function dss2tppm_branch!(tppm_data::Dict, dss_data::Dict, import_all::Bool)
line = merge(find_component(dss_data, line["like"], "line"), line)
end

linecode = deepcopy(get_linecode(dss_data, get(line, "linecode", "")))
linecode["linecode"] = pop!(linecode, "name", "")
if haskey(linecode, "like")
linecode = merge(find_component(dss_data, linecode["like"], "linecode"), linecode)
end
if haskey(line, "linecode")
linecode = deepcopy(get_linecode(dss_data, get(line, "linecode", "")))
if haskey(linecode, "like")
linecode = merge(find_component(dss_data, linecode["like"], "linecode"), linecode)
end

linecode["units"] = get(line, "units", "none") == "none" ? "none" : get(linecode, "units", "none")

merge!(line, linecode)
linecode = createLinecode(get(linecode, "name", ""); to_sym_keys(linecode)...)
delete!(linecode, "name")
else
linecode = Dict{String,Any}()
end

if haskey(line, "basefreq") && line["basefreq"] != tppm_data["basefreq"]
warn(LOGGER, "basefreq=$(line["basefreq"]) on line $(line["name"]) does not match circuit basefreq=$(tppm_data["basefreq"])")
Expand All @@ -499,6 +505,7 @@ function dss2tppm_branch!(tppm_data::Dict, dss_data::Dict, import_all::Bool)
end

defaults = createLine(line["bus1"], line["bus2"], line["name"]; to_sym_keys(line)...)
merge!(defaults, linecode)

bf, nodes = parse_busname(defaults["bus1"])
bt = parse_busname(defaults["bus2"])[1]
Expand Down
1 change: 1 addition & 0 deletions test/data/opendss/test2_master.dss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ Buscoords test2_Buscoords.dss
Solve

show taps
new Line.l8 bus1=b10 bus2=b11 linecode=lc/2 units=mi length=(0.013516796 1 1.6093 / *)
25 changes: 16 additions & 9 deletions test/opendss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TESTLOG = getlogger(PowerModels)
@test length(tppm) == 18
@test length(dss) == 12

for (key, len) in zip(["bus", "load", "shunt", "branch", "gen", "dcline"], [11, 4, 5, 15, 4, 0])
for (key, len) in zip(["bus", "load", "shunt", "branch", "gen", "dcline"], [12, 4, 5, 16, 4, 0])
@test haskey(tppm, key)
@test length(tppm[key]) == len
end
Expand Down Expand Up @@ -142,20 +142,27 @@ TESTLOG = getlogger(PowerModels)
end
end

for k in keys(tppm["branch"]["15"])
for k in keys(tppm["branch"]["16"])
if !(k in ["f_bus", "t_bus", "index", "name", "linecode", "source_id", "active_phases"])
if isa(tppm["branch"]["15"][k], PMs.MultiConductorValue)
@test all(isapprox.(tppm["branch"]["14"][k].values, tppm["branch"]["15"][k].values; atol=1e-12))
@test all(isapprox.(tppm["branch"]["12"][k].values, tppm["branch"]["13"][k].values; atol=1e-12))
if isa(tppm["branch"]["16"][k], PMs.MultiConductorValue)
@test all(isapprox.(tppm["branch"]["15"][k].values, tppm["branch"]["16"][k].values; atol=1e-12))
@test all(isapprox.(tppm["branch"]["13"][k].values, tppm["branch"]["14"][k].values; atol=1e-12))
@test all(isapprox.(tppm["branch"]["3"][k].values, tppm["branch"]["8"][k].values; atol=1e-12))
else
@test all(isapprox.(tppm["branch"]["14"][k], tppm["branch"]["15"][k]; atol=1e-12))
@test all(isapprox.(tppm["branch"]["12"][k], tppm["branch"]["13"][k]; atol=1e-12))
@test all(isapprox.(tppm["branch"]["15"][k], tppm["branch"]["16"][k]; atol=1e-12))
@test all(isapprox.(tppm["branch"]["13"][k], tppm["branch"]["14"][k]; atol=1e-12))
@test all(isapprox.(tppm["branch"]["3"][k], tppm["branch"]["8"][k]; atol=1e-12))
end
end
end

@testset "length units parsing" begin
@test tppm["branch"]["9"]["length"] == 1000.0 * len
@test all(isapprox.(tppm["branch"]["9"]["br_r"].values, rmatrix * len / tppm["basekv"]^2 * tppm["baseMVA"]; atol=1e-6))
@test all(isapprox.(tppm["branch"]["9"]["br_x"].values, xmatrix * len / tppm["basekv"]^2 * tppm["baseMVA"]; atol=1e-6))
@test all(isapprox.(tppm["branch"]["9"]["b_fr"].values, diag(tppm["basekv"]^2 / tppm["baseMVA"] * 2.0 * pi * 60.0 * cmatrix * len / 1e9) / 2.0; atol=1e-6))
end

tppm2 = TPPMs.parse_file("../test/data/opendss/test_simple4.dss")
@test length(tppm2["bus"]) == 4

Expand Down Expand Up @@ -190,8 +197,8 @@ TESTLOG = getlogger(PowerModels)
@test tppm["shunt"]["4"]["source_id"] == "reactor.reactor3" && length(tppm["shunt"]["4"]["active_phases"]) == 3

@test tppm["branch"]["1"]["source_id"] == "line.l1" && length(tppm["branch"]["1"]["active_phases"]) == 3
@test tppm["branch"]["13"]["source_id"] == "transformer.t5" && length(tppm["branch"]["13"]["active_phases"]) == 3
@test tppm["branch"]["14"]["source_id"] == "reactor.reactor1" && length(tppm["branch"]["14"]["active_phases"]) == 3
@test tppm["branch"]["14"]["source_id"] == "transformer.t5" && length(tppm["branch"]["14"]["active_phases"]) == 3
@test tppm["branch"]["15"]["source_id"] == "reactor.reactor1" && length(tppm["branch"]["15"]["active_phases"]) == 3

@test tppm["gen"]["1"]["source_id"] == "vsource.sourcebus" && length(tppm["gen"]["1"]["active_phases"]) == 3
@test tppm["gen"]["2"]["source_id"] == "generator.g1" && length(tppm["gen"]["2"]["active_phases"]) == 3
Expand Down

0 comments on commit 848b6e9

Please sign in to comment.