{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# DC Line dispatch with pandapower OPF\n", "This is an introduction into the usage of the pandapower optimal power flow with dc lines.\n", "\n", "## Example Network\n", "\n", "We use the following four bus example network for this tutorial:\n", "\n", "\n", "\n", "We first create this network in pandapower:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandapower as pp\n", "from numpy import array\n", "net = pp.create_empty_network()\n", "\n", "b1 = pp.create_bus(net, 380)\n", "b2 = pp.create_bus(net, 380)\n", "b3 = pp.create_bus(net, 380)\n", "b4 = pp.create_bus(net, 380)\n", "b5 = pp.create_bus(net, 380)\n", "\n", "l1 = pp.create_line(net, b1, b2, 30, \"490-AL1/64-ST1A 380.0\")\n", "l2 = pp.create_line(net, b3, b4, 20, \"490-AL1/64-ST1A 380.0\")\n", "l3 = pp.create_line(net, b4, b5, 20, \"490-AL1/64-ST1A 380.0\")\n", "\n", "dcl1 = pp.create_dcline(net, name=\"dc line\", from_bus=b2, to_bus=b3, p_mw=200, loss_percent=1.0, \n", " loss_mw=0.5, vm_from_pu=1.01, vm_to_pu=1.012, max_p_mw=1000,\n", " in_service=True)\n", "\n", "eg1 = pp.create_ext_grid(net, b1, 1.02, min_p_mw=0.)\n", "eg2 = pp.create_ext_grid(net, b5, 1.02, min_p_mw=0.)\n", "\n", "l1 = pp.create_load(net, bus=b4, p_mw=800, controllable = False)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "We now run a regular load flow to check out the DC line model:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "pp.runpp(net)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The transmission power of the DC line is defined in the loadflow as given by the p_kw parameter, which was set to 200 MW:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
0200.0152.443185-197.574.4917592.51.01-0.485951.012-0.725627
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 200.0 152.443185 -197.5 74.491759 2.5 1.01 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -0.48595 1.012 -0.725627 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The losses amount to 2.5 MW, which are made up of 0.5 MW conversion loss and 200 MW * 0.01 = 2 MW transmission losses. The voltage setpoints defined at from and to bus are complied with. \n", "\n", "Now lets define costs for the external grids to run an OPF:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [], "source": [ "costeg0 = pp.create_poly_cost(net, 0, 'ext_grid', cp1_eur_per_mw=10)\n", "costeg1 = pp.create_poly_cost(net, 1, 'ext_grid', cp1_eur_per_mw=8)\n", "net.bus['max_vm_pu'] = 1.5\n", "net.line['max_loading_percent'] = 1000" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "hp.pandapower.run - INFO: These elements have missing power constraint values, which are considered in OPF as +- 1000 TW: ['dcline']\n", "hp.pandapower.run - INFO: 'min_vm_pu' is missing in bus table. In OPF these limits are considered as 0.0 pu.\n" ] } ], "source": [ "pp.runopp(net, delta=1e-16)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This function runs an Optimal Power Flow using the PYPOWER OPF. To make sure that the PYPOWER OPF converges, we decrease the power tolerance `delta` (the default value is `delta=1e-10`). The power tolerance `delta` is a measure of the extent to which exceeding of minimum and maximum power limits is tolerated. That is, in above case, the limits considered by the OPF for the generators are `min_p_mw - delta` and `max_p_mw + delta` as lower and upper bound respectively on the active power. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since we defined lower costs for Ext Grid 2, it fully services the load:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_mwq_mvar
00.500070-7.787527
1805.0914850.628364
\n", "
" ], "text/plain": [ " p_mw q_mvar\n", "0 0.500070 -7.787527\n", "1 805.091485 0.628364" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_ext_grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While the DC line does not transmit any power:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
00.5000677.787487-0.000066-0.627070.5000011.019994-0.0014481.013925-1.563437
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 0.500067 7.787487 -0.000066 -0.62707 0.500001 1.019994 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -0.001448 1.013925 -1.563437 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we set the costs of the left grid to a lower value than the right grid and run the loadflow again:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "hp.pandapower.run - INFO: These elements have missing power constraint values, which are considered in OPF as +- 1000 TW: ['dcline']\n", "hp.pandapower.run - INFO: 'min_vm_pu' is missing in bus table. In OPF these limits are considered as 0.0 pu.\n" ] } ], "source": [ "net.poly_cost.cp1_eur_per_mw.at[costeg0] = 8\n", "net.poly_cost.cp1_eur_per_mw.at[costeg1] = 10\n", "pp.runopp(net, delta=1e-16)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that the power now comes from the left ext_grid:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_mwq_mvar
0821.524623-7.787199
10.000759-21.048015
\n", "
" ], "text/plain": [ " p_mw q_mvar\n", "0 821.524623 -7.787199\n", "1 0.000759 -21.048015" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_ext_grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And is transmitted over the DC line:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
0813.573163-26.445627-805.022934-21.7356988.5502291.011014-2.3998681.0275041.522331
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 813.573163 -26.445627 -805.022934 -21.735698 8.550229 1.011014 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -2.399868 1.027504 1.522331 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can however see that the lines on the left hand side are now overloaded:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 127.474837\n", "1 124.074276\n", "2 3.265845\n", "Name: loading_percent, dtype: float64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_line.loading_percent" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we set the maximum line loading to 100% and run the OPF again:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "hp.pandapower.run - INFO: These elements have missing power constraint values, which are considered in OPF as +- 1000 TW: ['dcline']\n", "hp.pandapower.run - INFO: 'min_vm_pu' is missing in bus table. In OPF these limits are considered as 0.0 pu.\n" ] } ], "source": [ "net.line[\"max_loading_percent\"] = 100\n", "pp.runopp(net, delta=1e-16)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that the lines are no longer overloaded:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 100.000007\n", "1 97.795377\n", "2 26.591814\n", "Name: loading_percent, dtype: float64" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_line.loading_percent" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Because the load is serviced from both grids:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_mwq_mvar
0644.488864-0.680457
1170.582480-16.528459
\n", "
" ], "text/plain": [ " p_mw q_mvar\n", "0 644.488864 -0.680457\n", "1 170.582480 -16.528459" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_ext_grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the DC line transmits only part of the power needed to service the load:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
0639.594579-6.207846-632.76691-10.0990656.8276691.012431-1.8750221.0243850.875621
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 639.594579 -6.207846 -632.76691 -10.099065 6.827669 1.012431 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -1.875022 1.024385 0.875621 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we can also define transmission costs for the DC line:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "hp.pandapower.run - INFO: These elements have missing power constraint values, which are considered in OPF as +- 1000 TW: ['dcline']\n", "hp.pandapower.run - INFO: 'min_vm_pu' is missing in bus table. In OPF these limits are considered as 0.0 pu.\n" ] } ], "source": [ "costeg1 = pp.create_poly_cost(net, 0, 'dcline', cp1_eur_per_mw=3)\n", "pp.runopp(net, delta=1e-16)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Because the sum of the costs for generating power on the left hand side (8) and transmitting it to the right side (3) is now larger than for generating on the right side (10), the OPF draws as much power from the right side as is possible without violating line loading constraints:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 25.067630\n", "1 24.770581\n", "2 100.000029\n", "Name: loading_percent, dtype: float64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_line.loading_percent" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
0161.0635646.442959-158.9738254.8972242.0897381.018095-0.4679911.016202-0.938724
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 161.063564 6.442959 -158.973825 4.897224 2.089738 1.018095 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -0.467991 1.016202 -0.938724 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we relax the line loading constraint and run the OPF again:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "hp.pandapower.run - INFO: These elements have missing power constraint values, which are considered in OPF as +- 1000 TW: ['dcline']\n", "hp.pandapower.run - INFO: 'min_vm_pu' is missing in bus table. In OPF these limits are considered as 0.0 pu.\n" ] } ], "source": [ "net.line[\"max_loading_percent\"] = 1000\n", "pp.runopp(net, delta=1e-16)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The load is once again fully serviced by the grid on the right hand side:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_mwq_mvar
00.503447-7.787432
1805.0880980.628941
\n", "
" ], "text/plain": [ " p_mw q_mvar\n", "0 0.503447 -7.787432\n", "1 805.088098 0.628941" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_ext_grid" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And the DC line is in open loop operation:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
p_from_mwq_from_mvarp_to_mwq_to_mvarpl_mwvm_from_puva_from_degreevm_to_puva_to_degree
00.5034447.787581-0.00341-0.6263090.5000341.019994-0.0014571.013925-1.563423
\n", "
" ], "text/plain": [ " p_from_mw q_from_mvar p_to_mw q_to_mvar pl_mw vm_from_pu \\\n", "0 0.503444 7.787581 -0.00341 -0.626309 0.500034 1.019994 \n", "\n", " va_from_degree vm_to_pu va_to_degree \n", "0 -0.001457 1.013925 -1.563423 " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_dcline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Little consistency check:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8056.418890964989" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_ext_grid.p_mw.at[0]*8 + net.res_ext_grid.p_mw.at[1]*10 + net.res_dcline.p_from_mw.at[0]*3" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "8056.418890964989" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net.res_cost" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 1 }