Skip to content

Commit

Permalink
Merge pull request #54 from NREL-Sienna/jd/psy3
Browse files Browse the repository at this point in the history
Jd/psy3
  • Loading branch information
jd-lara authored Sep 12, 2023
2 parents 89e3eb2 + c74b656 commit 33ef511
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerNetworkMatrices"
uuid = "bed98974-b02a-5e2f-9fe0-a103f5c450dd"
authors = ["Jose Daniel Lara", "Alessandro Castelli", "Sourabh Dalvi"]
version = "0.8.2"
version = "0.9.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -19,5 +19,5 @@ HDF5 = "0.16"
InfrastructureSystems = "^1.20"
KLU = "~0.4"
Pardiso = "~0.5"
PowerSystems = "2"
PowerSystems = "3"
julia = "^1.6"
2 changes: 1 addition & 1 deletion src/PowerNetworkMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export Ybus
using DocStringExtensions
import InfrastructureSystems
import PowerSystems
import PowerSystems: BusTypes
import PowerSystems: ACBusTypes

const IS = InfrastructureSystems
const PSY = PowerSystems
Expand Down
10 changes: 5 additions & 5 deletions src/PowerNetworkMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ end
Evaluates the map linking the system's buses and branches.
# Arguments
- `buses::AbstractVector{PSY.Bus}`:
- `buses::AbstractVector{PSY.ACBus}`:
system's buses
"""
function make_ax_ref(buses::AbstractVector{PSY.Bus})
function make_ax_ref(buses::AbstractVector{PSY.ACBus})
return make_ax_ref(PSY.get_number.(buses))
end

Expand Down Expand Up @@ -96,7 +96,7 @@ Gets bus indices to a certain branch name
- `lookup::Dict`:
Dictionary mapping branches and buses
"""
function lookup_index(i::PSY.Bus, lookup::Dict)
function lookup_index(i::PSY.ACBus, lookup::Dict)
return isa(i, Colon) ? Colon() : lookup[Base.to_index(i)]
end

Expand Down Expand Up @@ -170,7 +170,7 @@ Structure to store the keys of a power network matrix
# Arguments
- `product_iter::Base.Iterators.ProductIterator{T} where T <: Tuple`:
iterator of the indices of the network power matrix
iterator of the indices of the network power matrix
"""
struct PowerNetworkMatrixKeys{T <: Tuple}
product_iter::Base.Iterators.ProductIterator{T}
Expand Down Expand Up @@ -311,7 +311,7 @@ function Base.show(io::IO, array::PowerNetworkMatrix)
return
end

Base.to_index(b::PSY.Bus) = PSY.get_number(b)
Base.to_index(b::PSY.ACBus) = PSY.get_number(b)
Base.to_index(b::T) where {T <: PSY.ACBranch} = PSY.get_name(b)

"""returns the raw array data of the `PowerNetworkMatrix`"""
Expand Down
2 changes: 1 addition & 1 deletion src/adjacency_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Builds a AdjacencyMatrix from a collection of buses and branches. The return is
"""
function AdjacencyMatrix(
branches,
buses::Vector{PSY.Bus};
buses::Vector{PSY.ACBus};
check_connectivity::Bool = true,
kwargs...,
)
Expand Down
31 changes: 20 additions & 11 deletions src/common.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
function _add_to_collection!(collection::Vector{PSY.ACBranch}, branch::PSY.ACBranch)
push!(collection, branch)
return
end

function _add_to_collection!(::Vector{PSY.ACBranch}, ::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCDCLine})
return
end

"""
Gets the AC branches from a given Systems.
"""
function get_ac_branches(sys::PSY.System)
collection = Vector{PSY.ACBranch}()
for br in PSY.get_components(PSY.get_available, PSY.ACBranch, sys)
arc = PSY.get_arc(br)
if PSY.get_bustype(arc.from) == BusTypes.ISOLATED
if PSY.get_bustype(arc.from) == ACBusTypes.ISOLATED
throw(
IS.ConflictingInputsError(
"Branch $(PSY.get_name(br)) is set available and connected to isolated bus $(PSY.get_name(arc.from))",
),
)
end
if PSY.get_bustype(arc.to) == BusTypes.ISOLATED
if PSY.get_bustype(arc.to) == ACBusTypes.ISOLATED
throw(
IS.ConflictingInputsError(
"Branch $(PSY.get_name(br)) is set available and connected to isolated bus $(PSY.get_name(arc.to))",
),
)
end
push!(collection, br)
_add_to_collection!(collection, br)
end
return sort!(collection;
by = x -> (PSY.get_number(PSY.get_arc(x).from), PSY.get_number(PSY.get_arc(x).to)),
Expand All @@ -29,10 +38,10 @@ end
"""
Gets the non-isolated buses from a given System
"""
function get_buses(sys::PSY.System)::Vector{PSY.Bus}
function get_buses(sys::PSY.System)::Vector{PSY.ACBus}
return sort!(
collect(
PSY.get_components(x -> PSY.get_bustype(x) != BusTypes.ISOLATED, PSY.Bus, sys),
PSY.get_components(x -> PSY.get_bustype(x) != ACBusTypes.ISOLATED, PSY.ACBus, sys),
);
by = x -> PSY.get_number(x),
)
Expand All @@ -50,7 +59,7 @@ end
function find_slack_positions(buses, bus_lookup::Dict{Int, Int})::Set{Int}
slack_position = sort([
bus_lookup[PSY.get_number(n)]
for n in buses if PSY.get_bustype(n) == BusTypes.REF
for n in buses if PSY.get_bustype(n) == ACBusTypes.REF
])
if length(slack_position) == 0
error("Slack bus not identified in the Bus/buses list, can't build NetworkMatrix")
Expand All @@ -76,7 +85,7 @@ Evaluates the Incidence matrix A given the branches and node of a System.
# Arguments
- `branches`:
vector containing the branches of the considered system (should be AC branches).
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector containing the buses of the considered system.
NOTE:
Expand All @@ -85,7 +94,7 @@ NOTE:
"""
function calculate_A_matrix(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
)
ref_bus_positions = find_slack_positions(buses)
bus_lookup = make_ax_ref(buses)
Expand Down Expand Up @@ -117,10 +126,10 @@ Evaluates the Adjacency matrix given the banches and buses of a given System.
# Arguments
- `branches`:
vector containing the branches of the considered system (should be AC branches).
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector containing the buses of the considered system.
"""
function calculate_adjacency(branches, buses::Vector{PSY.Bus})
function calculate_adjacency(branches, buses::Vector{PSY.ACBus})
bus_ax = PSY.get_number.(buses)
return calculate_adjacency(branches, buses, make_ax_ref(bus_ax))
end
Expand All @@ -134,7 +143,7 @@ NOTE:
"""
function calculate_adjacency(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
bus_lookup::Dict{Int, Int},
)
buscount = length(buses)
Expand Down
10 changes: 5 additions & 5 deletions src/lodf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ of how a change in a line's flow affects the flows on other lines in the system.
- `data<:AbstractArray{Float64, 2}`:
the transposed LODF matrix.
- `axes<:NTuple{2, Dict}`:
Tuple containing two identical vectors containing the names of the
Tuple containing two identical vectors containing the names of the
branches related to each row/column.
- `lookup<:NTuple{2, Dict}`:
Tuple containing two identical dictionaries mapping the branches
Expand Down Expand Up @@ -162,14 +162,14 @@ Builds the LODF matrix given the data of branches and buses of the system.
# Arguments
- `branches`:
vector of the System AC branches
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector of the System buses
- `tol::Float64`:
Tolerance to eliminate entries in the LODF matrix (default eps())
"""
function LODF(
branches,
buses::Vector{PSY.Bus};
buses::Vector{PSY.ACBus};
linear_solver::String = "KLU",
tol::Float64 = eps(),
)
Expand Down Expand Up @@ -214,8 +214,8 @@ end
"""
Builds the LODF matrix given the Incidence Matrix and the PTDF matrix of the system.
NOTE: tol is referred to the LODF sparsification, not the PTDF one. PTDF matrix
must be considered as NON sparsified ("tol" argument not specified when calling
NOTE: tol is referred to the LODF sparsification, not the PTDF one. PTDF matrix
must be considered as NON sparsified ("tol" argument not specified when calling
the PTDF method).
# Arguments
Expand Down
24 changes: 12 additions & 12 deletions src/ptdf_calculations.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Power Transfer Distribution Factors (PTDF) indicate the incremental change in
real power that occurs on transmission lines due to real power injections
Power Transfer Distribution Factors (PTDF) indicate the incremental change in
real power that occurs on transmission lines due to real power injections
changes at the buses.
The PTDF struct is indexed using the Bus numbers and Branch names.
Expand All @@ -13,7 +13,7 @@ The PTDF struct is indexed using the Bus numbers and Branch names.
the second showing the branch names. The information contained in this
field matches the axes of the fiels `data`.
- `lookup<:NTuple{2, Dict}`:
Tuple containing two dictionaries mapping the bus numbers and branch
Tuple containing two dictionaries mapping the bus numbers and branch
names with the indices of the matrix contained in `data`.
- `subnetworks::Dict{Int, Set{Int}}`:
dictionary containing the set of bus indexes defining the subnetworks
Expand Down Expand Up @@ -42,7 +42,7 @@ PTDF(filename::AbstractString) = from_hdf5(PTDF, filename)

function _buildptdf(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
bus_lookup::Dict{Int, Int},
dist_slack::Vector{Float64},
linear_solver::String)
Expand Down Expand Up @@ -154,7 +154,7 @@ Computes the PTDF matrix by means of the KLU.LU factorization for sparse matrice
# Arguments
- `branches`:
vector of the System AC branches
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector of the System buses
- `bus_lookup::Dict{Int, Int}`:
dictionary mapping the bus numbers with their enumerated indexes.
Expand All @@ -163,7 +163,7 @@ Computes the PTDF matrix by means of the KLU.LU factorization for sparse matrice
"""
function calculate_PTDF_matrix_KLU(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
bus_lookup::Dict{Int, Int},
dist_slack::Vector{Float64})
A, ref_bus_positions = calculate_A_matrix(branches, buses)
Expand Down Expand Up @@ -252,7 +252,7 @@ Computes the PTDF matrix by means of the LAPACK and BLAS functions for dense mat
# Arguments
- `branches`:
vector of the System AC branches
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector of the System buses
- `bus_lookup::Dict{Int, Int}`:
dictionary mapping the bus numbers with their enumerated indexes.
Expand All @@ -261,7 +261,7 @@ Computes the PTDF matrix by means of the LAPACK and BLAS functions for dense mat
"""
function calculate_PTDF_matrix_DENSE(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
bus_lookup::Dict{Int, Int},
dist_slack::Vector{Float64})
A, ref_bus_positions = calculate_A_matrix(branches, buses)
Expand Down Expand Up @@ -336,7 +336,7 @@ Computes the PTDF matrix by means of the MKL Pardiso for dense matrices.
# Arguments
- `branches`:
vector of the System AC branches
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector of the System buses
- `bus_lookup::Dict{Int, Int}`:
dictionary mapping the bus numbers with their enumerated indexes.
Expand All @@ -345,7 +345,7 @@ Computes the PTDF matrix by means of the MKL Pardiso for dense matrices.
"""
function calculate_PTDF_matrix_MKLPardiso(
branches,
buses::Vector{PSY.Bus},
buses::Vector{PSY.ACBus},
bus_lookup::Dict{Int, Int},
dist_slack::Vector{Float64})
A, ref_bus_positions = calculate_A_matrix(branches, buses)
Expand All @@ -360,7 +360,7 @@ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF
# Arguments
- `branches`:
vector of the System AC branches
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
vector of the System buses
- `dist_slack::Vector{Float64}`:
vector of weights to be used as distributed slack bus.
Expand All @@ -372,7 +372,7 @@ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF
"""
function PTDF(
branches,
buses::Vector{PSY.Bus};
buses::Vector{PSY.ACBus};
dist_slack::Vector{Float64} = Float64[],
linear_solver::String = "KLU",
tol::Float64 = eps())
Expand Down
12 changes: 6 additions & 6 deletions src/virtual_lodf_calculations.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
The Virtual Line Outage Distribution Factor (VirtualLODF) structure gathers
the rows of the LODF matrix as they are evaluated on-the-go. These rows are
evalauted independently, cached in the structure and do not require the
computation of the whole matrix (therefore significantly reducing the
the rows of the LODF matrix as they are evaluated on-the-go. These rows are
evalauted independently, cached in the structure and do not require the
computation of the whole matrix (therefore significantly reducing the
computational requirements).
The VirtualLODF is initialized with no row stored.
Expand All @@ -20,12 +20,12 @@ The VirtualLODF struct is indexed using branch names.
Vector contiaining the element-wise reciprocal of the diagonal elements
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
Vector containing the indexes of the rows of the transposed BA matrix
corresponding to the refence buses.
- `axes<:NTuple{2, Dict}`:
Tuple containing two vectors showing the branch names.
- `lookup<:NTuple{2, Dict}`:
Tuple containing two dictionaries, mapping the branches names
Tuple containing two dictionaries, mapping the branches names
the enumerated row indexes indexes.
- `valid_ix::Vector{Int}`:
Vector containing the row/columns indices of matrices related the buses
Expand Down Expand Up @@ -101,7 +101,7 @@ end

function VirtualLODF(
branches,
buses::Vector{PSY.Bus};
buses::Vector{PSY.ACBus};
tol::Float64 = eps(),
max_cache_size::Int = MAX_CACHE_SIZE_MiB,
persistent_lines::Vector{String} = String[],
Expand Down
4 changes: 2 additions & 2 deletions src/virtual_ptdf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ PTDF array indexed with the branch numbers.
# Arguments
- `branches`:
Vector of the system's AC branches.
- `buses::Vector{PSY.Bus}`:
- `buses::Vector{PSY.ACBus}`:
Vector of the system's buses.
- `dist_slack::Vector{Float64} = Float64[]`:
Vector of weights to be used as distributed slack bus.
Expand All @@ -86,7 +86,7 @@ PTDF array indexed with the branch numbers.
"""
function VirtualPTDF(
branches,
buses::Vector{PSY.Bus};
buses::Vector{PSY.ACBus};
dist_slack::Vector{Float64} = Float64[],
tol::Float64 = eps(),
max_cache_size::Int = MAX_CACHE_SIZE_MiB,
Expand Down
Loading

2 comments on commit 33ef511

@jd-lara
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/91236

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.0 -m "<description of version>" 33ef511668e858eef60eb5e0b06996dbf61ecd6b
git push origin v0.9.0

Please sign in to comment.