Running a dynamic simulation with dynawo

You can use the module pypowsybl.dynamic in order to run time domain simulation on networks.

Start by importing the module:

import pypowsybl.network as pn
import pypowsybl.dynamic as dyn

Providers

For now we only support the Dynawo simulator integration, provided by the Dynawo project.

Prerequisites

The pypowsybl config file (generally located at ~/.itools/config.yml) must define the dynawo section to find your dynawo installation and defaults parameters Here is an example of a simple config.yml file. It uses the same configurations as in powsybl-dynawo. Note that parameters can be set programmatically with the Parameters class.

dynamic-simulation-default-parameters:
    startTime: 0
    stopTime: 30
dynawo:
    homeDir: PATH_TO_DYNAWO
    debug: true
dynawo-simulation-default-parameters:
    parametersFile: ./models.par
    network.parametersFile: ./network.par
    network.parametersId: "1"
    solver.type: IDA
    solver.parametersFile: ./solver.par
    solver.parametersId: "1"

Parameters

To make a dynamic simulation, you need multiple things:

  1. A dynamic mapping, it links the static elements (generators, loads, lines) to their dynamic behavior (alpha beta load)

  2. A event mapping, it maps the different events. (e.g equipment disconnection)

  3. A output variable mapping, it records the given values to be watch by the simulation tool (can be curves or final state values).

There is a class for each of these elements.

You will see a lot of arguments called parameterSetId. Dynawo simulator use a lot of parameters that will be stored in files.

Pypowsybl will find the path to this file in the powsybl config.yml in dynawo-simulation-default-parameters.parametersFile value or in Parameters.

The parameterSetId argument must match an id in this file (generally called models.par).

Simple example

To run a Dynawo simulation:

import pypowsybl.dynamic as dyn
import pypowsybl as pp
from pandas import DataFrame

# load a network
network = pp.network.create_eurostag_tutorial_example1_network()

# dynamic mapping
model_mapping = dyn.ModelMapping()

# get dynamic model categories dataframe
model_mapping.get_categories_information()
# get all supported model information dataframe
model_mapping.get_supported_models_information()
# or filtered by category
model_mapping.get_supported_models_information('SynchronizedGenerator')

# can be written with kwargs...
model_mapping.add_base_load(static_id='LOAD',
                            parameter_set_id='LAB',
                            model_name='LoadAlphaBeta') # and so on
# or dataframe
gen_df = DataFrame.from_records(
    index='static_id',
    columns=['static_id', 'parameter_set_id', 'model_name'],
    data=[('GEN', 'GENPV', 'GeneratorPV')])
model_mapping.add_synchronized_generator(gen_df)
# can also be created with the proper category
model_mapping.add_dynamic_model(category_name='SynchronizedGenerator'
                                static_id='GEN2',
                                parameter_set_id='GENPQ',
                                model_name='GeneratorPQ')

# events mapping
event_mapping = dyn.EventMapping()
event_mapping.add_disconnection(static_id='GEN', start_time=10)
# can also be created with the proper event name
event_mapping.add_event_model(event_name='Disconnect', static_id='NHV1_NHV2_1', start_time=10, disconnect_only='ONE')

# curves mapping
variables_mapping = dyn.OutputVariableMapping()
variables_mapping.add_curves("LOAD", ["load_PPu", "load_QPu"])
variables_mapping.add_final_state_values('NGEN', 'Upu_value') # and so on

# simulations parameters
parameters = dyn.Parameters(start_time=0, stop_time=50)
sim = dyn.Simulation()
# running the simulation
results = sim.run(network, model_mapping, event_mapping, variables_mapping, parameters)
# getting the results
results.status()
results.status_text() # error description if the simulation fails
results.curves() # dataframe containing the mapped curves
results.final_state_values() # dataframe containing the mapped final state values
results.timeline() # dataframe containing the simulation timeline