On May 16, 2011, at 1:36 AM, Li, Zhisong (lizs) wrote:
> Hi, Petsc Team,
>
> In my knowledge of Petsc, the PCMG object is the main tool for general
> multigrid calculations, as DMMG only works for simple constant matrix and RHS.
This is not correct. DMMG can be used for non-constant matrix. DMMG is
restricted to structured grids only. But if your problem is on a two or three
dimensional structured grid you can use it and it is much easier than coding
the pieces directly.
> But it's difficult to find any example code for using PCMG. I checked out
> the petsc-user mail archive on this topic but still not find a good
> description on it. I encounter similar errors in the practice as some
> previous question-raisers did.
>
> Here is my simple code implementing the PCMG based on my understanding from
> the user manual and tutorial. It is supposed to have multigrid of only two
> levels (finest and coarsest grid). The error message indicates SEGV
> segmentation violation because of this part of code. Anything wrong with
> this implementation?
>
This code looks more or less correct. You need to run with
-start_in_debugger to track down what is trigger the SEGV
src/ksp/ksp/examples/tutorials/ex19.c is a simple example that runs on two
levels.
Barry
>
> DAGetMatrix(da, MATAIJ, &M);
>
> KSPCreate(PETSC_COMM_WORLD, &ksp);
> KSPSetType(ksp, KSPGMRES);
> KSPGetPC(ksp, &pcmg);
> PCSetType(pcmg, PCMG);
>
> PCMGSetLevels(pcmg, 2, &PETSC_COMM_WORLD);
> PCMGSetType(pcmg, PC_MG_MULTIPLICATIVE);
> PCMGSetCycleType(pcmg, PC_MG_CYCLE_W);
> PCMGSetCyclesOnLevel(pcmg, 0, 1);
> PCMGSetCyclesOnLevel(pcmg, 1, 1);
>
> PCMGGetCoarseSolve(pcmg, &ksp);
>
> PCMGGetSmoother(pcmg, 0, &ksp);
> PCMGGetSmoother(pcmg, 1, &ksp);
> PCMGSetInterpolation(pcmg, 1, M);
> PCMGSetRestriction(pcmg, 1, M);
>
> PCMGSetResidual(pcmg, 0, PCMGDefaultResidual, M);
> PCMGSetResidual(pcmg, 1, PCMGDefaultResidual, M);
>
>
> The mandatory remaining PCMGSetRhs( ), PCMGSetX( ) and PCMGSetR( ) functions
> should be generated by Petsc automatically.
>
> It is tough to learn some Petsc functions when no detailed example and few
> guidance is provided. I wish you can add some tutorials codes on PCMG usage
> in the future version of Petsc.
>
>
> Thank you very much.
>
>
> Zhisong Li
>
>
>