Page Content
Table of Contents | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Introduction
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.
API Outline
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 Pinspins.
All interaction is routed through the two Python classes: 'Network
' and 'Test
'. The classes are located in the “opalopal.
ephasorsim” ephasorsim
package, inside the network and test modules respectively. The following outline lists the functionality of each class.
Code Block | ||
---|---|---|
| ||
# from opal.ephasorsim. import Network class Network: def list_models(): ... def Network(‘model'model_name’name'): ... def component_list([include], [exclude]): ... def types_of(tag): ... def get(comp_name, param_name): ... def get(comp_name, param_name, time): ... def get((comp_name, param_name, time), ...): ... def get_simulation_time(): ... def set(comp_name, param_name, value): ... def set(comp_name, param_name, time, value): ... def set((comp_name, param_name, time, value), ...) Note: time is relative to Now class opal.ephasorsim.Test Test(‘Network_obj_name’) ... |
Code Block | ||
---|---|---|
| ||
# from opal.ephasorsim import Test class Test: def Test('Network_obj_name'): ... def set(comp_name, param_name, value): ... def set(comp_name, param_name, time, value): ... def set((comp_name, param_name, time, value), ...): ... def get(comp_name, param_name, time): ... def get((comp_name, param_name, time), ...): ... def execute([time = 0]): ... def execute_at([my_time]): | ||
Background Color | ||
| ||
Note: ... |
Notes
my_time
is an absolute time.time
is relative to Now
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
Native Component | Python |
---|
Type Names | Tags ( |
---|
Group of |
---|
Components) | ||
---|---|---|
Bus |
|
|
SM_T1 |
|
|
SM_T2 |
| |
SM_T3 |
| |
PSS_T1 |
|
|
PSS_T2 |
| |
EX_T1 |
|
|
EX_T2 |
| |
TG_T1 |
|
|
TG_T2 |
| |
LD_CZ |
|
|
LD_CI |
| |
LD_CP |
| |
LN_PI |
|
|
XF_OLTC |
|
|
XF_2W |
| |
XF_3W |
| |
Switch |
|
|
Fixed Shunt |
|
|
Current Injector |
|
|
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 |
|
|
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) |
|
Example
See demo ‘PHASOR-13’ and ‘PHASOR-15’ examples phasor13_AUTOMATE
and phasor15_IEEE_EURO_LV
.
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
...
the 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.
...
color | #D3D3D3 |
---|
...
Note
Before running the simulations, make sure that the file
...
simulations.
...
json
does not exist in the directory:
...
%LOCALAPPDATA%\ePHASORSIM
my_first_script.py
...
Code Block | ||
---|---|---|
| ||
from opal.ephasorsim import Network, Test my_network = Network(‘phasor01'phasor01_IEEE39’IEEE39') # Set up a test sequence where a fault is applied to bus 30, 1 second into the # test execution. The fault is cleared 0.08s thereafter. my_test = Test(my_network) my_test.set( (“30”'30', “active3PGFault”'active3PGFault', 1, True), (“30”'30', “active3PGFault”'active3PGFault', 1.08, False)) my_test.execute() |