From 61bf3d157f21e82dbe7575eda71500859533729e Mon Sep 17 00:00:00 2001 From: Nicolas PIERRE Date: Wed, 14 Dec 2022 16:21:00 +0100 Subject: [PATCH 1/2] dynawaltz example Signed-off-by: Nicolas PIERRE --- dynawaltz.ipynb | 287 ++++++++++++++++++++++++++++++++++++++++++ dynawaltz/IEEE14.iidm | 224 +++++++++++++++++++++++++++++++++ dynawaltz/config.yaml | 18 +++ dynawaltz/models.par | 66 ++++++++++ dynawaltz/network.par | 25 ++++ dynawaltz/solver.par | 12 ++ 6 files changed, 632 insertions(+) create mode 100644 dynawaltz.ipynb create mode 100644 dynawaltz/IEEE14.iidm create mode 100644 dynawaltz/config.yaml create mode 100644 dynawaltz/models.par create mode 100644 dynawaltz/network.par create mode 100644 dynawaltz/solver.par diff --git a/dynawaltz.ipynb b/dynawaltz.ipynb new file mode 100644 index 0000000..e3a72e4 --- /dev/null +++ b/dynawaltz.ipynb @@ -0,0 +1,287 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Pypowsybl dynawaltz simulation" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "import pypowsybl as pp\n", + "import pypowsybl.dynamic as dyn\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "network = pp.network.load(\"./dynawaltz/IEEE14.iidm\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can add dynamic mappings with dataframes like this :" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "df_alpha_beta = pd.DataFrame.from_dict({\"static_id\": [network.get_loads().loc[l].name for l in network.get_loads().index],\n", + " \"parameter_set_id\": [\"LAB\" for l in network.get_loads().index]})\n", + "df_GSTWPR = pd.DataFrame.from_dict({\"static_id\": [network.get_generators().loc[l].name for l in network.get_generators().index],\n", + " \"parameter_set_id\": [\"GSTWPR\" for l in network.get_generators().index]})\n", + "df_omega_ref = pd.DataFrame.from_dict({\"generator_id\": [network.get_generators().loc[l].name for l in network.get_generators().index]})" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Don't forget to index the dataframe on the network element id column" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "model_mapping = dyn.ModelMapping()\n", + "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.ALPHA_BETA_LOAD, df_alpha_beta.set_index(\"static_id\"))\n", + "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.GENERATOR_SYNCHRONOUS_THREE_WINDINGS_PROPORTIONAL_REGULATIONS, df_GSTWPR.set_index(\"static_id\"))\n", + "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.OMEGA_REF, df_omega_ref.set_index(\"generator_id\"))" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Adding events" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "events = dyn.EventMapping()\n", + "events.add_event(\"EQD\", dyn.EventType.BRANCH_DISCONNECTION, \"_BUS____1-BUS____5-1_AC\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Adding curves, you can batch curves creation for a given id" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "timeseries = dyn.CurveMapping()\n", + "timeseries.add_curves(\"_LOAD___2_EC\", [\"load_PPu\", \"load_QPu\"])" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Running the simulation (will load the default config file in ~/.itools folder)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "sim = dyn.Simulation()\n", + "res = sim.run(network, model_mapping, events, timeseries, 0, 30)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Display data of the run:" + ] + }, + { + "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", + " \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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
_LOAD___2_EC_load_QPu_LOAD___2_EC_load_PPu
timestamp
00.1269920.216992
00.1269920.216992
00.1269920.216992
00.1269920.216992
00.1269920.216992
.........
99000.1252070.215157
127100.1252080.215157
183310.1252080.215158
283310.1252080.215158
300000.1252080.215158
\n", + "

252 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " _LOAD___2_EC_load_QPu _LOAD___2_EC_load_PPu\n", + "timestamp \n", + "0 0.126992 0.216992\n", + "0 0.126992 0.216992\n", + "0 0.126992 0.216992\n", + "0 0.126992 0.216992\n", + "0 0.126992 0.216992\n", + "... ... ...\n", + "9900 0.125207 0.215157\n", + "12710 0.125208 0.215157\n", + "18331 0.125208 0.215158\n", + "28331 0.125208 0.215158\n", + "30000 0.125208 0.215158\n", + "\n", + "[252 rows x 2 columns]" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res.status()\n", + "res.curves()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.8.10 (default, Jun 22 2022, 20:18:18) \n[GCC 9.4.0]" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/dynawaltz/IEEE14.iidm b/dynawaltz/IEEE14.iidm new file mode 100644 index 0000000..df38208 --- /dev/null +++ b/dynawaltz/IEEE14.iidm @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawaltz/config.yaml b/dynawaltz/config.yaml new file mode 100644 index 0000000..7b5176b --- /dev/null +++ b/dynawaltz/config.yaml @@ -0,0 +1,18 @@ +# copy to ~/.itools/config.yaml +dynamic-simulation-default-parameters: + startTime: 0 + stopTime: 30 + +dynawaltz: + homeDir: PATH/TO/DYNAWO # root directory of dynawo installation + debug: true + +dynawaltz-default-parameters: + # All the pathes can be relative to the root directory + parametersFile: ./dynawaltz/models.par + network.parametersFile: ./dynawaltz/network.par + network.parametersId: "1" + solver.type: IDA + solver.parametersFile: ./dynawaltz/solver.par + solver.parametersId: "1" + diff --git a/dynawaltz/models.par b/dynawaltz/models.par new file mode 100644 index 0000000..6054bdd --- /dev/null +++ b/dynawaltz/models.par @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawaltz/network.par b/dynawaltz/network.par new file mode 100644 index 0000000..91c6cda --- /dev/null +++ b/dynawaltz/network.par @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dynawaltz/solver.par b/dynawaltz/solver.par new file mode 100644 index 0000000..339c440 --- /dev/null +++ b/dynawaltz/solver.par @@ -0,0 +1,12 @@ + + + + + + + + + + + + From 1446716465ab1e6258d88de81a08f4f905a964d2 Mon Sep 17 00:00:00 2001 From: Nicolas PIERRE Date: Thu, 15 Dec 2022 11:10:38 +0100 Subject: [PATCH 2/2] remove omega ref --- dynawaltz.ipynb | 140 +++++------------------------------------------- 1 file changed, 12 insertions(+), 128 deletions(-) diff --git a/dynawaltz.ipynb b/dynawaltz.ipynb index e3a72e4..a690d23 100644 --- a/dynawaltz.ipynb +++ b/dynawaltz.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -39,15 +39,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_alpha_beta = pd.DataFrame.from_dict({\"static_id\": [network.get_loads().loc[l].name for l in network.get_loads().index],\n", " \"parameter_set_id\": [\"LAB\" for l in network.get_loads().index]})\n", "df_GSTWPR = pd.DataFrame.from_dict({\"static_id\": [network.get_generators().loc[l].name for l in network.get_generators().index],\n", - " \"parameter_set_id\": [\"GSTWPR\" for l in network.get_generators().index]})\n", - "df_omega_ref = pd.DataFrame.from_dict({\"generator_id\": [network.get_generators().loc[l].name for l in network.get_generators().index]})" + " \"parameter_set_id\": [\"GSTWPR\" for l in network.get_generators().index]})" ] }, { @@ -60,14 +59,13 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model_mapping = dyn.ModelMapping()\n", "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.ALPHA_BETA_LOAD, df_alpha_beta.set_index(\"static_id\"))\n", - "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.GENERATOR_SYNCHRONOUS_THREE_WINDINGS_PROPORTIONAL_REGULATIONS, df_GSTWPR.set_index(\"static_id\"))\n", - "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.OMEGA_REF, df_omega_ref.set_index(\"generator_id\"))" + "model_mapping.add_all_dynamic_mappings(dyn.DynamicMappingType.GENERATOR_SYNCHRONOUS_THREE_WINDINGS_PROPORTIONAL_REGULATIONS, df_GSTWPR.set_index(\"static_id\"))" ] }, { @@ -80,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -98,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -116,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -134,123 +132,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "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", - " \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", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
_LOAD___2_EC_load_QPu_LOAD___2_EC_load_PPu
timestamp
00.1269920.216992
00.1269920.216992
00.1269920.216992
00.1269920.216992
00.1269920.216992
.........
99000.1252070.215157
127100.1252080.215157
183310.1252080.215158
283310.1252080.215158
300000.1252080.215158
\n", - "

252 rows × 2 columns

\n", - "
" - ], - "text/plain": [ - " _LOAD___2_EC_load_QPu _LOAD___2_EC_load_PPu\n", - "timestamp \n", - "0 0.126992 0.216992\n", - "0 0.126992 0.216992\n", - "0 0.126992 0.216992\n", - "0 0.126992 0.216992\n", - "0 0.126992 0.216992\n", - "... ... ...\n", - "9900 0.125207 0.215157\n", - "12710 0.125208 0.215157\n", - "18331 0.125208 0.215158\n", - "28331 0.125208 0.215158\n", - "30000 0.125208 0.215158\n", - "\n", - "[252 rows x 2 columns]" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "res.status()\n", "res.curves()" @@ -273,7 +157,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10 (default, Jun 22 2022, 20:18:18) \n[GCC 9.4.0]" + "version": "3.8.10" }, "orig_nbformat": 4, "vscode": {