SIIP Tutorial

Using PowerSystems to calculate network matrices

Originally Contributed by: Clayton Barrows

Introduction

PowerSystems.jl supports the calculation of several different matrix representations of power system networks. This example demonstrates how to use PowerSystems.jl to calculate:

Dependencies

Let's use a dataset from the tabular data parsing example

using PowerSystems
using TimeSeries
base_dir = PowerSystems.download(PowerSystems.TestData; branch = "master");
sys = System(joinpath(base_dir, "matpower", "case5_re.m"))
sys
┌ Error: Generator voltage set-points for bus 3 are inconsistent. This can lead to unexpected results
└ @ PowerSystems ~/.julia/packages/PowerSystems/zVsmd/src/parsers/pm_io/matpower.jl:245
┌ Error: Generator voltage set-points for bus 10 are inconsistent. This can lead to unexpected results
└ @ PowerSystems ~/.julia/packages/PowerSystems/zVsmd/src/parsers/pm_io/matpower.jl:245
System
Property Value
System Units Base SYSTEM_BASE
Base Power 100.0
Base Frequency 60.0
Num Components 30
Static Components
Type Count Has Static Time Series Has Forecasts
Arc 6 false false
Area 1 false false
Bus 5 false false
Line 5 false false
LoadZone 1 false false
PhaseShiftingTransformer 2 false false
PowerLoad 3 false false
RenewableDispatch 2 false false
ThermalStandard 5 false false

Ybus

ybus = Ybus(sys)
PowerNetworkMatrix
    Dimension 1, [1, 2, 3, 4, 10]
    Dimension 2, [1, 2, 3, 4, 10]
And data, a (5, 5):
  22.2507-222.484im  -3.52348+35.2348im           ⋅           -3.2569+32.569im   -15.4703+154.703im
 -3.52348+35.2348im   12.6911-126.898im  -9.16758+91.6758im           ⋅                   ⋅    
          ⋅          -9.16758+91.6758im    15.525-155.247im  -7.45707+63.3779im           ⋅    
  -3.2569+32.569im            ⋅          -5.24067+63.5996im    12.948-129.473im  -3.33367+33.3367im
 -15.4703+154.703im           ⋅                   ⋅          -3.33367+33.3367im    18.804-188.021im

PTDF

ptdf = PTDF(sys)
PowerNetworkMatrix
    Dimension 1, ["bus1-bus2-i_1", "bus1-bus4-i_2", "bus1-bus5-i_3", "bus2-bus3-i_4", "bus3-bus4-i_6", "bus3-bus4-i_5", "bus4-bus5-i_7"]
    Dimension 2, [1, 2, 3, 4, 10]
And data, a (7, 5):
  0.23245   -0.37175   -0.219627  0.0   0.19124
  0.41667    0.201807   0.119226  0.0   0.342801
  0.35088    0.169943   0.100401  0.0  -0.53404
  0.23245    0.62825   -0.219627  0.0   0.19124
  0.116225   0.314125   0.390186  0.0   0.0956199
  0.116225   0.314125   0.390186  0.0   0.0956199
 -0.35088   -0.169943  -0.100401  0.0  -0.46596

LODF

lodf = LODF(sys)
PowerNetworkMatrix
    Dimension 1, ["bus1-bus2-i_1", "bus1-bus4-i_2", "bus1-bus5-i_3", "bus2-bus3-i_4", "bus3-bus4-i_6", "bus3-bus4-i_5", "bus4-bus5-i_7"]
    Dimension 2, ["bus1-bus2-i_1", "bus1-bus4-i_2", "bus1-bus5-i_3", "bus2-bus3-i_4", "bus3-bus4-i_6", "bus3-bus4-i_5", "bus4-bus5-i_7"]
And data, a (7, 7):
 -1.0        0.398488   0.3581   -1.0       -0.360154  -0.360154  -0.3581
  0.542857  -1.0        0.6419    0.542857   0.195512   0.195512  -0.6419
  0.457143   0.601512  -1.0       0.457143   0.164642   0.164642   1.0
 -1.0        0.398488   0.3581   -1.0       -0.360154  -0.360154  -0.3581
 -0.5        0.199244   0.17905  -0.5       -1.0        0.639846  -0.17905
 -0.5        0.199244   0.17905  -0.5        0.639846  -1.0       -0.17905
 -0.457143  -0.601512   1.0      -0.457143  -0.164642  -0.164642  -1.0

Indexing

Note that the axes of these matrices that correspond to buses are indexed by bus number (::Int64) while the branch axes are indexed by branch name (::String). You can access specific elements of the matrices as follows:

ptdf["bus3-bus4-i_6", 3]
0.39018648100730935

Additionally, PowerSystems provides accessors to the network matrices that take Componets as arguments so that you can pass references to the components themselves rather than the name or number. For example:

buses = collect(get_components(Bus, sys))
ybus[buses[1], buses[2]]
-3.2569046378322044 + 32.56904637832204im

If you would instead like to index by bus name, something like the following should work:

busname2num = get_components(Bus, sys) |> (c -> Dict(zip(get_name.(c), get_number.(c))))
ptdf["bus3-bus4-i_6", busname2num["bus3"]]
0.39018648100730935
CC BY-SA 4.0 "Dheepak Krishnamurthy". Last modified: August 26, 2022. Website built with Franklin.jl and the Julia programming language.