Sparse matrix utilities (structsolve.sparseutils)#
Utilities for sparse matrices
Removal of the null rows and columns of the system matrices, assembly of symmetric and skew-symmetric matrices from their upper triangle, and a check of symmetry.
- structsolve.sparseutils.finalize_symmetric_matrix(M)#
Check for nan and inf values and make a matrix symmetric
The stored values of
Mare checked withassertstatements, which are skipped when Python runs with optimizations (-O), and the matrix is completed withmake_symmetric()and converted to CSR format.- Parameters:
- Msparse matrix
A square matrix with the upper triangle defined, see
make_symmetric().
- Returns:
- M_symcsr_matrix
The symmetric sparse matrix.
- Raises:
- AssertionError
When
Mcontainsnanorinfvalues.
- structsolve.sparseutils.is_symmetric(m)#
Check if a sparse matrix is symmetric
The off-diagonal non-zero entries below the diagonal are compared with their transposed entries above it with
numpy.allclose(), i.e. with its default tolerances.Falseis returned without comparing the values when the numbers of stored entries below and above the diagonal differ.- Parameters:
- marray or sparse matrix
A square matrix.
- Returns:
- checkbool
The check result.
- Raises:
- ValueError
When
mis not square.
See also
structsolve.linear_buckling.is_symmetriccheck with a relative norm.
- 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
mhas to be defined.The rows, cols and values are evaluated such that where
rows > colsthe values will be ignored and recreated from the region wherecols > rows, with the opposite sign, in order to obtain a skew-symmetric matrix. The diagonal ofmis kept as given.- Parameters:
- marray or sparse matrix
A square matrix with the upper triangle defined.
- Returns:
- m_skewcoo_matrix
The skew-symmetric sparse matrix, of the shape and
dtypeofm.
- Raises:
- ValueError
When
mis not square.
See also
- 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
mhas to be defined.The rows, cols and values are evaluated such that where
rows > colsthe values will be ignored and recreated from the region wherecols > 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, of the shape and
dtypeofm.
- Raises:
- ValueError
When
mis not square.
See also
- 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_matrixto obtain a better performance.- silentbool, optional
Keyword argument telling whether the log messages should be printed. Default
False.- kwargskeyword arguments, optional
Only
silentis read; other keyword arguments are ignored.
- 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.
See also
structsolve.static.solveuses it before solving.