Actual source code: smg.c
1: /*$Id: smg.c,v 1.24 2001/08/07 03:03:36 balay Exp $*/
2: /*
3: Additive Multigrid V Cycle routine
4: */
5: #include src/ksp/pc/impls/mg/mgimpl.h
7: /*
8: MGACycle_Private - Given an MG structure created with MGCreate() runs
9: one cycle down through the levels and back up. Applys
10: the smoothers in an additive manner.
12: Iput Parameters:
13: . mg - structure created with MGCreate().
15: */
18: int MGACycle_Private(MG *mg)
19: {
20: int i,l = mg[0]->levels,ierr;
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: KSPSetRhs(mg[i]->smoothd,mg[i]->b);
33: KSPSetSolution(mg[i]->smoothd,mg[i]->x);
34: KSPSolve(mg[i]->smoothd);
35: if (mg[i]->eventsolve) {PetscLogEventEnd(mg[i]->eventsolve,0,0,0,0);}
36: }
37: for (i=1; i<l; i++) {
38: MatInterpolateAdd(mg[i]->interpolate,mg[i-1]->x,mg[i]->x,mg[i]->x);
39: }
40: return(0);
41: }