Powerflow
The power flow problem is about the calculation of voltage magnitudes and angles for one set of buses. The solution is obtained from a given set of voltage magnitudes and power levels for a specific model of the network configuration. The power flow solution exhibits the voltages and angles at all buses and real and reactive flows can be deduced from the same.
Power System Model
Power systems are modeled as a network of buses (nodes) and branches (lines). To a network bus, components such a generator, load, and transmission substation can be connected. Each bus in the network is fully described by the following four electrical quantities:
- $\vert V_{k} \vert$: the voltage magnitude
- $\theta_{k}$: the voltage phase angle
- $P_{k}$: the active power
- $Q_{k}$: the reactive power
There are three types of networks buses: VD bus, PV bus and PQ bus. Depending on the type of the bus, two of the four electrical quantities are specified as shown in the table below.
| Bus Type | Known | Unknown |
|---|---|---|
| $VD$ | $\vert V_{k} \vert, \theta_{k}$ | $P_{k}, Q_{k}$ |
| $PV$ | $P_{k}, \vert V_{k} \vert$ | $Q_{k}, \theta_{k}$ |
| $PQ$ | $P_{k}, Q_{k}$ | $\vert V_{k} \vert, \theta_{k}$ |
Single Phase Power Flow Problem
The power flow problem can be expressed by the goal to bring a mismatch function $\vec{f}$ to zero. The value of the mismatch function depends on a solution vector $\vec{x}$:
As $\vec{f}(\vec{x})$ will be nonlinear, the equation system will be solved with Newton-Raphson:
where $\Delta \vec{x}$ is the correction of the solution vector and $\textbf{J}(\vec{x})$ is the Jacobian matrix. The solution vector $\vec{x}$ represents the voltage $\vec{V}$ by polar or cartesian quantities. The mismatch function $\vec{f}$ will either represent the power mismatch $\Delta \vec{S}$ in terms of
or the current mismatch $\Delta \vec{I}$ in terms of
where the vectors split the complex quantities into real and imaginary parts. Futhermore, the solution vector $\vec{x}$ will represent $\vec{V}$ either by polar coordinates
or rectangular coordinates
This results in four different formulations of the powerflow problem:
- with power mismatch function and polar coordinates
- with power mismatch function and rectangular coordinates
- with current mismatch function and polar coordinates
- with current mismatch function and rectangular coordinates
To solve the problem using NR, we need to formulate $\textbf{J} (\vec{x})$ and $\vec{f} (\vec{x})$ for each powerflow problem formulation.
Of these four, DPsim currently implements the power mismatch function with polar
coordinates, detailed below. It is the formulation used by both the dense
(PFSolverPowerPolar) and sparse (PFSolverPowerPolarSparse) solvers; the other three
are not implemented.
Powerflow Problem with Power Mismatch Function and Polar Coordinates
Formulation of Mismatch Function
The injected power at a node $k$ is given by:
The current injection into any bus $k$ may be expressed as:
Substitution yields:
We may define $G_{kj}$ and $B_{kj}$ as the real and imaginary parts of the admittance matrix element $Y_{kj}$ respectively, so that $Y_{kj} = G_{kj} + jB_{kj}$. Then we may rewrite the last equation:
If we now perform the algebraic multiplication of the two terms inside the parentheses, and collect real and imaginary parts, and recall that $S_{k} = P_{k} + jQ_{k}$, we can express (1) as two equations: one for the real part, $P_{k}$, and one for the imaginary part, $Q_{k}$, according to:
These equations are called the power flow equations, and they form the fundamental building block from which we solve the power flow problem.
We consider a power system network having $N$ buses. We assume one VD bus, $N_{PV}-1$ PV buses and $N-N_{PV}$ PQ buses. We assume that the VD bus is numbered bus $1$, the PV buses are numbered $2,…,N_{PV}$, and the PQ buses are numbered $N_{PV}+1,…,N$. We define the vector of unknown as the composite vector of unknown angles $\vec{\theta}$ and voltage magnitudes $\vert \vec{V} \vert$:
The right-hand sides of equations (2) and (3) depend on the elements of the unknown vector $\vec{x}$. Expressing this dependency more explicitly, we rewrite these equations as:
We now define the mismatch vector $\vec{f} (\vec{x})$ as:
That is a system of nonlinear equations. This nonlinearity comes from the fact that $P_{k}$ and $Q_{k}$ have terms containing products of some of the unknowns and also terms containing trigonometric functions of some the unknowns.
Formulation of Jacobian
As discussed in the previous section, the power flow problem will be solved using the Newton-Raphson method. Here, the Jacobian matrix is obtained by taking all first-order partial derivates of the power mismatch functions with respect to the voltage angles $\theta_{k}$ and magnitudes $\vert V_{k} \vert$ as:
The formulas above use the voltage magnitude $\vert V_k \vert$ as the unknown. The DPsim implementation instead uses the relative voltage increment $\Delta \vert V_k \vert / \vert V_k \vert$, which scales every voltage-magnitude column ($J^{PV}$, $J^{QV}$) by $\vert V_k \vert$. For example $J_{jj}^{PV}$ becomes $P_j(\vec{x}) + G_{jj} \vert V_j \vert^2$. This is paired with the multiplicative voltage update $\vert V_k \vert \leftarrow \vert V_k \vert (1 + \Delta \vert V_k \vert / \vert V_k \vert)$, so the solution is identical; only the scaling of the voltage columns differs.
The linear system of equations that is solved in every Newton iteration can be written in matrix form as follows:
Solution of the Problem
The solution update formula is given by:
To sum up, the NR algorithm, for application to the power flow problem is:
- Set the iteration counter to $i=1$. Use the initial solution $V_{i} = 1 \angle 0^{\circ}$
- Compute the mismatch vector $\vec{f}({\vec{x}})$ using the power flow equations
- Perform the following stopping criterion tests:
- If $\vert \Delta P_{i} \vert < \epsilon_{P}$ for all type PQ and PV buses and
- If $\vert \Delta Q_{i} \vert < \epsilon_{Q}$ for all type PQ
- Then go to step 6
- Otherwise, go to step 4.
- Evaluate the Jacobian matrix $\textbf{J}^{(i)}$ and compute $\Delta \vec{x}^{(i)}$.
- Compute the update solution vector $\vec{x}^{(i+1)}$. Return to step 3.
- Stop.
Convergence and Step Control
The iteration is governed by two parameters:
- Tolerance (default $10^{-8}$): the run is converged once every entry of the mismatch vector satisfies $\vert f_{i}(\vec{x}) \vert <$ tolerance (an infinity-norm test over all $\Delta P$ and $\Delta Q$ components).
- Maximum iterations (default $20$): an upper bound on the number of Newton steps per power flow solve.
To improve robustness far from the solution, the full Newton step is scaled by a single factor $\alpha \in (0, 1]$ rather than damped component-wise. The factor is the largest value that keeps the per-step changes within fixed bounds:
with $\Delta\theta_{max} = 0.2\ \text{rad}$ and $\Delta V_{max} = 0.1\ \text{pu}$. Because the whole step is scaled by one factor, the Newton search direction is preserved, so $\alpha = 1$ near the solution and quadratic convergence is retained; $\alpha < 1$ only bounds large early steps. Voltage magnitudes are updated multiplicatively ($V_k \leftarrow V_k (1 + \alpha, \Delta V_k / V_k)$), consistent with the relative voltage increment used in the Jacobian.
Solver Implementations
DPsim ships two implementations of the Newton-Raphson power flow solver with power mismatch and polar coordinates. Both produce identical results (to round-off); they differ only in how the Jacobian is stored and factorized:
PFSolverPowerPolar(dense): assembles a dense Jacobian and computes a fresh factorization every Newton iteration. This is the default.PFSolverPowerPolarSparse(sparse): assembles the Jacobian into a sparse matrix whose sparsity pattern is fixed (derived once from the network admittance matrix). The symbolic factorization (ordering) is analyzed once and reused; only the numeric values are recomputed each Newton iteration. The first iteration of every power flow solve does a full factorization with pivoting, and subsequent iterations refactorize while reusing that ordering (via KLU when available). This scales better on large, sparse grids.
The dense solver is used by default. To opt in to the sparse solver:
sim.set_pf_solver_use_sparse(True)
The flag is ignored and the dense solver is used if DPsim was built without a sparse
linear solver. The benchmark notebook
examples/Notebooks/Grids/PF_Sparse_vs_Dense.ipynb runs a range of network sizes both
ways, verifies the converged voltages match, and compares run time.