Skip to content

Commit 0fbf5f7

Browse files
committed
FIX: apply_voltage_bounds! for multinetwork data
Creates the following functions to separate out the functionality for ENGINEERING vs MATHEMATICAL data models - discover_math_voltage_zones - discover_eng_voltage_zones - calc_math_voltage_bases - calc_eng_voltage_bases Fixes #388
1 parent 1ef95d0 commit 0fbf5f7

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## staged
44

5+
- Fixed bug in `apply_voltage_bounds!` for multinetwork data
56
- Added compat for JuMP v1
67
- Fixed bug in `_map_eng2math` where global keys were not being propagated in multinetwork
78
- Fixed bug/typo in `_create_storage` where `kwhstored` was derived from `:stored` instead of `Symbol("%stored")`

src/data_model/transformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ end
166166
add voltage bounds to all buses based on per-unit upper (`vm_ub`) and lower (`vm_lb`), scaled by the bus's voltage based
167167
"""
168168
function _apply_voltage_bounds!(data_eng::Dict{String,<:Any}; vm_lb::Union{Real,Missing}=0.9, vm_ub::Union{Real,Missing}=1.1, exclude::Vector{String}=!isempty(get(data_eng, "voltage_source", Dict())) ? String[x.second["bus"] for x in data_eng["voltage_source"]] : String[])
169-
(bus_vbases, edge_vbases) = calc_voltage_bases(data_eng, data_eng["settings"]["vbases_default"])
169+
(bus_vbases, _) = calc_eng_voltage_bases(data_eng, data_eng["settings"]["vbases_default"])
170170
for (id, bus) in filter(x->!(x.first in exclude), get(data_eng, "bus", Dict{String,Any}()))
171171
vbase = bus_vbases[id]
172172
if !ismissing(vm_lb) && !ismissing(vbase)

src/data_model/units.jl

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,37 @@ end
107107
"""
108108
discover_voltage_zones(data_model::Dict{String,<:Any})::Dict{Int,Set{Any}}
109109
110-
finds voltage zones by walking through the network and analyzing the transformers
110+
finds voltage zones by walking through the network and analyzing the transformers, attempting to decern the type of `data_model`
111111
"""
112112
function discover_voltage_zones(data_model::Dict{String,<:Any})::Dict{Int,Set{Any}}
113113
@assert iseng(data_model) || ismath(data_model) "unsupported data model"
114-
edge_elements = ismath(data_model) ? _math_edge_elements : _eng_edge_elements
115114

115+
return ismath(data_model) ? discover_math_voltage_zones(data_model) : discover_eng_voltage_zones(data_model)
116+
end
117+
118+
119+
"""
120+
discover_math_voltage_zones(data_model::Dict{String,<:Any})::Dict{Int,Set{Any}}
121+
122+
finds voltage zones by walking through the network and analyzing the transformers for a MATHEMATICAL `data_model`
123+
"""
124+
discover_math_voltage_zones(data_model::Dict{String,Any})::Dict{Int,Set{Any}} = _discover_voltage_zones(data_model, _math_edge_elements)
125+
126+
127+
"""
128+
discover_voltage_zones(data_model::Dict{String,<:Any})::Dict{Int,Set{Any}}
129+
130+
finds voltage zones by walking through the network and analyzing the transformers for a ENGINEERING `data_model`
131+
"""
132+
discover_eng_voltage_zones(data_model::Dict{String,Any})::Dict{Int,Set{Any}} = _discover_voltage_zones(data_model, _eng_edge_elements)
133+
134+
135+
"""
136+
discover_voltage_zones(data_model::Dict{String,<:Any}, edge_elements::Vector{String})::Dict{Int,Set{Any}}
137+
138+
finds voltage zones by walking through the network and analyzing the transformers
139+
"""
140+
function _discover_voltage_zones(data_model::Dict{String,<:Any}, edge_elements::Vector{String})::Dict{Int,Set{Any}}
116141
unused_components = Set("$comp_type.$id" for comp_type in edge_elements[edge_elements .!= "transformer"] for id in keys(get(data_model, comp_type, Dict())))
117142
bus_connectors = Dict([(id,Set()) for id in keys(get(data_model, "bus", Dict()))])
118143
for comp_type in edge_elements[edge_elements .!= "transformer"]
@@ -147,15 +172,40 @@ function discover_voltage_zones(data_model::Dict{String,<:Any})::Dict{Int,Set{An
147172
return zones
148173
end
149174

175+
"""
176+
calc_math_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict}
177+
178+
Calculates voltage bases for each voltage zone for buses and branches for a MATHEMATICAL `data_model`
179+
"""
180+
calc_math_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict} = _calc_voltage_bases(data_model, vbase_sources, _math_edge_elements)
181+
182+
183+
"""
184+
calc_eng_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict}
185+
186+
Calculates voltage bases for each voltage zone for buses and branches for a ENGINEERING `data_model`
187+
"""
188+
calc_eng_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict} = _calc_voltage_bases(data_model, vbase_sources, _eng_edge_elements)
189+
150190

151191
"""
152192
calc_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict}
153193
154-
Calculates voltage bases for each voltage zone for buses and branches
194+
Calculates voltage bases for each voltage zone for buses and branches, attempting to automatically decern the `data_model` type
155195
"""
156196
function calc_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real})::Tuple{Dict,Dict}
197+
return ismath(data_model) ? calc_math_voltage_bases(data_model, vbase_sources) : calc_eng_voltage_bases(data_model, vbase_sources)
198+
end
199+
200+
201+
"""
202+
_calc_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real}, edge_elements::Vector{String})::Tuple{Dict,Dict}
203+
204+
Calculates voltage bases for each voltage zone for buses and branches given a list of `edge_elements`
205+
"""
206+
function _calc_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{String,<:Real}, edge_elements::Vector{String})::Tuple{Dict,Dict}
157207
# find zones of buses connected by lines
158-
zones = discover_voltage_zones(data_model)
208+
zones = _discover_voltage_zones(data_model, edge_elements)
159209
bus_to_zone = Dict([(bus,zone) for (zone, buses) in zones for bus in buses])
160210

161211
# assign specified vbase to corresponding zones
@@ -214,10 +264,9 @@ function calc_voltage_bases(data_model::Dict{String,<:Any}, vbase_sources::Dict{
214264
end
215265
end
216266

217-
edge_elements = ismath(data_model) ? _math_edge_elements : _eng_edge_elements
218-
219267
bus_vbase = Dict([(bus,zone_vbase[zone]) for (bus,zone) in bus_to_zone])
220268
edge_vbase = Dict([("$edge_type.$id", bus_vbase["$(obj["f_bus"])"]) for edge_type in edge_elements[edge_elements .!= "transformer"] if haskey(data_model, edge_type) for (id,obj) in data_model[edge_type]])
269+
221270
return (bus_vbase, edge_vbase)
222271
end
223272

test/multinetwork.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77

88
@test result_mn["termination_status"] == LOCALLY_SOLVED
99
end
10+
11+
@testset "apply_voltage_bounds! to multinetworks" begin
12+
mn_eng = make_multinetwork(case3_balanced)
13+
14+
apply_voltage_bounds!(mn_eng)
15+
for (n,nw) in mn_eng["nw"]
16+
vbases, _ = calc_eng_voltage_bases(mn_eng["nw"]["1"], mn_eng["nw"]["1"]["settings"]["vbases_default"])
17+
18+
@test all(all(isapprox.(bus["vm_ub"][filter(x->xbus["grounded"],bus["terminals"])]/vbases[id], 1.1; atol=1e-6)) for (id,bus) in filter(x->x.first!="sourcebus",nw["bus"]))
19+
@test all(all(isapprox.(bus["vm_lb"][filter(x->xbus["grounded"],bus["terminals"])]/vbases[id], 0.9; atol=1e-6)) for (id,bus) in filter(x->x.first!="sourcebus",nw["bus"]))
20+
end
21+
end
1022
end

0 commit comments

Comments
 (0)