[petsc-users] Moving from KSPSetNullSpace to MatSetNullSpace

Gil Forsyth gforsyth at gwu.edu
Tue Sep 29 10:28:41 CDT 2015


Hi all,

I've been having some trouble with what should be a relatively simple
update to an immersed boundary CFD solver from PETSc 3.5.4 to 3.6.1

I'm getting indefinite PC errors for a simple lid-driven cavity test
problem, 32x32 at Re 100

Under PETSc 3.5.4 using KSPSetNullSpace we used the following to set the
null space.  This is for a 2D Poisson system with no immersed boundary and
so the null space is the constant vector.

  MatNullSpace nsp;
  ierr = MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0, NULL, &nsp);
CHKERRQ(ierr);
  ierr = KSPSetNullSpace(ksp2, nsp); CHKERRQ(ierr);
  ierr = MatNullSpaceDestroy(&nsp); CHKERRQ(ierr);


And then setup the KSP with

  ierr = KSPCreate(PETSC_COMM_WORLD, &ksp2); CHKERRQ(ierr);
  ierr = KSPSetOptionsPrefix(ksp2, "poisson_"); CHKERRQ(ierr);
  ierr = KSPSetOperators(ksp2, QTBNQ, QTBNQ); CHKERRQ(ierr);
  ierr = KSPSetInitialGuessNonzero(ksp2, PETSC_TRUE); CHKERRQ(ierr);
  ierr = KSPSetType(ksp2, KSPCG); CHKERRQ(ierr);
  ierr = KSPSetReusePreconditioner(ksp2, PETSC_TRUE); CHKERRQ(ierr);
  ierr = KSPSetFromOptions(ksp2); CHKERRQ(ierr);


The matrix QTBNQ does not change, only the rhs of the system is updated.

We run this with `-pc_type gamg -pc_gamg_type agg -pc_gamg_agg_nsmooths 1`
and everything seems to work as expected.

Under PETSc 3.6.1, we change only the KSPSetNullSpace line, to

  ierr = MatSetNullSpace(QTBNQ, nsp); CHKERRQ(ierr);

and the same code diverges after 1 timestep and returns a -8
KSP_DIVERGED_INDEFINITE_PC

This is weird, especially because if we change nsmooths to 2, it runs for
264 timesteps and the returns the same error.  But we have explicitly set
KSPSetReusePreconditioner so it should be using the same PC, right?

Change nsmooths to 3 and it again diverges after 1 timestep.

Change nsmooths to 4 and it runs to completion.

It seems like either gamg's behavior has changed, or that KSPSetNullSpace
was doing something implicitly that we now need to do explicitly in
addition to MatSetNullSpace?

Thanks,
Gil Forsyth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150929/0756aa3a/attachment-0001.html>


More information about the petsc-users mailing list