What is the structure of matrices in CFD?

CFD Direct's experts explain the structure of matrices in their OpenFOAM Training

See Training

5.1 Structure of matrices

As described in Sec. 3.4 , a matrix equation for solution variable eqn contains of a set of coefficients eqn where each row eqn corresponds to the linear equation for the cell with index eqn as follows:

2 3 2 3 2 3 a1;1 a1;2 a1;3 a1;N 1 b1 66 77 66 77 66 77 66 a2;1 a2;2 a2;3 a2;N 77 66 2 77 66 b2 77 66 a3;1 a3;2 a3;3 a3;N 77 66 3 77 = 66 b3 77 66 : : : : : 77 66 : 77 66 : 77 64 :: :: :: :: :: 75 64 :: 75 64 :: 75 aN;1 aN;2 aN;3 aN;N N bN \relax \special {t4ht=
(5.1)

Matrix sparsity

Imagine creating a matrix equation for a transport equation for a scalar field, e.g. Eq. (2.65 ) with zero heat source eqn.

PICT\relax \special {t4ht=

The figure shows a matrix of size eqn, where eqn is the number of cells. Circles denote non-zero coefficients, which are filled for the diagonal coefficients (eqn). The matrix eqn is sparse, i.e. the majority of the coefficients eqn are 0 (zero).

The sparsity is due to each cell interacting only with adjacent cells connected through its faces. For example, a 3D mesh of hexahedral cells produces up to 7 coefficients per matrix row, with one diagonal coefficient corresponding to a particular cell and 6 off-diagonal coefficients for the neighbour cells.

Matrix (a)symmetry

A symmetric matrix possesses the same coefficients across the diagonal, i.e. eqn. The discretisation of a Laplacian term, e.g. eqn, described in Sec. 3.7 , produces coefficients that are symmetric because the surface normal gradient Eq. (3.5 ) uses the current and neighbour cell values in equal measure.

PICT\relax \special {t4ht=

However, the discretisation of an advection term, e.g. eqn, generally produces asymmetric coefficients. For example, if the upwind scheme is applied for flow from cell 1 into cell 2, then there would a contribution to eqn but not to eqn.

Matrix size

Parallel simulation allows affordable solution on huge meshes. For a mesh of size eqn, the matrix would have eqn coefficients, typically with eqn that are are non-zero.

For reasons of efficiency, zero coefficients are not stored in the computer’s memory. Instead the storage provides an array of non-zero coefficients and addressing arrays of the corresponding row and column indices for each coefficient.

Notes on CFD: General Principles - 5.1 Structure of matrices