The ePHASORSIM provides a Python Application Programming Interface (API) which facilitates interacting with the solver. This chapter outlines the functionality included in the API and presents a number of example use cases.
The API aims to provide a simple and accessible way to programmatically interact with a running ePHASORSIM simulation. Two key actions, namely setting a component’s parameter, and getting a computed result, are made possible by the API. In this way, the API provides functionality similar to that of the ePHASORSIM Solver block’s Pins.
All interaction is routed through the two Python classes: 'Network' and 'Test'. The classes are located in the “opal.ephasorsim” package, inside the network and test modules respectively. The following outline lists the functionality of each class.
Note: my_time is an absolute time.
Component Types and Tags for API
The table below shows the list of all native components and the corresponding component type name used in python API and also the group that they belong to which is defined as a tag. These python type names and group tags can be used as an input for 'component_list()' routine to include or exclude them for listing.
List of Component Types and Their Group Tag
Python type names
Tags (group of components)
Multiphase Load (Single Phase)
Multiphase Load (Two Phase)
Multiphase Load (Three Phase)
Multiphase Shunt (Single Phase)
Multiphase Shunt (Two Phase)
Multiphase Shunt (Three Phase)
Transformer 3-phase Mutual
Multiphase Line (Single Phase)
Multiphase Line (Two Phase)
Multiphase Line (Three Phase)
Multiphase Fault (Single Phase)
Multiphase Fault (Two Phase)
Multiphase Fault (Three Phase)
See demo ‘PHASOR-13’ and ‘PHASOR-15’.
The following script demonstrates some of the API routines in action. First, select the Use post-init script checkbox in the Scripting tab of the Solver block and provide the '.py' script file containing the API routines. Then, when the simulation runs, the API commands in the '.py. file are executed. Alternatively, these commands can be executed step by step while the simulation is running using the RT-LAB python console. For example, load ‘phasor01_IEEE39’ example model on a target using RT-LAB and open the RT-LAB python console (under Tools/Python/Open Console). Finally, run the model and enter the commands one by one, while inspecting the results on a Simulink scope.
Note: Before running the simulations, make sure that the file “simulation.json” does not exist in the directory: C:\Users\[User Name]\AppData\Local\ePHASORSIM