Basic functions of SAInt API

This tutorial will focus on functions that are used to load an existing electric network and scenario into the memory and execute an electric simulation using the SAInt API. The objective is to learn on how to import the SAInt API dynamic link library (DLL) object into Python and execute a simulation using an existing network and scenario.

Please refer to the API reference section for additional details on the functions described in this tutorial.

The network, scenario and import files used in this tutorial can be found in (C:\Users\...\Documents\encoord\SAInt-v3\Projects\ENET09_13\). Make a copy of this folder as necessary.

1. Create a DLL object in Python

Let’s get started by opening your preferred Python IDE and creating a new directory and a new Python script. Once the new Python script is created, the first step to start using the SAInt API is to import dynamic link library (DLL) into your Python environment. We will use the Python ctypes module, which provides C-compatible data types and allows function calls from a DLL object. Add the following expression to your Python script and execute.

# Import ctypes package
from ctypes import *

# Path to the SAInt-API.dll file (located in the SAInt installation folder)
path = "C:\\Program Files\\encoord\\SAInt-v3\\SAInt-API.dll"

# Create a SAInt API DLL object
saint_dll = cdll.LoadLibrary(path)

2. Load the electric network

Copy the network and scenario files to your Python script directory. Then, we will use the openENET function to load the electric network file ENET09_13.enet. It takes the path to the SAInt electric network file as an argument. Add the following expression to your Python script and execute.

# Load the electric network
saint_dll.openENET(
        "ENET09_13.enet"
        )
Example 1. Logs from the openENET function

Loading Electric Network model from file: C:\..\ENET09_13.enet.

Electric Network loaded successfully.

3. Load the electric scenario

After successfully loading the electric network, the next step is to open the electric scenario file PCM_DCUCOPF_5.esce using the openESCE function by passing the path to the SAInt electric scenario file as an argument. Add the following expression to your Python script and execute.

# Load the electric scenario
saint_dll.openESCE(
        "PCM_DCUCOPF_5.esce"
        )
Example 2. Logs from the openESCE function

Loading Electric Scenario from file: C:\..\PCM_DCUCOPF_5.esce.

Electric Scenario loaded successfully.

4. Display simulation logs

The SAInt API allows displaying or hiding simulation logs in the output window using the showSIMLOG function. The simulation logs can help check the simulation status and relevant information. However, if desired, the user can hide the simulation logs' display, which can save computation time, especially when simulating large networks. It takes either True or False as an argument. Add the following expression to your Python script and execute.

# Choose to display simulation logs
saint_dll.showSIMLOG(True)
Example 3. Logs from the showSIMLOG function

Simulation log will be displayed!

5. Execute the simulation

The SAInt API has a range of functions to execute simulations depending on the type of energy network, e.g., use runESIM for running an electric simulation. Add the following expression into your Python script and execute.

# Run electric simulation
saint_dll.runESIM()
Example 4. Logs from the runESIM function

Starting simulation with …​

Electric network file: C:\..\ENET09_13.enet

Electric scenario file: C:\..\PCM_5days.esce

SAInt 3.2.10.3 - Starting DCUCOPF simulation at 06/02/2023 18:01:31

ConsecutiveRuns = 5 StepsTimeHorizon=24 StepsLookAhead=6

Scenario PCM_DCUCOPF_5 of type DCUCOPF has 120 steps of 60 minutes to 120 hours from 2022.01.03 00:00 to 2022.01.08 00:00

Solver = Gurobi GAP = 0.001 TimeLimit = 3600

. .

Simulation with 119 timesteps.

Total computing time [sec]: 43.215

DCUCOPF Simulation terminated.

DCUCOPF simulation completed successfully!