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