Actual source code: fasgalerkin.c

petsc-3.8.3 2017-12-09
Report Typos and Errors
  1:  #include <../src/snes/impls/fas/fasimpls.h>

  3: /*@
  4:    SNESFASGetGalerkin - Gets if the coarse problems are formed by projection to the fine problem

  6:    Input Parameter:
  7: .  snes - the nonlinear solver context

  9:    Output parameter:
 10: .  flg - the status of the galerkin problem

 12:    Level: advanced

 14: .keywords: FAS, galerkin

 16: .seealso: SNESFASSetLevels(), SNESFASSetGalerkin()
 17: @*/
 18: PetscErrorCode SNESFASGetGalerkin(SNES snes, PetscBool *flg)
 19: {
 20:   SNES_FAS * fas = (SNES_FAS*)snes->data;

 23:   *flg = fas->galerkin;
 24:   return(0);
 25: }

 27: /*@
 28:    SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem

 30:    Input Parameter:
 31: .  snes - the nonlinear solver context
 32: .  flg - the status of the galerkin problem

 34:    Level: advanced

 36: .keywords: FAS, galerkin

 38: .seealso: SNESFASSetLevels(), SNESFASGetGalerkin()
 39: @*/
 40: PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg)
 41: {
 42:   SNES_FAS       * fas = (SNES_FAS*)snes->data;

 46:   fas->galerkin = flg;
 47:   if (fas->next) {SNESFASSetGalerkin(fas->next, flg);}
 48:   return(0);
 49: }

 51: /*
 52: SNESFASGalerkinDefaultFunction

 54:  */
 55: PetscErrorCode SNESFASGalerkinDefaultFunction(SNES snes, Vec X, Vec F, void * ctx)
 56: {
 57:   /* the Galerkin FAS function evalutation is defined as
 58:    F^l(x^l) = I^l_0F^0(P^0_lx^l)
 59:    */
 60:   SNES           fassnes;
 61:   SNES_FAS       *fas;
 62:   SNES_FAS       *prevfas;
 63:   SNES           prevsnes;
 64:   Vec            b_temp;

 68:   /* prolong to the fine level and evaluate there. */
 69:   fassnes  = (SNES)ctx;
 70:   fas      = (SNES_FAS*)fassnes->data;
 71:   prevsnes = fas->previous;
 72:   prevfas  = (SNES_FAS*)prevsnes->data;
 73:   /* interpolate down the solution */
 74:   MatInterpolate(prevfas->interpolate, X, prevfas->Xg);
 75:   /* the RHS we care about is at the coarsest level */
 76:   b_temp            = prevsnes->vec_rhs;
 77:   prevsnes->vec_rhs = NULL;
 78:   SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);
 79:   prevsnes->vec_rhs = b_temp;
 80:   /* restrict up the function */
 81:   MatRestrict(prevfas->restrct, prevfas->Fg, F);
 82:   return(0);
 83: }