Skip to content

Commit

Permalink
FIX: switch line parameters
Browse files Browse the repository at this point in the history
Native PF assumes no virtual branches in the MATHEMATICAL model, so we removed the line loss parameters after parse in the tests.

Also, according to documentation, switch=y has the effect of x1=1, x0=1, r1=1, r0=1, c1=1.1, c0=1, length=0.001, units=none, so the parser was updated to correct this.
  • Loading branch information
pseudocubic committed Oct 31, 2023
1 parent c28ec19 commit 011e98f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## staged

- Fixed bug in parsing of dss lines where `switch=y`
- Fixed bug in `DssLine` parser where `c1` was being set to `c0`
- Fixed native pf unit tests, which assume no virtual branches from switches (applied `make_lossless!` before test)
- Added `g_fr`, `g_to`, `b_fr`, `b_to` to switches in `dss2eng` and `eng2math`
- Fixed bug in parsing of dss lines where `switch=y` actually implies `x1=1`, `x0=1`, `r1=1`, `r0=1`, `c1=1.1`, `c0=1`, `length=0.001`, and `units=none`

## v0.15.1

Expand Down
44 changes: 22 additions & 22 deletions src/data_model/dss/edge_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ OpenDSS documentation for valid fields and ways to specify the different
properties.
"""
function create_dss_object(::Type{T}, property_pairs::Vector{Pair{String,String}}, dss::OpenDssDataModel, dss_raw::OpenDssRawDataModel)::T where T <: DssLine
for (i,(field,value)) in enumerate(collect(property_pairs))
if field == "switch" && parse(Bool, startswith("y", value) ? "true" : "false")
for item in reverse(["r1"=>"1","x1"=>"1","r0"=>"1","x0"=>"1","c1"=>"1.1","c0"=>"1","length"=>"0.001","units"=>"none"])
insert!(property_pairs, i+1, item)
end
end
end
@warn property_pairs
raw_fields = _get_raw_fields(property_pairs)

line = _apply_property_pairs(T(), property_pairs, dss, dss_raw)
Expand All @@ -41,7 +49,7 @@ function create_dss_object(::Type{T}, property_pairs::Vector{Pair{String,String}
if line.phases == 1
line.r0 = line.r1
line.x0 = line.x1
line.c0 = line.c1
line.c0 = line.c0
line.b0 = line.b1
else
if :b0 raw_fields
Expand Down Expand Up @@ -90,27 +98,19 @@ function create_dss_object(::Type{T}, property_pairs::Vector{Pair{String,String}
line.xmatrix .-= xgmod
line.xmatrix .*= lenmult * (line.basefreq / circuit_basefreq)

if !line.switch
line.r1 = line.r1 / _convert_to_meters[line.units]
line.x1 = line.x1 / _convert_to_meters[line.units]
line.r0 = line.r0 / _convert_to_meters[line.units]
line.x0 = line.x0 / _convert_to_meters[line.units]
line.c1 = line.c1 / _convert_to_meters[line.units]
line.c0 = line.c0 / _convert_to_meters[line.units]
line.rmatrix = line.rmatrix / _convert_to_meters[line.units]
line.xmatrix = line.xmatrix / _convert_to_meters[line.units]
line.cmatrix = line.cmatrix / _convert_to_meters[line.units]
line.b1 = line.b1 / _convert_to_meters[line.units]
line.b0 = line.b0 / _convert_to_meters[line.units]
line.length = line.length * _convert_to_meters[line.units]
line.units = "m"
else
# TODO: bug in DSS?
line.b1 = line.b1 / _convert_to_meters[line.units]
line.b0 = line.b0 / _convert_to_meters[line.units]
line.length = 0.001
line.units = "none"
end
line.r1 = line.r1 / _convert_to_meters[line.units]
line.x1 = line.x1 / _convert_to_meters[line.units]
line.r0 = line.r0 / _convert_to_meters[line.units]
line.x0 = line.x0 / _convert_to_meters[line.units]
line.c1 = line.c1 / _convert_to_meters[line.units]
line.c0 = line.c0 / _convert_to_meters[line.units]
line.rmatrix = line.rmatrix / _convert_to_meters[line.units]
line.xmatrix = line.xmatrix / _convert_to_meters[line.units]
line.cmatrix = line.cmatrix / _convert_to_meters[line.units]
line.b1 = line.b1 / _convert_to_meters[line.units]
line.b0 = line.b0 / _convert_to_meters[line.units]
line.length = line.length * _convert_to_meters[line.units]
line.units = "m"

return line
end
Expand Down
4 changes: 0 additions & 4 deletions src/data_model/transformations/dss2eng.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,6 @@ function _dss2eng_line!(data_eng::Dict{String,<:Any}, data_dss::OpenDssDataModel
eng_obj["state"] = CLOSED
eng_obj["dispatchable"] = YES

for key in ["g_fr", "b_fr", "g_to", "b_to"]
delete!(eng_obj, key)
end

_add_eng_obj!(data_eng, "switch", id, eng_obj)
else
_add_eng_obj!(data_eng, "line", id, eng_obj)
Expand Down
8 changes: 4 additions & 4 deletions src/data_model/transformations/eng2math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ function _map_eng2math_switch!(data_math::Dict{String,<:Any}, data_eng::Dict{Str
"t_connections" => eng_obj["t_connections"], # should be identical to the switch's to-side connections
"br_r" => _impedance_conversion(data_eng, eng_obj, "rs"),
"br_x" => _impedance_conversion(data_eng, eng_obj, "xs"),
"g_fr" => zeros(nphases, nphases),
"g_to" => zeros(nphases, nphases),
"b_fr" => zeros(nphases, nphases),
"b_to" => zeros(nphases, nphases),
"g_fr" => _admittance_conversion(data_eng, eng_obj, "g_fr"),
"g_to" => _admittance_conversion(data_eng, eng_obj, "g_to"),
"b_fr" => _admittance_conversion(data_eng, eng_obj, "b_fr"),
"b_to" => _admittance_conversion(data_eng, eng_obj, "b_to"),
"angmin" => fill(-10.0, nphases),
"angmax" => fill( 10.0, nphases),
"c_rating_a" => fill(Inf, nphases),
Expand Down
1 change: 1 addition & 0 deletions test/en_pf_native_validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ filter!(e -> e ≠ "case3_balanced_battery_3ph", cases)
case_path = "$data_dir/$case.dss"

data_eng = parse_file(case_path, transformations=[transform_loops!])
make_lossless!(data_eng; exclude=collect(filter(x->x!="switch",keys(PowerModelsDistribution._loss_model_objects))))

data_math = transform_data_model(data_eng; kron_reduce=false)

Expand Down
2 changes: 1 addition & 1 deletion test/opf_bf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

vbase = case3_unbalanced_switch["settings"]["vbases_default"]["sourcebus"]
@test all(isapprox.(result["solution"]["bus"]["loadbus"]["vm"] ./ vbase, [0.98102, 0.98922, 0.98692]; atol=9e-2))
@test all(isapprox.(result["solution"]["bus"]["loadbus"]["va"], [-0.2, -120.1, 120.1]; atol=3e-2))
@test all(isapprox.(result["solution"]["bus"]["loadbus"]["va"], [-0.2312, -120.1135, 120.1174]; atol=3e-2))
end

@testset "3-bus unbalanced fbs opf_bf with yy transformer" begin
Expand Down

0 comments on commit 011e98f

Please sign in to comment.