KSPSetNullSpace and CG for singular systems
Stephan Kramer
stephan.kramer at imperial.ac.uk
Sat Aug 2 05:04:06 CDT 2008
Shao-Ching Huang wrote:
> Hi,
>
> I am trying to use CG to solve a singular systems (i.e. Poisson
> equation with periodic conditions on all boundaries).
>
> The code works when I use GMRES, but it diverges when I switch CG.
>
> Since the null space is a constant vector, in the code I have:
>
I might be missing something here, but aren't linearly varying vectors
in your null space as well?
Cheers
Stephan
> KSP ksp;
> MatNullSpace nullspace;
> ...
> MatNullSpaceCreate(MPI_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, &nullspace);
> KSPSetNullSpace(ksp, nullspace);
> MatNullSpaceRemove(nullspace, f->p_rhs, PETSC_NULL);
>
> KSPSetFromOptions(ksp);
> KSPSetUp(ksp);
> KSPSolve(ksp, f->p_rhs, f->phi);
>
> [f->p_rhs is the RHS vector. f->phi is the solution vector.]
>
> When I use "-ksp_type gmres", it converges (shown by -ksp_monitor).
>
> However, when I switch to "-ksp_type cg", it diverges.
> In this case (cg), "-ksp_converged_reason" says:
>
> Linear solve did not converge due to DIVERGED_INDEFINITE_PC iterations 1
>
> I also try adding "-sub_pc_factor_shift_nonzero 0.0000000001" but the
> CG case still fails.
>
> Am I missing some step in handling the null space when using CG?
>
> Thanks,
>
> Shao-Ching Huang
>
>
>
>
More information about the petsc-users
mailing list