Power Flow Solver for MATPOWER Cases
Operator: Abdulla Al Fahad. How tools are built and checked
A load flow answers the first question about any power system: given who generates what and who consumes what, what are the voltages and where does the power flow? This page solves that for a network written in the MATPOWER case format, by Newton-Raphson in polar form or by the fast-decoupled XB and BX methods, and shows bus voltages, branch flows, losses and generator output, a one-line diagram coloured by voltage, and a screen of every single-branch outage. The IEEE 14-bus test case is built in, and any case file can be pasted or loaded and edited as text.
Key features
- MATPOWER version 2 case files with baseMVA, bus, generator and branch tables in per unit, up to 300 buses and 700 branches
- Newton-Raphson in polar form with a convergence log that names the worst bus at each iteration, and fast-decoupled XB and BX
- Reactive-limit enforcement: the PV bus with the biggest violation becomes PQ at its limit, and goes back when its voltage allows
- Tap ratios, phase shifters, line charging and bus shunts, branch loading against the rating, and a table of voltage and loading violations against limits you set
- A one-line diagram with buses coloured by voltage and arrows for the direction of active power, drawn by an automatic layout
- Load scaling, a branch taken out of service, N-1 screening of all branches, and exports to CSV, XLSX and a MATPOWER case with the solution written in
The MATPOWER case format and the solvers
A case file defines mpc.baseMVA, then three matrices. A bus row holds the bus number, type (1 PQ, 2 PV, 3 slack, 4 isolated), Pd and Qd in MW and MVAr, shunt Gs and Bs in MW and MVAr at 1 pu voltage, the starting voltage magnitude and angle, and the voltage limits. A generator row holds its bus, Pg, Qg, Qmax, Qmin, the voltage set point, its status and Pmax and Pmin. A branch row holds the end buses, r, x and total charging b in per unit, the rating, the tap ratio (0 meaning 1) and the shift angle in degrees, and the status.
Cost tables, area data and other fields are ignored. Exactly one slack bus is required, every generator and branch must refer to buses in the table, and a branch may not have zero resistance and zero reactance. Edit the text in the box to change any number, and the solution updates.
How it works
Newton-Raphson unknowns are the angles of all PV and PQ buses and the voltage magnitudes of the PQ buses. Each iteration builds the Jacobian from the bus admittance matrix, solves for the corrections by LU decomposition with partial pivoting, and stops when the largest power mismatch is below the tolerance, 10^-8 per unit by default. The matrices are dense, which is why the size is capped.
Fast-decoupled iterations use two constant matrices, B′ for the angle half-step and B″ for the voltage half-step, built the way MATPOWER builds them: B′ ignores taps, shunts and charging, XB also drops resistance from B′, and BX drops it from B″ instead. They are factored once and need more iterations than Newton, but each is cheap.
After a solution the page checks the reactive output of each PV generator. If one is over its Qmax or under its Qmin the worst offender is converted to a PQ bus holding that limit, the case is solved again, and a held bus returns to PV when its voltage has moved past its set point. The slack bus has no reactive limit.
Common use cases
- A student wants to see the effect of loading: at 100% the 14-bus case converges in 4 iterations, and at 600% of load the page stops after 30 and reports the mismatch and the bus where it is largest.
- An engineer lowers generator 2's Qmax from 50 to 20 MVAr: the page holds it at 20, its terminal voltage falls from 1.045 to 1.0371 pu, and one generator is listed at its limit.
- A planner runs N-1 on the 14-bus case with limits of 0.95 to 1.10 pu: 18 of the 20 branch outages give no new violation, 7-8 separates bus 8, and 1-2 has no solution with the Q limits on.
How to use this tool
- Load a case file or press Load IEEE 14-bus.
- Choose the method, the starting point and whether to enforce generator reactive limits.
- Scale the load or take a branch out to see its effect, and set the voltage limits for the violation check.
- Read the result card, the diagram and the bus and branch tables.
- Press Run N-1 to screen all branches, and cancel it if the case is large.
- Download the tables, or the case file with the solution.
Example
The built-in IEEE 14-bus case from a flat start with Newton-Raphson, then the fast-decoupled methods
Method Newton-Raphson, tolerance 1e-8, flat start, generator Q limits on.Convergence and results
Largest mismatch per iteration (pu): 0.92, 0.10, 7.1e-4, 6.0e-8, 1.0e-14, so 4 iterations; fast-decoupled XB needs 8 and BX 10
Generation 272.393 MW and 82.438 MVAr, load 259.0 MW and 73.5 MVAr, branch losses 13.393 MW and 30.122 MVAr
Bus 4: 1.0177 pu at -10.313 degrees; bus 14: 1.0355 pu at -16.034 degrees
Branch 1-2 at the bus 1 end: 156.88 MW and -20.40 MVArTips for best results
- Start from a flat voltage profile when you edit a case heavily, and from the case voltages when you only changed a load slightly; both reach the same answer.
- Compare the slack generator's active power with the total load and losses: if it is far from what you expect, a load or a generator was mistyped.
- For a quick stress test use the load scale rather than editing each bus, and watch where the iteration log's worst bus moves as you approach the limit of convergence.
- Set the voltage limits to the ones your standard uses; the case's own Vmax and Vmin are not applied, and the 14-bus set points of 1.07 and 1.09 pu are above the usual 1.05.
Common pitfalls
A case that does not converge after an outage may have no solution at all. Voltage collapse is real, and reactive limits make it more likely.
A PV bus with no generator in service is treated as PQ, and a slack bus with none keeps the voltage written in the bus table, so a disconnected generator can quietly change how a bus is solved.
The one-line diagram uses an automatic layout. It shows connectivity, voltages and flow directions, not the geography or the layout of your substations.
Only active and reactive power, voltages and loading are solved. There is no short-circuit, stability, optimal dispatch or protection study here.
Common errors and how to fix them
- No slack bus (type 3) is defined.
- Set the type of exactly one bus to 3 in the bus table; the reference generator sits there.
- Branch 1-77 refers to a bus that is not in the bus table.
- Check the bus numbers in the branch rows against the first column of the bus table.
- The case has 412 buses; this tool solves up to 300.
- Reduce the network, or study a part of it; dense matrices make larger cases slow in a browser.
- The largest mismatch is still 2342.234 MW or MVAr at bus 11 after 30 iterations.
- The data or the loading is beyond what the network can carry. Lower the load scale, look at bus 11 and its neighbours, and check for an unintentionally open branch.
Best practices
- Keep a copy of the original case and edit the text, so each study starts from the same base.
- Check the balance before the plots: generation minus load equals the total losses.
- Treat N-1 as a screen. A list of no violations is not a security assessment.
- State the method, tolerance and Q-limit setting with any result you share.
Newton or fast-decoupled?
Newton-Raphson converges quadratically, as the mismatch row of the example shows: 7.1e-4, then 6.0e-8, then 1.0e-14. Fast-decoupled methods converge linearly but each iteration solves two smaller constant systems. They are accurate for typical transmission networks with a low r/x ratio and may struggle or fail on distribution feeders. Both reached the same voltages in the example, to 4e-11 per unit.
What N-1 screening reports
Each branch is taken out in turn and the case is re-solved from the base solution with the Q limits on. A violation is listed only if the base case did not have it or the outage made it clearly worse, by more than 0.002 per unit in voltage or 1% in loading. A branch whose loss cuts a bus off from the slack is reported as separating the network, and a case that does not converge is reported as such, with no violation list.
Reading the case rows
A branch with a nonzero tap in the case is a transformer, with the ratio applied at the from end. The 14-bus case has three: 4-7 at 0.978, 4-9 at 0.969 and 5-6 at 0.932. Bus 9 has a 19 MVAr shunt, which injects 19 times the square of its voltage in MVAr and enters the reactive balance.
Frequently asked questions
Does the solution match the published IEEE 14-bus results?
For the IEEE 14-bus case the solved angles agree with the published solution to 0.001 degrees and the voltages to the three decimals it lists: -4.983 at bus 2, -12.725 at bus 3, -10.313 at bus 4, -8.774 at bus 5, -14.221 at bus 6 and -16.034 at bus 14, and magnitudes of 1.018 at bus 4 and 1.020 at bus 5. Total losses are 13.393 MW, and the slack generator produces 232.393 MW. Generation minus load equals the branch losses to 3e-14 MW, and the reactive balance, with the bus 9 shunt, to 1e-12 MVAr. The fast-decoupled solution equals Newton's to 4e-11.
Why is generator 2 at 43.56 MVAr when the case file lists 42.4?
The generator table in the case file holds starting values from an older solution. The solved reactive output is 43.56 MVAr, and the bus table's angles, which are the solution, agree with the page.
Why does the page say a generator is held at a limit and then its voltage is below the set point?
A generator at Qmax cannot raise its voltage further, so the bus acts as a PQ bus with that output and its voltage settles below the set point. It returns to voltage control when the voltage would go above the set point.
Can I use a case from another program?
If it can write a MATPOWER case file, yes. PSS/E raw files, CDF and other formats are not read; convert them to MATPOWER first.
Is a larger network just slower, or does it stop?
Above 300 buses or 700 branches it stops with a message, because the Jacobian is stored as a dense matrix and would take too long and too much memory in a browser tab.