Skip to content

Commit

Permalink
add connected_busses, sj, and sj_per_unit methods
Browse files Browse the repository at this point in the history
supporting single phase unrelaxed BIM
  • Loading branch information
NLaws committed Nov 16, 2024
1 parent 4e8f5af commit 5560c4b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
17 changes: 11 additions & 6 deletions src/CommonOPF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export
MultiPhaseVariableContainerType,
check_paths_for_loads,
info_max_rpu_xpu,
info_max_Ppu_Qpu,

# graphs
make_graph,
Expand Down Expand Up @@ -75,26 +74,32 @@ export
combine_parallel_lines!,
trim_above_bus!,

# attributes of the Network
edges,
busses,
connected_busses,
leaf_busses,
phases_into_bus,
i_to_j,
j_to_k,
phases_into_bus,
kron_reduce,

info_max_Ppu_Qpu,
leaf_busses,
get_variable_values,
Network,
edges,
busses,
conductors,
conductors_with_attribute_value,
load_busses,
voltage_regulator_edges,
is_connected,

# loads
load_busses,
real_load_busses,
reactive_load_busses,
total_load_kw,
total_load_kvar,
sj,
sj_per_unit,

# test Networks
Network_IEEE13_SinglePhase,
Expand Down
10 changes: 10 additions & 0 deletions src/busses/busses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ end
The default action after build_busses.
"""
check_busses!(busses::AbstractVector{<:AbstractBus}) = nothing


"""
connected_busses(j::String, net::Network)::AbstractVector{String}
Return a vector of all the busses connected to bus `j`.
"""
function connected_busses(j::String, net::Network)::AbstractVector{String}
vcat(i_to_j(j, net), j_to_k(j, net))
end
27 changes: 27 additions & 0 deletions src/busses/loads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,30 @@ total_load_kw(net::Network{SinglePhase}) = sum(net[load_bus][:Load].kws1 for loa


total_load_kvar(net::Network{SinglePhase}) = sum(net[load_bus][:Load].kvars1 for load_bus in real_load_busses(net))


"""
sj(j::String, net::Network{SinglePhase})::AbstractVector{ComplexF64}
Return the complex power injections (negative of load) at bus `j` in kW / kVaR.
"""
function sj(j::String, net::Network{SinglePhase})::AbstractVector{ComplexF64}
pj, qj = 0.0, 0.0
if j in real_load_busses(net)
pj = -net[j][:Load].kws1
end
if j in reactive_load_busses(net)
qj = -net[j][:Load].kvars1
end
return pj + im * qj
end


"""
sj_per_unit(j::String, net::Network{SinglePhase})::AbstractVector{ComplexF64}
Return the complex power injections (negative of load) at bus `j` per-unit power.
"""
function sj_per_unit(j::String, net::Network{SinglePhase})::AbstractVector{ComplexF64}
return sj(j, net) * 1e3 / net.Sbase
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ with_logger(test_logger) do

include("test_io.jl")

include("test_loads.jl")

include("test_network_reduction.jl")

include("test_network.jl")
Expand Down
32 changes: 8 additions & 24 deletions test/test_busses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,18 @@ end
@test length(concrete_test_busses) == length(bus_dicts)
# end

@testset "Load" begin
bad_load = CommonOPF.Load(; bus="bname") # no load defined
# a warning should be logged about removing bad_load
loads = CommonOPF.Load[bad_load]
clear_log!(test_logger)
CommonOPF.check_busses!(loads)
@test occursin("has been removed", test_logger.logs[end].message)
@test isempty(loads)

# test fill_load
load = CommonOPF.Load(;
bus="bname",
q_to_p=0.1,
kws1=[10],
kws2=[20],
kws3=[30],
)
CommonOPF.fill_load!(load)
@test load.kvars1 == [1]
@test load.kvars2 == [2]
@test load.kvars3 == [3]
end


@testset "ShuntAdmittance" begin
shunt = CommonOPF.ShuntAdmittance(;
bus="b",
g=1,
b=1.1,
)
end
end


@testset "connected_busses" begin
net = Network_IEEE13_SinglePhase()
expected_busses = ["670", "680", "684", "692"]
@test sort(connected_busses("671", net)) == sort(expected_busses)
end
30 changes: 30 additions & 0 deletions test/test_loads.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@testset "Load struct" begin
bad_load = CommonOPF.Load(; bus="bname") # no load defined
# a warning should be logged about removing bad_load
loads = CommonOPF.Load[bad_load]
clear_log!(test_logger)
CommonOPF.check_busses!(loads)
@test occursin("has been removed", test_logger.logs[end].message)
@test isempty(loads)

# test fill_load
load = CommonOPF.Load(;
bus="bname",
q_to_p=0.1,
kws1=[10],
kws2=[20],
kws3=[30],
)
CommonOPF.fill_load!(load)
@test load.kvars1 == [1]
@test load.kvars2 == [2]
@test load.kvars3 == [3]
end


@testset "sj power getters" begin
net = Network_IEEE13_SinglePhase()
net.Sbase = 1e6
@test sj("634", net) [-133.33 + -im*96.67]
@test sj_per_unit("634", net) [-133.33 + -im*96.67] / 1e3
end

0 comments on commit 5560c4b

Please sign in to comment.