[petsc-users] PCMG and DMMG

Barry Smith bsmith at mcs.anl.gov
Wed Feb 18 18:28:40 CST 2015


> On Feb 18, 2015, at 2:38 PM, DU Yongle <yongle.du at gmail.com> wrote:
> 
> Dear Smith:
> 
> Sorry to bother. A few questions about PCMG, because I am confused while reading the manual and source code.
> 
> Suppose I have 29 points along a one-dimensional domain, which can be reduced twice, and gives 3 grid levels.
> 
> (1) when I set PCMG, should the levels be 2 or 3? or in other words, the PCMG includes the finest level on which we are solving the equations or not?

  Yes, that counts as a level
> 
> (2) What's the difference between PCMGGetsmoother and PCMGGetCoaseSolve? One the mid level #1, should I use the former or the latter?

  PCMGGetsmoother() gives back the solver used as the smoother for ANY level. PCMGGetCoaseSolve() is just syntactic sugar for the coarsest level
> 
> 
> (3) What are PCMGGetsmootherup and PCMGGetSmootherDown supposed to do?

  By default the pre and post smooth (what I call the down and up smoother) are the same. If you want them to be different you can call the above routines and set different solver options on each (plus supply the operator). Normally it is fine for them to be the same unless you know something about your problem that would make you want them to be different.

> 
> (4) It appears simpler to solve the equation Ax=b using PCMG. However, if I have several consecutive equations in the similar form, for example multi-level implicit RK method, where we have to solve A1 x1 = b1, A2 x2 = b2 ... successively in a step,, and An are defined as matrix-free, what's the best approach to implement?

  I would make a different KSP for each system, for example ksp1, ksp2, ksp3. 

  Multigrid (and PCMG) can be used with matrix-free operators but  you are limited with what smoothers you can use (essentially Chebychev or one of the other Krylov methods with a PCType of none).  You need to use MatCreateShell() to create the matrix (one matrix for each level) and provide a matrix-vector routine to do the matrix-vector product with your matrix-free operator). Otherwise you put together the PCMG the same way whether it is matrix free or not. In fact if you can provide a matrix-free matrix-vector product for the interpolation and restriction then you can also make those operators with MatCreateShell().

  Barry
> 
> 
> Thanks a lot for your help.
> 
> 
> 
> On Mon, Feb 9, 2015 at 12:09 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
>   Looks like you are looking at a very old PETSc. You should be using version 3.5.3 and nothing earlier. DMMG has been gone from PETSc for a long time.
> 
>   Here is the easiest way to provide the information:  Loop over the levels yourself and provide the matrices, function pointers etc. See for example src/ksp/ksp/examples/tests/ex19.c This example only sets up MG for two levels but you can see the pattern from the code. It creates the matrix operator for each level and vectors, and sets it for the level,
> 
>   ierr = FormJacobian_Grid(&user,&user.coarse,&user.coarse.J);CHKERRQ(ierr);
>   ierr = FormJacobian_Grid(&user,&user.fine,&user.fine.J);CHKERRQ(ierr);
> 
>   /* Create coarse level */
>   ierr = PCMGGetCoarseSolve(pc,&user.ksp_coarse);CHKERRQ(ierr);
>   ierr = KSPSetOptionsPrefix(user.ksp_coarse,"coarse_");CHKERRQ(ierr);
>   ierr = KSPSetFromOptions(user.ksp_coarse);CHKERRQ(ierr);
>   ierr = KSPSetOperators(user.ksp_coarse,user.coarse.J,user.coarse.J);CHKERRQ(ierr);
>   ierr = PCMGSetX(pc,COARSE_LEVEL,user.coarse.x);CHKERRQ(ierr);
>   ierr = PCMGSetRhs(pc,COARSE_LEVEL,user.coarse.b);CHKERRQ(ierr);
> 
>   /* Create fine level */
>   ierr = PCMGGetSmoother(pc,FINE_LEVEL,&ksp_fine);CHKERRQ(ierr);
>   ierr = KSPSetOptionsPrefix(ksp_fine,"fine_");CHKERRQ(ierr);
>   ierr = KSPSetFromOptions(ksp_fine);CHKERRQ(ierr);
>   ierr = KSPSetOperators(ksp_fine,user.fine.J,user.fine.J);CHKERRQ(ierr);
>   ierr = PCMGSetR(pc,FINE_LEVEL,user.fine.r);CHKERRQ(ierr);
> 
>   and it creates the interpolation and sets it
>   /* Create interpolation between the levels */
>   ierr = DMCreateInterpolation(user.coarse.da,user.fine.da,&user.Ii,NULL);CHKERRQ(ierr);
>   ierr = PCMGSetInterpolation(pc,FINE_LEVEL,user.Ii);CHKERRQ(ierr);
>   ierr = PCMGSetRestriction(pc,FINE_LEVEL,user.Ii);CHKERRQ(ierr);
> 
>   Note that PETSc by default uses the transpose of the interpolation for the restriction so even though it looks strange to set the same operator for both PETSc automatically uses the transpose when needed.
> 
>   Barry
> 
> 
> > On Feb 9, 2015, at 10:09 AM, DU Yongle <yongle.du at gmail.com> wrote:
> >
> > Good morning, everyone:
> >
> > I have an existing general CFD solver with multigrid implemented. All functions (initialization, restriction, prolong/interpolation, coarse/fine grids solver......) are working correctly. Now I am trying to rewrite it with PETSc. I found that the manual provides very little information about this and is difficult to follow. I found another lecture notes by Barry Smith on web, which is:
> > http://www.mcs.anl.gov/petsc/documentation/tutorials/Columbia04/DDandMultigrid.pdf
> >
> > However, it is still not clear the difference and connection between PCMG and DMMG. Some questions are:
> >
> > 1. Should DMMG be used to initialize the coarse grids (and boundary conditions) before PCMG could be used? If not, how does PCMG know all information on coarse grids?
> >
> > 2. Due to the customized boundary conditions, indices of the grids, boundary conditions, grid dimensions on each coarse grid levels are required for particular computations. How to extract these information in either DMMG or PCMG? I have not found a function for this purpose. I have set up all information myself, should I pass these information to the coarse grid levels to the coarse levels? How and again how to extract these information?
> >
> > 3. I have the restriction, interpolation, coarse grid solver ... implemented. How could these be integrated with PETSc functions? It appears that some functions like PCMGGetSmoother/UP/Down, PCMGSetInterpolation .... should be used, but how? The online manual simply repeat the name, and provides no other information.
> >
> > Thanks a lot.
> >
> >
> >
> >
> 
> 



More information about the petsc-users mailing list