xref: /petsc/src/snes/impls/fas/fasgalerkin.c (revision 26f7fa13d894e02c8192cf9a0d4955dba2e1288c)
1 #include "../src/snes/impls/fas/fasimpls.h" /*I  "petscsnesfas.h"  I*/
2 
3 #undef __FUNCT__
4 #define __FUNCT__ "SNESFASGetGalerkin"
5 /*@
6    SNESFASGetGalerkin - Gets if the coarse problems are formed by projection to the fine problem
7 
8    Input Parameter:
9 .  snes - the nonlinear solver context
10 
11    Output parameter:
12 .  flg - the status of the galerkin problem
13 
14    Level: advanced
15 
16 .keywords: FAS, galerkin
17 
18 .seealso: SNESFASSetLevels(), SNESFASSetGalerkin()
19 @*/
20 PetscErrorCode SNESFASGetGalerkin(SNES snes, PetscBool *flg)
21 {
22   SNES_FAS * fas = (SNES_FAS *)snes->data;
23   PetscFunctionBegin;
24   *flg = fas->galerkin;
25   PetscFunctionReturn(0);
26 }
27 
28 #undef __FUNCT__
29 #define __FUNCT__ "SNESFASSetGalerkin"
30 /*@
31    SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem
32 
33    Input Parameter:
34 .  snes - the nonlinear solver context
35 .  flg - the status of the galerkin problem
36 
37    Level: advanced
38 
39 .keywords: FAS, galerkin
40 
41 .seealso: SNESFASSetLevels(), SNESFASGetGalerkin()
42 @*/
43 PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg)
44 {
45   SNES_FAS * fas = (SNES_FAS *)snes->data;
46   PetscErrorCode ierr;
47   PetscFunctionBegin;
48   fas->galerkin = flg;
49   if (fas->next) {ierr = SNESFASSetGalerkin(fas->next, flg);CHKERRQ(ierr);}
50   PetscFunctionReturn(0);
51 }
52 
53 #undef __FUNCT__
54 #define __FUNCT__ "SNESFASGalerkinDefaultFunction"
55 /*
56 SNESFASGalerkinDefaultFunction
57 
58  */
59 PetscErrorCode SNESFASGalerkinDefaultFunction(SNES snes, Vec X, Vec F, void * ctx)
60 {
61   /* the Galerkin FAS function evalutation is defined as
62    F^l(x^l) = I^l_0F^0(P^0_lx^l)
63    */
64   SNES           fassnes;
65   SNES_FAS       *fas;
66   SNES_FAS       *prevfas;
67   SNES           prevsnes;
68   Vec            b_temp;
69   PetscErrorCode ierr;
70 
71   PetscFunctionBegin;
72   /* prolong to the fine level and evaluate there. */
73   fassnes = (SNES)ctx;
74   fas     = (SNES_FAS *)fassnes->data;
75   prevsnes = fas->previous;
76   prevfas = (SNES_FAS *)prevsnes->data;
77   /* interpolate down the solution */
78   ierr = MatInterpolate(prevfas->interpolate, X, prevfas->Xg);CHKERRQ(ierr);
79   /* the RHS we care about is at the coarsest level */
80   b_temp = prevsnes->vec_rhs;
81   prevsnes->vec_rhs = PETSC_NULL;
82   ierr = SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);CHKERRQ(ierr);
83   prevsnes->vec_rhs = b_temp;
84   /* restrict up the function */
85   ierr = MatRestrict(prevfas->restrct, prevfas->Fg, F);CHKERRQ(ierr);
86   PetscFunctionReturn(0);
87 }
88