|
| 1 | +<!-- |
| 2 | +SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org> |
| 3 | +
|
| 4 | +SPDX-License-Identifier: MPL-2.0 |
| 5 | +--> |
| 6 | + |
| 7 | +# LU Solver |
| 8 | + |
| 9 | +Power system equations can be modeled as matrix equations. A matrix equation solver is therefore |
| 10 | +key to the power grid model. |
| 11 | + |
| 12 | +This section documents the need for a custom sparse LU solver and its implementation. |
| 13 | + |
| 14 | +## Background |
| 15 | + |
| 16 | +The choice for the matrix equation solver type heavily leans on the need for |
| 17 | +[performance](#performance-considerations), the |
| 18 | +[topological structure](#topological-structure) of the grid and the |
| 19 | +[properties of the equations](#power-system-equation-properties). They are documented here. |
| 20 | + |
| 21 | +### Performance considerations |
| 22 | + |
| 23 | +There is a large variety of usages of the power grid model that require good performance. This |
| 24 | +imposes some constraints on the algorithms that can be used. |
| 25 | + |
| 26 | +* Highly accurate and fast calculations are needed for very large grids. This means that direct |
| 27 | + methods are strongly preferred, and approximate methods can only be used when there is no other |
| 28 | + alternative, and only if can be iteratively refined with a fast convergence rate. |
| 29 | +* Sometimes, very many repetitive calculations are required, e.g., for time series. In those cases, |
| 30 | + separating the decomposition of a matrix and solving two systems of equations separately can give |
| 31 | + major performance boosts. |
| 32 | + |
| 33 | +### Topological structure |
| 34 | + |
| 35 | +Distribution grids consist of substations that distribute power in a region. This can be represented |
| 36 | +in a topological way as vertices and edges. As a consequence of the locality of Kirchoff's laws, |
| 37 | +power system equations also take on the same topological structure in block-matrix equation form. |
| 38 | + |
| 39 | +#### Sparsity |
| 40 | + |
| 41 | +It is common that a substation is fed by a single upstream substation, i.e., most grids are operated |
| 42 | +in a tree-like structure. Meshed grid operations are rare, and even when they do happen, it is |
| 43 | +usually only for a small section of the grid. All this gives rise to extremely sparse topologies |
| 44 | +and, as a result, extremely sparse matrix equations with a block structure. |
| 45 | + |
| 46 | +Sparse matrix equations can be solved efficiently: they can be solved in linear time complexity, as |
| 47 | +opposed to the cubic complexity of naive Gaussian elimination. As a result, a sparse matrix solver |
| 48 | +is key to the performance of the power grid model. QR decomposition therefore is not a good |
| 49 | +candidate. |
| 50 | + |
| 51 | +#### Pivot operations |
| 52 | + |
| 53 | +Pivoting of blocks is expensive, both computationally and memory-wise, as it interferes with the |
| 54 | +sparse block structure of the matrix equations. To this end, a pre-fixed permutation can be chosen |
| 55 | +to avoid bock pivoting at a later stage. |
| 56 | + |
| 57 | +The [topological structure](#topological-structure) of the grid does not change during the |
| 58 | +solving phase, so the permutation can be obtained by the minimum degree algorithm from just the |
| 59 | +topology alone, at the cost of potential [ill-conditioned pivot elements](#pivot-perturbation). |
| 60 | + |
| 61 | +### Power system equation properties |
| 62 | + |
| 63 | +[Power flow equations](../../user_manual/calculations.md#power-flow-algorithms) are not Hermitian |
| 64 | +and also not positive (semi-)definite. As a result, methods that depend on these properties cannot |
| 65 | +be used. |
| 66 | + |
| 67 | +[State estimation equations](../../user_manual/calculations.md#state-estimation-algorithms) are |
| 68 | +intrinsically positive definite and Hermitian, but for |
| 69 | +[performance reasons](#performance-considerations), the matrix equation is augmented to achieve |
| 70 | +a consistent structure across the entire topology using Lagrange multipliers. |
| 71 | + |
| 72 | +### Block-sparsity considerations |
| 73 | + |
| 74 | +The power flow and state estimation equations involve block-sparse matrices: dense blocks, with a |
| 75 | +dimensionality varying between different calculation types, methods and symmetries, are distributed |
| 76 | +across the matrix in an extremely sparse way. The sparse structure can be pre-calculated, but the |
| 77 | +dense blocks need to be inverted separately. To make matters worse, the dense blocks may differ |
| 78 | +heavily in structure and contents between different nodes, and are often not solvable without |
| 79 | +pivoting. |
| 80 | + |
| 81 | +### Custom sparse LU solver |
| 82 | + |
| 83 | +The choice for a custom LU solver implementation comes from a number of considerations: |
| 84 | + |
| 85 | +* LU-decomposition is the best choice, because QR-decomposition and Cholesky decomposition cannot |
| 86 | + solve the power system equations efficiently as a consequence of the properties |
| 87 | +* Alternative LU solver implementations are optimized for a variety of use cases that are less |
| 88 | + sparse than the ones encountered in power systems. |
| 89 | +* Alternative LU solver implementations do not have good block-sparse matrix equation solvers. |
| 90 | + |
| 91 | +## Implementation |
| 92 | + |
| 93 | +The LU solver implemented in the power grid model consists of 3 components: |
| 94 | + |
| 95 | +* A sparse LU solver that: |
| 96 | + * handles factorization using the topological structure up to block-level |
| 97 | + * solves the sparse matrix equation given the factorization |
| 98 | +* A dense LU factor that handles individual blocks within the matrix equation |
| 99 | + |
| 100 | +### Pivot perturbation |
| 101 | + |
| 102 | +The LU solver implemented in the power grid model has support for pivot perturbation. The methods |
| 103 | +are described in [Li99](https://portal.nersc.gov/project/sparse/superlu/siam_pp99.pdf) and |
| 104 | +[Schenk04](http://ftp.gwdg.de/pub/misc/EMIS/journals/ETNA/vol.23.2006/pp158-179.dir/pp158-179.pdf). |
| 105 | +Pivot perturbation consists of selecting a pivot element. If its magnitude is too small compared |
| 106 | +to that of the other elements in the matrix, then it cannot be used in its current form. Selecting |
| 107 | +another pivot element is not desirable, as described in the section on |
| 108 | +[pivot operations](#pivot-operations), so the matrix is ill-conditioned. |
| 109 | + |
| 110 | +Instead, a small perturbation is done on the pivot element. This makes the matrix equation solvable |
| 111 | +without selecting a different pivot element, at the cost of propating rounding errors. |
| 112 | +slightly different matrix that is then iteratively refined. |
| 113 | + |
| 114 | +#### Pivot perturbation algorithm |
| 115 | + |
| 116 | +\begin{align*} |
| 117 | +A = B && C = D \\ |
| 118 | +&& E = F |
| 119 | +\end{align*} |
| 120 | +<!-- if (|pivot_element| < perturbation_threshold) then |
| 121 | + pivot_element = perturbation_threshold |
| 122 | +endif --> |
| 123 | + |
| 124 | +### Dense LU factorization |
| 125 | + |
| 126 | +The power grid model uses a modified version of the |
| 127 | +[`LUFullPiv` defined in Eigen](https://gitlab.com/libeigen/eigen/-/blob/3.4/Eigen/src/LU/FullPivLU.h) |
| 128 | +(credits go to the original author). The modification adds opt-in support for |
| 129 | +[pivot perturbation](#pivot-perturbation). |
| 130 | + |
| 131 | +1. Set the remaining square matrix |
| 132 | +2. Find largest element in the remaining matrix by magnitude. This is the pivot element. |
| 133 | +3. If the magnitude of the pivot element is too small: |
| 134 | + 1. If pivot perturbation is enabled, apply [pivot perturbation](#pivot-perturbation). |
| 135 | + 2. Otherwise, if the matrix is exactly singular (pivot element is identically $0$) is disabled, |
| 136 | + raise a `SparseMatrixError`. |
0 commit comments