Date: 2016-07-24T17:09:26+00:00

Actual source code: fasgalerkin.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      1: #include <../src/snes/impls/fas/fasimpls.h> /*I  "petscsnes.h"  I*/

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

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

     11:    Output parameter:
     12: .  flg - the status of the galerkin problem

     14:    Level: advanced

     16: .keywords: FAS, galerkin

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

     25:   *flg = fas->galerkin;
     26:   return(0);
     27: }

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

     34:    Input Parameter:
     35: .  snes - the nonlinear solver context
     36: .  flg - the status of the galerkin problem

     38:    Level: advanced

     40: .keywords: FAS, galerkin

     42: .seealso: SNESFASSetLevels(), SNESFASGetGalerkin()
     43: @*/
     44: PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg)
     45: {
     46:   SNES_FAS       * fas = (SNES_FAS*)snes->data;

     50:   fas->galerkin = flg;
     51:   if (fas->next) {SNESFASSetGalerkin(fas->next, flg);}
     52:   return(0);
     53: }

     57: /*
     58: SNESFASGalerkinDefaultFunction

     60:  */
     61: PetscErrorCode SNESFASGalerkinDefaultFunction(SNES snes, Vec X, Vec F, void * ctx)
     62: {
     63:   /* the Galerkin FAS function evalutation is defined as
     64:    F^l(x^l) = I^l_0F^0(P^0_lx^l)
     65:    */
     66:   SNES           fassnes;
     67:   SNES_FAS       *fas;
     68:   SNES_FAS       *prevfas;
     69:   SNES           prevsnes;
     70:   Vec            b_temp;

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