Skip to content

Commit

Permalink
add bus_size to DW
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bossart committed Dec 15, 2023
1 parent faf0f99 commit 2e8b6f4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/base/device_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct DynamicWrapper{T <: PSY.DynamicInjection}
ix_range::Vector{Int}
ode_range::Vector{Int}
bus_ix::Int
bus_size::Int
global_index::Base.ImmutableDict{Symbol, Int}
component_state_mapping::Base.ImmutableDict{Int, Vector{Int}}
input_port_mapping::Base.ImmutableDict{Int, Vector{Int}}
Expand All @@ -65,6 +66,7 @@ struct DynamicWrapper{T <: PSY.DynamicInjection}
ix_range,
ode_range,
bus_ix::Int,
bus_size::Int,
global_index::Base.ImmutableDict{Symbol, Int},
component_state_mapping::Base.ImmutableDict{Int, Vector{Int}},
input_port_mapping::Base.ImmutableDict{Int, Vector{Int}},
Expand All @@ -87,6 +89,7 @@ struct DynamicWrapper{T <: PSY.DynamicInjection}
Vector{Int}(ix_range),
Vector{Int}(ode_range),
bus_ix,
bus_size,
global_index,
component_state_mapping,
input_port_mapping,
Expand Down Expand Up @@ -119,6 +122,7 @@ function DynamicWrapper(
device::T,
dynamic_device::D,
bus_ix::Int,
bus_size::Int,
ix_range,
ode_range,
inner_var_range,
Expand Down Expand Up @@ -152,6 +156,7 @@ function DynamicWrapper(
ix_range,
ode_range,
bus_ix,
bus_size,
Base.ImmutableDict(
sort!(device_states .=> ix_range; by = x -> x.second, rev = true)...,
),
Expand All @@ -173,6 +178,7 @@ function DynamicWrapper(
device::PSY.ThermalStandard,
dynamic_device::PSY.AggregateDistributedGenerationA,
bus_ix::Int,
bus_size::Int,
ix_range,
ode_range,
inner_var_range,
Expand Down Expand Up @@ -200,6 +206,7 @@ function DynamicWrapper(
ix_range,
ode_range,
bus_ix,
bus_size,
Base.ImmutableDict(
sort!(device_states .=> ix_range; by = x -> x.second, rev = true)...,
),
Expand All @@ -221,6 +228,7 @@ function DynamicWrapper(
device::PSY.Source,
dynamic_device::D,
bus_ix::Int,
bus_size::Int,
ix_range,
ode_range,
inner_var_range,
Expand All @@ -246,6 +254,7 @@ function DynamicWrapper(
collect(ix_range),
collect(ode_range),
bus_ix,
bus_size,
Base.ImmutableDict(Dict(device_states .=> ix_range)...),
Base.ImmutableDict{Int, Vector{Int}}(),
Base.ImmutableDict{Int, Vector{Int}}(),
Expand Down
3 changes: 2 additions & 1 deletion src/base/simulation_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function _wrap_dynamic_injector_data(sys::PSY.System, lookup, injection_start::I
inner_vars_count = 1
sys_base_power = PSY.get_base_power(sys)
sys_base_freq = PSY.get_frequency(sys)
bus_size = get_n_buses(sys)
@assert !isempty(injector_data)
for (ix, device) in enumerate(injector_data)
@debug "Wrapping $(PSY.get_name(device))"
Expand All @@ -181,11 +182,11 @@ function _wrap_dynamic_injector_data(sys::PSY.System, lookup, injection_start::I
@debug "ix_range=$ix_range ode_range=$ode_range inner_vars_range= $inner_vars_range"
dynamic_device = PSY.get_dynamic_injector(device)
@assert dynamic_device !== nothing
#TODO - add bus_size to the dynamic injector -- allows you to index into the voltages.
wrapped_injector[ix] = DynamicWrapper(
device,
dynamic_device,
bus_ix,
bus_size,
ix_range,
ode_range,
inner_vars_range,
Expand Down
2 changes: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Revise
using PlotlyJS
using PowerSimulationsDynamics
using PowerSystems
using Test
Expand Down
26 changes: 13 additions & 13 deletions test/test_case57_degov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ csv_file_degov_delay_speed =
@test LinearAlgebra.norm(ω_pw_delay - ω_psid_delay, Inf) <= 3.1e-5

#Plotting for debug (add PlotlyJS):
#= t1 = PlotlyJS.scatter(; x = t_pw, y = ω_pw_nodelay, name = "speed-pw -- no delay")
t2 = PlotlyJS.scatter(;
x = t_psid,
y = ω_psid_nodelay,
name = "speed-psid -- no delay",
)
t3 = PlotlyJS.scatter(; x = t_pw, y = ω_pw_delay, name = "speed-pw -- 1s delay")
t4 = PlotlyJS.scatter(;
x = t_psid,
y = ω_psid_delay,
name = "speed-psid -- 1s delay",
)
display(PlotlyJS.plot([t1, t2, t3, t4])) =#
#= t1 = PlotlyJS.scatter(; x = t_pw, y = ω_pw_nodelay, name = "speed-pw -- no delay")
t2 = PlotlyJS.scatter(;
x = t_psid,
y = ω_psid_nodelay,
name = "speed-psid -- no delay",
)
t3 = PlotlyJS.scatter(; x = t_pw, y = ω_pw_delay, name = "speed-pw -- 1s delay")
t4 = PlotlyJS.scatter(;
x = t_psid,
y = ω_psid_delay,
name = "speed-psid -- 1s delay",
)
display(PlotlyJS.plot([t1, t2, t3, t4])) =#

finally
@info("removing test files")
Expand Down

0 comments on commit 2e8b6f4

Please sign in to comment.