# OpenFOAM guide/Matrix coefficients

(Redirected from Matrix coefficients)

The matrix coefficients are coefficients that result from the discretization process. They are closely related to the discretization coefficients. OpenFOAM uses matrix coefficients in its source code.

## 1 Definition

The matrix coefficients have the form:

$A_{ii} \boldsymbol \psi_i + \sum_j A_{ij} \boldsymbol \psi_j = \mathbf{S}_i$

or:

$\mathbf{A}\boldsymbol \psi = \mathbf S$

Where:

• A are the matrix coefficients;
• $\boldsymbol \psi \,\!$ is the matrix vector of variables being solved for; and
• i and j are cell indices.

## 2 Coefficient matrix

The coefficient matrix is:

• an N x N square matrix, where N is the number of cells in the mesh;
• sparse; and
• diagonally dominant.

For example, given a simple 3 x 3 orthogonal mesh (in 2-dimensions):

 -1- -2- -3- -6- -5- -4- -7- -8- -9-

The coefficient matrix might look like:

Non-zero coefficients
i -1- -2- -3- -4- -5- -6- -7- -8- -9-
-1- X N N
-2- O X N N
-3- O X N
-4- O X N N
-5- O O X N N
-6- O O X N
-7- O X N
-8- O O X N
-9- O O X

Where:

• X indicates diagonal cells; and
• O and N indicate non-zero off-diagonal cells.

Since the matrix is sparse, only the non-zero entries need to be stored, something that is achieved by lduAddressing used by the matrices in OpenFOAM. lduAddressing works by recognizing that:

• Every cell has a diagonal coefficient; and
• Every cell has off-diagonal coefficients for each of their neighbours.

Therefore the diagonal coefficients are stored in an N-long vector array, where N is the number of cells. The number of off-diagonal coefficients is equal to the number of cell-pairs that directly influence one another in the linearized equations. At the matrix level in OpenFOAM, this only includes adjacent cells. Therefore the number of off-diagonal coefficients is equal to the number of shared faces in the mesh.

### 2.1 Storage in OpenFOAM

OpenFOAM stores:

• diagonal coefficients as a scalar field, indexed by cell volume; and
• off-diagonal coefficients as two scalar fields, indexed by face centres.

lduAddressing is used to related the two indexing methods.

## 3 Relationship with discretization coefficients

Every matrix coefficient has a corresponding discretization coefficient. They are related according to:

$A_p = A_{pp}\,\!$

$A_{r,p} = - \left \lbrack A_{ij} \right \rbrack_{i \neq j}$

That is, the off-diagonal matrix coefficients are opposite in sign to their corresponding discretization coefficient; whereas the diagonal has the same sign as its corresponding discretization coefficient.