Skip to content

Dynawaltz example #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions dynawaltz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pypowsybl dynawaltz simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"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": null,
"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": 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]})"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Don't forget to index the dataframe on the network element id column"
]
},
{
"cell_type": "code",
"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\"))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Adding events"
]
},
{
"cell_type": "code",
"execution_count": null,
"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": null,
"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": null,
"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": null,
"metadata": {},
"outputs": [],
"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"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading