From a1d636f7c93b6f439c57f4836b8b1415fe35946e Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 16 Jan 2024 12:59:24 -0700 Subject: [PATCH] address PR comments --- src/BA_ABA_matrices.jl | 14 +++--- src/adjacency_matrix.jl | 2 +- src/common.jl | 2 +- src/incedence_matrix.jl | 4 +- src/lodf_calculations.jl | 63 ++++++++++++++----------- src/network_radial_reduction.jl | 2 +- src/ptdf_calculations.jl | 44 +++++++++++------ src/virtual_lodf_calculations.jl | 14 +++--- src/virtual_ptdf_calculations.jl | 14 +++--- test/test_A_BA_ABA_with_radial_lines.jl | 2 +- 10 files changed, 91 insertions(+), 70 deletions(-) diff --git a/src/BA_ABA_matrices.jl b/src/BA_ABA_matrices.jl index ddb15a87..c39e2443 100644 --- a/src/BA_ABA_matrices.jl +++ b/src/BA_ABA_matrices.jl @@ -15,8 +15,8 @@ Structure containing the BA matrix and other relevant data. with the names of buses and branches - `ref_bus_positions::Set{Int}`: Set containing the indexes of the columns of the BA matrix corresponding - to the refence buses -- `radial_branches::RadialNetworkReduction`: + to the reference buses +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -25,7 +25,7 @@ struct BA_Matrix{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64} axes::Ax lookup::L ref_bus_positions::Set{Int} - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end """ @@ -72,10 +72,10 @@ Structure containing the ABA matrix and other relevant data. with the number of the buses. - `ref_bus_positions::Set{Int}`: Vector containing the indexes of the columns of the BA matrix corresponding - to the refence buses + to the reference buses - `K<:Union{Nothing, KLU.KLUFactorization{Float64, Int}}`: either nothing or a container for KLU factorization matrices (LU factorization) -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -89,7 +89,7 @@ struct ABA_Matrix{ lookup::L ref_bus_positions::Set{Int} K::F - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end """ @@ -155,7 +155,7 @@ function factorize(ABA::ABA_Matrix{Ax, L, Nothing}) where {Ax, L <: NTuple{2, Di deepcopy(ABA.lookup), deepcopy(ABA.ref_bus_positions), klu(ABA.data), - deepcopy(ABA.radial_branches), + deepcopy(ABA.radial_network_reduction), ) return ABA_lu end diff --git a/src/adjacency_matrix.jl b/src/adjacency_matrix.jl index 993d75de..49b8538e 100644 --- a/src/adjacency_matrix.jl +++ b/src/adjacency_matrix.jl @@ -17,7 +17,7 @@ The AdjacencyMatrix Struct is indexed using the Bus Numbers, no need for them to with the names of branches and buses - `ref_bus_positions::Set{Int}`: Vector containing the indexes of the columns of the BA matrix corresponding - to the refence buses + to the reference buses """ struct AdjacencyMatrix{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Int8} data::SparseArrays.SparseMatrixCSC{Int8, Int} diff --git a/src/common.jl b/src/common.jl index f3d80ef9..9bd8a019 100644 --- a/src/common.jl +++ b/src/common.jl @@ -204,7 +204,7 @@ Evaluates the transposed BA matrix given the System's banches, reference bus pos vector containing the branches of the considered system (should be AC branches). - `ref_bus_positions::Set{Int}`: Vector containing the indexes of the columns of the BA matrix corresponding - to the refence buses + to the reference buses - `bus_lookup::Dict{Int, Int}`: dictionary mapping the bus numbers with their enumerated indexes. """ diff --git a/src/incedence_matrix.jl b/src/incedence_matrix.jl index 0b0bbc2d..5c12d82d 100644 --- a/src/incedence_matrix.jl +++ b/src/incedence_matrix.jl @@ -12,7 +12,7 @@ Incidence matrix: shows connection between buses, defining lines and buses with their enumerated indexes. - `ref_bus_positions::Set{Int}`: Vector containing the indices of the reference slack buses. -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -52,7 +52,7 @@ values. # Arguments - `sys::PSY.System`: the PowerSystem system to consider -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ diff --git a/src/lodf_calculations.jl b/src/lodf_calculations.jl index 8939a65f..9f817d9b 100644 --- a/src/lodf_calculations.jl +++ b/src/lodf_calculations.jl @@ -14,7 +14,7 @@ of how a change in a line's flow affects the flows on other lines in the system. - `tol::Base.RefValue{Float64}`: tolerance used for sparsifying the matrix (dropping element whose absolute value is below this threshold). -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -24,7 +24,7 @@ struct LODF{Ax, L <: NTuple{2, Dict}, M <: AbstractArray{Float64, 2}} <: axes::Ax lookup::L tol::Base.RefValue{Float64} - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end function _buildlodf( @@ -268,7 +268,7 @@ Builds the LODF matrix given the data of branches and buses of the system. Default solver: "KLU". - `tol::Float64`: Tolerance to eliminate entries in the LODF matrix (default eps()) -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the ma """ @@ -277,7 +277,7 @@ function LODF( buses::Vector{PSY.ACBus}; linear_solver::String = "KLU", tol::Float64 = eps(), - radial_branches::RadialNetworkReduction = RadialNetworkReduction(), + radial_network_reduction::RadialNetworkReduction = RadialNetworkReduction(), ) # get axis names @@ -292,14 +292,20 @@ function LODF( if tol > eps() lodf_t = _buildlodf(a, ptdf_t, linear_solver) - return LODF(sparsify(lodf_t, tol), axes, look_up, Ref(tol), radial_branches) + return LODF( + sparsify(lodf_t, tol), + axes, + look_up, + Ref(tol), + radial_network_reduction, + ) else return LODF( _buildlodf(a, ptdf_t, linear_solver), axes, look_up, Ref(tol), - radial_branches, + radial_network_reduction, ) end end @@ -329,7 +335,7 @@ function LODF( end branches = get_ac_branches(sys, rb.radial_branches) buses = get_buses(sys, rb.bus_reduction_map) - return LODF(branches, buses; radial_branches = rb, kwargs...) + return LODF(branches, buses; radial_network_reduction = rb, kwargs...) end """ @@ -373,26 +379,26 @@ function LODF( end if reduce_radial_branches - if !isempty(PTDFm.radial_branches) - radial_branches = PTDFm.radial_branches - @info "Non-empty `radial_branches` field found in PTDF matrix. LODF is evaluated considering radial branches and leaf nodes removed." + if !isempty(PTDFm.radial_network_reduction) + radial_network_reduction = PTDFm.radial_network_reduction + @info "Non-empty `radial_network_reduction` field found in PTDF matrix. LODF is evaluated considering radial branches and leaf nodes removed." else - error("PTDF has empty `radial_branches` field.") + error("PTDF has empty `radial_network_reduction` field.") end A_matrix = reduce_A_matrix( A, - radial_branches.bus_reduction_map, - radial_branches.meshed_branches, + radial_network_reduction.bus_reduction_map, + radial_network_reduction.meshed_branches, ) - ax_ref = make_ax_ref(sort!(collect(radial_branches.meshed_branches))) + ax_ref = make_ax_ref(sort!(collect(radial_network_reduction.meshed_branches))) else - if isempty(PTDFm.radial_branches) - radial_branches = RadialNetworkReduction() + if isempty(PTDFm.radial_network_reduction) + radial_network_reduction = RadialNetworkReduction() A_matrix = A.data ax_ref = make_ax_ref(A.axes[1]) else error( - "Field `radial_branches` in PTDF must be empty if `reduce_radial_branches` is not true.", + "Field `radial_network_reduction` in PTDF must be empty if `reduce_radial_network_reduction` is not true.", ) end end @@ -404,7 +410,7 @@ function LODF( (A.axes[1], A.axes[1]), (ax_ref, ax_ref), Ref(tol), - radial_branches, + radial_network_reduction, ) end return LODF( @@ -412,7 +418,7 @@ function LODF( (A.axes[1], A.axes[1]), (ax_ref, ax_ref), Ref(tol), - radial_branches, + radial_network_reduction, ) end @@ -448,22 +454,23 @@ function LODF( ax_ref = make_ax_ref(A.axes[1]) if reduce_radial_branches # BA and ABA must contain the same, non-empty RadialNetworkReduction stucture - if !isempty(BA.radial_branches) && !isempty(ABA.radial_branches) && - isequal(BA.radial_branches, ABA.radial_branches) - radial_branches = BA.radial_branches + if !isempty(BA.radial_network_reduction) && + !isempty(ABA.radial_network_reduction) && + isequal(BA.radial_network_reduction, ABA.radial_network_reduction) + radial_network_reduction = BA.radial_network_reduction @info "Non-empty `radial_branches` field found in BA and ABA matrix. LODF is evaluated considering radial branches and leaf nodes removed." else error("Mismatch in `radial_branches` field between BA and ABA matrices.") end A_matrix = reduce_A_matrix( A, - radial_branches.bus_reduction_map, - radial_branches.meshed_branches, + radial_network_reduction.bus_reduction_map, + radial_network_reduction.meshed_branches, ) else # BA and ABA must contain the same, empty RadialNetworkReduction stucture - if isempty(BA.radial_branches) && isempty(ABA.radial_branches) - radial_branches = RadialNetworkReduction() + if isempty(BA.radial_network_reduction) && isempty(ABA.radial_network_reduction) + radial_network_reduction = RadialNetworkReduction() A_matrix = A.data else error( @@ -479,7 +486,7 @@ function LODF( (A.axes[1], A.axes[1]), (ax_ref, ax_ref), Ref(tol), - radial_branches, + radial_network_reduction, ) end return LODF( @@ -487,7 +494,7 @@ function LODF( (A.axes[1], A.axes[1]), (ax_ref, ax_ref), Ref(tol), - radial_branches, + radial_network_reduction, ) end diff --git a/src/network_radial_reduction.jl b/src/network_radial_reduction.jl index f81a1a8d..b927286e 100644 --- a/src/network_radial_reduction.jl +++ b/src/network_radial_reduction.jl @@ -166,7 +166,7 @@ ignored in the models by exploring the structure of the incidence matrix - `bus_map::Dict{Int, Int}`: Map of Bus Name to Matrix Index - `ref_bus_positions::Set{Int}`: Set containing the indexes of the columns of the BA matrix corresponding - to the refence buses + to the reference buses """ function calculate_radial_branches( A::SparseArrays.SparseMatrixCSC{Int8, Int64}, diff --git a/src/ptdf_calculations.jl b/src/ptdf_calculations.jl index 34444c57..7e695ac7 100644 --- a/src/ptdf_calculations.jl +++ b/src/ptdf_calculations.jl @@ -21,7 +21,7 @@ The PTDF struct is indexed using the Bus numbers and Branch names. - `tol::Base.RefValue{Float64}`: tolerance used for sparsifying the matrix (dropping element whose absolute value is below this threshold). -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -33,7 +33,7 @@ struct PTDF{Ax, L <: NTuple{2, Dict}, M <: AbstractArray{Float64, 2}} <: subnetworks::Dict{Int, Set{Int}} ref_bus_positions::Set{Int} tol::Base.RefValue{Float64} - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end """ @@ -377,7 +377,7 @@ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF Linear solver to be used. Options are "Dense", "KLU" and "MKLPardiso - `tol::Float64`: Tolerance to eliminate entries in the PTDF matrix (default eps()) -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the ma """ @@ -387,7 +387,7 @@ function PTDF( dist_slack::Vector{Float64} = Float64[], linear_solver::String = "KLU", tol::Float64 = eps(), - radial_branches::RadialNetworkReduction = RadialNetworkReduction(), + radial_network_reduction::RadialNetworkReduction = RadialNetworkReduction(), ) validate_linear_solver(linear_solver) @@ -418,10 +418,18 @@ function PTDF( subnetworks, ref_bus_positions, Ref(tol), - radial_branches, + radial_network_reduction, ) end - return PTDF(S, axes, look_up, subnetworks, ref_bus_positions, Ref(tol), radial_branches) + return PTDF( + S, + axes, + look_up, + subnetworks, + ref_bus_positions, + Ref(tol), + radial_network_reduction, + ) end """ @@ -454,7 +462,13 @@ function PTDF( end branches = get_ac_branches(sys, rb.radial_branches) buses = get_buses(sys, rb.bus_reduction_map) - return PTDF(branches, buses; dist_slack = dist_slack, radial_branches = rb, kwargs...) + return PTDF( + branches, + buses; + dist_slack = dist_slack, + radial_network_reduction = rb, + kwargs..., + ) end """ @@ -489,22 +503,22 @@ function PTDF( validate_linear_solver(linear_solver) @warn "PTDF creates via other matrices doesn't compute the subnetworks" if reduce_radial_branches - if !isempty(BA.radial_branches) - radial_branches = BA.radial_branches + if !isempty(BA.radial_network_reduction) + radial_network_reduction = BA.radial_network_reduction @info "Non-empty `radial_branches` field found in BA matrix. PTDF is evaluated considering radial branches and leaf nodes removed." else error("BA has empty `radial_branches` field.") end A_matrix = reduce_A_matrix( A, - radial_branches.bus_reduction_map, - radial_branches.meshed_branches, + radial_network_reduction.bus_reduction_map, + radial_network_reduction.meshed_branches, ) axes = BA.axes lookup = BA.lookup else - if isempty(BA.radial_branches) - radial_branches = RadialNetworkReduction() + if isempty(BA.radial_network_reduction) + radial_network_reduction = RadialNetworkReduction() A_matrix = A.data axes = (A.axes[2], A.axes[1]) lookup = (A.lookup[2], A.lookup[1]) @@ -529,7 +543,7 @@ function PTDF( Dict{Int, Set{Int}}(), BA.ref_bus_positions, Ref(tol), - radial_branches, + radial_network_reduction, ) else return PTDF( @@ -539,7 +553,7 @@ function PTDF( Dict{Int, Set{Int}}(), BA.ref_bus_positions, Ref(tol), - radial_branches, + radial_network_reduction, ) end end diff --git a/src/virtual_lodf_calculations.jl b/src/virtual_lodf_calculations.jl index 189c3488..a4e9c762 100644 --- a/src/virtual_lodf_calculations.jl +++ b/src/virtual_lodf_calculations.jl @@ -21,7 +21,7 @@ The VirtualLODF struct is indexed using branch names. coming from multuiplying the PTDF matrix with th Incidence matrix - `ref_bus_positions::Set{Int}`: Vector containing the indexes of the rows of the transposed BA matrix - corresponding to the refence buses. + corresponding to the reference buses. - `axes<:NTuple{2, Dict}`: Tuple containing two vectors showing the branch names. - `lookup<:NTuple{2, Dict}`: @@ -38,7 +38,7 @@ The VirtualLODF struct is indexed using branch names. Dictionary containing the subsets of buses defining the different subnetwork of the system. - `tol::Base.RefValue{Float64}`: Tolerance related to scarification and values to drop. -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -55,7 +55,7 @@ struct VirtualLODF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64} cache::RowCache subnetworks::Dict{Int, Set{Int}} tol::Base.RefValue{Float64} - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualLODF) @@ -121,7 +121,7 @@ function VirtualLODF( end branches = get_ac_branches(sys, rb.radial_branches) buses = get_buses(sys, rb.bus_reduction_map) - return VirtualLODF(branches, buses; radial_branches = rb, kwargs...) + return VirtualLODF(branches, buses; radial_network_reduction = rb, kwargs...) end """ @@ -141,7 +141,7 @@ VirtualLODF struct with an empty cache. max cache size in MiB (inizialized as MAX_CACHE_SIZE_MiB). - `persistent_lines::Vector{String}`: line to be evaluated as soon as the VirtualPTDF is created (initialized as empty vector of strings). -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -151,7 +151,7 @@ function VirtualLODF( tol::Float64 = eps(), max_cache_size::Int = MAX_CACHE_SIZE_MiB, persistent_lines::Vector{String} = String[], - radial_branches::RadialNetworkReduction = RadialNetworkReduction(), + radial_network_reduction::RadialNetworkReduction = RadialNetworkReduction(), ) #Get axis names and lookups @@ -209,7 +209,7 @@ function VirtualLODF( empty_cache, subnetworks, Ref(tol), - radial_branches, + radial_network_reduction, ) end diff --git a/src/virtual_ptdf_calculations.jl b/src/virtual_ptdf_calculations.jl index 45223319..adb8fd0d 100644 --- a/src/virtual_ptdf_calculations.jl +++ b/src/virtual_ptdf_calculations.jl @@ -17,7 +17,7 @@ matrix. BA matric - `ref_bus_positions::Set{Int}`: Vector containing the indexes of the columns of the BA matrix corresponding - to the refence buses + to the reference buses - `dist_slack::Vector{Float64}`: Vector of weights to be used as distributed slack bus. The distributed slack vector has to be the same length as the number of buses. @@ -42,7 +42,7 @@ matrix. Dictionary containing the subsets of buses defining the different subnetwork of the system. - `tol::Base.RefValue{Float64}`: Tolerance related to scarification and values to drop. -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -58,7 +58,7 @@ struct VirtualPTDF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64} cache::RowCache subnetworks::Dict{Int, Set{Int}} tol::Base.RefValue{Float64} - radial_branches::RadialNetworkReduction + radial_network_reduction::RadialNetworkReduction end function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualPTDF) @@ -89,7 +89,7 @@ VirtualPTDF struct with an empty cache. max cache size in MiB (inizialized as MAX_CACHE_SIZE_MiB). - `persistent_lines::Vector{String}`: line to be evaluated as soon as the VirtualPTDF is created (initialized as empty vector of strings). -- `radial_branches::RadialNetworkReduction`: +- `radial_network_reduction::RadialNetworkReduction`: Structure containing the radial branches and leaf buses that were removed while evaluating the matrix """ @@ -100,7 +100,7 @@ function VirtualPTDF( tol::Float64 = eps(), max_cache_size::Int = MAX_CACHE_SIZE_MiB, persistent_lines::Vector{String} = String[], - radial_branches::RadialNetworkReduction = RadialNetworkReduction(), + radial_network_reduction::RadialNetworkReduction = RadialNetworkReduction(), ) if length(dist_slack) != 0 @info "Distributed bus" @@ -149,7 +149,7 @@ function VirtualPTDF( empty_cache, subnetworks, Ref(tol), - radial_branches, + radial_network_reduction, ) end @@ -189,7 +189,7 @@ function VirtualPTDF( branches, buses; dist_slack = dist_slack, - radial_branches = rb, + radial_network_reduction = rb, kwargs..., ) end diff --git a/test/test_A_BA_ABA_with_radial_lines.jl b/test/test_A_BA_ABA_with_radial_lines.jl index 02427d0a..91a045b7 100644 --- a/test/test_A_BA_ABA_with_radial_lines.jl +++ b/test/test_A_BA_ABA_with_radial_lines.jl @@ -7,7 +7,7 @@ # ... and with radial lines BA_rad = BA_Matrix(sys; reduce_radial_branches = true) # get inidices for the leaf nodes - rb = BA_rad.radial_branches + rb = BA_rad.radial_network_reduction bus_numbers = [] for i in keys(rb.bus_reduction_map) append!(bus_numbers, collect(rb.bus_reduction_map[i]))