Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nr_pf_solver #54

Merged
merged 24 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
Expand All @@ -22,6 +23,7 @@ DataStructures = "0.18"
Dates = "1"
InfrastructureSystems = "2"
JSON3 = "1"
KLU = "0.6.0"
rbolgaryn marked this conversation as resolved.
Show resolved Hide resolved
LinearAlgebra = "1"
Logging = "1"
NLsolve = "4"
Expand Down
60 changes: 30 additions & 30 deletions src/PowerFlowData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ flows and angles, as well as these ones.
- `neighbors::Vector{Set{Int}}`: Vector with the sets of adjacent buses.
"""
struct PowerFlowData{
M <: PNM.PowerNetworkMatrix,
N <: Union{PNM.PowerNetworkMatrix, Nothing},
M<:PNM.PowerNetworkMatrix,
N<:Union{PNM.PowerNetworkMatrix,Nothing},
} <: PowerFlowContainer
bus_lookup::Dict{Int, Int}
branch_lookup::Dict{String, Int}
bus_lookup::Dict{Int,Int}
branch_lookup::Dict{String,Int}
bus_activepower_injection::Matrix{Float64}
bus_reactivepower_injection::Matrix{Float64}
bus_activepower_withdrawals::Matrix{Float64}
Expand All @@ -81,7 +81,7 @@ struct PowerFlowData{
bus_magnitude::Matrix{Float64}
bus_angles::Matrix{Float64}
branch_flow_values::Matrix{Float64}
timestep_map::Dict{Int, String}
timestep_map::Dict{Int,String}
valid_ix::Vector{Int}
power_network_matrix::M
aux_network_matrix::N
Expand Down Expand Up @@ -119,8 +119,8 @@ end
# TODO -> MULTI PERIOD: AC Power Flow Data
function _calculate_neighbors(
Yb::PNM.Ybus{
Tuple{Vector{Int64}, Vector{Int64}},
Tuple{Dict{Int64, Int64}, Dict{Int64, Int64}},
Tuple{Vector{Int64},Vector{Int64}},
Tuple{Dict{Int64,Int64},Dict{Int64,Int64}},
},
)
I, J, V = SparseArrays.findnz(Yb.data)
Expand Down Expand Up @@ -157,11 +157,11 @@ NOTE: use it for AC power flow computations.
WARNING: functions for the evaluation of the multi-period AC PF still to be implemented.
"""
function PowerFlowData(
::ACPowerFlow,
::Union{NLSolveACPowerFlow,KLUACPowerFlow},
sys::PSY.System;
time_steps::Int = 1,
timestep_names::Vector{String} = String[],
check_connectivity::Bool = true)
time_steps::Int=1,
timestep_names::Vector{String}=String[],
check_connectivity::Bool=true)

# assign timestep_names
# timestep names are then allocated in a dictionary to map matrix columns
Expand All @@ -174,7 +174,7 @@ function PowerFlowData(
end

# get data for calculations
power_network_matrix = PNM.Ybus(sys; check_connectivity = check_connectivity)
power_network_matrix = PNM.Ybus(sys; check_connectivity=check_connectivity)

# get number of buses and branches
n_buses = length(axes(power_network_matrix, 1))
Expand All @@ -185,8 +185,8 @@ function PowerFlowData(
n_branches = length(branches)

bus_lookup = power_network_matrix.lookup[2]
branch_lookup = Dict{String, Int}()
temp_bus_map = Dict{Int, String}(
branch_lookup = Dict{String,Int}()
temp_bus_map = Dict{Int,String}(
PSY.get_number(b) => PSY.get_name(b) for b in PSY.get_components(PSY.Bus, sys)
)
branch_types = Vector{DataType}(undef, n_branches)
Expand Down Expand Up @@ -250,9 +250,9 @@ NOTE: use it for DC power flow computations.
function PowerFlowData(
::DCPowerFlow,
sys::PSY.System;
time_steps::Int = 1,
timestep_names::Vector{String} = String[],
check_connectivity::Bool = true)
time_steps::Int=1,
timestep_names::Vector{String}=String[],
check_connectivity::Bool=true)

# assign timestep_names
# timestep names are then allocated in a dictionary to map matrix columns
Expand All @@ -263,7 +263,7 @@ function PowerFlowData(
end

# get the network matrices
power_network_matrix = PNM.ABA_Matrix(sys; factorize = true)
power_network_matrix = PNM.ABA_Matrix(sys; factorize=true)
aux_network_matrix = PNM.BA_Matrix(sys)

# get number of buses and branches
Expand All @@ -272,7 +272,7 @@ function PowerFlowData(

bus_lookup = aux_network_matrix.lookup[1]
branch_lookup = aux_network_matrix.lookup[2]
temp_bus_map = Dict{Int, String}(
temp_bus_map = Dict{Int,String}(
PSY.get_number(b) => PSY.get_name(b) for b in PSY.get_components(PSY.ACBus, sys)
)
valid_ix = setdiff(1:n_buses, aux_network_matrix.ref_bus_positions)
Expand Down Expand Up @@ -317,9 +317,9 @@ NOTE: use it for DC power flow computations.
function PowerFlowData(
::PTDFDCPowerFlow,
sys::PSY.System;
time_steps::Int = 1,
timestep_names::Vector{String} = String[],
check_connectivity::Bool = true)
time_steps::Int=1,
timestep_names::Vector{String}=String[],
check_connectivity::Bool=true)

# assign timestep_names
# timestep names are then allocated in a dictionary to map matrix columns
Expand All @@ -333,15 +333,15 @@ function PowerFlowData(

# get the network matrices
power_network_matrix = PNM.PTDF(sys)
aux_network_matrix = PNM.ABA_Matrix(sys; factorize = true)
aux_network_matrix = PNM.ABA_Matrix(sys; factorize=true)

# get number of buses and branches
n_buses = length(axes(power_network_matrix, 1))
n_branches = length(axes(power_network_matrix, 2))

bus_lookup = power_network_matrix.lookup[1]
branch_lookup = power_network_matrix.lookup[2]
temp_bus_map = Dict{Int, String}(
temp_bus_map = Dict{Int,String}(
PSY.get_number(b) => PSY.get_name(b) for b in PSY.get_components(PSY.Bus, sys)
)
valid_ix = setdiff(1:n_buses, aux_network_matrix.ref_bus_positions)
Expand Down Expand Up @@ -385,9 +385,9 @@ NOTE: use it for DC power flow computations.
function PowerFlowData(
::vPTDFDCPowerFlow,
sys::PSY.System;
time_steps::Int = 1,
timestep_names::Vector{String} = String[],
check_connectivity::Bool = true)
time_steps::Int=1,
timestep_names::Vector{String}=String[],
check_connectivity::Bool=true)

# assign timestep_names
# timestep names are then allocated in a dictionary to map matrix columns
Expand All @@ -401,15 +401,15 @@ function PowerFlowData(

# get the network matrices
power_network_matrix = PNM.VirtualPTDF(sys) # evaluates an empty virtual PTDF
aux_network_matrix = PNM.ABA_Matrix(sys; factorize = true)
aux_network_matrix = PNM.ABA_Matrix(sys; factorize=true)

# get number of buses and branches
n_buses = length(axes(power_network_matrix, 2))
n_branches = length(axes(power_network_matrix, 1))

bus_lookup = power_network_matrix.lookup[2]
branch_lookup = power_network_matrix.lookup[1]
temp_bus_map = Dict{Int, String}(
temp_bus_map = Dict{Int,String}(
PSY.get_number(b) => PSY.get_name(b) for b in PSY.get_components(PSY.Bus, sys)
)
valid_ix = setdiff(1:n_buses, aux_network_matrix.ref_bus_positions)
Expand Down Expand Up @@ -440,7 +440,7 @@ Create an appropriate `PowerFlowContainer` for the given `PowerFlowEvaluationMod
"""
function make_power_flow_container end

make_power_flow_container(pfem::ACPowerFlow, sys::PSY.System; kwargs...) =
make_power_flow_container(pfem::NLSolveACPowerFlow, sys::PSY.System; kwargs...) =
PowerFlowData(pfem, sys; kwargs...)

make_power_flow_container(pfem::DCPowerFlow, sys::PSY.System; kwargs...) =
Expand Down
4 changes: 3 additions & 1 deletion src/PowerFlows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export solve_powerflow
export solve_ac_powerflow!
export PowerFlowData
export DCPowerFlow
export ACPowerFlow
rbolgaryn marked this conversation as resolved.
Show resolved Hide resolved
export NLSolveACPowerFlow
export KLUACPowerFlow
export PTDFDCPowerFlow
export vPTDFDCPowerFlow
export PSSEExportPowerFlow
Expand All @@ -20,6 +21,7 @@ import PowerSystems
import PowerSystems: System
import LinearAlgebra
import NLsolve
import KLU
import SparseArrays
import InfrastructureSystems
import PowerNetworkMatrices
Expand Down
Loading
Loading