{ "cells": [ { "cell_type": "markdown", "source": [ "# Selective flow constraints with [PowerSimulations.jl](https://github.com/NREL/PowerSimulations.jl)" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "**Originally Contributed by**: Clayton Barrows and Sourabh Dalvi" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Introduction" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "The [Operations Problems example]](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/3_PowerSimulations_examples/02_sequential_simulations.ipynb)\n", "shows the basic building blocks of building optimization problems with PowerSimulations.jl.\n", "This example shows how to customize the enforcement of branch flow constraints as is common\n", "when trying to build large scale simulations." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Dependencies\n", "### Modeling Packages" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using PowerSystems\n", "using PowerSimulations\n", "using PowerSystemCaseBuilder" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Optimization packages\n", "For this simple example, we can use the HiGHS solver with a relatively relaxed tolerance." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using HiGHS # mip solver\n", "solver = optimizer_with_attributes(HiGHS.Optimizer, \"mip_rel_gap\" => 0.5)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Create a `System` from RTS-GMLC data" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sys = build_system(PSITestSystems, \"modified_RTS_GMLC_DA_sys\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Selecting flow limited lines\n", "Since PowerSimulations will apply constraints by component type (e.g. Line), we need to\n", "change the component type of the lines on which we want to enforce flow limits. So, let's\n", "change the device type of certain branches from Line to MonitoredLine differentiate\n", "treatment when we build the model. Here, we can select inter-regional lines, or lines\n", "above a voltage threshold." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "for line in get_components(Line, sys)\n", " if (get_base_voltage(get_from(get_arc(line))) >= 230.0) &&\n", " (get_base_voltage(get_to(get_arc(line))) >= 230.0)\n", " #if get_area(get_from(get_arc(line))) != get_area(get_to(get_arc(line)))\n", " @info \"Changing $(get_name(line)) to MonitoredLine\"\n", " convert_component!(MonitoredLine, line, sys)\n", " end\n", "end" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Let's start with a standard unit commitment template using the `PTDFPowerModel` network\n", "formulation which only constructs the admittance matrix rows corresponding to \"bounded\" lines:" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "template = template_unit_commitment(network = PTDFPowerModel)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Notice that there is no entry for `MonitoredLine`, so we can add one:" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "set_device_model!(template, MonitoredLine, StaticBranch)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "We can also relax the formulation applied to the `Line` components to an unbounded flow formulation.\n", "This formulation still enforces Kirchoff's laws, but does not apply flow constraints." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "set_device_model!(template, Line, StaticBranchUnbounded)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Build an `OperationsProblem`" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "uc_prob = DecisionModel(template, sys, horizon = 24, optimizer = solver)\n", "build!(uc_prob, output_dir = mktempdir())" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Solve the relaxed problem" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "solve!(uc_prob)" ], "metadata": {}, "execution_count": null }, { "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 }