Skip to content

Commit 3cb659d

Browse files
authored
Merge pull request #54 from NREL-Sienna/jd/psy3
Jd/psy3
2 parents 73d507a + 98674db commit 3cb659d

12 files changed

Lines changed: 227 additions & 56 deletions

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PowerNetworkMatrices"
22
uuid = "bed98974-b02a-5e2f-9fe0-a103f5c450dd"
33
authors = ["Jose Daniel Lara", "Alessandro Castelli", "Sourabh Dalvi"]
4-
version = "0.8.2"
4+
version = "0.9.0"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
@@ -19,5 +19,5 @@ HDF5 = "0.16"
1919
InfrastructureSystems = "^1.20"
2020
KLU = "~0.4"
2121
Pardiso = "~0.5"
22-
PowerSystems = "2"
22+
PowerSystems = "3"
2323
julia = "^1.6"

src/PowerNetworkMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export Ybus
2121
using DocStringExtensions
2222
import InfrastructureSystems
2323
import PowerSystems
24-
import PowerSystems: BusTypes
24+
import PowerSystems: ACBusTypes
2525

2626
const IS = InfrastructureSystems
2727
const PSY = PowerSystems

src/PowerNetworkMatrix.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ end
2929
Evaluates the map linking the system's buses and branches.
3030
3131
# Arguments
32-
- `buses::AbstractVector{PSY.Bus}`:
32+
- `buses::AbstractVector{PSY.ACBus}`:
3333
system's buses
3434
"""
35-
function make_ax_ref(buses::AbstractVector{PSY.Bus})
35+
function make_ax_ref(buses::AbstractVector{PSY.ACBus})
3636
return make_ax_ref(PSY.get_number.(buses))
3737
end
3838

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

@@ -170,7 +170,7 @@ Structure to store the keys of a power network matrix
170170
171171
# Arguments
172172
- `product_iter::Base.Iterators.ProductIterator{T} where T <: Tuple`:
173-
iterator of the indices of the network power matrix
173+
iterator of the indices of the network power matrix
174174
"""
175175
struct PowerNetworkMatrixKeys{T <: Tuple}
176176
product_iter::Base.Iterators.ProductIterator{T}
@@ -311,7 +311,7 @@ function Base.show(io::IO, array::PowerNetworkMatrix)
311311
return
312312
end
313313

314-
Base.to_index(b::PSY.Bus) = PSY.get_number(b)
314+
Base.to_index(b::PSY.ACBus) = PSY.get_number(b)
315315
Base.to_index(b::T) where {T <: PSY.ACBranch} = PSY.get_name(b)
316316

317317
"""returns the raw array data of the `PowerNetworkMatrix`"""

src/adjacency_matrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Builds a AdjacencyMatrix from a collection of buses and branches. The return is
5858
"""
5959
function AdjacencyMatrix(
6060
branches,
61-
buses::Vector{PSY.Bus};
61+
buses::Vector{PSY.ACBus};
6262
check_connectivity::Bool = true,
6363
kwargs...,
6464
)

src/common.jl

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
function _add_to_collection!(collection::Vector{PSY.ACBranch}, branch::PSY.ACBranch)
2+
push!(collection, branch)
3+
return
4+
end
5+
6+
function _add_to_collection!(::Vector{PSY.ACBranch}, ::Union{PSY.TwoTerminalHVDCLine, PSY.TwoTerminalVSCDCLine})
7+
return
8+
end
9+
110
"""
211
Gets the AC branches from a given Systems.
312
"""
413
function get_ac_branches(sys::PSY.System)
514
collection = Vector{PSY.ACBranch}()
615
for br in PSY.get_components(PSY.get_available, PSY.ACBranch, sys)
716
arc = PSY.get_arc(br)
8-
if PSY.get_bustype(arc.from) == BusTypes.ISOLATED
17+
if PSY.get_bustype(arc.from) == ACBusTypes.ISOLATED
918
throw(
1019
IS.ConflictingInputsError(
1120
"Branch $(PSY.get_name(br)) is set available and connected to isolated bus $(PSY.get_name(arc.from))",
1221
),
1322
)
1423
end
15-
if PSY.get_bustype(arc.to) == BusTypes.ISOLATED
24+
if PSY.get_bustype(arc.to) == ACBusTypes.ISOLATED
1625
throw(
1726
IS.ConflictingInputsError(
1827
"Branch $(PSY.get_name(br)) is set available and connected to isolated bus $(PSY.get_name(arc.to))",
1928
),
2029
)
2130
end
22-
push!(collection, br)
31+
_add_to_collection!(collection, br)
2332
end
2433
return sort!(collection;
2534
by = x -> (PSY.get_number(PSY.get_arc(x).from), PSY.get_number(PSY.get_arc(x).to)),
@@ -29,10 +38,10 @@ end
2938
"""
3039
Gets the non-isolated buses from a given System
3140
"""
32-
function get_buses(sys::PSY.System)::Vector{PSY.Bus}
41+
function get_buses(sys::PSY.System)::Vector{PSY.ACBus}
3342
return sort!(
3443
collect(
35-
PSY.get_components(x -> PSY.get_bustype(x) != BusTypes.ISOLATED, PSY.Bus, sys),
44+
PSY.get_components(x -> PSY.get_bustype(x) != ACBusTypes.ISOLATED, PSY.ACBus, sys),
3645
);
3746
by = x -> PSY.get_number(x),
3847
)
@@ -50,7 +59,7 @@ end
5059
function find_slack_positions(buses, bus_lookup::Dict{Int, Int})::Set{Int}
5160
slack_position = sort([
5261
bus_lookup[PSY.get_number(n)]
53-
for n in buses if PSY.get_bustype(n) == BusTypes.REF
62+
for n in buses if PSY.get_bustype(n) == ACBusTypes.REF
5463
])
5564
if length(slack_position) == 0
5665
error("Slack bus not identified in the Bus/buses list, can't build NetworkMatrix")
@@ -76,7 +85,7 @@ Evaluates the Incidence matrix A given the branches and node of a System.
7685
# Arguments
7786
- `branches`:
7887
vector containing the branches of the considered system (should be AC branches).
79-
- `buses::Vector{PSY.Bus}`:
88+
- `buses::Vector{PSY.ACBus}`:
8089
vector containing the buses of the considered system.
8190
8291
NOTE:
@@ -85,7 +94,7 @@ NOTE:
8594
"""
8695
function calculate_A_matrix(
8796
branches,
88-
buses::Vector{PSY.Bus},
97+
buses::Vector{PSY.ACBus},
8998
)
9099
ref_bus_positions = find_slack_positions(buses)
91100
bus_lookup = make_ax_ref(buses)
@@ -117,10 +126,10 @@ Evaluates the Adjacency matrix given the banches and buses of a given System.
117126
# Arguments
118127
- `branches`:
119128
vector containing the branches of the considered system (should be AC branches).
120-
- `buses::Vector{PSY.Bus}`:
129+
- `buses::Vector{PSY.ACBus}`:
121130
vector containing the buses of the considered system.
122131
"""
123-
function calculate_adjacency(branches, buses::Vector{PSY.Bus})
132+
function calculate_adjacency(branches, buses::Vector{PSY.ACBus})
124133
bus_ax = PSY.get_number.(buses)
125134
return calculate_adjacency(branches, buses, make_ax_ref(bus_ax))
126135
end
@@ -134,7 +143,7 @@ NOTE:
134143
"""
135144
function calculate_adjacency(
136145
branches,
137-
buses::Vector{PSY.Bus},
146+
buses::Vector{PSY.ACBus},
138147
bus_lookup::Dict{Int, Int},
139148
)
140149
buscount = length(buses)

src/lodf_calculations.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ of how a change in a line's flow affects the flows on other lines in the system.
66
- `data<:AbstractArray{Float64, 2}`:
77
the transposed LODF matrix.
88
- `axes<:NTuple{2, Dict}`:
9-
Tuple containing two identical vectors containing the names of the
9+
Tuple containing two identical vectors containing the names of the
1010
branches related to each row/column.
1111
- `lookup<:NTuple{2, Dict}`:
1212
Tuple containing two identical dictionaries mapping the branches
@@ -162,14 +162,14 @@ Builds the LODF matrix given the data of branches and buses of the system.
162162
# Arguments
163163
- `branches`:
164164
vector of the System AC branches
165-
- `buses::Vector{PSY.Bus}`:
165+
- `buses::Vector{PSY.ACBus}`:
166166
vector of the System buses
167167
- `tol::Float64`:
168168
Tolerance to eliminate entries in the LODF matrix (default eps())
169169
"""
170170
function LODF(
171171
branches,
172-
buses::Vector{PSY.Bus};
172+
buses::Vector{PSY.ACBus};
173173
linear_solver::String = "KLU",
174174
tol::Float64 = eps(),
175175
)
@@ -214,8 +214,8 @@ end
214214
"""
215215
Builds the LODF matrix given the Incidence Matrix and the PTDF matrix of the system.
216216
217-
NOTE: tol is referred to the LODF sparsification, not the PTDF one. PTDF matrix
218-
must be considered as NON sparsified ("tol" argument not specified when calling
217+
NOTE: tol is referred to the LODF sparsification, not the PTDF one. PTDF matrix
218+
must be considered as NON sparsified ("tol" argument not specified when calling
219219
the PTDF method).
220220
221221
# Arguments

src/ptdf_calculations.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Power Transfer Distribution Factors (PTDF) indicate the incremental change in
3-
real power that occurs on transmission lines due to real power injections
2+
Power Transfer Distribution Factors (PTDF) indicate the incremental change in
3+
real power that occurs on transmission lines due to real power injections
44
changes at the buses.
55
66
The PTDF struct is indexed using the Bus numbers and Branch names.
@@ -13,7 +13,7 @@ The PTDF struct is indexed using the Bus numbers and Branch names.
1313
the second showing the branch names. The information contained in this
1414
field matches the axes of the fiels `data`.
1515
- `lookup<:NTuple{2, Dict}`:
16-
Tuple containing two dictionaries mapping the bus numbers and branch
16+
Tuple containing two dictionaries mapping the bus numbers and branch
1717
names with the indices of the matrix contained in `data`.
1818
- `subnetworks::Dict{Int, Set{Int}}`:
1919
dictionary containing the set of bus indexes defining the subnetworks
@@ -42,7 +42,7 @@ PTDF(filename::AbstractString) = from_hdf5(PTDF, filename)
4242

4343
function _buildptdf(
4444
branches,
45-
buses::Vector{PSY.Bus},
45+
buses::Vector{PSY.ACBus},
4646
bus_lookup::Dict{Int, Int},
4747
dist_slack::Vector{Float64},
4848
linear_solver::String)
@@ -154,7 +154,7 @@ Computes the PTDF matrix by means of the KLU.LU factorization for sparse matrice
154154
# Arguments
155155
- `branches`:
156156
vector of the System AC branches
157-
- `buses::Vector{PSY.Bus}`:
157+
- `buses::Vector{PSY.ACBus}`:
158158
vector of the System buses
159159
- `bus_lookup::Dict{Int, Int}`:
160160
dictionary mapping the bus numbers with their enumerated indexes.
@@ -163,7 +163,7 @@ Computes the PTDF matrix by means of the KLU.LU factorization for sparse matrice
163163
"""
164164
function calculate_PTDF_matrix_KLU(
165165
branches,
166-
buses::Vector{PSY.Bus},
166+
buses::Vector{PSY.ACBus},
167167
bus_lookup::Dict{Int, Int},
168168
dist_slack::Vector{Float64})
169169
A, ref_bus_positions = calculate_A_matrix(branches, buses)
@@ -252,7 +252,7 @@ Computes the PTDF matrix by means of the LAPACK and BLAS functions for dense mat
252252
# Arguments
253253
- `branches`:
254254
vector of the System AC branches
255-
- `buses::Vector{PSY.Bus}`:
255+
- `buses::Vector{PSY.ACBus}`:
256256
vector of the System buses
257257
- `bus_lookup::Dict{Int, Int}`:
258258
dictionary mapping the bus numbers with their enumerated indexes.
@@ -261,7 +261,7 @@ Computes the PTDF matrix by means of the LAPACK and BLAS functions for dense mat
261261
"""
262262
function calculate_PTDF_matrix_DENSE(
263263
branches,
264-
buses::Vector{PSY.Bus},
264+
buses::Vector{PSY.ACBus},
265265
bus_lookup::Dict{Int, Int},
266266
dist_slack::Vector{Float64})
267267
A, ref_bus_positions = calculate_A_matrix(branches, buses)
@@ -336,7 +336,7 @@ Computes the PTDF matrix by means of the MKL Pardiso for dense matrices.
336336
# Arguments
337337
- `branches`:
338338
vector of the System AC branches
339-
- `buses::Vector{PSY.Bus}`:
339+
- `buses::Vector{PSY.ACBus}`:
340340
vector of the System buses
341341
- `bus_lookup::Dict{Int, Int}`:
342342
dictionary mapping the bus numbers with their enumerated indexes.
@@ -345,7 +345,7 @@ Computes the PTDF matrix by means of the MKL Pardiso for dense matrices.
345345
"""
346346
function calculate_PTDF_matrix_MKLPardiso(
347347
branches,
348-
buses::Vector{PSY.Bus},
348+
buses::Vector{PSY.ACBus},
349349
bus_lookup::Dict{Int, Int},
350350
dist_slack::Vector{Float64})
351351
A, ref_bus_positions = calculate_A_matrix(branches, buses)
@@ -360,7 +360,7 @@ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF
360360
# Arguments
361361
- `branches`:
362362
vector of the System AC branches
363-
- `buses::Vector{PSY.Bus}`:
363+
- `buses::Vector{PSY.ACBus}`:
364364
vector of the System buses
365365
- `dist_slack::Vector{Float64}`:
366366
vector of weights to be used as distributed slack bus.
@@ -372,7 +372,7 @@ Builds the PTDF matrix from a group of branches and buses. The return is a PTDF
372372
"""
373373
function PTDF(
374374
branches,
375-
buses::Vector{PSY.Bus};
375+
buses::Vector{PSY.ACBus};
376376
dist_slack::Vector{Float64} = Float64[],
377377
linear_solver::String = "KLU",
378378
tol::Float64 = eps())

src/virtual_lodf_calculations.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
The Virtual Line Outage Distribution Factor (VirtualLODF) structure gathers
3-
the rows of the LODF matrix as they are evaluated on-the-go. These rows are
4-
evalauted independently, cached in the structure and do not require the
5-
computation of the whole matrix (therefore significantly reducing the
3+
the rows of the LODF matrix as they are evaluated on-the-go. These rows are
4+
evalauted independently, cached in the structure and do not require the
5+
computation of the whole matrix (therefore significantly reducing the
66
computational requirements).
77
88
The VirtualLODF is initialized with no row stored.
@@ -20,12 +20,12 @@ The VirtualLODF struct is indexed using branch names.
2020
Vector contiaining the element-wise reciprocal of the diagonal elements
2121
coming from multuiplying the PTDF matrix with th Incidence matrix
2222
- `ref_bus_positions::Set{Int}`:
23-
Vector containing the indexes of the rows of the transposed BA matrix
23+
Vector containing the indexes of the rows of the transposed BA matrix
2424
corresponding to the refence buses.
2525
- `axes<:NTuple{2, Dict}`:
2626
Tuple containing two vectors showing the branch names.
2727
- `lookup<:NTuple{2, Dict}`:
28-
Tuple containing two dictionaries, mapping the branches names
28+
Tuple containing two dictionaries, mapping the branches names
2929
the enumerated row indexes indexes.
3030
- `valid_ix::Vector{Int}`:
3131
Vector containing the row/columns indices of matrices related the buses
@@ -101,7 +101,7 @@ end
101101

102102
function VirtualLODF(
103103
branches,
104-
buses::Vector{PSY.Bus};
104+
buses::Vector{PSY.ACBus};
105105
tol::Float64 = eps(),
106106
max_cache_size::Int = MAX_CACHE_SIZE_MiB,
107107
persistent_lines::Vector{String} = String[],

src/virtual_ptdf_calculations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ PTDF array indexed with the branch numbers.
7272
# Arguments
7373
- `branches`:
7474
Vector of the system's AC branches.
75-
- `buses::Vector{PSY.Bus}`:
75+
- `buses::Vector{PSY.ACBus}`:
7676
Vector of the system's buses.
7777
- `dist_slack::Vector{Float64} = Float64[]`:
7878
Vector of weights to be used as distributed slack bus.
@@ -86,7 +86,7 @@ PTDF array indexed with the branch numbers.
8686
"""
8787
function VirtualPTDF(
8888
branches,
89-
buses::Vector{PSY.Bus};
89+
buses::Vector{PSY.ACBus};
9090
dist_slack::Vector{Float64} = Float64[],
9191
tol::Float64 = eps(),
9292
max_cache_size::Int = MAX_CACHE_SIZE_MiB,

0 commit comments

Comments
 (0)