#undef __FUNCT__  
#define __FUNCT__ "PCMGKCycle_Private"
PetscErrorCode PCMGKCycle_Private(PC pc,PC_MG_Levels **mglevels)
{
  PetscErrorCode ierr;
  PetscInt       i,l = mglevels[0]->levels;

  PetscFunctionBegin;
  /* restrict the RHS through all levels to coarsest. */
  for (i=l-1; i>0; i--){
    if (mglevels[i]->eventinterprestrict) {ierr = 
PetscLogEventBegin(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
    ierr = 
MatRestrict(mglevels[i]->restrct,mglevels[i]->b,mglevels[i-1]->b);CHKERRQ(ierr);
 
    if (mglevels[i]->eventinterprestrict) {ierr = 
PetscLogEventEnd(mglevels[i]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
  }
  
  /* work our way up through the levels */
  ierr = VecSet(mglevels[0]->x,0.0);CHKERRQ(ierr); 
  for (i=0; i<l-1; i++) {
    if (mglevels[i]->eventsmoothsolve) {ierr = 
PetscLogEventBegin(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
    ierr = 
KSPSolve(mglevels[i]->smoothd,mglevels[i]->b,mglevels[i]->x);CHKERRQ(ierr);
    if (mglevels[i]->eventsmoothsolve) {ierr = 
PetscLogEventEnd(mglevels[i]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
    if (mglevels[i+1]->eventinterprestrict) {ierr = 
PetscLogEventBegin(mglevels[i+1]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
    ierr = 
MatInterpolate(mglevels[i+1]->interpolate,mglevels[i]->x,mglevels[i+1]->x);CHKERRQ(ierr);
    if (mglevels[i+1]->eventinterprestrict) {ierr = 
PetscLogEventEnd(mglevels[i+1]->eventinterprestrict,0,0,0,0);CHKERRQ(ierr);}
  }
  if (mglevels[l-1]->eventsmoothsolve) {ierr = 
PetscLogEventBegin(mglevels[l-1]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}
  ierr = 
KSPSolve(mglevels[l-1]->smoothd,mglevels[l-1]->b,mglevels[l-1]->x);CHKERRQ(ierr);
  if (mglevels[l-1]->eventsmoothsolve) {ierr = 
PetscLogEventEnd(mglevels[l-1]->eventsmoothsolve,0,0,0,0);CHKERRQ(ierr);}

  PetscFunctionReturn(0);
}


On Aug 13, 2012, at 3:19 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> Shorthand for this is -pc_mg_type kaskade.
> 
> On Mon, Aug 13, 2012 at 1:01 PM, John Fettig <john.fettig at gmail.com> wrote:
> Barry,
> 
> Thank you for answering my question.  I have another one for you:  it
> seems the special case of zero pre-smooths is somewhat non-trivial.
> The best I can do is set the pre-smoother to Richardson with PCNONE
> and zero as max_its. However, if you aren't careful in setting
> KSPSetInitialGuessNonzero this can have unexpected results since the
> generic KSPSolve will clobber your solution before it even tries a
> convergence criteria (thus ruling out KSPPREONLY).  It also does a
> couple of unnecessary residual calculations. Would it be reasonable to
> put a zero-iteration special case in KSPSolve so that if you don't
> want any iterations it doesn't actually do anything (no setup, no
> preconditioner, no residual, no scaling, etc.)?
> 
> Thanks,
> John
> 
> On Thu, Aug 9, 2012 at 6:37 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> >   John,
> >
> > On Aug 9, 2012, at 9:50 AM, John Fettig <john.fettig at gmail.com> wrote:
> >
> >> I am a little confused about what Richardson means.  If you use
> >> multiplicative V-cycle multigrid with Richardson KSP (and no
> >> convergence monitor), it sets the applyrichardson operator to
> >> PCApplyRichardson_MG, which appears to just run V-cycles until
> >> convergence.
> >
> >      Yes, this is correct.
> >
> >>  As far as I can tell, it doesn't ever update according
> >> to the documented
> >>
> >> x^{n+1} = x^{n} + scale*B(b - A x^{n})
> >>
> >       In exact arithmetic it is actually "implicitly" doing exactly this 
> > update.  It is difficult to see why this is true generally (because B is 
> > rather complicated for multigrid) but if you consider only two levels with 
> > a direct solver on the coarse grid and SSOR as the pre and post smooth you 
> > can write out the formulas and map back and forth between the two forms.  
> > The reason for the PCApplyRichardson_ forms is because they are a bit more 
> > efficient than  separating out the action of B and then doing the update as 
> > above.
> >
> >
> >> If on the other hand you use full MG, it does update according to the
> >> above formula.  This also happens if you set a convergence monitor.
> >>
> >> I can see how multiplicative V-cycle with Richardson is simply using
> >> multigrid as a solver.  What I don't understand is how full MG with
> >> Richardson is using multigrid as a solver, because it is using the
> >> update formula above in between cycles..  Shouldn't there be a
> >> applyrichardson for full multigrid as well?  If not, why?
> >
> >     I think there could be a applyRichardson for full multigrid but it 
> > would be kind of complicated and would not benefit much because the amount 
> > of work in a full multigrid step is much higher so the savings would be a 
> > much lower percentage than with V cycle.
> >
> >    Barry
> >
> >>
> >> Thanks,
> >> John
> >
> 

Reply via email to