Usage of MatNullSpace

Hello, I am having convergence issues solving a nearly singular system using a KSP object with -pc_type lu. From the PETSc documentation, I understand that adding a nullspace constraint using MatNullSpace might help solve my issue. However, when I try to add such a constraint, I see no difference in the solver behavior with the additional MatNullSpace parameter added. Does anyone have any advice or an example code that uses this feature? The null vector in my case does not correspond to any simple solid body motion as in the other FreeFEM examples I’ve found here. I am using it as below:

Mat dA;
real[int,int] NSVec(dA.n,1);
real[int] q; // a known approximation of the nullspace
NSVec(:,0) = q;
set(dA, sparams = "...", MatNullSpace = NSVec);

Do you have has attached near null space with -ksp_view?

Yes, I do. This doesn’t seem to affect how the solver behaves, however.

what are you using for ksp_type? Can you post the matrix?
Do you need to invert it or just solve something?

preonly. You can read about a similar system in Govaertz 2000 Ch 4.1.2. Basically, it involves a (nonsingular) bordered block matrix consisting of a near-singular Jacobian matrix augmented by one additional row and column which resolve the singularity. In this case, the system is solved using Schur complement factorizations that exploit the matrix’s block structure, then an LU factorization of the large, sparse 00-block. No explicit inverses are ever needed.

CG or GMRES work? IS that author’s name with a z or s?

Thanks! This issue is now fixed.