[petsc-users] KSP with MatNullSpace

Barry Smith bsmith at mcs.anl.gov
Sat Dec 3 13:32:03 CST 2011


On Dec 3, 2011, at 1:24 PM, Shiyuan wrote:

> Hi, I traced the program on the level of KSPSolve_CG,  and I don't see the MatNullSpace is used. Where is MatNullSpace used? Can KSP CG automatically handle the null space provided by MatNullSpace?

   It is used, it is just a little convoluted:

#define KSP_PCApply(ksp,x,y)            (!ksp->transpose_solve) ? (PCApply(ksp->pc,x,y) || KSP_RemoveNullSpace(ksp,y))                      : PCApplyTranspose(ksp->pc,x,y) 

so it automatically removes the null space after applying the preconditioner.

> Or I need to change to some other solver? The matrix is semi-positive-definite with only one zero eigenvalue. The zero eigenvector is obtained by an eigensolver.

    My guess is that the zero eigenvector obtained with the eigensolver is just not accurate enough.  Is there any way to increase the accuracy of the eigenvector? Is there any explicit formula for the eigenvector you can derived based on the PDE?

   Barry

For the null space removal to work with CG you need a very accurate form of the null space.


> Any suggestion? Thanks.
> 
>  
> Shiyuan  
> 
> On Fri, Dec 2, 2011 at 11:17 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
> On Dec 2, 2011, at 10:57 PM, Shiyuan wrote:
> 
> > I notice that when the vector indicating the nullspace is not very accurate (norm(A*phi) very small but not zero), KSP (CG) will return KSP_INDEFINITE_PC. When b is very close to zero in AX=b, KSP (CG) has the same error. Is it controlled by some tolerance? How can I set the tolerance?
> 
>   No it is not controlled by some tolerance, it cannot be controlled by some tolerance because the indication of indefiniteness is determined by
> 
>     } else if ((i > 0) && (beta*betaold < 0.0)) {
>       ksp->reason = KSP_DIVERGED_INDEFINITE_PC;
>       ierr = PetscInfo(ksp,"diverging due to indefinite preconditioner\n");CHKERRQ(ierr);
>       break;
> 
> as soon as beta*betaold is negative the entire CG algorithm breaks down and there is no way to recover.
> 
>   Barry
> 
> 
> 
> > Thanks.
> >
> > Shiyuan
> >
> > On Wed, Nov 23, 2011 at 5:00 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> > On Nov 23, 2011, at 1:31 PM, Shiyuan wrote:
> >
> > > I've check it in Matlab. the matrix A is symmetric and has no negative eigenvalues( only a zero eigen value). I've also checked that the nullspace is correct(  norm(A*phi)<1e-11);
> >
> >   Hmm. You can run with -ksp_view_binary and email to petsc-maint at mcs.anl.gov the resulting file called binaryoutput.
> >
> >   Barry
> >
> >
> > > Thanks.
> > >
> > > On Wed, Nov 23, 2011 at 1:26 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> > >
> > >   Print out the matrix for a small grid then check in Matlab that it is symmetric and has no negative eigenvalues.
> > >
> > >   Barry
> > >
> > >
> > > On Nov 23, 2011, at 9:50 AM, Shiyuan wrote:
> > >
> > > > Hi,
> > > >     I want to solve a singular system with a known nullspace. However, I the KSP solve diverges with KSP_INDEFINTE_PC even if I disable the preconditioning by PCNONE.
> > > > this is how I setup the system. What did I do wrong? Any possible causes? Thanks.
> > > >
> > > >    ierr=MatNullSpaceCreate(PETSC_COMM_SELF,PETSC_FALSE,1,&phi,&nsp);CHKERRV(ierr);
> > > >   ierr=KSPCreate(PETSC_COMM_SELF,&ksp);CHKERRV(ierr);
> > > >   ierr=KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRV(ierr);
> > > >   ierr=KSPSetNullSpace(ksp,nsp);CHKERRV(ierr);
> > > >   ierr=KSPSetType(ksp,KSPCG);CHKERRV(ierr);
> > > >   ierr=KSPGetPC(ksp,&prec);CHKERRV(ierr);
> > > >   ierr=PCSetType(prec,PCNONE);CHKERRV(ierr);
> > > >   ierr=KSPSetTolerances(ksp,1e-5,1e-20,1e5,10000);CHKERRV(ierr);
> > > >   ierr=KSPSetFromOptions(ksp);CHKERRV(ierr);
> > > >   ierr=KSPSetUp(ksp);CHKERRV(ierr);
> > > >
> > > > Shiyuan
> > >
> > >
> >
> >
> 
> 



More information about the petsc-users mailing list