xref: /petsc/src/snes/impls/fas/fasgalerkin.c (revision bebe2cf65d55febe21a5af8db2bd2e168caaa2e7)
1 #include <../src/snes/impls/fas/fasimpls.h> /*I  "petscsnes.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 
24   PetscFunctionBegin;
25   *flg = fas->galerkin;
26   PetscFunctionReturn(0);
27 }
28 
29 #undef __FUNCT__
30 #define __FUNCT__ "SNESFASSetGalerkin"
31 /*@
32    SNESFASSetGalerkin - Sets coarse problems as formed by projection to the fine problem
33 
34    Input Parameter:
35 .  snes - the nonlinear solver context
36 .  flg - the status of the galerkin problem
37 
38    Level: advanced
39 
40 .keywords: FAS, galerkin
41 
42 .seealso: SNESFASSetLevels(), SNESFASGetGalerkin()
43 @*/
44 PetscErrorCode SNESFASSetGalerkin(SNES snes, PetscBool flg)
45 {
46   SNES_FAS       * fas = (SNES_FAS*)snes->data;
47   PetscErrorCode ierr;
48 
49   PetscFunctionBegin;
50   fas->galerkin = flg;
51   if (fas->next) {ierr = SNESFASSetGalerkin(fas->next, flg);CHKERRQ(ierr);}
52   PetscFunctionReturn(0);
53 }
54 
55 #undef __FUNCT__
56 #define __FUNCT__ "SNESFASGalerkinDefaultFunction"
57 /*
58 SNESFASGalerkinDefaultFunction
59 
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;
71   PetscErrorCode ierr;
72 
73   PetscFunctionBegin;
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   ierr = MatInterpolate(prevfas->interpolate, X, prevfas->Xg);CHKERRQ(ierr);
81   /* the RHS we care about is at the coarsest level */
82   b_temp            = prevsnes->vec_rhs;
83   prevsnes->vec_rhs = NULL;
84   ierr              = SNESComputeFunction(prevsnes, prevfas->Xg, prevfas->Fg);CHKERRQ(ierr);
85   prevsnes->vec_rhs = b_temp;
86   /* restrict up the function */
87   ierr = MatRestrict(prevfas->restrct, prevfas->Fg, F);CHKERRQ(ierr);
88   PetscFunctionReturn(0);
89 }
90