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", + " | _LOAD___2_EC_load_QPu | \n", + "_LOAD___2_EC_load_PPu | \n", + "
---|---|---|
timestamp | \n", + "\n", + " | \n", + " |
0 | \n", + "0.126992 | \n", + "0.216992 | \n", + "
0 | \n", + "0.126992 | \n", + "0.216992 | \n", + "
0 | \n", + "0.126992 | \n", + "0.216992 | \n", + "
0 | \n", + "0.126992 | \n", + "0.216992 | \n", + "
0 | \n", + "0.126992 | \n", + "0.216992 | \n", + "
... | \n", + "... | \n", + "... | \n", + "
9900 | \n", + "0.125207 | \n", + "0.215157 | \n", + "
12710 | \n", + "0.125208 | \n", + "0.215157 | \n", + "
18331 | \n", + "0.125208 | \n", + "0.215158 | \n", + "
28331 | \n", + "0.125208 | \n", + "0.215158 | \n", + "
30000 | \n", + "0.125208 | \n", + "0.215158 | \n", + "
252 rows × 2 columns
\n", + "