Actual source code: smg.c

  1: /*
  2:      Additive Multigrid V Cycle routine    
  3: */
 4:  #include src/ksp/pc/impls/mg/mgimpl.h

  6: /*
  7:        MGACycle_Private - Given an MG structure created with MGCreate() runs 
  8:                   one cycle down through the levels and back up. Applys
  9:                   the smoothers in an additive manner.

 11:     Iput Parameters:
 12: .   mg - structure created with  MGCreate().

 14: */
 17: PetscErrorCode MGACycle_Private(MG *mg)
 18: {
 20:   PetscInt       i,l = mg[0]->levels;
 21:   PetscScalar    zero = 0.0;

 24:   /* compute RHS on each level */
 25:   for (i=l-1; i>0; i--) {
 26:     MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
 27:   }
 28:   /* solve seperately on each level */
 29:   for (i=0; i<l; i++) {
 30:     VecSet(&zero,mg[i]->x);
 31:     if (mg[i]->eventsolve) {PetscLogEventBegin(mg[i]->eventsolve,0,0,0,0);}
 32:     KSPSolve(mg[i]->smoothd,mg[i]->b,mg[i]->x);
 33:     if (mg[i]->eventsolve) {PetscLogEventEnd(mg[i]->eventsolve,0,0,0,0);}
 34:   }
 35:   for (i=1; i<l; i++) {
 36:     MatInterpolateAdd(mg[i]->interpolate,mg[i-1]->x,mg[i]->x,mg[i]->x);
 37:   }
 38:   return(0);
 39: }