{
"cells": [
{
"cell_type": "markdown",
"source": [
"Using PowerSystems to calculate network matrices"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"**Originally Contributed by**: Clayton Barrows"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## Introduction"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"PowerSystems.jl supports the calculation of several different matrix representations of\n",
"power system networks. This example demonstrates how to use PowerSystems.jl to calculate:\n",
" - Y bus\n",
" - Power transfer distribution factor (PTDF)\n",
" - Line outage distribution factor (LODF)"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### Dependencies\n",
"Let's use a dataset from the [tabular data parsing example](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/2_PowerSystems_examples/parse_matpower.ipynb)"
],
"metadata": {}
},
{
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ Info: Correcting vm in bus 1 to 1.07762 to match generator set-point\n",
"[ Info: Correcting vm in bus 3 to 1.1 to match generator set-point\n",
"[ Info: Correcting vm in bus 4 to 1.06414 to match generator set-point\n",
"[ Info: Correcting vm in bus 10 to 1.06907 to match generator set-point\n",
"[ Info: Correcting vm in bus 3 to 1.0 to match generator set-point\n",
"┌ Error: Generator voltage set-points for bus 3 are inconsistent. This can lead to unexpected results\n",
"└ @ PowerSystems ~/.julia/packages/PowerSystems/gGFFl/src/parsers/pm_io/matpower.jl:245\n",
"[ Info: Correcting vm in bus 10 to 1.0 to match generator set-point\n",
"┌ Error: Generator voltage set-points for bus 10 are inconsistent. This can lead to unexpected results\n",
"└ @ PowerSystems ~/.julia/packages/PowerSystems/gGFFl/src/parsers/pm_io/matpower.jl:245\n",
"[ Info: extending matpower format with data: areas 1x3\n",
"[ Info: extending matpower format with data: gen_name 7x4\n",
"[ Info: extending matpower format by appending matrix \"gen_name\" in to \"gen\"\n",
"[ Info: reversing the orientation of branch 6 (4, 3) to be consistent with other parallel branches\n",
"[ Info: the voltage setpoint on generator 6 does not match the value at bus 3\n",
"[ Info: the voltage setpoint on generator 7 does not match the value at bus 10\n",
"[ Info: removing 1 cost terms from generator 4: [4000.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 1: [1400.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 5: [1000.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 2: [1500.0, 0.0]\n",
"[ Info: removing 3 cost terms from generator 6: Float64[]\n",
"[ Info: removing 3 cost terms from generator 7: Float64[]\n",
"[ Info: removing 1 cost terms from generator 3: [3000.0, 0.0]\n",
"┌ Info: Constructing System from Power Models\n",
"│ data[\"name\"] = \"nesta_case5_pjm\"\n",
"└ data[\"source_type\"] = \"matpower\"\n",
"[ Info: Reading bus data\n",
"[ Info: Reading generator data\n",
"[ Info: Reading branch data\n",
"[ Info: Reading branch data\n",
"[ Info: Reading DC Line data\n",
"[ Info: Reading storage data\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": "System\n┌───────────────────┬─────────────┐\n│ Property │ Value │\n├───────────────────┼─────────────┤\n│ System Units Base │ SYSTEM_BASE │\n│ Base Power │ 100.0 │\n│ Base Frequency │ 60.0 │\n│ Num Components │ 30 │\n└───────────────────┴─────────────┘\n\nStatic Components\n┌──────────────────────────┬───────┬────────────────────────┬───────────────┐\n│ Type │ Count │ Has Static Time Series │ Has Forecasts │\n├──────────────────────────┼───────┼────────────────────────┼───────────────┤\n│ Arc │ 6 │ false │ false │\n│ Area │ 1 │ false │ false │\n│ Bus │ 5 │ false │ false │\n│ Line │ 5 │ false │ false │\n│ LoadZone │ 1 │ false │ false │\n│ PhaseShiftingTransformer │ 2 │ false │ false │\n│ PowerLoad │ 3 │ false │ false │\n│ RenewableDispatch │ 2 │ false │ false │\n│ ThermalStandard │ 5 │ false │ false │\n└──────────────────────────┴───────┴────────────────────────┴───────────────┘\n\n",
"text/html": [
"\n",
"\n",
"\n",
"\n",
"
\n",
"\n",
" System\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" System Units Base | \n",
" SYSTEM_BASE | \n",
"
\n",
" \n",
" Base Power | \n",
" 100.0 | \n",
"
\n",
" \n",
" Base Frequency | \n",
" 60.0 | \n",
"
\n",
" \n",
" Num Components | \n",
" 30 | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" Static Components\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Arc | \n",
" 6 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Area | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Bus | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Line | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" LoadZone | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PhaseShiftingTransformer | \n",
" 2 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PowerLoad | \n",
" 3 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" RenewableDispatch | \n",
" 2 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" ThermalStandard | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n"
]
},
"metadata": {},
"execution_count": 1
}
],
"cell_type": "code",
"source": [
"using SIIPExamples\n",
"\n",
"pkgpath = dirname(dirname(pathof(SIIPExamples)))\n",
"include(joinpath(pkgpath, \"test\", \"2_PowerSystems_examples\", \"02_parse_matpower.jl\"))"
],
"metadata": {},
"execution_count": 1
},
{
"cell_type": "markdown",
"source": [
"### Ybus"
],
"metadata": {}
},
{
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ Info: Validating connectivity with Goderya algorithm\n",
"[ Info: The System has no islands\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": "PowerNetworkMatrix\n:\n 22.2507-222.484im -3.52348+35.2348im … -15.4703+154.703im\n -3.52348+35.2348im 12.6911-126.898im ⋅ \n ⋅ -9.16758+91.6758im ⋅ \n -3.2569+32.569im ⋅ -3.33367+33.3367im\n -15.4703+154.703im ⋅ 18.804-188.021im"
},
"metadata": {},
"execution_count": 2
}
],
"cell_type": "code",
"source": [
"ybus = Ybus(sys)"
],
"metadata": {},
"execution_count": 2
},
{
"cell_type": "markdown",
"source": [
"### PTDF"
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "PowerNetworkMatrix\n:\n 0.23245 -0.37175 -0.219627 0.0 0.19124\n 0.41667 0.201807 0.119226 0.0 0.342801\n 0.35088 0.169943 0.100401 0.0 -0.53404\n 0.23245 0.62825 -0.219627 0.0 0.19124\n 0.116225 0.314125 0.390186 0.0 0.0956199\n 0.116225 0.314125 0.390186 0.0 0.0956199\n -0.35088 -0.169943 -0.100401 0.0 -0.46596"
},
"metadata": {},
"execution_count": 3
}
],
"cell_type": "code",
"source": [
"ptdf = PTDF(sys)"
],
"metadata": {},
"execution_count": 3
},
{
"cell_type": "markdown",
"source": [
"### LODF"
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "PowerNetworkMatrix\n:\n -1.0 0.398488 0.3581 -1.0 -0.360154 -0.360154 -0.3581\n 0.542857 -1.0 0.6419 0.542857 0.195512 0.195512 -0.6419\n 0.457143 0.601512 -1.0 0.457143 0.164642 0.164642 1.0\n -1.0 0.398488 0.3581 -1.0 -0.360154 -0.360154 -0.3581\n -0.5 0.199244 0.17905 -0.5 -1.0 0.639846 -0.17905\n -0.5 0.199244 0.17905 -0.5 0.639846 -1.0 -0.17905\n -0.457143 -0.601512 1.0 -0.457143 -0.164642 -0.164642 -1.0"
},
"metadata": {},
"execution_count": 4
}
],
"cell_type": "code",
"source": [
"lodf = LODF(sys)"
],
"metadata": {},
"execution_count": 4
},
{
"cell_type": "markdown",
"source": [
"### Indexing\n",
"Note that the axes of these matrices that correspond to buses are indexed by bus number\n",
"(::Int64) while the branch axes are indexed by branch name (::String). You can access\n",
"specific elements of the matrices as follows:"
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "0.39018648100730935"
},
"metadata": {},
"execution_count": 5
}
],
"cell_type": "code",
"source": [
"ptdf[\"bus3-bus4-i_6\", 3]"
],
"metadata": {},
"execution_count": 5
},
{
"cell_type": "markdown",
"source": [
"Additionally, PowerSystems provides accessors to the network matrices that take `Componets`\n",
"as arguments so that you can pass references to the components themselves rather than the\n",
"name or number. For example:"
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "-3.2569046378322044 + 32.56904637832204im"
},
"metadata": {},
"execution_count": 6
}
],
"cell_type": "code",
"source": [
"buses = collect(get_components(Bus, sys))\n",
"ybus[buses[1], buses[2]]"
],
"metadata": {},
"execution_count": 6
},
{
"cell_type": "markdown",
"source": [
"If you would instead like to index by bus name, something like the following should work:"
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "0.39018648100730935"
},
"metadata": {},
"execution_count": 7
}
],
"cell_type": "code",
"source": [
"busname2num = get_components(Bus, sys) |> (c -> Dict(zip(get_name.(c), get_number.(c))))\n",
"ptdf[\"bus3-bus4-i_6\", busname2num[\"bus3\"]]"
],
"metadata": {},
"execution_count": 7
},
{
"cell_type": "markdown",
"source": [
"---\n",
"\n",
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*"
],
"metadata": {}
}
],
"nbformat_minor": 3,
"metadata": {
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.2"
},
"kernelspec": {
"name": "julia-1.7",
"display_name": "Julia 1.7.2",
"language": "julia"
}
},
"nbformat": 4
}