xref: /petsc/src/snes/impls/fas/fasgalerkin.c (revision 1f0e42cf17e8fdc56355134e13a5edcdb6dc1c19)
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   SNES_FAS * fas = (SNES_FAS *)snes->data;
22   PetscFunctionBegin;
23   *flg = fas->galerkin;
24   PetscFunctionReturn(0);
25 }
26 
27 #undef __FUNCT__
28 #define __FUNCT__ "SNESFASSetGalerkin"
29 /*@
30    SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem
31 
32    Input Parameter:
33 .  snes - the nonlinear solver context
34 .  flg - the status of the galerkin problem
35 
36    Level: advanced
37 
38 .keywords: FAS, galerkin
39 
40 .seealso: SNESFASSetLevels(), SNESFASGetGalerkin()
41 @*/
42 PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg) {
43   SNES_FAS * fas = (SNES_FAS *)snes->data;
44   PetscErrorCode ierr;
45   PetscFunctionBegin;
46   fas->galerkin = flg;
47   if (fas->next) {ierr = SNESFASSetGalerkin(fas->next, flg);CHKERRQ(ierr);}
48   PetscFunctionReturn(0);
49 }
50 
51 #undef __FUNCT__
52 #define __FUNCT__ "SNESFASGalerkinDefaultFunction"
53 /*
54 SNESFASGalerkinDefaultFunction
55 
56  */
57 PetscErrorCode SNESFASGalerkinDefaultFunction(SNES snes, Vec X, Vec F, void * ctx) {
58   /* the Galerkin FAS function evalutation is defined as
59    F^l(x^l) = I^l_0F^0(P^0_lx^l)
60    */
61   SNES       fassnes;
62   SNES_FAS * fas;
63   SNES_FAS * prevfas;
64   SNES       prevsnes;
65   Vec b_temp;
66   PetscErrorCode ierr;
67   PetscFunctionBegin;
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   ierr = MatInterpolate(prevfas->interpolate, X, prevfas->Xg);CHKERRQ(ierr);
75   /* the RHS we care about is at the coarsest level */
76   b_temp = prevsnes->vec_rhs;
77   prevsnes->vec_rhs = PETSC_NULL;
78   ierr = SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);CHKERRQ(ierr);
79   prevsnes->vec_rhs = b_temp;
80   /* restrict up the function */
81   ierr = MatRestrict(prevfas->restrct, prevfas->Fg, F);CHKERRQ(ierr);
82   PetscFunctionReturn(0);
83 }
84