{ "cells": [ { "outputs": [], "cell_type": "code", "source": [ "#[PSSE 240 Bus Case system with Renewables](https://www.nrel.gov/grid/test-case-repository.html)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "**Originally Contributed by**: José Daniel Lara" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "# Introduction" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "This tutorial will introduce the industry models of Renewable Energy the comparisons between\n", "DiffEq Integration techniques for comparison. We show the uses of Sundials and OrdinaryDiffEq\n", "to obtain the transient response of a system to a perturbation." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using PowerSimulationsDynamics\n", "using PowerSystemCaseBuilder\n", "using PowerSystems\n", "using Sundials\n", "using Plots\n", "using OrdinaryDiffEq\n", "PSD = PowerSimulationsDynamics" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Load the system\n", "The system data is provided through PowerSystemCaseBuilder." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sys = build_system(PSSETestSystems, \"psse_240_case_renewable_sys\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Build the simulation and initialize the problem" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "The next step is to create the simulation structure. This will create the indexing\n", "of our system that will be used to formulate the differential-algebraic system of\n", "equations. To do so, it is required to specify the perturbation that will occur in\n", "the system. In this case, we will use a ResidualModel formulation, for more details\n", "about the formulation checkout the [Models Section](https://nrel-siip.github.io/PowerSimulationsDynamics.jl/stable/models/)\n", "in `PowerSimulationsDynamics.jl` documentation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using Logging\n", "sim_ida = PSD.Simulation(\n", " ResidualModel,\n", " sys, #system\n", " pwd(),\n", " (0.0, 20.0), #time span\n", " BranchTrip(1.0, Line, \"CORONADO -1101-PALOVRDE -1401-i_10\");\n", " console_level = Logging.Info,\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Run the simulation using Sundials\n", "We will now run the simulation using Sundials.jl solver IDA() by specifying the maximum\n", "dt we want for the simulation. In our experience with this solver, solution times are faster\n", "when supplying information about the maximum time step than the tolerances as we can see in the example" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "PSD.execute!(sim_ida, IDA(), dtmax = 0.01)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Read the results and plot a system variable\n", "After the simulation is completed, we can extract the results and make plots as desired.\n", "In this case, we will plot the voltage magnitude at the bus at which the line was connected." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "res_ida = read_results(sim_ida)\n", "v1101_ida = get_voltage_magnitude_series(res_ida, 1101);\n", "plot(v1101_ida)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Run the simulation using Rodas4()\n", "In this case, we will use a MassMatrixModel formulation, for more details\n", "about the formulation checkout the [Models Section](https://nrel-siip.github.io/PowerSimulationsDynamics.jl/stable/models/)\n", "in `PowerSimulationsDynamics.jl` documentation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sim_rodas = PSD.Simulation(\n", " MassMatrixModel,\n", " sys, #system\n", " pwd(),\n", " (0.0, 20.0), #time span\n", " BranchTrip(1.0, Line, \"CORONADO -1101-PALOVRDE -1401-i_10\");\n", " console_level = Logging.Info,\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "We will now run the simulation using OrdinaryDiffEq.jl solver Rodas4() by specifying the\n", "tolerance we want for the simulation. In our experience with this solver, solution times are faster\n", "when supplying information about the atol and rtol values as we can see in the example. The solver will also\n", "work with a specified dtmax but take a significantly longer time to solve.\n", "When using OrdinaryDiffEq.jl solvers always pass the option `initializealg = NoInit()` to avoid\n", "unnecessary re-initialization of the algebraic equations." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "PSD.execute!(\n", " sim_rodas,\n", " Rodas4(),\n", " saveat = 0.01,\n", " atol = 1e-10,\n", " rtol = 1e-10,\n", " initializealg = NoInit(),\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Read the results\n", "After the simulation is completed, we can extract the results and make plots as desired.\n", "In this case, we will plot the voltage magnitude at the bus at which the line was connected." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "res_rodas = read_results(sim_rodas)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Compare the results\n", "After the simulation is completed, we can extract the results and make plots as desired.\n", "In this case, we will plot the voltage magnitude at the bus at which the line was connected.\n", "For both of the solution techniques." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "v1101 = get_voltage_magnitude_series(res_rodas, 1101);\n", "plot(v1101, label = \"RODAS4\")\n", "plot!(v1101_ida, label = \"IDA\")" ], "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 }