[petsc-users] multigrid implementation problem

Nakib Haider Protik nprot048 at uottawa.ca
Sun Jun 10 00:10:56 CDT 2012


Hello

I am working on a Poisson Solver and ran into a problem using the
multigrid preconditioner. I am using petsc-3.0.0-p12. 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);


    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);
///////////////////////////////////////////////////

As you can see, using the line //PCMGGetSmoother(pc, 1, &ksp); causes the
solver to converge to a wrong value. What's appearing strange to me is
that this exact code works for a 1 dimensional laplacian matrix (for both
uniform and nonuniform grids). I don't understand why it won't work with a
2 dimensional case.

Another important point is that, without the culprit line, the code
converges to the right solution. Also, if I use a different ksp object and
pass that object to the smoother on level 1, the code works again.

I would be greatly helped if anyone can explain what is happening here.

Thanks

-- 
Nakib


More information about the petsc-users mailing list