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