Skip to content

Commit

Permalink
multiple sources at one bus and no other devices (#11)
Browse files Browse the repository at this point in the history
* multiple sources at one bus and no other devices

* add test for only sources
  • Loading branch information
m-bossart authored Dec 2, 2022
1 parent 54eddcb commit 293f117
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ function _power_redistribution_ref(
P_gen -= sum(PSY.get_active_power.(sources))
devices_ = setdiff(devices_, sources)
@warn "Found sources and non-source devices at the same bus. Active power re-distribution is not well defined for this case. Source active power will remain unchanged and remaining active power will be re-distributed among non-source devices."
elseif length(sources) > 1 && length(non_source_devices) == 0
Psources = sum(PSY.get_active_power.(sources))
Qsources = sum(PSY.get_reactive_power.(sources))
if isapprox(Psources, P_gen; atol=0.001) && isapprox(Qsources, Q_gen; atol=0.001)
@warn "Only sources found at reference bus --- no redistribution of active or reactive power will take place"
return
else
@warn "Total source P: $(Psources), Total source Q:$(Qsources) Bus P:$(P_gen), Bus Q:$(Q_gen)"
error("Sources do not match P and/or Q requirements for reference bus.")
end
end
if length(devices_) == 1
device = first(devices_)
Expand Down Expand Up @@ -268,6 +278,15 @@ function _reactive_power_redistribution_pv(sys::PSY.System, Q_gen::Float64, bus:
Q_gen -= sum(PSY.get_reactive_power.(sources))
devices_ = setdiff(devices_, sources)
@warn "Found sources and non-source devices at the same bus. Reactive power re-distribution is not well defined for this case. Source reactive power will remain unchanged and remaining reactive power will be re-distributed among non-source devices."
elseif length(sources) > 1 && length(non_source_devices) == 0
Qsources = sum(PSY.get_active_power.(sources))
if isapprox(Qsources, Q_gen; atol=0.001)
@warn "Only sources found at PV bus --- no redistribution of reactive power will take place"
return
else
@warn "Total source Q:$(Qsources), Bus Q:$(Q_gen)"
error("Sources do not match Q requirements for PV bus.")
end
end
if length(devices_) == 1
@debug "Only one generator in the bus"
Expand Down
42 changes: 42 additions & 0 deletions test/test_powerflow_with_sources.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@testset "Powerflow with multiple sources at bus" begin
sys = System(100.0)
b = Bus(
number=1,
name="01",
bustype=BusTypes.REF,
angle=0.0,
magnitude=1.1,
voltage_limits=(0.0, 2.0),
base_voltage=230,
)
add_component!(sys, b)

#Test two sources with equal and opposite P and Q
s1 = Source(
name="source_1",
available=true,
bus=b,
active_power=0.5,
reactive_power=0.1,
R_th=1e-5,
X_th=1e-5,
)
add_component!(sys, s1)
s2 = Source(
name="source_2",
available=true,
bus=b,
active_power=-0.5,
reactive_power=-0.1,
R_th=1e-5,
X_th=1e-5,
)
add_component!(sys, s2)
@test run_powerflow!(sys, finite_diff=true)

#Create power mismatch, test for error
set_active_power!(get_component(Source, sys, "source_1"), -0.4)
@test_throws ErrorException(
"Sources do not match P and/or Q requirements for reference bus.",
) run_powerflow!(sys, finite_diff=true)
end

0 comments on commit 293f117

Please sign in to comment.