Power Grid Model

1.13.54 · active · verified Thu Apr 16

Power Grid Model is a Python/C++ library designed for high-performance steady-state distribution power system analysis. It provides functionalities for Power Flow, State Estimation, and Short Circuit calculations, with its core implemented in C++ for efficiency. The library is actively developed, with frequent releases providing new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a simple two-node, one-line network with a source and a symmetric load, create a `PowerGridModel` instance, perform a power flow calculation, and retrieve the results. Data is provided as dictionaries of NumPy structured arrays, which is the native data interface for the C++ core.

import numpy as np
from power_grid_model import PowerGridModel, initialize_array, ComponentType, AttributeType, DatasetType

# 1. Define input data using structured NumPy arrays
# Node data
node_data = initialize_array(DatasetType.input, ComponentType.node, 2)
node_data[AttributeType.id] = [1, 2]
node_data[AttributeType.u_rated] = [10.5e3, 10.5e3] # 10.5 kV rated voltage

# Line data
line_data = initialize_array(DatasetType.input, ComponentType.line, 1)
line_data[AttributeType.id] = [3]
line_data[AttributeType.from_node] = [1]
line_data[AttributeType.to_node] = [2]
line_data[AttributeType.r1] = [0.1] # Resistance
line_data[AttributeType.x1] = [0.2] # Reactance

# Symmetric load data for node 2
sym_load_data = initialize_array(DatasetType.input, ComponentType.sym_load, 1)
sym_load_data[AttributeType.id] = [4]
sym_load_data[AttributeType.node] = [2]
sym_load_data[AttributeType.p_const] = [1e5] # 100 kW constant power
sym_load_data[AttributeType.q_const] = [5e4] # 50 kVAr constant reactive power

# Source data for node 1
source_data = initialize_array(DatasetType.input, ComponentType.source, 1)
source_data[AttributeType.id] = [5]
source_data[AttributeType.node] = [1]
source_data[AttributeType.u_ref] = [1.0] # 1.0 p.u. voltage reference
source_data[AttributeType.u_rated] = [10.5e3]

input_data = {
    ComponentType.node: node_data,
    ComponentType.line: line_data,
    ComponentType.sym_load: sym_load_data,
    ComponentType.source: source_data
}

# 2. Create the power grid model instance
model = PowerGridModel(system_frequency=50.0, input_data=input_data)

# 3. Perform a power flow calculation
output_data = model.calculate_power_flow()

# 4. Access results (example: node voltages)
node_output = output_data[ComponentType.node]
print("Node Voltage Results:")
for node_id, voltage in zip(node_output[AttributeType.id], node_output[AttributeType.u]):
    print(f"Node {node_id}: {voltage:.2f} V")

view raw JSON →