2.1. Introduction
For each transport equation, the discretisation and linearisation process leads to a system of linear equations, which is written as the following general matrix equation:
where
A is the coefficient matrix resulting from the linearisation and mesh geometry,
u is the vector that contains the unknown values of the dependent variable at the cell centroids which needs to be solved for, while
b is the vector containing all the sources, constants and boundary conditions.
With the momentum-predictor in the previous section (Eq.
3), it is easy to see how it is translated into a general matrix equation:
,
,
,
while in the pressure-corrector (Eq.
6) the translation is a bit less apparent:
,
p,
,
where is the resulting coefficient matrix after combining with the discretised Laplace operator coefficients of p.
The linear systems are solved by linear solvers, for which different solution methods exist, which are generally grouped into direct and iterative methods, each consisting of many sub-groups. Due to the linearisation process with the finite volume method, the coefficient matrix is very large (many cells required for accuracy), very sparse, and diagonal dominant. Iterative methods therefore have been more popular because they are more suited for this type of applications as they typically require lower computational cost per iteration and lower memory. The (modified) direct methods can, however, be used as a preconditioner, in which they are used to replace the coefficient matrix by a matrix for which the corresponding linear system of equations is easier to solve, while keeping the same solution. The solution methods that are used in OpenFOAM are discussed here.
2.2. Direct Methods
Even though direct methods, as stand-alone solvers, are not efficient for solving sparse systems of linear equations due to their high computational cost, their discussion will lead the way for introducing efficient iterative methods in the next sections.
Direct methods apply some form of Gaussian elimination techniques to solve the above mentioned system of linear equations. The modern version is the
LU factorisation, which computes the lower and upper triangular matrix
L and
U, such that
For diagonal dominant matrices, the upper triangular matrix
U is constructed by performing Gaussian elimination on matrix
A, while the elements of
L consist of the Gauss factors by which the rows of
A are multiplied to get
U. Furthermore, the diagonal elements of
L are set equal to one, so for a 3x3 matrix, Eq.
8 becomes
When
L and
U are found, the problem
is split into two problems that are much easier to solve
To avoid rounding errors it might be necessary to apply some form of pivoting, i.e. reordering the rows of matrix
A. However for diagonal dominant matrices this is not necessary [?]. If
is Symmetric Positive Definite (SPD) the LU-factorisation reduces to the
Cholesky factorisation of
A.
Where C is a lower triangular matrix. This results to even more memory and compuational savings as only one triangular matrix needs to be computed.
The efficiency of the direct methods however is lost due to the occurrence of fill-in after factorisation, where many zero entries in the sparse matrix become nonzero during the factorisation process. This significantly increases the memory requirements and computational cost, thereby disrupting the advantages of sparse matrix storage, especially for large practical CFD applications. This leaves an opening for iterative methods.
It will be shown that direct methods are very suitable as preconditioners for the Krylov subspace methods where the sparsity pattern is deliberately kept after factorisation, known as incomplete factorisation, so that or .
2.3. Basic Iterative Methods
The linear solvers in most CFD codes make use of iterative methods. Iterative methods are techniques created to obtain an approximate solution of linear systems. For the implementation of these methods, successive approximations are used. Starting from an initial guess , a new approximation is obtained at each iteration k, until an approximated solution is found that is close enough to the exact solution u.
The error vector is defined as
Solving the error vector is just as difficult as solving the exact solution of the discrete linear system
=
b. A computable measure of the quality of the approximation is therefore obtained from the residual,
which represents the
imbalance of the approximation of the conservation laws, with
being the exact solution. A common stopping criterion or tolerance (
) for iterative methods is the relative residual, defined as the 2-norm of the residual of the
k-th iteration divided by the 2-norm of the right-hand side,
The idea of an iterative method is that the matrix
A is decomposed into two matrices,
M and
N. Such that
; and the original linear system
transforms into:
rearranging terms we obtain:
The latter system is used to perform an iterative process, finding at each iteration (
k) a more accurate solution. Most of the iterative methods are derived from the following recurrence relation:
Or after rearranging and using Eq.
13
where the matrix
M is chosen such that
can be determined easily, so for example a diagonal or triangular matrix.
Basic iterative methods (BIM) are obtained by decomposing the system matrix as
(see
Figure 1) .
D being the diagonal of
A, and
E and
F are the strictly lower and upper parts. Based on the choice of
M and
N, different iterative methods can be obtained. Some of the BIMs are presented in
Table 1, of which Jacobi and Gauss-Seidel are the options for OpenFOAM’s BIM solver
smoothSolver.
Out of presented methods, the Successive Over-Relaxation method is significantly faster than the others for optimal damping parameters
, which value is not straightforward to find. Nevertheless, BIMs in general are too slow for engineering problems as stand alone solvers, as they are only effective in eliminating the high frequency components of the error, but very slow with reducing the low frequency components (
Figure 2). This gets worse for finer meshes.
Nevertheless, it is the ability of eliminating the high frequency error components (smoothing) why the BIMs serve as the second set of building blocks for more efficient iterative methods, in addition to the direct methods. As smoothers for the multigrid method or as preconditioners for the Krylov subspace methods.
2.4. Multigrid Methods
The convergence of a BIM can be accelerated with a multigrid method, which is known to be among the most efficient solvers for elliptic problems [
7] , such as the steady-state transport equation of a particular scalar
The basic idea of a multigrid method is to first smooth the error with a BIM, then transferring the remaining low frequency error components (recursively) to a coarser grid without losing information, until the problem is small enough to solve directly, after which a correction can be transferred back to the fine grid. As a result, the number of iterations required for convergence becomes nearly independent of the mesh element size, and the total computational cost scales approximately linearly with the number of unknowns. This high efficiency explains why multigrid methods are widely used in many CFD codes [
3,
8,
9] . Depending on the size of the 2D or 3D mesh, the speed-up can be one or multiple orders of magnitude as compared to the BIM [
2].
The detailed procedure is a follows:
- 1.
Presmoothing - Starting from an initial guess
, apply a few number
of iterations with a BIM to eliminate the high frequency error components (recall from Eq.
18).
where
and the superscript
h denotes the fine grid size.
- 2.
Restriction - To transfer the residual to a coarser grid of grid size
H, we use the
restriction operator
where superscript
H denotes the coarse grid size.
- 3.
-
Solve coarse grid error - The residual can now be used to determine the coarse grid error by combining Eqs.
12 and
13
This is known as the residual equation. As mentioned before, solving this equation is just as hard as solving the original system of linear equations. However, at the current grid level the problem is small enough to solve it directly and the obtained error vector can be used as an approximation at the fine grid in the following step.
- 4.
Prolongation - The error
is projected into the fine grid using the
prolongation operator
(inverse of
), and the vector
is corrected with the approximated error.
- 5.
Postsmoothing - Apply a few number of postsmoothing iterations as described in step 1 to obtain
In the above procedure, the sequence described by steps 2 to 4 is known as the
defect correction, or
coarse grid correction (CGC) and can be summarised by the following equation
Although the BIM and the CGC are individually not efficient, the combination of the two as applied above is very efficient as they effectively reduce all the frequency components of the error. The described procedure above is essentially a two-grid cycle when going through the steps once. When steps 1-2 (hence also steps 4-5) are done recursively within one loop we arrive at the multigrid method. Most of the times this is necessary as the long wavelengths of the error modes become shorter in the coarser mesh and therefore presmoothing is needed to eliminate them quickly. Applying a certain number of the restriction-step will lead to a negligible cost of solving the residual equation compared to a smoothing sweep at the finest grid.
Applying step 3 only once is called a V-cycle, and applying it multiple times can result in a W-cycle or an F-cycle, which are more accurate but require also more work. A schematic is shown in
Figure 3. There are many strategies and choices to tune the multigrid method, such as the amount of smoothing sweeps, grid-levels, and cycles, with varying trade-offs between speed of solving a single iteration and the overall rate of convergence.
One of the approaches to construct the coarser grid is by applying the restriction operator directly to the system matrix, which is known as the algebraic multigrid (AMG). This method is relatively easy to implement, but works as a black-box solver as it does not have any geometric interpretation of the mesh. The geometric multigrid (GMG) on the other hand obtains the coarser grid by clustering (or agglomerating) the cells of the mesh.
OpenFOAM works with the
generalised method of geometric-algebraic multigrid (GAMG) which by default operates as a GMG solver, but also gives the option to enable the older AMG implementation (of its predecessor) instead [?]. The GMG solver agglomerates the cells by pairing each cell with an unpaired neighbour cell with the largest shared face area. This is repeated for every coarse grid level. An examples is shown in
Figure 4. If a cells does not have a match, it will be added to the neighbouring group. The system matrix is adjusted accordingly.
The GAMG is a V-cycle method where the user can select a smoother (Gauss Seidel being most favoured) and adjust certain parameters, such as the mesh size at the coarsest level, the amount of presmoothing and postsmoothing sweeps. The solver calculates automatically the amount of intermediate coarse grid levels. A practical example of how the GAMG solver is set up is shown in Sec.
Section 3.
Next to multigrid methods, another class of solvers called Krylov subspace methods can be adopted.
2.5. Krylov Subspace Methods
In this section a few other solvers are presented that are currently used in OpenFOAM, which are also one of the most efficient methods for solving large linear systems [
1]. These methods are based on projection processes onto Krylov subspaces
, that is
where
is called the Krylov space of dimension
i corresponding to matrix
and initial residual
(Eq.
13). The basic idea of Krylov subspace methods is that, for large and sparse matrices, it is more efficient to use
A only in matrix–vector products. In this way, the approximate solution is constructed as a polynomial in
A applied to the initial residual, without explicitly forming or inverting the matrix [
10].
The
Conjugate Gradient (CG) method is a Krylov subspace method that is developed to minimize the following quadratic equation
where
is an SPD matrix. Solving this minimization problem (which is finding
such that
) is equivalent to solving
, and falls under the type of gradient methods (see
Figure 5).
The solution
is approached recursively via the relation
where
is the search direction for the next iteration. One way is to choose the residual vector as the search direction, which is known as the
method. However, this can lead to the same search directions being computed more than once and oscillations occurring around the local minima, leading to very slow convergence. Therefore in the CG method, every search direction should be in a unique direction. This is accomplished by selecting a set of search directions that are
-orthogonal (or
-
) to the previous directions. This means that they satisfy the condition
, for
.
The CG method starts with the residual vector being chosen as the first search direction,
The factor
in Eq.
27 ensures that the minimum point is found along the current search direction, which can be derived to the following expression
After obtaining the new value for
(Eq.
27), the new residual is calculated,
To make sure that the next search direction is
-conjugate to the previous, the following coefficient is used which is simplified to,
so that finally the next search direction can be calculated, which completes the algorithm,
If
A is SPD and the denominators of Eq.
29 and Eq.
31 are equal to zero, it means that the CG method breaks down when the problem is already solved (
= 0), which makes the method robust. The rate of convergence of the CG methods depends on the spectral properties (i.e. the eigenvalue distribution) of matrix
A and is related to the condition number of matrix
,
where
and
are the largest and smallest eigenvalues of
, respectively. The more clustered the eigenvalues are, the smaller the value of
, hence faster convergence. For CFD applications, the condition number is about the square of the maximum number of grid points, hence the standard CG method is slow [
2].
2.5.1. Preconditioners
Preconditioners are used to accelerate the convergence by transforming the problem into a similar one, but with a more clustered eigenvalue distribution. This is done by multiplying the original system of equations by the inverse of the preconditioned matrix
as follows
In order for the preconditioned matrix
to be effective it must fulfill the following requirements.
should approximate
, the computation of
should be cheap, and the condition number of the transformed system should be smaller than that of the original system of equations,
For the CG method,
must also be an SPD matrix. Therefore, a good and common choice is the Cholesky factorisation (Eq.
11), which yields
. But due to fill-in, it takes large amounts of work and memory to construct
. Hence, the non-zero fill-in elements are disregarded, leading to the
incomplete Cholesky factorisation of
.
The algorithm of the CG method (Eqs.
27 -
32) can be transformed into that of the preconditioned CG method by replacing
with
. The modification of the CG method is summarized in Algorithm 1.
|
Algorithm 1 Preconditioned Conjugate Gradient (PCG) method |
and ▹ Choose starting direction for until convergence do end for
|
Due to its superlinear convergence and for being robust, the preconditioned CG (PCG) method is one of the best methods for solving the heat equation and the pressure corrector equation (Eq.
6), as the coefficient matrices
that result from discretising these diffusion equations on the mesh are SPD.
For the general transport equations which contain the advection term, the coefficient matrix is not symmetric. Therefore the PCG method is not applicable. A significant amount of Krylov subspace methods are developed for general non-SPD matrices A, but none have all the following three nice properties which the CG method has for SPD matrices:
- 1.
It is a Krylov subspace method:
- 2.
Optimality: the minimizer of the quadratic function (Eq.
26) exists, hence convergence is guaranteed.
- 3.
Short recurrences, hence requiring low computing work and storage.
2.5.2. General matrices
The
Bi-Conjugate Gradient (BiCG) method is a Krylov subspace method for general matrices that transforms the unsymmetrical system into a symmetrical one so that it can by solved using a modified CG method. This is done by rewriting
as
where
is a dummy variable which is not solved for, but only used to convert the system. The update relations in the CG method for the residuals and search directions are augmented by their shadow equivalents which are based on
,
and
The orthogonality of the residual and search direction with their shadow counterparts is ensured via the relation
hence the name bi-orthogonal or bi-conjugate. The BiCG method is very close to the CG method and generates the same solution as the CG method if A is SPD. It does however require two matrix-vector multiplications (with
and with
) instead of one, such that every iteration is nearly twice as expensive as compared to the CG method.
Although the BiCG method shares two of the nice properties of the CG method, there is no optimality for general matrices
, hence convergence is not guaranteed. Moreover, the irregular convergence can lead to serious break-down due to large rounding errors. The
Biconjugate Gradient STABilized (Bi-CGSTAB) method [
11] is a more robust variant where the recurrence relations
are modified to a form
such that the multiplication with
is avoided. For this recurrence, a
-th degree polynomial is taken of the form
with suitable constants
in the
k-th iteration that minimizes residual
with respect to
, giving the method a
semi-optimality property and smoother convergence behaviour as compared to the BiCG method. The Bi-CGSTAB method is currently the most recent and advanced Krylov subspace method that is implemented in the standard library of OpenFOAM, and can be preconditioned using e.g. the
incomplete LU factorisation which is appropriate for general matrices. It is much faster than its predecessor, but sudden breakdown due to rounding errors still occur for the more difficult problems in this paper.
2.5.3. Other Krylov Subspace Methods
Although not used in this work, it is worth to mention the
Generalized Minimal RESidual (GMRES) method [
1], which falls under another class of Krylov subspace methods for solving general systems of linear equations. It is a stable method with respect to rounding errors, and has an optimality property which guarantees convergence. While the CG method aims at minimizing the
A-norm of the error
(only possible for SPD matrices), the GMRES method finds orthogonal vectors (search directions) that minimize the Euclidean norm of the residual
, leading to a comparable superlinear convergence behavior as the CG method. The main drawback however is that the whole sequence of search directions from the previous iterates have to be stored and multiplied with, such that the computational and memory requirements quickly become prohibitive if the method does not converge after a few iterations. Restarting the method after a certain number of iterations overcomes this limitation of long recurrences, but comes at the cost of losing the nice convergence properties due to throwing away all search information [
12]. The generalized conjugate residual (GCR) method is similar to the GMRES method but with somewhat more floating point operations per iteration. However, the GCR method gives the ability to truncate to the last few search directions that are saved for the next iteration, which in return performs better than restarting the GMRES method.
Hybrid methods provide a balance between the short recurrences of the BiCG-type methods on one side and the optimality property of the GMRES-type methods on the other. First on the list is the
GMRES Recursive (GMRESR) method [
12] that consists of an inner and outer loop. The solution is first approximated in an inner-loop with the restarted GMRES method, after which the found search directions are condensed to the outer-loop, where they are used to approximate the solution with the truncated GCR method. The GMRESR method generally speeds up the convergence rate of the restarted GMRES method. Later improvements of the GMRESR-type methods are the
GCRO-type methods, where the inner iteration loop takes place in a Krylov subspace orthogonal to the subspace of the outer loop (so-called
subspace recycling), yielding further acceleration of the convergence rate[
13] [
14].
The final hybrid method worth mentioning, which leans more towards the BiCG-type methods, is the
Induced Dimension Reduction (IDR) method. This method was already proposed before the Bi-CGSTAB method but has been revived to a more generalized variant IDR(s) [
15]. The IDR(s) method is closely related to the Bi-CGSTAB method in the sense that the matrix-vector multiplication with
is avoided via a minimizing polynomial. The main difference is that the generated residuals are forced to be in subspaces of decreasing order until an
s-dimensional space is reached. For the right value of
s (typically
10.), this robust and efficient method is at least as fast as the Bi-CGSTAB method when
s = 1 (original IDR method) and significantly faster for increased values of
s, especially for more difficult problems. When
s is large enough, the rate of convergence is nearly as good as full GMRES [
16]. Hybrid methods such as the
IDR(s) method and the
GCRO-type methods are good candidates for the next generation of linear solvers for general matrices to implement in OpenFOAM.