4.6. Creating a Sparse Matrix Using the CSR Format

The *SMAT command has an option to allocate a sparse matrix using the CSR format. This format represents a matrix by three one-dimensional arrays. The arrays are specified in the Val2, Val3, and Val4 fields of *SMAT and contain the following data:

1st array: nonzero values
2nd array: the extents of rows (this vector stores the locations in the values vector that start a row)
3rd array: column indices

For example, consider this 4 x 4 matrix M:

The matrix can be described by these three vectors:

A = [ 1 2 4 3 5 -1 2 ]This array is of length NNZ (number of nonzero values) and holds all the nonzero entries of M.
IA = [ 1 4 5 6 8 ]This array is of length m+1 (m is the size of the matrix), and is defined by the recursive definition:
IA[1] = 1
IA[i] = IA[i-1] + number of nonzero values on the (i-1) row
IA[m+1] = NNZ+1
JA = [ 1 2 3 2 3 3 4 ]This array is of length NNZ and holds the column indices of the nonzero values of the matrix.

The following APDL commands create the above matrix.

DIM=4
NNZ=7

*VEC,A,D,ALLOC,NNZ
A(1)=1,2,4,3,5,-1,2

*VEC,IA,L,ALLOC,DIM+1
IA(1)=1,4,5,6,8

*VEC,JA,I,ALLOC,NNZ
JA(1)=1,2,3,2,3,3,4

*SMAT,M,D,ALLOC,CSR,IA,JA,A,FALSE
*PRINT,M