[petsc-users] multigrid implementation problem

Jed Brown jedbrown at mcs.anl.gov
Sun Jun 10 09:28:13 CDT 2012


On Sun, Jun 10, 2012 at 12:10 AM, Nakib Haider Protik
<nprot048 at uottawa.ca>wrote:

> I am working on a Poisson Solver and ran into a problem using the
> multigrid preconditioner. I am using petsc-3.0.0-p12.
>

Please upgrade to petsc-3.3


> Here's the relevant
> section of the code:
>
> ////////////////////Solver Stuff////////////////////
>    KSPCreate(PETSC_COMM_WORLD, &ksp);
>    KSPSetType(ksp, KSPGMRES);
>
>    KSPSetFromOptions(ksp);
>
>    KSPGetPC(ksp, &pc);
>    PCSetType(pc, PCMG);
>    PCMGSetLevels(pc, 2, PETSC_NULL);
>    PCMGSetType(pc, PC_MG_MULTIPLICATIVE);
>    PCMGSetCycleType(pc, PC_MG_CYCLE_V);
>    MatDuplicate(A, MAT_COPY_VALUES, &P);
>    PCMGSetCyclesOnLevel(pc, 0, 1);
>    PCMGSetCyclesOnLevel(pc, 1, 1);
>    PCMGGetCoarseSolve(pc, &ksp);
>    PCMGGetSmoother(pc, 0, &ksp);
>    PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);
>    PCMGSetRestriction(pc, 1, P);
>    PCMGSetInterpolation(pc, 1, P);
>    PCMGSetRestriction(pc, 1, P);
>    PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);
>
>    //Code breaks if I use the next line. Why?
>    //It worked fine in the 1d case.
>    //PCMGGetSmoother(pc, 1, &ksp);
>

This overwrites the "ksp" variable


>
>
>    KSPSetOperators(ksp, A, P, DIFFERENT_NONZERO_PATTERN);
>    //KSPSetOperators( ksp, A, A, SAME_NONZERO_PATTERN );
>    //KSPSetOperators( ksp, A, A, SAME_PRECONDITIONER );
>    KSPSetFromOptions(ksp);
>    KSPSolve(ksp, breal, xreal_harm);
>    KSPSolve(ksp, bimag, ximag_harm);
>

which you use in place of the "fine grid" problem here.

It probably accidentally works in 1D because the "smoother" involved ILU
which is equivalent to LU for a 1D problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120610/69c61771/attachment.html>


More information about the petsc-users mailing list