Actual source code: fmg.c
1: /*$Id: fmg.c,v 1.26 2001/08/21 21:03:20 bsmith Exp $*/
2: /*
3: Full multigrid using either additive or multiplicative V or W cycle
4: */
5: #include src/sles/pc/impls/mg/mgimpl.h
7: EXTERN int MGMCycle_Private(MG *,PetscTruth*);
9: /*
10: MGFCycle_Private - Given an MG structure created with MGCreate() runs
11: full multigrid.
13: Iput Parameters:
14: . mg - structure created with MGCreate().
16: Note: This may not be what others call full multigrid. What we
17: do is restrict the rhs to all levels, then starting
18: on the coarsest level work our way up generating
19: initial guess for the next level. This provides an
20: improved preconditioner but not a great improvement.
21: */
22: int MGFCycle_Private(MG *mg)
23: {
24: int i,l = mg[0]->levels,ierr;
25: PetscScalar zero = 0.0;
28: /* restrict the RHS through all levels to coarsest. */
29: for (i=l-1; i>0; i--){
30: MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
31: }
32:
33: /* work our way up through the levels */
34: VecSet(&zero,mg[0]->x);
35: for (i=0; i<l-1; i++) {
36: MGMCycle_Private(&mg[i],PETSC_NULL);
37: MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
38: }
39: MGMCycle_Private(&mg[l-1],PETSC_NULL);
40: return(0);
41: }
43: /*
44: MGKCycle_Private - Given an MG structure created with MGCreate() runs
45: full Kascade MG solve.
47: Iput Parameters:
48: . mg - structure created with MGCreate().
50: Note: This may not be what others call Kascadic MG.
51: */
52: int MGKCycle_Private(MG *mg)
53: {
54: int i,l = mg[0]->levels,its,ierr;
55: PetscScalar zero = 0.0;
58: /* restrict the RHS through all levels to coarsest. */
59: for (i=l-1; i>0; i--){
60: MatRestrict(mg[i]->restrct,mg[i]->b,mg[i-1]->b);
61: }
62:
63: /* work our way up through the levels */
64: VecSet(&zero,mg[0]->x);
65: for (i=0; i<l-1; i++) {
66: SLESSolve(mg[i]->smoothd,mg[i]->b,mg[i]->x,&its);
67: MatInterpolate(mg[i+1]->interpolate,mg[i]->x,mg[i+1]->x);
68: }
69: SLESSolve(mg[l-1]->smoothd,mg[l-1]->b,mg[l-1]->x,&its);
71: return(0);
72: }