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--){
18: MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
19: }
20:
21: /* work our way up through the levels */
22: VecSet(mg[0]->x,0.0);
23: for (i=0; i<l-1; i++) {
24: PCMGMCycle_Private(&mg[i],PETSC_NULL);
25: MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
26: }
27: PCMGMCycle_Private(&mg[l-1],PETSC_NULL);
28: return(0);
29: }
33: PetscErrorCode PCMGKCycle_Private(PC_MG **mg)
34: {
36: PetscInt i,l = mg[0]->levels;
39: /* restrict the RHS through all levels to coarsest. */
40: for (i=l-1; i>0; i--){
41: MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
42: }
43:
44: /* work our way up through the levels */
45: VecSet(mg[0]->x,0.0);
46: for (i=0; i<l-1; i++) {
48: KSPSolve(mg[i]->smoothd,mg[i]->b,mg[i]->x);
50: MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
51: }
53: KSPSolve(mg[l-1]->smoothd,mg[l-1]->b,mg[l-1]->x);
56: return(0);
57: }