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: 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
