Actual source code: fasgalerkin.c

  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:    Not collective but the result would be the same on all MPI ranks

  8:    Input Parameter:
  9: .  snes - the `SNESFAS` nonlinear solver context

 11:    Output parameter:
 12: .  flg - `PETSC_TRUE` if the coarse problem is formed by projection

 14:    Level: advanced

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

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

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

 31:    Collective

 33:    Input Parameters:
 34: +  snes - the `SNESFAS` nonlinear solver context
 35: -  flg - `PETSC_TRUE` to use the projection process

 37:    Level: advanced

 39: .seealso: `SNESFAS`, `SNESFASSetLevels()`, `SNESFASGetGalerkin()`
 40: @*/
 41: PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg)
 42: {
 43:   SNES_FAS *fas;

 46:   fas           = (SNES_FAS *)snes->data;
 47:   fas->galerkin = flg;
 48:   if (fas->next) SNESFASSetGalerkin(fas->next, flg);
 49:   return 0;
 50: }

 52: /*@C
 53:    SNESFASGalerkinFunctionDefault - Computes the Galerkin FAS function

 55:    Collective

 57:    Input Parameters:
 58: +  snes - the `SNESFAS` nonlinear solver context
 59: .  X - input vector
 60: -  ctx - the application context

 62:    Output Parameter:
 63: .  F - output vector

 65:    Note:
 66:    The Galerkin FAS function evaluation is defined as
 67: $  F^l(x^l) = I^l_0 F^0(P^0_l x^l)

 69:    Level: developer

 71: .seealso: `SNESFAS`, `SNESFASGetGalerkin()`, `SNESFASSetGalerkin()`
 72: @*/
 73: PetscErrorCode SNESFASGalerkinFunctionDefault(SNES snes, Vec X, Vec F, void *ctx)
 74: {
 75:   SNES      fassnes;
 76:   SNES_FAS *fas;
 77:   SNES_FAS *prevfas;
 78:   SNES      prevsnes;
 79:   Vec       b_temp;

 81:   /* prolong to the fine level and evaluate there. */
 82:   fassnes  = (SNES)ctx;
 83:   fas      = (SNES_FAS *)fassnes->data;
 84:   prevsnes = fas->previous;
 85:   prevfas  = (SNES_FAS *)prevsnes->data;
 86:   /* interpolate down the solution */
 87:   MatInterpolate(prevfas->interpolate, X, prevfas->Xg);
 88:   /* the RHS we care about is at the coarsest level */
 89:   b_temp            = prevsnes->vec_rhs;
 90:   prevsnes->vec_rhs = NULL;
 91:   SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);
 92:   prevsnes->vec_rhs = b_temp;
 93:   /* restrict up the function */
 94:   MatRestrict(prevfas->restrct, prevfas->Fg, F);
 95:   return 0;
 96: }