# How to solve a linear problem A x = b in PETSC when matrix A has zero diagonal enteries?

I am solving a structural mechanics problem that involves setting constraints, and I use Lagrange multipliers to set it. Consequently, some diagonal entries of the tangent stiffness matrix vanish, and I couldn't solve the system using the KSP solver.

I will appreciate any help.

• Are you using the name "pivots" to mean "diagonal entries of $A$"? I always used it to mean "diagonal elements of the $U$ factor of $A=LU$", so I am a bit confused: if a matrix has $U_{kk}=0$ it is singular, at least up to perturbations of the order of machine precision. – Federico Poloni Nov 29 '20 at 16:03
• Why can't you use the KSP solvers? That's pretty much exactly what they're meant to be used for. – Wolfgang Bangerth Nov 29 '20 at 17:51
• Also, what are your constraints? – Wolfgang Bangerth Nov 29 '20 at 17:51
• @FedericoPoloni Yes, diagonal entries of A. – ARUN KUMAR Nov 29 '20 at 18:31
• @WolfgangBangerth Sir, I used linear solve PCLU. The PETSC couldn't set up the preconditioner even. I got this error- PCSETUP_FAILED due to FACTOR_NUMERIC_ZEROPIVOT. As pointed out in the answer below I tried using PCFIELDSPLIT. I used options " -ksp_type gmres -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_detect_saddle point " . Still I could not succeed. I am not sure if made any mistake. – ARUN KUMAR Nov 29 '20 at 18:45

Use of Lagrange multipliers produces a saddle-point problem, $$\begin{pmatrix} A & B^T \\ B & 0 \end{pmatrix} \begin{pmatrix} u \\ \lambda \end{pmatrix} = \begin{pmatrix} b \\ 0 \end{pmatrix}$$

As you've noticed, many preconditioners break down for this sort of system. One can use direct solvers that support pivoting, but if you want iterative solvers, a common flexible strategy is to use PCFIELDSPLIT; see the factorization (Schur) methods in the Users Manual section on Solving Block Matrices.

Note that the fact that you cannot use conjugate gradients because this problem is not positive definite. You can use MINRES with some preconditioners, but it's sometimes more effective to use nonsymmetric (usually block triangular) preconditioners.

• "One can use direct solvers that support pivoting", could you suggest one. I used PCLU and got this error - "PCSETUP_FAILED due to FACTOR_NUMERIC_ZEROPIVOT". – ARUN KUMAR Nov 29 '20 at 19:00
• I tried field split with two field sets and options: " -ksp_type gmres -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_detect_saddle point " . I am not sure if any made any mistake, but I could not succeed. – ARUN KUMAR Nov 29 '20 at 19:01
• MUMPS, SuperLU, SuiteSparse, Pardiso are some of the external packages interface with PETSc and they all support pivoting. However, if the linear system is large (for example >300k, depending on your machine and amount of available RAM) then direct solvers are not advisable. I would suggest following Jed's suggestion related to the iterative solvers. – Abdullah Ali Sivas Nov 29 '20 at 19:10