In Matpower, a power ﬂow is executed by calling runpf with a case struct or case ﬁle
name as the ﬁrst argument (casedata). In addition to printing output to the
screen, which it does by default, runpf optionally returns the solution in a results
struct.

>> results = runpf(casedata);

The results struct is a superset of the input Matpowercase struct mpc, with some
additional ﬁelds as well as additional columns in some of the existing data ﬁelds. The
solution values are stored as shown in Table 4-1.

Table 4-1:Power Flow Results

name

description

results.success

success ﬂag, 1 = succeeded, 0 = failed

results.et

computation time required for solution

results.iterations

number of iterations required for solution

results.order

see ext2int help for details on this ﬁeld

results.bus(:, VM)^{†}

bus voltage magnitudes

results.bus(:, VA)

bus voltage angles

results.gen(:, PG)

generator real power injections

results.gen(:, QG)^{†}

generator reactive power injections

results.branch(:, PF)

real power injected into “from” end of branch

results.branch(:, PT)

real power injected into “to” end of branch

results.branch(:, QF)^{†}

reactive power injected into “from” end of branch

results.branch(:, QT)^{†}

reactive power injected into “to” end of branch

^{†}AC power ﬂow only.

Table 4-2:Power Flow Options

name

default

description

model

'AC'

AC vs. DC modeling for power ﬂow and OPF formulation

'AC' –

use AC formulation and corresponding alg options

'DC' –

use DC formulation and corresponding alg options

–

pf.alg

'NR'

AC power ﬂow algorithm:

'NR' –

Newtons’s method (formulationdepends on values of pf.current_balance andpf.v_cartesian options)

use current, as opposed to power, balance for AC PF, 0 or 1

pf.v_cartesian^{‡}

0

use cartesian, as opposed to polar, representation for voltagesfor AC PF, 0 or 1

pf.tol

termination tolerance on per unit P and Q dispatch

pf.nr.max_it

10

maximum number of iterations for Newton’s method

pf.nr.lin_solver

''

linear solver option for mplinsolve for computing Newtonupdate step

(see mplinsolve for complete list of all options)

'' –

default to '∖' for small systems, 'LU3' for larger ones

'∖' –

built-in backslash operator

'LU' –

explicit default LU decomposition and back substitution

'LU3' –

3 output arg form of lu, Gilbert-Peierls algorithm withapproximate minimum degree (AMD) reordering

'LU4' –

4 output arg form of lu, UMFPACK solver (same as'LU')

'LU5' –

5 output arg form of lu, UMFPACK solver w/row scaling

–

pf.fd.max_it

30

maximum number of iterations for fast-decoupled method

pf.gs.max_it

1000

maximum number of iterations for Gauss-Seidel method

pf.radial.max_it

20

maximum number of iterations for radial power ﬂow methods

pf.radial.vcorr

0

perform voltage correction procedure in distribution powerﬂow

0 –

do not perform voltage correction

1 –

perform voltage correction

–

pf.enforce_q_lims

0

enforce gen reactive power limits at expense of

0 –

do not enforce limits

1 –

enforce limits, simultaneous bus type conversion

2 –

enforce limits, one-at-a-time bus type conversion

–

^{†}Automatically sets/overrides pf.current_balance and pf.v_cartesian options with corresponding values.^{‡}Only relevant for Newton power ﬂow solver.

Additional optional input arguments can be used to set options (mpopt) and provide
ﬁle names for saving the pretty printed output (fname) or the solved case data
(solvedcase).

The options that control the power ﬂow simulation are listed in Table 4-2 and those
controlling the output printed to the screen in Table 4-3.

By default, runpf solves an AC power ﬂow problem using a standard Newton’s method
solver. To run a DC power ﬂow, the model option must be set to 'DC'. For convenience,
Matpowerprovides a function rundcpf which is simply a wrapper that sets the model
option to 'DC' before calling runpf.

Table 4-3:Power Flow Output Options

name

default

description

verbose

1

amount of progress info to be printed

0 –

print no progress info

1 –

print a little progress info

2 –

print a lot of progress info

3 –

print all progress info

–

out.all

-1

controls pretty-printing of results

-1 –

individual ﬂags control what is printed

0 –

do not print anything^{†}

1 –

print everything^{†}

–

out.sys_sum

1

print system summary (0 or 1)

out.area_sum

0

print area summaries (0 or 1)

out.bus

1

print bus detail, includes per bus gen info (0 or 1)

out.branch

1

print branch detail (0 or 1)

out.gen

0

print generator detail (0 or 1)

out.force

0

print results even if success ﬂag = 0 (0 or 1)

out.suppress_detail

-1

suppress all output but system summary

-1 –

suppress details for large systems ( 500 buses)

0 –

do not suppress any output speciﬁed by other ﬂags

1 –

suppress all output except system summary section^{†}

–

^{†}Overrides individual ﬂags, but (in the case of out.suppress_detail) not out.all = 1.

Internally, the runpf function does a number of conversions to the problem data before
calling the appropriate solver routine for the selected power ﬂow algorithm. This
external-to-internal format conversion is performed by the ext2int function, described
in more detail in Section 7.3.1, and includes the elimination of out-of-service
equipment and the consecutive renumbering of buses. All computations are done
using this internal indexing. When the simulation has completed, the data is
converted back to external format by int2ext before the results are printed and
returned.