[petsc-users] multigrid implementation problem

Nakib Haider Protik nprot048 at uottawa.ca
Sun Jun 10 19:54:27 CDT 2012


Okay, so here is the code that works. This gives the correct result, but I
want to make sure that it is not giving the correct result accidentally.
Thank you very much for your time.

    KSPCreate(PETSC_COMM_WORLD, &ksp);
    KSPCreate(PETSC_COMM_WORLD, &cksp);
    KSPCreate(PETSC_COMM_WORLD, &uksp);
    KSPCreate(PETSC_COMM_WORLD, &dksp);
    KSPSetType(ksp, KSPGMRES);
    KSPSetType(cksp, KSPGMRES);
    KSPSetType(uksp, KSPGMRES);
    KSPSetType(dksp, KSPGMRES);

    KSPGetPC(ksp, &pc);
    KSPGetPC(cksp, &pc);
    KSPGetPC(uksp, &pc);
    KSPGetPC(dksp, &pc);

    KSPSetFromOptions(ksp);

    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, &cksp);
    PCMGGetSmootherDown(pc, 0,  &dksp);
    PCMGGetSmootherUp(pc, 1, &uksp);

    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);
    KSPSolve(ksp, breal, xreal_harm);
    KSPSolve(ksp, bimag, ximag_harm);
    //////////////////////////////////////////////////////////

> On Sun, Jun 10, 2012 at 7:32 PM, Nakib Haider Protik
> <nprot048 at uottawa.ca>wrote:
>
>> Okay. But if I understood correctly, doing the following would also be
>> wrong since I will have made three extra outer KSP objects. I am not
>> sure
>> I understand what these functions want.
>>
>>  KSP cksp, uksp, dksp;
>>  PCMGGetCoarseSolve(pc, &cksp);/**/
>>  PCMGGetSmootherDown(pc, 0, &dksp);/**/
>>  PCMGGetSmootherUp(pc, 1, &uksp);/**/
>>
>
> This is fine, all of these are getting references to inner objects without
> overwriting the outer objects. Of course you don't need to get these
> references if you aren't going to modify them.
>
> I recommend that you experiment with algorithms using the command line and
> check that it does what you expect using -ksp_view.
>


-- 
Nakib :)


More information about the petsc-users mailing list