{ "cells": [ { "cell_type": "markdown", "source": [ "# PTDF with [PowerSimulations.jl](https://github.com/NREL-SIIP/PowerSimulations.jl)" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "**Originally Contributed by**: Sourabh Dalvi" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Introduction" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "PowerSimulations.jl supports linear PTDF optimal power flow formulation. This example shows a\n", "single multi-period optimization of economic dispatch with a linearized DC-OPF representation of\n", "using PTDF power flow and how to extract duals values or locational marginal prices for energy." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Dependencies" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using SIIPExamples\n", "using PowerSystems\n", "using PowerSimulations\n", "using PowerSystemCaseBuilder\n", "using DataFrames" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "Since we'll be retrieving duals, we need a solver that returns duals values\n", "here we use Ipopt." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "MathOptInterface.OptimizerWithAttributes(Ipopt.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute,Any}[])" }, "metadata": {}, "execution_count": 2 } ], "cell_type": "code", "source": [ "using Ipopt\n", "solver = optimizer_with_attributes(Ipopt.Optimizer)" ], "metadata": {}, "execution_count": 2 }, { "cell_type": "markdown", "source": [ "We can use the same RTS data and some of the initialization as in\n", "[OperationsProblem example](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/3_PowerSimulations_examples/01_operations_problems.ipynb)" ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ Info: Loaded time series from storage file existing=modified_RTS_GMLC_DA_sys_time_series_storage.h5 new=/var/folders/27/2jr8c7gn4j72fvrg4qt81zrw8w_711/T/jl_i2adzQ\n", "┌ Warning: Rate 500.0 MW for C31-2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for B8 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B26 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A32-2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for CA-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for A5 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B34 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B19 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B31-2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C30 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B27 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A21 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A32-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B29 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A18 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C5 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C13-2 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C24 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C28 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A29 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for A3 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for AB1 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for AB2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C27 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 722.0 MW for C35 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A25-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for B5 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for B2 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B31-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C20 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B23 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A28 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A19 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C9 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C1 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C2 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B25-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for A9 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C11 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C19 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C23 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C25-1 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C32-2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for B20 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for B9 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C25-2 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 175.0 MW for C12-1 is larger than the max expected in the range of (min = 47.0, max = 52.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A27 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for C21 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n", "┌ Warning: Rate 500.0 MW for A34 is larger than the max expected in the range of (min = 134.0, max = 145.0).\n", "└ @ PowerSystems ~/.julia/packages/PowerSystems/N2l8o/src/utils/IO/branchdata_checks.jl:148\n" ] }, { "output_type": "execute_result", "data": { "text/plain": "System\n======\nSystem Units Base: SYSTEM_BASE\nBase Power: 100.0\nBase Frequency: 60.0\n\nComponents\n==========\nNum components: 529\n\n\u001b[1m16×3 DataFrame\u001b[0m\n\u001b[1m Row \u001b[0m│\u001b[1m ConcreteType \u001b[0m\u001b[1m SuperTypes \u001b[0m\u001b[1m Count \u001b[0m\n\u001b[1m \u001b[0m│\u001b[90m String \u001b[0m\u001b[90m String \u001b[0m\u001b[90m Int64 \u001b[0m\n─────┼────────────────────────────────────────────────────────────────────────\n 1 │ Arc Topology <: Component <: Infrast… 109\n 2 │ Area AggregationTopology <: Topology … 3\n 3 │ Bus Topology <: Component <: Infrast… 73\n 4 │ GenericBattery Storage <: StaticInjection <: De… 1\n 5 │ HVDCLine DCBranch <: Branch <: Device <: … 1\n 6 │ HydroDispatch HydroGen <: Generator <: StaticI… 1\n 7 │ HydroEnergyReservoir HydroGen <: Generator <: StaticI… 19\n 8 │ Line ACBranch <: Branch <: Device <: … 105\n 9 │ LoadZone AggregationTopology <: Topology … 21\n 10 │ PowerLoad StaticLoad <: ElectricLoad <: St… 51\n 11 │ RenewableDispatch RenewableGen <: Generator <: Sta… 30\n 12 │ RenewableFix RenewableGen <: Generator <: Sta… 31\n 13 │ TapTransformer ACBranch <: Branch <: Device <: … 15\n 14 │ ThermalStandard ThermalGen <: Generator <: Stati… 64\n 15 │ VariableReserve{ReserveDown} Reserve{ReserveDown} <: Service … 1\n 16 │ VariableReserve{ReserveUp} Reserve{ReserveUp} <: Service <:… 4\n\nTimeSeriesContainer\n===================\nComponents with time series data: 140\nTotal StaticTimeSeries: 180\nTotal Forecasts: 180\nResolution: 60 minutes\nFirst initial time: 2020-01-01T00:00:00\nLast initial time: 2020-12-30T00:00:00\nHorizon: 48\nInterval: 1440 minutes\nForecast window count: 365\n", "text/html": [ "
Base Power: 100.0
\n", "Num components: 529
\n", "ConcreteType | SuperTypes | Count | |
---|---|---|---|
String | String | Int64 | |
1 | Arc | Topology <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 109 |
2 | Area | AggregationTopology <: Topology <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 3 |
3 | Bus | Topology <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 73 |
4 | GenericBattery | Storage <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 1 |
5 | HVDCLine | DCBranch <: Branch <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 1 |
6 | HydroDispatch | HydroGen <: Generator <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 1 |
7 | HydroEnergyReservoir | HydroGen <: Generator <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 19 |
8 | Line | ACBranch <: Branch <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 105 |
9 | LoadZone | AggregationTopology <: Topology <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 21 |
10 | PowerLoad | StaticLoad <: ElectricLoad <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 51 |
11 | RenewableDispatch | RenewableGen <: Generator <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 30 |
12 | RenewableFix | RenewableGen <: Generator <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 31 |
13 | TapTransformer | ACBranch <: Branch <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 15 |
14 | ThermalStandard | ThermalGen <: Generator <: StaticInjection <: Device <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 64 |
15 | VariableReserve{ReserveDown} | Reserve{ReserveDown} <: Service <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 1 |
16 | VariableReserve{ReserveUp} | Reserve{ReserveUp} <: Service <: Component <: InfrastructureSystemsComponent <: InfrastructureSystemsType <: Any | 4 |
Components with time series data: 140
\n", "Total StaticTimeSeries: 180
\n", "Total Forecasts: 180
\n", "Resolution: 60 minutes
\n", "First initial time: 2020-01-01T00:00:00
\n", "Last initial time: 2020-12-30T00:00:00
\n", "Horizon: 48
\n", "Interval: 1440 minutes
\n", "Forecast window count: 365
\n" ] }, "metadata": {}, "execution_count": 3 } ], "cell_type": "code", "source": [ "sys = build_system(PSITestSystems, \"modified_RTS_GMLC_DA_sys\")" ], "metadata": {}, "execution_count": 3 }, { "cell_type": "markdown", "source": [ "Here, we want do define an economic dispatch (linear generation decisions) with\n", "linear DC-OPF using PTDF network representation.\n", "So, starting with the network, we can select from _almost_ any of the endpoints on this\n", "tree:" ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AbstractPowerModel\n", "├─ AbstractACPModel\n", "│ └─ ACPPowerModel\n", "├─ AbstractACRModel\n", "│ ├─ ACRPowerModel\n", "│ └─ AbstractIVRModel\n", "│ └─ IVRPowerModel\n", "├─ AbstractACTModel\n", "│ └─ ACTPowerModel\n", "├─ AbstractActivePowerModel\n", "│ ├─ AreaBalancePowerModel\n", "│ ├─ CopperPlatePowerModel\n", "│ └─ AbstractDCPModel\n", "│ ├─ DCPPowerModel\n", "│ ├─ AbstractDCMPPModel\n", "│ │ └─ DCMPPowerModel\n", "│ ├─ AbstractDCPLLModel\n", "│ │ └─ DCPLLPowerModel\n", "│ ├─ AbstractNFAModel\n", "│ │ └─ NFAPowerModel\n", "│ └─ AbstractPTDFModel\n", "│ ├─ PTDFPowerModel\n", "│ └─ StandardPTDFModel\n", "├─ AbstractBFModel\n", "│ ├─ AbstractBFAModel\n", "│ │ └─ BFAPowerModel\n", "│ ├─ AbstractBFConicModel\n", "│ │ └─ AbstractSOCBFConicModel\n", "│ │ └─ SOCBFConicPowerModel\n", "│ └─ AbstractBFQPModel\n", "│ └─ AbstractSOCBFModel\n", "│ └─ SOCBFPowerModel\n", "├─ AbstractConicModel\n", "│ ├─ AbstractWRConicModel\n", "│ │ └─ AbstractSOCWRConicModel\n", "│ │ └─ SOCWRConicPowerModel\n", "│ └─ AbstractWRMModel\n", "│ └─ AbstractSDPWRMModel\n", "│ ├─ AbstractSparseSDPWRMModel\n", "│ │ └─ SparseSDPWRMPowerModel\n", "│ │ ⋮\n", "│ │ \n", "│ └─ SDPWRMPowerModel\n", "├─ AbstractLPACModel\n", "│ └─ AbstractLPACCModel\n", "│ └─ LPACCPowerModel\n", "└─ AbstractWRModel\n", " ├─ AbstractQCWRModel\n", " │ ├─ AbstractQCLSModel\n", " │ │ └─ QCLSPowerModel\n", " │ └─ AbstractQCRMPowerModel\n", " │ └─ QCRMPowerModel\n", " └─ AbstractSOCWRModel\n", " └─ SOCWRPowerModel\n" ] } ], "cell_type": "code", "source": [ "print_tree(PowerSimulations.PM.AbstractPowerModel)" ], "metadata": {}, "execution_count": 4 }, { "cell_type": "markdown", "source": [ "For now, let's just choose a standard PTDF formulation." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "\nOperations Problem Specification\n============================================\nTransmission: StandardPTDFModel\n============================================\nDevices Models: \n\n\tType: ThermalStandard\n \tFormulation: ThermalDispatch\n\n\tType: HydroDispatch\n \tFormulation: HydroDispatchRunOfRiver\n\n\tType: PowerLoad\n \tFormulation: StaticPowerLoad\n\n\tType: RenewableFix\n \tFormulation: FixedOutput\n\n\tType: RenewableDispatch\n \tFormulation: RenewableFullDispatch\n\n\tType: HydroEnergyReservoir\n \tFormulation: HydroDispatchRunOfRiver\n\n\tType: InterruptibleLoad\n \tFormulation: InterruptiblePowerLoad\n\n============================================\nBranches Models: \n\n\tType: Line\n \tFormulation: StaticBranch\n\n\tType: TapTransformer\n \tFormulation: StaticBranch\n\n\tType: Transformer2W\n \tFormulation: StaticBranch\n\n\tType: HVDCLine\n \tFormulation: HVDCDispatch\n\n============================================\nServices Models:\n\n\tType: VariableReserve{ReserveDown}\n \tFormulation: RangeReserve\n\n\tType: VariableReserve{ReserveUp}\n \tFormulation: RangeReserve\n\n============================================\n" }, "metadata": {}, "execution_count": 5 } ], "cell_type": "code", "source": [ "ed_template = template_economic_dispatch(network = StandardPTDFModel)" ], "metadata": {}, "execution_count": 5 }, { "cell_type": "markdown", "source": [ "Currently energy budget data isn't stored in the RTS-GMLC dataset." ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ Info: Overwriting HydroEnergyReservoir existing model\n" ] } ], "cell_type": "code", "source": [ "set_device_model!(ed_template, HydroEnergyReservoir, HydroDispatchRunOfRiver)" ], "metadata": {}, "execution_count": 6 }, { "cell_type": "markdown", "source": [ "Calculate the PTDF matrix." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "PowerNetworkMatrix\n:\n 0.436221 -0.506679 0.0955772 … 0.0139213 0.0168526\n 0.242695 0.220093 -0.199576 -0.0291078 -0.0352191\n 0.321083 0.286586 0.103999 0.0151865 0.0183664\n 0.240805 0.269317 0.029752 0.00430723 0.00522632\n 0.195416 0.224003 0.0658252 0.00961407 0.0116263\n 0.0884399 0.0729336 0.422869 … 0.0616101 0.0745751\n 0.154255 0.14716 0.377554 -0.0907179 -0.109794\n 0.240805 0.269317 0.029752 0.00430723 0.00522632\n 0.321083 0.286586 0.103999 0.0151865 0.0183664\n 0.195416 0.224003 0.0658252 0.00961407 0.0116263\n ⋮ ⋱ \n -0.00640688 -0.00621149 -0.0125463 -0.170422 -0.0870865\n -0.00640688 -0.00621149 -0.0125463 -0.170422 -0.0870865\n -0.0101178 -0.00980923 -0.0198131 0.129136 -0.137527\n -0.0101178 -0.00980923 -0.0198131 0.129136 -0.137527\n -0.0101178 -0.00980923 -0.0198131 … 0.129136 -0.137527\n -0.0101178 -0.00980923 -0.0198131 0.129136 -0.137527\n -0.000301309 -0.00029212 -0.000590038 0.0124161 -0.00409559\n -0.0284356 -0.0275684 -0.0556839 0.496086 -0.386515\n -0.0284356 -0.0275684 -0.0556839 0.496086 0.613485" }, "metadata": {}, "execution_count": 7 } ], "cell_type": "code", "source": [ "PTDF_matrix = PTDF(sys)" ], "metadata": {}, "execution_count": 7 }, { "cell_type": "markdown", "source": [ "Now we can build a 4-hour economic dispatch / OPF problem with the RTS data.\n", "Here, we have to pass the keyword argument `constraint_duals` to OperationsProblem\n", "with the name of the constraint for which duals are required for them to be returned in the results." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "BuildStatus.BUILT = 0" }, "metadata": {}, "execution_count": 8 } ], "cell_type": "code", "source": [ "problem = OperationsProblem(\n", " EconomicDispatchProblem,\n", " ed_template,\n", " sys,\n", " horizon = 1,\n", " optimizer = solver,\n", " balance_slack_variables = true,\n", " constraint_duals = [\n", " :CopperPlateBalance,\n", " :network_flow__Line,\n", " :network_flow__TapTransformer,\n", " ],\n", " PTDF = PTDF_matrix,\n", ")\n", "build!(problem, output_dir = mktempdir())" ], "metadata": {}, "execution_count": 8 }, { "cell_type": "markdown", "source": [ "And solve the problem and collect the results" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "RunStatus.SUCCESSFUL = 0" }, "metadata": {}, "execution_count": 9 } ], "cell_type": "code", "source": [ "solve!(problem)" ], "metadata": {}, "execution_count": 9 }, { "cell_type": "markdown", "source": [ "Here we collect the dual values from the results for the `:CopperPlateBalance` and `:network_flow`\n", "constraints. In the case of PTDF network formulation we need to compute the final LMP for each bus in the system by\n", "subtracting the duals (μ) of `:network_flow` constraints multiplied by the PTDF matrix\n", "from the dual (λ) of `:CopperPlateBalance` constraint." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "1×120 Array{Union{Missing, Float64},2}:\n -1.05088e-6 1.67219e-6 -3.46606e-6 … 3.33268e-7 1.12191e-6 2.53909e-6" }, "metadata": {}, "execution_count": 10 } ], "cell_type": "code", "source": [ "res = ProblemResults(problem)\n", "duals = get_duals(res)\n", "λ = convert(Array, duals[:CopperPlateBalance][:, :var])\n", "flow_duals = outerjoin(\n", " [duals[k] for k in [:network_flow__Line, :network_flow__TapTransformer]]...,\n", " on = :DateTime,\n", ")\n", "μ = Matrix(flow_duals[:, PTDF_matrix.axes[1]])" ], "metadata": {}, "execution_count": 10 }, { "cell_type": "markdown", "source": [ "Here we create Dict to store the calculate congestion component of the LMP which is a product of μ and the PTDF matrix." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "\u001b[1m1×73 DataFrame\u001b[0m\n\u001b[1m Row \u001b[0m│\u001b[1m Abel \u001b[0m\u001b[1m Adams \u001b[0m\u001b[1m Adler \u001b[0m\u001b[1m Agricola \u001b[0m\u001b[1m Aiken \u001b[0m\u001b[1m Alber \u001b[0m\u001b[1m \u001b[0m ⋯\n\u001b[1m \u001b[0m│\u001b[90m Float64? \u001b[0m\u001b[90m Float64? \u001b[0m\u001b[90m Float64? \u001b[0m\u001b[90m Float64? \u001b[0m\u001b[90m Float64? \u001b[0m\u001b[90m Float64? \u001b[0m\u001b[90m \u001b[0m ⋯\n─────┼──────────────────────────────────────────────────────────────────────────\n 1 │ 2.28716e-6 3.4901e-6 2.51587e-7 5.34001e-6 4.97636e-6 8.22617e-6 ⋯\n\u001b[36m 67 columns omitted\u001b[0m", "text/html": [ "Abel | Adams | Adler | Agricola | Aiken | Alber | Alder | |
---|---|---|---|---|---|---|---|
Float64? | Float64? | Float64? | Float64? | Float64? | Float64? | Float64? | |
1 | 2.28716e-6 | 3.4901e-6 | 2.51587e-7 | 5.34001e-6 | 4.97636e-6 | 8.22617e-6 | -9.02173e-6 |
Abel | Adams | Adler | Agricola | Aiken | Alber | Alder | Alger | Ali | |
---|---|---|---|---|---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 | -1.0e6 |