1 #include <../src/snes/impls/fas/fasimpls.h> /*I "petscsnes.h" I*/ 2 3 /*@ 4 SNESFASGetGalerkin - Gets if the coarse problems are formed by projection to the fine problem 5 6 Input Parameter: 7 . snes - the nonlinear solver context 8 9 Output parameter: 10 . flg - the status of the galerkin problem 11 12 Level: advanced 13 14 .seealso: SNESFASSetLevels(), SNESFASSetGalerkin() 15 @*/ 16 PetscErrorCode SNESFASGetGalerkin(SNES snes, PetscBool *flg) 17 { 18 SNES_FAS *fas; 19 20 PetscFunctionBegin; 21 PetscValidHeaderSpecificType(snes,SNES_CLASSID,1,SNESFAS); 22 fas = (SNES_FAS*)snes->data; 23 *flg = fas->galerkin; 24 PetscFunctionReturn(0); 25 } 26 27 /*@ 28 SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem 29 30 Input Parameters: 31 + snes - the nonlinear solver context 32 - flg - the status of the galerkin problem 33 34 Level: advanced 35 36 .seealso: SNESFASSetLevels(), SNESFASGetGalerkin() 37 @*/ 38 PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg) 39 { 40 SNES_FAS *fas; 41 PetscErrorCode ierr; 42 43 PetscFunctionBegin; 44 PetscValidHeaderSpecificType(snes,SNES_CLASSID,1,SNESFAS); 45 fas = (SNES_FAS*)snes->data; 46 fas->galerkin = flg; 47 if (fas->next) {ierr = SNESFASSetGalerkin(fas->next, flg);CHKERRQ(ierr);} 48 PetscFunctionReturn(0); 49 } 50 51 /*@C 52 SNESFASGalerkinFunctionDefault - Computes the Galerkin FAS function 53 54 Input Parameters: 55 + snes - the nonlinear solver context 56 . X - input vector 57 - ctx - the FAS context 58 59 Output Parameter: 60 . F - output vector 61 62 Notes: 63 The Galerkin FAS function evalutation is defined as 64 $ F^l(x^l) = I^l_0 F^0(P^0_l x^l) 65 66 Level: developer 67 68 .seealso: SNESFASGetGalerkin(), SNESFASSetGalerkin() 69 @*/ 70 PetscErrorCode SNESFASGalerkinFunctionDefault(SNES snes, Vec X, Vec F, void *ctx) 71 { 72 SNES fassnes; 73 SNES_FAS *fas; 74 SNES_FAS *prevfas; 75 SNES prevsnes; 76 Vec b_temp; 77 PetscErrorCode ierr; 78 79 PetscFunctionBegin; 80 /* prolong to the fine level and evaluate there. */ 81 fassnes = (SNES)ctx; 82 fas = (SNES_FAS*)fassnes->data; 83 prevsnes = fas->previous; 84 prevfas = (SNES_FAS*)prevsnes->data; 85 /* interpolate down the solution */ 86 ierr = MatInterpolate(prevfas->interpolate, X, prevfas->Xg);CHKERRQ(ierr); 87 /* the RHS we care about is at the coarsest level */ 88 b_temp = prevsnes->vec_rhs; 89 prevsnes->vec_rhs = NULL; 90 ierr = SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);CHKERRQ(ierr); 91 prevsnes->vec_rhs = b_temp; 92 /* restrict up the function */ 93 ierr = MatRestrict(prevfas->restrct, prevfas->Fg, F);CHKERRQ(ierr); 94 PetscFunctionReturn(0); 95 } 96