solve

PETScLinearSolver.solve(A, b, x0=None, solver_type='cg', precondioner='jacobi', maxiter=None, atol=None, rtol=None)[source]

Solves and returns the solution to the linear system, Ax = b.

This method converts the solution vector from a PETSc.Vec instance to a numpy array, and finally destroys all the PETSc objects to free memory.

Parameters
  • A (csr_matrix) – Coefficients matrix in Ax = b

  • b (ndarray) – Right-hand-side vector in Ax = b

  • solver_type (str, optional) – Default is the iterative solver ‘cg’ based on the Conjugate Gradient method.

  • preconditioner (str, optional) – Default is the ‘jacobi’ preconditioner, i.e., diagonal scaling preconditioning. The preconditioner is used with iterative solvers. When a direct solver is used, this parameter is ignored.

  • factorization_type (str, optional) – The factorization type used with the direct solver. Default is ‘lu’. This parameter is ignored when an iterative solver is used.

Returns

The solution to Ax = b

Return type

ndarray

Notes

Certain combinations of iterative solvers and precondioners or direct solvers and factorization types are not supported. The summary table of the different possibilities can be found here