Sparse matrix utilities (structsolve.sparseutils)#

Utilities for sparse matrices

structsolve.sparseutils.finalize_symmetric_matrix(M)#

Check for nan and inf values and make a matrix symmetric

Parameters:
Msparse matrix

A square matrix with the upper triangle defined, see make_symmetric().

Returns:
M_symcsr_matrix

The symmetric sparse matrix.

structsolve.sparseutils.is_symmetric(m)#

Check if a sparse matrix is symmetric

Parameters:
marray or sparse matrix

A square matrix.

Returns:
checkbool

The check result.

structsolve.sparseutils.make_skew_symmetric(m)#

Returns a new coo_matrix which is skew-symmetric

Convenient function to populate a sparse matrix skew-symmetricaly, where the off-diagonal elements below the diagonal are negative when compared to the terms above the diagonal. Only the upper triagle of matrix m has to be defined.

The rows, cols and values are evaluated such that where rows > cols the values will be ignored and recreated from the region where cols > rows, in order to obtain a symmetric matrix.

Parameters:
marray or sparse matrix

A square matrix with the upper triangle defined.

Returns:
m_symcoo_matrix

The symmetric sparse matrix.

structsolve.sparseutils.make_symmetric(m)#

Returns a new coo_matrix which is symmetric

Convenient function to populate a sparse matrix symmetricaly. Only the upper triagle of matrix m has to be defined.

The rows, cols and values are evaluated such that where rows > cols the values will be ignored and recreated from the region where cols > rows, in order to obtain a symmetric matrix.

Parameters:
marray or sparse matrix

A square matrix with the upper triangle defined.

Returns:
m_symcoo_matrix

The symmetric sparse matrix.

structsolve.sparseutils.remove_null_cols(*args, **kwargs)#

Remove null rows and cols of a square sparse matrix.

A degree of freedom is removed when both its row and its column of the first matrix are null, such that an unsymmetric matrix, e.g. with the load stiffness of a follower load, never loses an equation whose row is not null. For a matrix with a symmetric pattern of null rows and columns this is the same as removing the null columns.

Parameters:
argslist of sparse matrices

The first matrix in this list will be used to extract the rows and columns to be removed from all the other matrices. Use csr_matrix to obtain a better performance.

silentbool, optional

Keyword argument telling whether the log messages should be printed.

Returns:
outlist of sparse matrices and used columns

A list with the reduced matrices, in CSR format and in the same order of args, plus an array containing the indices of the columns that were kept at the last position.