[petsc-users] multigrid implementation problem

Nakib Haider Protik nprot048 at uottawa.ca
Sun Jun 10 15:49:04 CDT 2012


Thank you very much for the reply. Here's a change that works for the 2D
case:

////////////////////MG Solver Stuff////////////////////
    KSPCreate(PETSC_COMM_WORLD, &ksp);
    KSPSetType(ksp, KSPGMRES);

    KSPCreate(PETSC_COMM_WORLD, &kspu);
    KSPSetType(kspu, KSPGMRES);

    KSPGetPC(ksp, &pc);
    KSPGetPC(kspu, &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);
    PCMGGetSmootherDown(pc, 0, &ksp);
    PCMGGetSmootherUp(pc, 1, &kspu);//(*)//
    PCMGSetInterpolation(pc, 1, P);
    PCMGSetRestriction(pc, 1, P);
    PCMGSetResidual(pc, 0, PCMGDefaultResidual, P);
    PCMGSetResidual(pc, 1, PCMGDefaultResidual, P);
    KSPSetOperators(ksp, A, P, SAME_NONZERO_PATTERN);
    KSPSetFromOptions(ksp);
    KSPSolve(ksp, breal, xreal_harm);
    KSPSolve(ksp, bimag, ximag_harm);
    //////////////////////////////////////////////////////////

Do you think this is working again because of some accident? Without the
step marked with a //(*)//, the code works too.

Thanks

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


-- 
Nakib :)


More information about the petsc-users mailing list