Ac branch pi model

From xuansenpa1/skillrevise · View interactive version

Ac branch pi model is an AI agent skill from the GitHub repository xuansenpa1/skillrevise. AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields. Use when computing branch flows in either direction, aggregating bus injections for nodal balance, checking MVA (rateA) limits, computing branc

How to use this skill

Skill file

AC Branch Pi-Model + Transformer Handling

Implement the exact branch power flow equations in acopf-math-model.md using MATPOWER branch data:

[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, TAP, SHIFT, BR_STATUS, ANGMIN, ANGMAX]

Quick start

Example:

import json
import numpy as np

from scripts.branch_flows import compute_branch_flows_pu, build_bus_id_to_idx

data = json.load(open("/root/network.json"))
baseMVA = float(data["baseMVA"])
buses = np.array(data["bus"], dtype=float)
branches = np.array(data["branch"], dtype=float)

bus_id_to_idx = build_bus_id_to_idx(buses)

Vm = buses[:, 7]  # initial guess VM
Va = np.deg2rad(buses[:, 8])  # initial guess VA

br = branches[0]
P_ij, Q_ij, P_ji, Q_ji = compute_branch_flows_pu(Vm, Va, br, bus_id_to_idx)

S_ij_MVA = (P_ij**2 + Q_ij**2) ** 0.5 * baseMVA
S_ji_MVA = (P_ji**2 + Q_ji**2) ** 0.5 * baseMVA
print(S_ij_MVA, S_ji_MVA)

Model details (match the task formulation)

Per-unit conventions

Transformer handling (MATPOWER TAP + SHIFT)

Series admittance

Given BR_R = r, BR_X = x:

Line charging susceptance

Power flow equations (use these exactly)

Let:

Then the real/reactive power flow from i→j is:

And from j→i is:

Compute apparent power:

Common uses

Enforce MVA limits (rateA)

Compute branch loading %

For reporting “most loaded branches”:

Aggregate bus injections for nodal balance

To build the branch flow sum for each bus \(i\):

This yields arrays P_out[i], Q_out[i] such that the nodal balance can be written as:

Sanity checks (fast debug)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.