Skip to content

Commit

Permalink
Modify PowerFlowData constructors given new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Jan 14, 2025
1 parent bc6c9c8 commit 3ad7195
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
25 changes: 17 additions & 8 deletions src/PowerFlowData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ flows and angles, as well as these ones.
- `bus_angles::Matrix{Float64}`:
"(b, t)" matrix containing the bus angles, ordered according to
"bus_lookup". b: number of buses, t: number of time period.
- `branch_activepower_flow_values::Matrix{Float64}`:
"(br, t)" matrix containing the active power flows, ordered according to
"branch_lookup". br: number of branches, t: number of time period.
- `branch_reactivepower_flow_values::Matrix{Float64}`:
"(br, t)" matrix containing the reactive power flows, ordered according to
"branch_lookup". br: number of branches, t: number of time period.
- `branch_activepower_flow_from_to::Matrix{Float64}`:
"(br, t)" matrix containing the active power flows measured at the `from` bus,
ordered according to "branch_lookup". br: number of branches, t: number of time
period.
- `branch_reactivepower_flow_from_to::Matrix{Float64}`:
"(br, t)" matrix containing the reactive power flows measured at the `from` bus,
ordered according to "branch_lookup". br: number of branches, t: number of time
period.
- `branch_activepower_flow_to_from::Matrix{Float64}`:
"(br, t)" matrix containing the active power flows measured at the `to` bus, ordered
according to "branch_lookup". br: number of branches, t: number of time period.
- `branch_reactivepower_flow_to_from::Matrix{Float64}`:
"(br, t)" matrix containing the reactive power flows measured at the `to` bus,
ordered according to "branch_lookup". br: number of branches, t: number of time
period.
- `timestep_map::Dict{Int, S}`:
dictonary mapping the number of the time periods (corresponding to the
column number of the previosly mentioned matrices) and their names.
Expand Down Expand Up @@ -84,10 +93,10 @@ struct PowerFlowData{
branch_type::Vector{DataType}
bus_magnitude::Matrix{Float64}
bus_angles::Matrix{Float64}
branch_activepower_flow_to_from::Matrix{Float64}
branch_reactivepower_flow_to_from::Matrix{Float64}
branch_activepower_flow_from_to::Matrix{Float64}
branch_reactivepower_flow_from_to::Matrix{Float64}
branch_activepower_flow_to_from::Matrix{Float64}
branch_reactivepower_flow_to_from::Matrix{Float64}
timestep_map::Dict{Int, String}
valid_ix::Vector{Int}
power_network_matrix::M
Expand Down
55 changes: 34 additions & 21 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function make_dc_powerflowdata(
temp_bus_map,
valid_ix,
)
branch_types = Vector{DataType}(undef, length(branch_lookup))
branch_type = Vector{DataType}(undef, length(branch_lookup))
for (ix, b) in enumerate(PNM.get_ac_branches(sys))
branch_types[ix] = typeof(b)
branch_type[ix] = typeof(b)
end
bus_reactivepower_bounds = Vector{Vector{Float64}}()
timestep_map = Dict(zip([i for i in 1:time_steps], timestep_names))
Expand All @@ -135,7 +135,7 @@ function make_dc_powerflowdata(
bus_lookup,
branch_lookup,
temp_bus_map,
branch_types,
branch_type,
bus_reactivepower_bounds,
timestep_map,
valid_ix,
Expand All @@ -153,7 +153,7 @@ function make_powerflowdata(
bus_lookup,
branch_lookup,
temp_bus_map,
branch_types,
branch_type,
bus_reactivepower_bounds,
timestep_map,
valid_ix,
Expand Down Expand Up @@ -192,27 +192,37 @@ function make_powerflowdata(
sys,
)

# initialize data
init_1 = zeros(n_buses, time_steps)
init_2 = zeros(n_branches, time_steps)
# Shapes to reuse
zeros_bus_time = () -> zeros(n_buses, time_steps)
zeros_branch_time = () -> zeros(n_branches, time_steps)

# define fields as matrices whose number of columns is eqault to the number of time_steps
bus_activepower_injection_1 = deepcopy(init_1)
bus_reactivepower_injection_1 = deepcopy(init_1)
bus_activepower_withdrawals_1 = deepcopy(init_1)
bus_reactivepower_withdrawals_1 = deepcopy(init_1)
bus_magnitude_1 = deepcopy(init_1)
bus_angles_1 = deepcopy(init_1)
branch_flow_values_1 = deepcopy(init_2)
# Define fields as matrices whose number of columns is equal to the number of time_steps
bus_activepower_injection_1 = zeros_bus_time()
bus_reactivepower_injection_1 = zeros_bus_time()
bus_activepower_withdrawals_1 = zeros_bus_time()
bus_reactivepower_withdrawals_1 = zeros_bus_time()
bus_reactivepower_bounds_1 = Matrix{Vector{Float64}}(undef, n_buses, time_steps)
bus_magnitude_1 = zeros_bus_time()
bus_angles_1 = zeros_bus_time()

# initial values related to first timestep allocated in the first column
# Initial values related to first timestep allocated in the first column
bus_activepower_injection_1[:, 1] .= bus_activepower_injection
bus_reactivepower_injection_1[:, 1] .= bus_reactivepower_injection
bus_activepower_withdrawals_1[:, 1] .= bus_activepower_withdrawals
bus_reactivepower_withdrawals_1[:, 1] .= bus_reactivepower_withdrawals
bus_reactivepower_bounds_1[:, 1] .= bus_reactivepower_bounds
bus_magnitude_1[:, 1] .= bus_magnitude
bus_angles_1[:, 1] .= bus_angles
branch_flow_values_1[:, 1] .= zeros(n_branches)

# Initial bus types are same for every time period
bus_type_1 = repeat(bus_type; outer = [1, time_steps])
@assert size(bus_type_1) == (n_buses, time_steps)

# Initial flows are all zero
branch_activepower_flow_from_to = zeros_branch_time()
branch_reactivepower_flow_from_to = zeros_branch_time()
branch_activepower_flow_to_from = zeros_branch_time()
branch_reactivepower_flow_to_from = zeros_branch_time()

return PowerFlowData(
bus_lookup,
Expand All @@ -221,12 +231,15 @@ function make_powerflowdata(
bus_reactivepower_injection_1,
bus_activepower_withdrawals_1,
bus_reactivepower_withdrawals_1,
bus_reactivepower_bounds,
bus_type,
branch_types,
bus_reactivepower_bounds_1,
bus_type_1,
branch_type,
bus_magnitude_1,
bus_angles_1,
branch_flow_values_1,
branch_activepower_flow_from_to,
branch_reactivepower_flow_from_to,
branch_activepower_flow_to_from,
branch_reactivepower_flow_to_from,
timestep_map,
valid_ix,
power_network_matrix,
Expand Down

0 comments on commit 3ad7195

Please sign in to comment.