# [petsc-users] move from KSPSetNullSpace to MatSetNullSpace

Stephan Kramer s.kramer at imperial.ac.uk
Mon Jun 22 13:13:55 CDT 2015

```Dear petsc devs

I've been trying to move our code from using KSPSetNullSpace to use
MatSetNullSpace instead. Although I appreciate the convenience of the
nullspace being propagated automatically through the solver hierarchy,
I'm still a little confused on how to deal with the case that mat/=pmat
in a ksp.

If I read the code correctly I need to call MatSetNullSpace on the pmat
in order for a ksp to project that nullspace out of the residual during
the krylov iteration. However the nullspaces of mat and pmat are not
necessarily the same. For instance, what should I do if the system that
I want to solve has a nullspace (i.e. the `mat` has a null vector), but
the preconditioner matrix does not.

As an example of existing setups that we have for which this is the
case: take a standard Stokes velocity, pressure system - where we want
to solve for pressure through a Schur complement. Suppose the boundary
conditions are Dirichlet for velocity on all boundaries, then the
pressure equation has the standard, constant nullspace. A frequently
used preconditioner is the "scaled pressure mass matrix" where G^T
K^{-1} G is approximated by a pressure mass matrix that is scaled by the
value of the viscosity. So in this case the actual system has a
nullspace, but the preconditioner matrix does not.

The way we previously used to solve this is by setting the nullspace on
the ksp of the Schur system, where the mat comes from
MatCreateSchurComplement and the pmat is the scaled mass matrix. We then
set the pctype to PCKSP and do not set a nullspace on its associated
ksp. I don't really see how I can do this using only MatSetNullSpace -
unless I create a copy of the mass matrix and have one copy with and one
copy without a nullspace so that I could use the one with the nullspace
for the pmat of the Schur ksp (and thus the mat of the pcksp) and the
copy without the nullspace as the pmat for the pcksp.

We would very much appreciate some guidance on what the correct way to
deal with this kind of situation is

Cheers
Stephan
```