pygeon.numerics.block_diag_solver module

pygeon.numerics.block_diag_solver.assemble_inverse(M, rtol=1e-10)[source]

Assembles the block-wise inverse of a sparse matrix based on connected components.

This function computes the inverse of a sparse matrix M by dividing it into submatrices corresponding to connected components. Each submatrix is inverted independently, and the results are assembled into the final inverse matrix.

Parameters:
  • M (sps.csc_array) – A sparse matrix in Compressed Sparse Column (CSC) format.

  • rtol (float) – Relative tolerance for removing small matrix entries. Default 1e-10.

Returns:

The block-wise inverse of the input matrix M in CSC format.

Return type:

sps.csc_array

Notes

  • The function uses the connected components of the graph represented by M to determine the blocks for inversion.

  • The inversion is performed using dense matrix operations for each block, which may be computationally expensive for large blocks.

pygeon.numerics.block_diag_solver.block_diag_solver(M, B, rtol=1e-10)[source]

Solves a block diagonal system of linear equations for each connected component.

This function takes a sparse block diagonal matrix M assumed to be symmetric and positive defined and a right-hand side matrix B, and solves the system MX = B for each connected component of the matrix M.

The connected components are determined using a graph representation of the matrix.

Parameters:
  • M (sps.csc_array) – A symmetric and positive defined sparse matrix in Compressed Sparse Column (CSC) format, representing the block diagonal system. It is assumed to be symmetric and positive definite.

  • B (sps.csc_array) – The right-hand side matrix in Compressed Sparse Column (CSC) format.

  • rtol (float) – Relative tolerance for removing small matrix entries. Default 1e-10.

Returns:

The solution matrix X.

Return type:

sps.csc_array

Notes

  • The function identifies connected components of the matrix M using the connected_components function from scipy.sparse.csgraph.

  • For each connected component, the corresponding submatrix and subvector are extracted, and the system is solved using numpy.linalg.solve.

  • If the right-hand side B is sparse and contains zero entries for a connected component, the solution for that component is skipped.

pygeon.numerics.block_diag_solver.block_diag_solver_dense(M, b, rtol=1e-10)[source]

Solves a system of linear equations where the coefficient matrix M is symmetric and positive definite block diagonal, and the right-hand side is given by b a numpy array.

Parameters:
  • M (sps.csc_array) – A symmetric and positive definite sparse matrix in Compressed Sparse Column (CSC) format representing the block diagonal coefficient matrix.

  • b (np.ndarray) – The right-hand side of the equation. Can be a 1D array (vector) or a 2D array (matrix). If 1D, it will be treated as a column vector.

  • rtol (float) – Relative tolerance for removing small matrix entries. Default 1e-10.

Returns:

The solution to the system of equations. If b is a 1D array, the solution will also be returned as a 1D array. If b is a 2D array, the solution will be returned as a 2D array.

Return type:

np.ndarray