1*ab8d36c9SPeter Brune #include "../src/snes/impls/fas/fasimpls.h" /*I "petscsnesfas.h" I*/ 2*ab8d36c9SPeter Brune 3*ab8d36c9SPeter Brune #undef __FUNCT__ 4*ab8d36c9SPeter Brune #define __FUNCT__ "SNESFASGetGalerkin" 5*ab8d36c9SPeter Brune /*@ 6*ab8d36c9SPeter Brune SNESFASGetGalerkin - Gets if the coarse problems are formed by projection to the fine problem 7*ab8d36c9SPeter Brune 8*ab8d36c9SPeter Brune Input Parameter: 9*ab8d36c9SPeter Brune . snes - the nonlinear solver context 10*ab8d36c9SPeter Brune 11*ab8d36c9SPeter Brune Output parameter: 12*ab8d36c9SPeter Brune . flg - the status of the galerkin problem 13*ab8d36c9SPeter Brune 14*ab8d36c9SPeter Brune Level: advanced 15*ab8d36c9SPeter Brune 16*ab8d36c9SPeter Brune .keywords: FAS, galerkin 17*ab8d36c9SPeter Brune 18*ab8d36c9SPeter Brune .seealso: SNESFASSetLevels(), SNESFASSetGalerkin() 19*ab8d36c9SPeter Brune @*/ 20*ab8d36c9SPeter Brune PetscErrorCode SNESFASGetGalerkin(SNES snes, PetscBool *flg) { 21*ab8d36c9SPeter Brune SNES_FAS * fas = (SNES_FAS *)snes->data; 22*ab8d36c9SPeter Brune PetscFunctionBegin; 23*ab8d36c9SPeter Brune *flg = fas->galerkin; 24*ab8d36c9SPeter Brune PetscFunctionReturn(0); 25*ab8d36c9SPeter Brune } 26*ab8d36c9SPeter Brune 27*ab8d36c9SPeter Brune #undef __FUNCT__ 28*ab8d36c9SPeter Brune #define __FUNCT__ "SNESFASSetGalerkin" 29*ab8d36c9SPeter Brune /*@ 30*ab8d36c9SPeter Brune SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem 31*ab8d36c9SPeter Brune 32*ab8d36c9SPeter Brune Input Parameter: 33*ab8d36c9SPeter Brune . snes - the nonlinear solver context 34*ab8d36c9SPeter Brune . flg - the status of the galerkin problem 35*ab8d36c9SPeter Brune 36*ab8d36c9SPeter Brune Level: advanced 37*ab8d36c9SPeter Brune 38*ab8d36c9SPeter Brune .keywords: FAS, galerkin 39*ab8d36c9SPeter Brune 40*ab8d36c9SPeter Brune .seealso: SNESFASSetLevels(), SNESFASGetGalerkin() 41*ab8d36c9SPeter Brune @*/ 42*ab8d36c9SPeter Brune PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg) { 43*ab8d36c9SPeter Brune SNES_FAS * fas = (SNES_FAS *)snes->data; 44*ab8d36c9SPeter Brune PetscErrorCode ierr; 45*ab8d36c9SPeter Brune PetscFunctionBegin; 46*ab8d36c9SPeter Brune fas->galerkin = flg; 47*ab8d36c9SPeter Brune if (fas->next) {ierr = SNESFASSetGalerkin(fas->next, flg);CHKERRQ(ierr);} 48*ab8d36c9SPeter Brune PetscFunctionReturn(0); 49*ab8d36c9SPeter Brune } 506273346dSPeter Brune 516273346dSPeter Brune #undef __FUNCT__ 526273346dSPeter Brune #define __FUNCT__ "SNESFASGalerkinDefaultFunction" 536273346dSPeter Brune /* 546273346dSPeter Brune SNESFASGalerkinDefaultFunction 556273346dSPeter Brune 566273346dSPeter Brune */ 576273346dSPeter Brune PetscErrorCode SNESFASGalerkinDefaultFunction(SNES snes, Vec X, Vec F, void * ctx) { 586273346dSPeter Brune /* the Galerkin FAS function evalutation is defined as 596273346dSPeter Brune F^l(x^l) = I^l_0F^0(P^0_lx^l) 606273346dSPeter Brune */ 616273346dSPeter Brune SNES fassnes; 626273346dSPeter Brune SNES_FAS * fas; 636273346dSPeter Brune SNES_FAS * prevfas; 646273346dSPeter Brune SNES prevsnes; 6575d4ebe3SPeter Brune Vec b_temp; 666273346dSPeter Brune PetscErrorCode ierr; 676273346dSPeter Brune PetscFunctionBegin; 686273346dSPeter Brune /* prolong to the fine level and evaluate there. */ 696273346dSPeter Brune fassnes = (SNES)ctx; 706273346dSPeter Brune fas = (SNES_FAS *)fassnes->data; 716273346dSPeter Brune prevsnes = fas->previous; 726273346dSPeter Brune prevfas = (SNES_FAS *)prevsnes->data; 736273346dSPeter Brune /* interpolate down the solution */ 746273346dSPeter Brune ierr = MatInterpolate(prevfas->interpolate, X, prevfas->Xg);CHKERRQ(ierr); 7575d4ebe3SPeter Brune /* the RHS we care about is at the coarsest level */ 7675d4ebe3SPeter Brune b_temp = prevsnes->vec_rhs; 7775d4ebe3SPeter Brune prevsnes->vec_rhs = PETSC_NULL; 786273346dSPeter Brune ierr = SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);CHKERRQ(ierr); 7975d4ebe3SPeter Brune prevsnes->vec_rhs = b_temp; 806273346dSPeter Brune /* restrict up the function */ 816273346dSPeter Brune ierr = MatRestrict(prevfas->restrct, prevfas->Fg, F);CHKERRQ(ierr); 826273346dSPeter Brune PetscFunctionReturn(0); 836273346dSPeter Brune } 84