Actual source code: fmg.c

  1: /*
  2:      Full multigrid using either additive or multiplicative V or W cycle
  3: */
 4:  #include src/ksp/pc/impls/mg/mgimpl.h

  6: EXTERN PetscErrorCode PCMGMCycle_Private(PC_MG **,PetscTruth*);

 10: PetscErrorCode PCMGFCycle_Private(PC_MG **mg)
 11: {
 13:   PetscInt       i,l = mg[0]->levels;

 16:   /* restrict the RHS through all levels to coarsest. */
 17:   for (i=l-1; i>0; i--){
 19:     MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
 21:   }
 22: 
 23:   /* work our way up through the levels */
 24:   VecSet(mg[0]->x,0.0);
 25:   for (i=0; i<l-1; i++) {
 26:     PCMGMCycle_Private(&mg[i],PETSC_NULL);
 28:     MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
 30:   }
 31:   PCMGMCycle_Private(&mg[l-1],PETSC_NULL);
 32:   return(0);
 33: }

 37: PetscErrorCode PCMGKCycle_Private(PC_MG **mg)
 38: {
 40:   PetscInt       i,l = mg[0]->levels;

 43:   /* restrict the RHS through all levels to coarsest. */
 44:   for (i=l-1; i>0; i--){
 46:     MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
 48:   }
 49: 
 50:   /* work our way up through the levels */
 51:   VecSet(mg[0]->x,0.0);
 52:   for (i=0; i<l-1; i++) {
 54:     KSPSolve(mg[i]->smoothd,mg[i]->b,mg[i]->x);
 57:     MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
 59:   }
 61:   KSPSolve(mg[l-1]->smoothd,mg[l-1]->b,mg[l-1]->x);

 64:   return(0);
 65: }