xref: /petsc/src/snes/tutorials/ex19.c (revision dfd57a172ac9fa6c7b5fe6de6ab5df85cefc2996) !
1c4762a1bSJed Brown 
2c4762a1bSJed Brown static char help[] = "Nonlinear driven cavity with multigrid in 2d.\n \
3c4762a1bSJed Brown   \n\
4c4762a1bSJed Brown The 2D driven cavity problem is solved in a velocity-vorticity formulation.\n\
5c4762a1bSJed Brown The flow can be driven with the lid or with bouyancy or both:\n\
6c4762a1bSJed Brown   -lidvelocity &ltlid&gt, where &ltlid&gt = dimensionless velocity of lid\n\
7c4762a1bSJed Brown   -grashof &ltgr&gt, where &ltgr&gt = dimensionless temperature gradent\n\
8c4762a1bSJed Brown   -prandtl &ltpr&gt, where &ltpr&gt = dimensionless thermal/momentum diffusity ratio\n\
9c4762a1bSJed Brown  -contours : draw contour plots of solution\n\n";
10c4762a1bSJed Brown /* in HTML, '&lt' = '<' and '&gt' = '>' */
11c4762a1bSJed Brown 
12c4762a1bSJed Brown /*
13c4762a1bSJed Brown       See src/ksp/ksp/tutorials/ex45.c
14c4762a1bSJed Brown */
15c4762a1bSJed Brown 
16c4762a1bSJed Brown /*T
17c4762a1bSJed Brown    Concepts: SNES^solving a system of nonlinear equations (parallel multicomponent example);
18c4762a1bSJed Brown    Concepts: DMDA^using distributed arrays;
19c4762a1bSJed Brown    Concepts: multicomponent
20c4762a1bSJed Brown    Processors: n
21c4762a1bSJed Brown T*/
22c4762a1bSJed Brown 
23c4762a1bSJed Brown /*F-----------------------------------------------------------------------
24c4762a1bSJed Brown 
25c4762a1bSJed Brown     We thank David E. Keyes for contributing the driven cavity discretization within this example code.
26c4762a1bSJed Brown 
27c4762a1bSJed Brown     This problem is modeled by the partial differential equation system
28c4762a1bSJed Brown 
29c4762a1bSJed Brown \begin{eqnarray}
30c4762a1bSJed Brown         - \triangle U - \nabla_y \Omega & = & 0  \\
31c4762a1bSJed Brown         - \triangle V + \nabla_x\Omega & = & 0  \\
32c4762a1bSJed Brown         - \triangle \Omega + \nabla \cdot ([U*\Omega,V*\Omega]) - GR* \nabla_x T & = & 0  \\
33c4762a1bSJed Brown         - \triangle T + PR* \nabla \cdot ([U*T,V*T]) & = & 0
34c4762a1bSJed Brown \end{eqnarray}
35c4762a1bSJed Brown 
36c4762a1bSJed Brown     in the unit square, which is uniformly discretized in each of x and y in this simple encoding.
37c4762a1bSJed Brown 
38c4762a1bSJed Brown     No-slip, rigid-wall Dirichlet conditions are used for $ [U,V]$.
39c4762a1bSJed Brown     Dirichlet conditions are used for Omega, based on the definition of
40c4762a1bSJed Brown     vorticity: $ \Omega = - \nabla_y U + \nabla_x V$, where along each
41c4762a1bSJed Brown     constant coordinate boundary, the tangential derivative is zero.
42c4762a1bSJed Brown     Dirichlet conditions are used for T on the left and right walls,
43c4762a1bSJed Brown     and insulation homogeneous Neumann conditions are used for T on
44c4762a1bSJed Brown     the top and bottom walls.
45c4762a1bSJed Brown 
46c4762a1bSJed Brown     A finite difference approximation with the usual 5-point stencil
47c4762a1bSJed Brown     is used to discretize the boundary value problem to obtain a
48c4762a1bSJed Brown     nonlinear system of equations.  Upwinding is used for the divergence
49c4762a1bSJed Brown     (convective) terms and central for the gradient (source) terms.
50c4762a1bSJed Brown 
51c4762a1bSJed Brown     The Jacobian can be either
52c4762a1bSJed Brown       * formed via finite differencing using coloring (the default), or
53c4762a1bSJed Brown       * applied matrix-free via the option -snes_mf
54c4762a1bSJed Brown         (for larger grid problems this variant may not converge
55c4762a1bSJed Brown         without a preconditioner due to ill-conditioning).
56c4762a1bSJed Brown 
57c4762a1bSJed Brown   ------------------------------------------------------------------------F*/
58c4762a1bSJed Brown 
59c4762a1bSJed Brown /*
60c4762a1bSJed Brown    Include "petscdmda.h" so that we can use distributed arrays (DMDAs).
61c4762a1bSJed Brown    Include "petscsnes.h" so that we can use SNES solvers.  Note that this
62c4762a1bSJed Brown    file automatically includes:
63c4762a1bSJed Brown      petscsys.h       - base PETSc routines   petscvec.h - vectors
64c4762a1bSJed Brown      petscmat.h - matrices
65c4762a1bSJed Brown      petscis.h     - index sets            petscksp.h - Krylov subspace methods
66c4762a1bSJed Brown      petscviewer.h - viewers               petscpc.h  - preconditioners
67c4762a1bSJed Brown      petscksp.h   - linear solvers
68c4762a1bSJed Brown */
69c4762a1bSJed Brown #if defined(PETSC_APPLE_FRAMEWORK)
70c4762a1bSJed Brown #import <PETSc/petscsnes.h>
71c4762a1bSJed Brown #import <PETSc/petscdmda.h>
72c4762a1bSJed Brown #else
73c4762a1bSJed Brown #include <petscsnes.h>
74c4762a1bSJed Brown #include <petscdm.h>
75c4762a1bSJed Brown #include <petscdmda.h>
76c4762a1bSJed Brown #endif
77c4762a1bSJed Brown 
78c4762a1bSJed Brown /*
79c4762a1bSJed Brown    User-defined routines and data structures
80c4762a1bSJed Brown */
81c4762a1bSJed Brown typedef struct {
82c4762a1bSJed Brown   PetscScalar u,v,omega,temp;
83c4762a1bSJed Brown } Field;
84c4762a1bSJed Brown 
85c4762a1bSJed Brown PetscErrorCode FormFunctionLocal(DMDALocalInfo*,Field**,Field**,void*);
86c4762a1bSJed Brown 
87c4762a1bSJed Brown typedef struct {
88c4762a1bSJed Brown   PetscReal   lidvelocity,prandtl,grashof;  /* physical parameters */
89c4762a1bSJed Brown   PetscBool   draw_contours;                /* flag - 1 indicates drawing contours */
90c4762a1bSJed Brown } AppCtx;
91c4762a1bSJed Brown 
92c4762a1bSJed Brown extern PetscErrorCode FormInitialGuess(AppCtx*,DM,Vec);
93c4762a1bSJed Brown extern PetscErrorCode NonlinearGS(SNES,Vec,Vec,void*);
94c4762a1bSJed Brown 
95c4762a1bSJed Brown int main(int argc,char **argv)
96c4762a1bSJed Brown {
97c4762a1bSJed Brown   AppCtx         user;                /* user-defined work context */
98c4762a1bSJed Brown   PetscInt       mx,my,its;
99c4762a1bSJed Brown   PetscErrorCode ierr;
100c4762a1bSJed Brown   MPI_Comm       comm;
101c4762a1bSJed Brown   SNES           snes;
102c4762a1bSJed Brown   DM             da;
103c4762a1bSJed Brown   Vec            x;
104c4762a1bSJed Brown 
105c4762a1bSJed Brown   ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
106c4762a1bSJed Brown 
107c4762a1bSJed Brown   PetscFunctionBeginUser;
108c4762a1bSJed Brown   comm = PETSC_COMM_WORLD;
109c4762a1bSJed Brown   ierr = SNESCreate(comm,&snes);CHKERRQ(ierr);
110c4762a1bSJed Brown 
111c4762a1bSJed Brown   /*
112c4762a1bSJed Brown       Create distributed array object to manage parallel grid and vectors
113c4762a1bSJed Brown       for principal unknowns (x) and governing residuals (f)
114c4762a1bSJed Brown   */
115c4762a1bSJed Brown   ierr = DMDACreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,4,4,PETSC_DECIDE,PETSC_DECIDE,4,1,0,0,&da);CHKERRQ(ierr);
116c4762a1bSJed Brown   ierr = DMSetFromOptions(da);CHKERRQ(ierr);
117c4762a1bSJed Brown   ierr = DMSetUp(da);CHKERRQ(ierr);
118c4762a1bSJed Brown   ierr = SNESSetDM(snes,(DM)da);CHKERRQ(ierr);
119c4762a1bSJed Brown   ierr = SNESSetNGS(snes, NonlinearGS, (void*)&user);CHKERRQ(ierr);
120c4762a1bSJed Brown 
121c4762a1bSJed Brown   ierr = DMDAGetInfo(da,0,&mx,&my,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);CHKERRQ(ierr);
122c4762a1bSJed Brown   /*
123c4762a1bSJed Brown      Problem parameters (velocity of lid, prandtl, and grashof numbers)
124c4762a1bSJed Brown   */
125c4762a1bSJed Brown   user.lidvelocity = 1.0/(mx*my);
126c4762a1bSJed Brown   user.prandtl     = 1.0;
127c4762a1bSJed Brown   user.grashof     = 1.0;
128c4762a1bSJed Brown 
129c4762a1bSJed Brown   ierr = PetscOptionsGetReal(NULL,NULL,"-lidvelocity",&user.lidvelocity,NULL);CHKERRQ(ierr);
130c4762a1bSJed Brown   ierr = PetscOptionsGetReal(NULL,NULL,"-prandtl",&user.prandtl,NULL);CHKERRQ(ierr);
131c4762a1bSJed Brown   ierr = PetscOptionsGetReal(NULL,NULL,"-grashof",&user.grashof,NULL);CHKERRQ(ierr);
132c4762a1bSJed Brown   ierr = PetscOptionsHasName(NULL,NULL,"-contours",&user.draw_contours);CHKERRQ(ierr);
133c4762a1bSJed Brown 
134c4762a1bSJed Brown   ierr = DMDASetFieldName(da,0,"x_velocity");CHKERRQ(ierr);
135c4762a1bSJed Brown   ierr = DMDASetFieldName(da,1,"y_velocity");CHKERRQ(ierr);
136c4762a1bSJed Brown   ierr = DMDASetFieldName(da,2,"Omega");CHKERRQ(ierr);
137c4762a1bSJed Brown   ierr = DMDASetFieldName(da,3,"temperature");CHKERRQ(ierr);
138c4762a1bSJed Brown 
139c4762a1bSJed Brown   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140c4762a1bSJed Brown      Create user context, set problem data, create vector data structures.
141c4762a1bSJed Brown      Also, compute the initial guess.
142c4762a1bSJed Brown      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
143c4762a1bSJed Brown 
144c4762a1bSJed Brown   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145c4762a1bSJed Brown      Create nonlinear solver context
146c4762a1bSJed Brown 
147c4762a1bSJed Brown      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
148c4762a1bSJed Brown   ierr = DMSetApplicationContext(da,&user);CHKERRQ(ierr);
149c4762a1bSJed Brown   ierr = DMDASNESSetFunctionLocal(da,INSERT_VALUES,(PetscErrorCode (*)(DMDALocalInfo*,void*,void*,void*))FormFunctionLocal,&user);CHKERRQ(ierr);
150c4762a1bSJed Brown   ierr = SNESSetFromOptions(snes);CHKERRQ(ierr);
151c4762a1bSJed Brown   ierr = PetscPrintf(comm,"lid velocity = %g, prandtl # = %g, grashof # = %g\n",(double)user.lidvelocity,(double)user.prandtl,(double)user.grashof);CHKERRQ(ierr);
152c4762a1bSJed Brown 
153c4762a1bSJed Brown   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154c4762a1bSJed Brown      Solve the nonlinear system
155c4762a1bSJed Brown      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
156c4762a1bSJed Brown   ierr = DMCreateGlobalVector(da,&x);CHKERRQ(ierr);
157c4762a1bSJed Brown   ierr = FormInitialGuess(&user,da,x);CHKERRQ(ierr);
158c4762a1bSJed Brown 
159c4762a1bSJed Brown   ierr = SNESSolve(snes,NULL,x);CHKERRQ(ierr);
160c4762a1bSJed Brown 
161c4762a1bSJed Brown   ierr = SNESGetIterationNumber(snes,&its);CHKERRQ(ierr);
162c4762a1bSJed Brown   ierr = PetscPrintf(comm,"Number of SNES iterations = %D\n", its);CHKERRQ(ierr);
163c4762a1bSJed Brown 
164c4762a1bSJed Brown   /*
165c4762a1bSJed Brown      Visualize solution
166c4762a1bSJed Brown   */
167c4762a1bSJed Brown   if (user.draw_contours) {
168c4762a1bSJed Brown     ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
169c4762a1bSJed Brown   }
170c4762a1bSJed Brown 
171c4762a1bSJed Brown   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172c4762a1bSJed Brown      Free work space.  All PETSc objects should be destroyed when they
173c4762a1bSJed Brown      are no longer needed.
174c4762a1bSJed Brown      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
175c4762a1bSJed Brown   ierr = VecDestroy(&x);CHKERRQ(ierr);
176c4762a1bSJed Brown   ierr = DMDestroy(&da);CHKERRQ(ierr);
177c4762a1bSJed Brown   ierr = SNESDestroy(&snes);CHKERRQ(ierr);
178c4762a1bSJed Brown   ierr = PetscFinalize();
179c4762a1bSJed Brown   return ierr;
180c4762a1bSJed Brown }
181c4762a1bSJed Brown 
182c4762a1bSJed Brown /* ------------------------------------------------------------------- */
183c4762a1bSJed Brown 
184c4762a1bSJed Brown /*
185c4762a1bSJed Brown    FormInitialGuess - Forms initial approximation.
186c4762a1bSJed Brown 
187c4762a1bSJed Brown    Input Parameters:
188c4762a1bSJed Brown    user - user-defined application context
189c4762a1bSJed Brown    X - vector
190c4762a1bSJed Brown 
191c4762a1bSJed Brown    Output Parameter:
192c4762a1bSJed Brown    X - vector
193c4762a1bSJed Brown */
194c4762a1bSJed Brown PetscErrorCode FormInitialGuess(AppCtx *user,DM da,Vec X)
195c4762a1bSJed Brown {
196c4762a1bSJed Brown   PetscInt       i,j,mx,xs,ys,xm,ym;
197c4762a1bSJed Brown   PetscErrorCode ierr;
198c4762a1bSJed Brown   PetscReal      grashof,dx;
199c4762a1bSJed Brown   Field          **x;
200c4762a1bSJed Brown 
201c4762a1bSJed Brown   PetscFunctionBeginUser;
202c4762a1bSJed Brown   grashof = user->grashof;
203c4762a1bSJed Brown 
204c4762a1bSJed Brown   ierr = DMDAGetInfo(da,0,&mx,0,0,0,0,0,0,0,0,0,0,0);CHKERRQ(ierr);
205c4762a1bSJed Brown   dx   = 1.0/(mx-1);
206c4762a1bSJed Brown 
207c4762a1bSJed Brown   /*
208c4762a1bSJed Brown      Get local grid boundaries (for 2-dimensional DMDA):
209c4762a1bSJed Brown        xs, ys   - starting grid indices (no ghost points)
210c4762a1bSJed Brown        xm, ym   - widths of local grid (no ghost points)
211c4762a1bSJed Brown   */
212c4762a1bSJed Brown   ierr = DMDAGetCorners(da,&xs,&ys,NULL,&xm,&ym,NULL);CHKERRQ(ierr);
213c4762a1bSJed Brown 
214c4762a1bSJed Brown   /*
215c4762a1bSJed Brown      Get a pointer to vector data.
216c4762a1bSJed Brown        - For default PETSc vectors, VecGetArray() returns a pointer to
217c4762a1bSJed Brown          the data array.  Otherwise, the routine is implementation dependent.
218c4762a1bSJed Brown        - You MUST call VecRestoreArray() when you no longer need access to
219c4762a1bSJed Brown          the array.
220c4762a1bSJed Brown   */
221c4762a1bSJed Brown   ierr = DMDAVecGetArrayWrite(da,X,&x);CHKERRQ(ierr);
222c4762a1bSJed Brown 
223c4762a1bSJed Brown   /*
224c4762a1bSJed Brown      Compute initial guess over the locally owned part of the grid
225c4762a1bSJed Brown      Initial condition is motionless fluid and equilibrium temperature
226c4762a1bSJed Brown   */
227c4762a1bSJed Brown   for (j=ys; j<ys+ym; j++) {
228c4762a1bSJed Brown     for (i=xs; i<xs+xm; i++) {
229c4762a1bSJed Brown       x[j][i].u     = 0.0;
230c4762a1bSJed Brown       x[j][i].v     = 0.0;
231c4762a1bSJed Brown       x[j][i].omega = 0.0;
232c4762a1bSJed Brown       x[j][i].temp  = (grashof>0)*i*dx;
233c4762a1bSJed Brown     }
234c4762a1bSJed Brown   }
235c4762a1bSJed Brown 
236c4762a1bSJed Brown   /*
237c4762a1bSJed Brown      Restore vector
238c4762a1bSJed Brown   */
239c4762a1bSJed Brown   ierr = DMDAVecRestoreArrayWrite(da,X,&x);CHKERRQ(ierr);
240c4762a1bSJed Brown   PetscFunctionReturn(0);
241c4762a1bSJed Brown }
242c4762a1bSJed Brown 
243c4762a1bSJed Brown PetscErrorCode FormFunctionLocal(DMDALocalInfo *info,Field **x,Field **f,void *ptr)
244c4762a1bSJed Brown {
245c4762a1bSJed Brown   AppCtx         *user = (AppCtx*)ptr;
246c4762a1bSJed Brown   PetscErrorCode ierr;
247c4762a1bSJed Brown   PetscInt       xints,xinte,yints,yinte,i,j;
248c4762a1bSJed Brown   PetscReal      hx,hy,dhx,dhy,hxdhy,hydhx;
249c4762a1bSJed Brown   PetscReal      grashof,prandtl,lid;
250c4762a1bSJed Brown   PetscScalar    u,uxx,uyy,vx,vy,avx,avy,vxp,vxm,vyp,vym;
251c4762a1bSJed Brown 
252c4762a1bSJed Brown   PetscFunctionBeginUser;
253c4762a1bSJed Brown   grashof = user->grashof;
254c4762a1bSJed Brown   prandtl = user->prandtl;
255c4762a1bSJed Brown   lid     = user->lidvelocity;
256c4762a1bSJed Brown 
257c4762a1bSJed Brown   /*
258c4762a1bSJed Brown      Define mesh intervals ratios for uniform grid.
259c4762a1bSJed Brown 
260c4762a1bSJed Brown      Note: FD formulae below are normalized by multiplying through by
261c4762a1bSJed Brown      local volume element (i.e. hx*hy) to obtain coefficients O(1) in two dimensions.
262c4762a1bSJed Brown 
263c4762a1bSJed Brown   */
264c4762a1bSJed Brown   dhx   = (PetscReal)(info->mx-1);  dhy = (PetscReal)(info->my-1);
265c4762a1bSJed Brown   hx    = 1.0/dhx;                   hy = 1.0/dhy;
266c4762a1bSJed Brown   hxdhy = hx*dhy;                 hydhx = hy*dhx;
267c4762a1bSJed Brown 
268c4762a1bSJed Brown   xints = info->xs; xinte = info->xs+info->xm; yints = info->ys; yinte = info->ys+info->ym;
269c4762a1bSJed Brown 
270c4762a1bSJed Brown   /* Test whether we are on the bottom edge of the global array */
271c4762a1bSJed Brown   if (yints == 0) {
272c4762a1bSJed Brown     j     = 0;
273c4762a1bSJed Brown     yints = yints + 1;
274c4762a1bSJed Brown     /* bottom edge */
275c4762a1bSJed Brown     for (i=info->xs; i<info->xs+info->xm; i++) {
276c4762a1bSJed Brown       f[j][i].u     = x[j][i].u;
277c4762a1bSJed Brown       f[j][i].v     = x[j][i].v;
278c4762a1bSJed Brown       f[j][i].omega = x[j][i].omega + (x[j+1][i].u - x[j][i].u)*dhy;
279c4762a1bSJed Brown       f[j][i].temp  = x[j][i].temp-x[j+1][i].temp;
280c4762a1bSJed Brown     }
281c4762a1bSJed Brown   }
282c4762a1bSJed Brown 
283c4762a1bSJed Brown   /* Test whether we are on the top edge of the global array */
284c4762a1bSJed Brown   if (yinte == info->my) {
285c4762a1bSJed Brown     j     = info->my - 1;
286c4762a1bSJed Brown     yinte = yinte - 1;
287c4762a1bSJed Brown     /* top edge */
288c4762a1bSJed Brown     for (i=info->xs; i<info->xs+info->xm; i++) {
289c4762a1bSJed Brown       f[j][i].u     = x[j][i].u - lid;
290c4762a1bSJed Brown       f[j][i].v     = x[j][i].v;
291c4762a1bSJed Brown       f[j][i].omega = x[j][i].omega + (x[j][i].u - x[j-1][i].u)*dhy;
292c4762a1bSJed Brown       f[j][i].temp  = x[j][i].temp-x[j-1][i].temp;
293c4762a1bSJed Brown     }
294c4762a1bSJed Brown   }
295c4762a1bSJed Brown 
296c4762a1bSJed Brown   /* Test whether we are on the left edge of the global array */
297c4762a1bSJed Brown   if (xints == 0) {
298c4762a1bSJed Brown     i     = 0;
299c4762a1bSJed Brown     xints = xints + 1;
300c4762a1bSJed Brown     /* left edge */
301c4762a1bSJed Brown     for (j=info->ys; j<info->ys+info->ym; j++) {
302c4762a1bSJed Brown       f[j][i].u     = x[j][i].u;
303c4762a1bSJed Brown       f[j][i].v     = x[j][i].v;
304c4762a1bSJed Brown       f[j][i].omega = x[j][i].omega - (x[j][i+1].v - x[j][i].v)*dhx;
305c4762a1bSJed Brown       f[j][i].temp  = x[j][i].temp;
306c4762a1bSJed Brown     }
307c4762a1bSJed Brown   }
308c4762a1bSJed Brown 
309c4762a1bSJed Brown   /* Test whether we are on the right edge of the global array */
310c4762a1bSJed Brown   if (xinte == info->mx) {
311c4762a1bSJed Brown     i     = info->mx - 1;
312c4762a1bSJed Brown     xinte = xinte - 1;
313c4762a1bSJed Brown     /* right edge */
314c4762a1bSJed Brown     for (j=info->ys; j<info->ys+info->ym; j++) {
315c4762a1bSJed Brown       f[j][i].u     = x[j][i].u;
316c4762a1bSJed Brown       f[j][i].v     = x[j][i].v;
317c4762a1bSJed Brown       f[j][i].omega = x[j][i].omega - (x[j][i].v - x[j][i-1].v)*dhx;
318c4762a1bSJed Brown       f[j][i].temp  = x[j][i].temp - (PetscReal)(grashof>0);
319c4762a1bSJed Brown     }
320c4762a1bSJed Brown   }
321c4762a1bSJed Brown 
322c4762a1bSJed Brown   /* Compute over the interior points */
323c4762a1bSJed Brown   for (j=yints; j<yinte; j++) {
324c4762a1bSJed Brown     for (i=xints; i<xinte; i++) {
325c4762a1bSJed Brown 
326c4762a1bSJed Brown       /*
327c4762a1bSJed Brown        convective coefficients for upwinding
328c4762a1bSJed Brown       */
329c4762a1bSJed Brown       vx  = x[j][i].u; avx = PetscAbsScalar(vx);
330c4762a1bSJed Brown       vxp = .5*(vx+avx); vxm = .5*(vx-avx);
331c4762a1bSJed Brown       vy  = x[j][i].v; avy = PetscAbsScalar(vy);
332c4762a1bSJed Brown       vyp = .5*(vy+avy); vym = .5*(vy-avy);
333c4762a1bSJed Brown 
334c4762a1bSJed Brown       /* U velocity */
335c4762a1bSJed Brown       u         = x[j][i].u;
336c4762a1bSJed Brown       uxx       = (2.0*u - x[j][i-1].u - x[j][i+1].u)*hydhx;
337c4762a1bSJed Brown       uyy       = (2.0*u - x[j-1][i].u - x[j+1][i].u)*hxdhy;
338c4762a1bSJed Brown       f[j][i].u = uxx + uyy - .5*(x[j+1][i].omega-x[j-1][i].omega)*hx;
339c4762a1bSJed Brown 
340c4762a1bSJed Brown       /* V velocity */
341c4762a1bSJed Brown       u         = x[j][i].v;
342c4762a1bSJed Brown       uxx       = (2.0*u - x[j][i-1].v - x[j][i+1].v)*hydhx;
343c4762a1bSJed Brown       uyy       = (2.0*u - x[j-1][i].v - x[j+1][i].v)*hxdhy;
344c4762a1bSJed Brown       f[j][i].v = uxx + uyy + .5*(x[j][i+1].omega-x[j][i-1].omega)*hy;
345c4762a1bSJed Brown 
346c4762a1bSJed Brown       /* Omega */
347c4762a1bSJed Brown       u             = x[j][i].omega;
348c4762a1bSJed Brown       uxx           = (2.0*u - x[j][i-1].omega - x[j][i+1].omega)*hydhx;
349c4762a1bSJed Brown       uyy           = (2.0*u - x[j-1][i].omega - x[j+1][i].omega)*hxdhy;
350c4762a1bSJed Brown       f[j][i].omega = uxx + uyy + (vxp*(u - x[j][i-1].omega) + vxm*(x[j][i+1].omega - u))*hy +
351c4762a1bSJed Brown                       (vyp*(u - x[j-1][i].omega) + vym*(x[j+1][i].omega - u))*hx -
352c4762a1bSJed Brown                       .5*grashof*(x[j][i+1].temp - x[j][i-1].temp)*hy;
353c4762a1bSJed Brown 
354c4762a1bSJed Brown       /* Temperature */
355c4762a1bSJed Brown       u            = x[j][i].temp;
356c4762a1bSJed Brown       uxx          = (2.0*u - x[j][i-1].temp - x[j][i+1].temp)*hydhx;
357c4762a1bSJed Brown       uyy          = (2.0*u - x[j-1][i].temp - x[j+1][i].temp)*hxdhy;
358c4762a1bSJed Brown       f[j][i].temp =  uxx + uyy  + prandtl*((vxp*(u - x[j][i-1].temp) + vxm*(x[j][i+1].temp - u))*hy +
359c4762a1bSJed Brown                                             (vyp*(u - x[j-1][i].temp) + vym*(x[j+1][i].temp - u))*hx);
360c4762a1bSJed Brown     }
361c4762a1bSJed Brown   }
362c4762a1bSJed Brown 
363c4762a1bSJed Brown   /*
364c4762a1bSJed Brown      Flop count (multiply-adds are counted as 2 operations)
365c4762a1bSJed Brown   */
366c4762a1bSJed Brown   ierr = PetscLogFlops(84.0*info->ym*info->xm);CHKERRQ(ierr);
367c4762a1bSJed Brown   PetscFunctionReturn(0);
368c4762a1bSJed Brown }
369c4762a1bSJed Brown 
370c4762a1bSJed Brown /*
371c4762a1bSJed Brown     Performs sweeps of point block nonlinear Gauss-Seidel on all the local grid points
372c4762a1bSJed Brown */
373c4762a1bSJed Brown PetscErrorCode NonlinearGS(SNES snes, Vec X, Vec B, void *ctx)
374c4762a1bSJed Brown {
375c4762a1bSJed Brown   DMDALocalInfo  info;
376c4762a1bSJed Brown   Field          **x,**b;
377c4762a1bSJed Brown   PetscErrorCode ierr;
378c4762a1bSJed Brown   Vec            localX, localB;
379c4762a1bSJed Brown   DM             da;
380c4762a1bSJed Brown   PetscInt       xints,xinte,yints,yinte,i,j,k,l;
381c4762a1bSJed Brown   PetscInt       max_its,tot_its;
382c4762a1bSJed Brown   PetscInt       sweeps;
383c4762a1bSJed Brown   PetscReal      rtol,atol,stol;
384c4762a1bSJed Brown   PetscReal      hx,hy,dhx,dhy,hxdhy,hydhx;
385c4762a1bSJed Brown   PetscReal      grashof,prandtl,lid;
386c4762a1bSJed Brown   PetscScalar    u,uxx,uyy,vx,vy,avx,avy,vxp,vxm,vyp,vym;
387c4762a1bSJed Brown   PetscScalar    fu, fv, fomega, ftemp;
388c4762a1bSJed Brown   PetscScalar    dfudu;
389c4762a1bSJed Brown   PetscScalar    dfvdv;
390c4762a1bSJed Brown   PetscScalar    dfodu, dfodv, dfodo;
391c4762a1bSJed Brown   PetscScalar    dftdu, dftdv, dftdt;
392c4762a1bSJed Brown   PetscScalar    yu=0, yv=0, yo=0, yt=0;
393c4762a1bSJed Brown   PetscScalar    bjiu, bjiv, bjiomega, bjitemp;
394c4762a1bSJed Brown   PetscBool      ptconverged;
395c4762a1bSJed Brown   PetscReal      pfnorm,pfnorm0,pynorm,pxnorm;
396c4762a1bSJed Brown   AppCtx         *user = (AppCtx*)ctx;
397c4762a1bSJed Brown 
398c4762a1bSJed Brown   PetscFunctionBeginUser;
399c4762a1bSJed Brown   grashof = user->grashof;
400c4762a1bSJed Brown   prandtl = user->prandtl;
401c4762a1bSJed Brown   lid     = user->lidvelocity;
402c4762a1bSJed Brown   tot_its = 0;
403c4762a1bSJed Brown   ierr    = SNESNGSGetTolerances(snes,&rtol,&atol,&stol,&max_its);CHKERRQ(ierr);
404c4762a1bSJed Brown   ierr    = SNESNGSGetSweeps(snes,&sweeps);CHKERRQ(ierr);
405c4762a1bSJed Brown   ierr    = SNESGetDM(snes,(DM*)&da);CHKERRQ(ierr);
406c4762a1bSJed Brown   ierr    = DMGetLocalVector(da,&localX);CHKERRQ(ierr);
407c4762a1bSJed Brown   if (B) {
408c4762a1bSJed Brown     ierr = DMGetLocalVector(da,&localB);CHKERRQ(ierr);
409c4762a1bSJed Brown   }
410c4762a1bSJed Brown   /*
411c4762a1bSJed Brown      Scatter ghost points to local vector, using the 2-step process
412c4762a1bSJed Brown         DMGlobalToLocalBegin(), DMGlobalToLocalEnd().
413c4762a1bSJed Brown   */
414c4762a1bSJed Brown   ierr = DMGlobalToLocalBegin(da,X,INSERT_VALUES,localX);CHKERRQ(ierr);
415c4762a1bSJed Brown   ierr = DMGlobalToLocalEnd(da,X,INSERT_VALUES,localX);CHKERRQ(ierr);
416c4762a1bSJed Brown   if (B) {
417c4762a1bSJed Brown     ierr = DMGlobalToLocalBegin(da,B,INSERT_VALUES,localB);CHKERRQ(ierr);
418c4762a1bSJed Brown     ierr = DMGlobalToLocalEnd(da,B,INSERT_VALUES,localB);CHKERRQ(ierr);
419c4762a1bSJed Brown   }
420c4762a1bSJed Brown   ierr = DMDAGetLocalInfo(da,&info);CHKERRQ(ierr);
421c4762a1bSJed Brown   ierr = DMDAVecGetArrayWrite(da,localX,&x);CHKERRQ(ierr);
422c4762a1bSJed Brown   if (B) {
423c4762a1bSJed Brown     ierr = DMDAVecGetArrayRead(da,localB,&b);CHKERRQ(ierr);
424c4762a1bSJed Brown   }
425c4762a1bSJed Brown   /* looks like a combination of the formfunction / formjacobian routines */
426c4762a1bSJed Brown   dhx   = (PetscReal)(info.mx-1);dhy   = (PetscReal)(info.my-1);
427c4762a1bSJed Brown   hx    = 1.0/dhx;               hy    = 1.0/dhy;
428c4762a1bSJed Brown   hxdhy = hx*dhy;                hydhx = hy*dhx;
429c4762a1bSJed Brown 
430c4762a1bSJed Brown   xints = info.xs; xinte = info.xs+info.xm; yints = info.ys; yinte = info.ys+info.ym;
431c4762a1bSJed Brown 
432c4762a1bSJed Brown   /* Set the boundary conditions on the momentum equations */
433c4762a1bSJed Brown   /* Test whether we are on the bottom edge of the global array */
434c4762a1bSJed Brown   if (yints == 0) {
435c4762a1bSJed Brown     j     = 0;
436c4762a1bSJed Brown     /* bottom edge */
437c4762a1bSJed Brown     for (i=info.xs; i<info.xs+info.xm; i++) {
438c4762a1bSJed Brown 
439c4762a1bSJed Brown       if (B) {
440c4762a1bSJed Brown         bjiu = b[j][i].u;
441c4762a1bSJed Brown         bjiv = b[j][i].v;
442c4762a1bSJed Brown       } else {
443c4762a1bSJed Brown         bjiu = 0.0;
444c4762a1bSJed Brown         bjiv = 0.0;
445c4762a1bSJed Brown       }
446c4762a1bSJed Brown       x[j][i].u = 0.0 + bjiu;
447c4762a1bSJed Brown       x[j][i].v = 0.0 + bjiv;
448c4762a1bSJed Brown     }
449c4762a1bSJed Brown   }
450c4762a1bSJed Brown 
451c4762a1bSJed Brown   /* Test whether we are on the top edge of the global array */
452c4762a1bSJed Brown   if (yinte == info.my) {
453c4762a1bSJed Brown     j     = info.my - 1;
454c4762a1bSJed Brown     /* top edge */
455c4762a1bSJed Brown     for (i=info.xs; i<info.xs+info.xm; i++) {
456c4762a1bSJed Brown       if (B) {
457c4762a1bSJed Brown         bjiu = b[j][i].u;
458c4762a1bSJed Brown         bjiv = b[j][i].v;
459c4762a1bSJed Brown       } else {
460c4762a1bSJed Brown         bjiu = 0.0;
461c4762a1bSJed Brown         bjiv = 0.0;
462c4762a1bSJed Brown       }
463c4762a1bSJed Brown       x[j][i].u = lid + bjiu;
464c4762a1bSJed Brown       x[j][i].v = bjiv;
465c4762a1bSJed Brown     }
466c4762a1bSJed Brown   }
467c4762a1bSJed Brown 
468c4762a1bSJed Brown   /* Test whether we are on the left edge of the global array */
469c4762a1bSJed Brown   if (xints == 0) {
470c4762a1bSJed Brown     i     = 0;
471c4762a1bSJed Brown     /* left edge */
472c4762a1bSJed Brown     for (j=info.ys; j<info.ys+info.ym; j++) {
473c4762a1bSJed Brown       if (B) {
474c4762a1bSJed Brown         bjiu = b[j][i].u;
475c4762a1bSJed Brown         bjiv = b[j][i].v;
476c4762a1bSJed Brown       } else {
477c4762a1bSJed Brown         bjiu = 0.0;
478c4762a1bSJed Brown         bjiv = 0.0;
479c4762a1bSJed Brown       }
480c4762a1bSJed Brown       x[j][i].u = 0.0 + bjiu;
481c4762a1bSJed Brown       x[j][i].v = 0.0 + bjiv;
482c4762a1bSJed Brown     }
483c4762a1bSJed Brown   }
484c4762a1bSJed Brown 
485c4762a1bSJed Brown   /* Test whether we are on the right edge of the global array */
486c4762a1bSJed Brown   if (xinte == info.mx) {
487c4762a1bSJed Brown     i     = info.mx - 1;
488c4762a1bSJed Brown     /* right edge */
489c4762a1bSJed Brown     for (j=info.ys; j<info.ys+info.ym; j++) {
490c4762a1bSJed Brown       if (B) {
491c4762a1bSJed Brown         bjiu = b[j][i].u;
492c4762a1bSJed Brown         bjiv = b[j][i].v;
493c4762a1bSJed Brown       } else {
494c4762a1bSJed Brown         bjiu = 0.0;
495c4762a1bSJed Brown         bjiv = 0.0;
496c4762a1bSJed Brown       }
497c4762a1bSJed Brown       x[j][i].u = 0.0 + bjiu;
498c4762a1bSJed Brown       x[j][i].v = 0.0 + bjiv;
499c4762a1bSJed Brown     }
500c4762a1bSJed Brown   }
501c4762a1bSJed Brown 
502c4762a1bSJed Brown   for (k=0; k < sweeps; k++) {
503c4762a1bSJed Brown     for (j=info.ys; j<info.ys + info.ym; j++) {
504c4762a1bSJed Brown       for (i=info.xs; i<info.xs + info.xm; i++) {
505c4762a1bSJed Brown         ptconverged = PETSC_FALSE;
506c4762a1bSJed Brown         pfnorm0     = 0.0;
507c4762a1bSJed Brown         fu          = 0.0;
508c4762a1bSJed Brown         fv          = 0.0;
509c4762a1bSJed Brown         fomega      = 0.0;
510c4762a1bSJed Brown         ftemp       = 0.0;
511c4762a1bSJed Brown         /*  Run Newton's method on a single grid point */
512c4762a1bSJed Brown         for (l = 0; l < max_its && !ptconverged; l++) {
513c4762a1bSJed Brown           if (B) {
514c4762a1bSJed Brown             bjiu     = b[j][i].u;
515c4762a1bSJed Brown             bjiv     = b[j][i].v;
516c4762a1bSJed Brown             bjiomega = b[j][i].omega;
517c4762a1bSJed Brown             bjitemp  = b[j][i].temp;
518c4762a1bSJed Brown           } else {
519c4762a1bSJed Brown             bjiu     = 0.0;
520c4762a1bSJed Brown             bjiv     = 0.0;
521c4762a1bSJed Brown             bjiomega = 0.0;
522c4762a1bSJed Brown             bjitemp  = 0.0;
523c4762a1bSJed Brown           }
524c4762a1bSJed Brown 
525c4762a1bSJed Brown           if (i != 0 && i != info.mx - 1 && j != 0 && j != info.my-1) {
526c4762a1bSJed Brown             /* U velocity */
527c4762a1bSJed Brown             u     = x[j][i].u;
528c4762a1bSJed Brown             uxx   = (2.0*u - x[j][i-1].u - x[j][i+1].u)*hydhx;
529c4762a1bSJed Brown             uyy   = (2.0*u - x[j-1][i].u - x[j+1][i].u)*hxdhy;
530c4762a1bSJed Brown             fu    = uxx + uyy - .5*(x[j+1][i].omega-x[j-1][i].omega)*hx - bjiu;
531c4762a1bSJed Brown             dfudu = 2.0*(hydhx + hxdhy);
532c4762a1bSJed Brown             /* V velocity */
533c4762a1bSJed Brown             u     = x[j][i].v;
534c4762a1bSJed Brown             uxx   = (2.0*u - x[j][i-1].v - x[j][i+1].v)*hydhx;
535c4762a1bSJed Brown             uyy   = (2.0*u - x[j-1][i].v - x[j+1][i].v)*hxdhy;
536c4762a1bSJed Brown             fv    = uxx + uyy + .5*(x[j][i+1].omega-x[j][i-1].omega)*hy - bjiv;
537c4762a1bSJed Brown             dfvdv = 2.0*(hydhx + hxdhy);
538c4762a1bSJed Brown             /*
539c4762a1bSJed Brown              convective coefficients for upwinding
540c4762a1bSJed Brown              */
541c4762a1bSJed Brown             vx  = x[j][i].u; avx = PetscAbsScalar(vx);
542c4762a1bSJed Brown             vxp = .5*(vx+avx); vxm = .5*(vx-avx);
543c4762a1bSJed Brown             vy  = x[j][i].v; avy = PetscAbsScalar(vy);
544c4762a1bSJed Brown             vyp = .5*(vy+avy); vym = .5*(vy-avy);
545c4762a1bSJed Brown             /* Omega */
546c4762a1bSJed Brown             u      = x[j][i].omega;
547c4762a1bSJed Brown             uxx    = (2.0*u - x[j][i-1].omega - x[j][i+1].omega)*hydhx;
548c4762a1bSJed Brown             uyy    = (2.0*u - x[j-1][i].omega - x[j+1][i].omega)*hxdhy;
549c4762a1bSJed Brown             fomega = uxx + uyy +  (vxp*(u - x[j][i-1].omega) + vxm*(x[j][i+1].omega - u))*hy +
550c4762a1bSJed Brown                      (vyp*(u - x[j-1][i].omega) + vym*(x[j+1][i].omega - u))*hx -
551c4762a1bSJed Brown                      .5*grashof*(x[j][i+1].temp - x[j][i-1].temp)*hy - bjiomega;
552c4762a1bSJed Brown             /* convective coefficient derivatives */
553c4762a1bSJed Brown             dfodo = 2.0*(hydhx + hxdhy) + ((vxp - vxm)*hy + (vyp - vym)*hx);
554c4762a1bSJed Brown             if (PetscRealPart(vx) > 0.0) dfodu = (u - x[j][i-1].omega)*hy;
555c4762a1bSJed Brown             else dfodu = (x[j][i+1].omega - u)*hy;
556c4762a1bSJed Brown 
557c4762a1bSJed Brown             if (PetscRealPart(vy) > 0.0) dfodv = (u - x[j-1][i].omega)*hx;
558c4762a1bSJed Brown             else dfodv = (x[j+1][i].omega - u)*hx;
559c4762a1bSJed Brown 
560c4762a1bSJed Brown             /* Temperature */
561c4762a1bSJed Brown             u     = x[j][i].temp;
562c4762a1bSJed Brown             uxx   = (2.0*u - x[j][i-1].temp - x[j][i+1].temp)*hydhx;
563c4762a1bSJed Brown             uyy   = (2.0*u - x[j-1][i].temp - x[j+1][i].temp)*hxdhy;
564c4762a1bSJed Brown             ftemp =  uxx + uyy  + prandtl*((vxp*(u - x[j][i-1].temp) + vxm*(x[j][i+1].temp - u))*hy + (vyp*(u - x[j-1][i].temp) + vym*(x[j+1][i].temp - u))*hx) - bjitemp;
565c4762a1bSJed Brown             dftdt = 2.0*(hydhx + hxdhy) + prandtl*((vxp - vxm)*hy + (vyp - vym)*hx);
566c4762a1bSJed Brown             if (PetscRealPart(vx) > 0.0) dftdu = prandtl*(u - x[j][i-1].temp)*hy;
567c4762a1bSJed Brown             else dftdu = prandtl*(x[j][i+1].temp - u)*hy;
568c4762a1bSJed Brown 
569c4762a1bSJed Brown             if (PetscRealPart(vy) > 0.0) dftdv = prandtl*(u - x[j-1][i].temp)*hx;
570c4762a1bSJed Brown             else dftdv = prandtl*(x[j+1][i].temp - u)*hx;
571c4762a1bSJed Brown 
572c4762a1bSJed Brown             /* invert the system:
573c4762a1bSJed Brown              [ dfu / du     0        0        0    ][yu] = [fu]
574c4762a1bSJed Brown              [     0    dfv / dv     0        0    ][yv]   [fv]
575c4762a1bSJed Brown              [ dfo / du dfo / dv dfo / do     0    ][yo]   [fo]
576c4762a1bSJed Brown              [ dft / du dft / dv     0    dft / dt ][yt]   [ft]
577c4762a1bSJed Brown              by simple back-substitution
578c4762a1bSJed Brown            */
579c4762a1bSJed Brown             yu = fu / dfudu;
580c4762a1bSJed Brown             yv = fv / dfvdv;
581c4762a1bSJed Brown             yo = (fomega - (dfodu*yu + dfodv*yv)) / dfodo;
582c4762a1bSJed Brown             yt = (ftemp - (dftdu*yu + dftdv*yv)) / dftdt;
583c4762a1bSJed Brown 
584c4762a1bSJed Brown             x[j][i].u     = x[j][i].u - yu;
585c4762a1bSJed Brown             x[j][i].v     = x[j][i].v - yv;
586c4762a1bSJed Brown             x[j][i].temp  = x[j][i].temp - yt;
587c4762a1bSJed Brown             x[j][i].omega = x[j][i].omega - yo;
588c4762a1bSJed Brown           }
589c4762a1bSJed Brown           if (i == 0) {
590c4762a1bSJed Brown             fomega        = x[j][i].omega - (x[j][i+1].v - x[j][i].v)*dhx - bjiomega;
591c4762a1bSJed Brown             ftemp         = x[j][i].temp - bjitemp;
592c4762a1bSJed Brown             yo            = fomega;
593c4762a1bSJed Brown             yt            = ftemp;
594c4762a1bSJed Brown             x[j][i].omega = x[j][i].omega - fomega;
595c4762a1bSJed Brown             x[j][i].temp  = x[j][i].temp - ftemp;
596c4762a1bSJed Brown           }
597c4762a1bSJed Brown           if (i == info.mx - 1) {
598c4762a1bSJed Brown             fomega        = x[j][i].omega - (x[j][i].v - x[j][i-1].v)*dhx - bjiomega;
599c4762a1bSJed Brown             ftemp         = x[j][i].temp - (PetscReal)(grashof>0) - bjitemp;
600c4762a1bSJed Brown             yo            = fomega;
601c4762a1bSJed Brown             yt            = ftemp;
602c4762a1bSJed Brown             x[j][i].omega = x[j][i].omega - fomega;
603c4762a1bSJed Brown             x[j][i].temp  = x[j][i].temp - ftemp;
604c4762a1bSJed Brown           }
605c4762a1bSJed Brown           if (j == 0) {
606c4762a1bSJed Brown             fomega        = x[j][i].omega + (x[j+1][i].u - x[j][i].u)*dhy - bjiomega;
607c4762a1bSJed Brown             ftemp         = x[j][i].temp-x[j+1][i].temp - bjitemp;
608c4762a1bSJed Brown             yo            = fomega;
609c4762a1bSJed Brown             yt            = ftemp;
610c4762a1bSJed Brown             x[j][i].omega = x[j][i].omega - fomega;
611c4762a1bSJed Brown             x[j][i].temp  = x[j][i].temp - ftemp;
612c4762a1bSJed Brown           }
613c4762a1bSJed Brown           if (j == info.my - 1) {
614c4762a1bSJed Brown             fomega        = x[j][i].omega + (x[j][i].u - x[j-1][i].u)*dhy - bjiomega;
615c4762a1bSJed Brown             ftemp         = x[j][i].temp-x[j-1][i].temp - bjitemp;
616c4762a1bSJed Brown             yo            = fomega;
617c4762a1bSJed Brown             yt            = ftemp;
618c4762a1bSJed Brown             x[j][i].omega = x[j][i].omega - fomega;
619c4762a1bSJed Brown             x[j][i].temp  = x[j][i].temp - ftemp;
620c4762a1bSJed Brown           }
621c4762a1bSJed Brown           tot_its++;
622c4762a1bSJed Brown           pfnorm = PetscRealPart(fu*fu + fv*fv + fomega*fomega + ftemp*ftemp);
623c4762a1bSJed Brown           pfnorm = PetscSqrtReal(pfnorm);
624c4762a1bSJed Brown           pynorm = PetscRealPart(yu*yu + yv*yv + yo*yo + yt*yt);
625c4762a1bSJed Brown           pynorm = PetscSqrtReal(pynorm);
626c4762a1bSJed Brown           pxnorm = PetscRealPart(x[j][i].u*x[j][i].u + x[j][i].v*x[j][i].v + x[j][i].omega*x[j][i].omega + x[j][i].temp*x[j][i].temp);
627c4762a1bSJed Brown           pxnorm = PetscSqrtReal(pxnorm);
628c4762a1bSJed Brown           if (l == 0) pfnorm0 = pfnorm;
629c4762a1bSJed Brown           if (rtol*pfnorm0 >pfnorm || atol > pfnorm || pxnorm*stol > pynorm) ptconverged = PETSC_TRUE;
630c4762a1bSJed Brown         }
631c4762a1bSJed Brown       }
632c4762a1bSJed Brown     }
633c4762a1bSJed Brown   }
634c4762a1bSJed Brown   ierr = DMDAVecRestoreArrayWrite(da,localX,&x);CHKERRQ(ierr);
635c4762a1bSJed Brown   if (B) {
636c4762a1bSJed Brown     ierr = DMDAVecRestoreArrayRead(da,localB,&b);CHKERRQ(ierr);
637c4762a1bSJed Brown   }
638c4762a1bSJed Brown   ierr = DMLocalToGlobalBegin(da,localX,INSERT_VALUES,X);CHKERRQ(ierr);
639c4762a1bSJed Brown   ierr = DMLocalToGlobalEnd(da,localX,INSERT_VALUES,X);CHKERRQ(ierr);
640c4762a1bSJed Brown   ierr = PetscLogFlops(tot_its*(84.0 + 41.0 + 26.0));CHKERRQ(ierr);
641c4762a1bSJed Brown   ierr = DMRestoreLocalVector(da,&localX);CHKERRQ(ierr);
642c4762a1bSJed Brown   if (B) {
643c4762a1bSJed Brown     ierr = DMRestoreLocalVector(da,&localB);CHKERRQ(ierr);
644c4762a1bSJed Brown   }
645c4762a1bSJed Brown   PetscFunctionReturn(0);
646c4762a1bSJed Brown }
647c4762a1bSJed Brown 
648c4762a1bSJed Brown /*TEST
649c4762a1bSJed Brown 
650c4762a1bSJed Brown    test:
651c4762a1bSJed Brown       nsize: 2
652c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type mg -ksp_type fgmres -pc_mg_type full
653c4762a1bSJed Brown       requires: !single
654c4762a1bSJed Brown 
655c4762a1bSJed Brown    test:
656c4762a1bSJed Brown       suffix: 10
657c4762a1bSJed Brown       nsize: 3
658c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -pc_fieldsplit_type symmetric_multiplicative -snes_view -da_refine 1 -ksp_type fgmres
659c4762a1bSJed Brown       requires: !single
660c4762a1bSJed Brown 
661c4762a1bSJed Brown    test:
662c4762a1bSJed Brown       suffix: 11
663c4762a1bSJed Brown       nsize: 4
664c4762a1bSJed Brown       requires: pastix
665c4762a1bSJed Brown       args: -snes_monitor_short -pc_type redundant -dm_mat_type mpiaij -redundant_pc_factor_mat_solver_type pastix -pc_redundant_number 2 -da_refine 4 -ksp_type fgmres
666c4762a1bSJed Brown 
667c4762a1bSJed Brown    test:
668c4762a1bSJed Brown       suffix: 12
669c4762a1bSJed Brown       nsize: 12
670c4762a1bSJed Brown       requires: pastix
671c4762a1bSJed Brown       args: -snes_monitor_short -pc_type redundant -dm_mat_type mpiaij -redundant_pc_factor_mat_solver_type pastix -pc_redundant_number 5 -da_refine 4 -ksp_type fgmres
672c4762a1bSJed Brown 
673c4762a1bSJed Brown    test:
674c4762a1bSJed Brown       suffix: 13
675c4762a1bSJed Brown       nsize: 3
676c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -pc_fieldsplit_type multiplicative -snes_view -da_refine 1 -ksp_type fgmres -snes_mf_operator
677c4762a1bSJed Brown       requires: !single
678c4762a1bSJed Brown 
679c4762a1bSJed Brown    test:
680c4762a1bSJed Brown       suffix: 14
681c4762a1bSJed Brown       nsize: 4
682c4762a1bSJed Brown       args: -snes_monitor_short -pc_type mg -dm_mat_type baij -mg_coarse_pc_type bjacobi -da_refine 3 -ksp_type fgmres
683c4762a1bSJed Brown       requires: !single
684c4762a1bSJed Brown 
685c4762a1bSJed Brown    test:
686c4762a1bSJed Brown       suffix: 14_ds
687c4762a1bSJed Brown       nsize: 4
688c4762a1bSJed Brown       args: -snes_converged_reason -pc_type mg -dm_mat_type baij -mg_coarse_pc_type bjacobi -da_refine 3 -ksp_type fgmres -mat_fd_type ds
689c4762a1bSJed Brown       output_file: output/ex19_2.out
690c4762a1bSJed Brown       requires: !single
691c4762a1bSJed Brown 
692c4762a1bSJed Brown    test:
693c4762a1bSJed Brown       suffix: 17
694c4762a1bSJed Brown       args: -snes_monitor_short -ksp_pc_side right
695c4762a1bSJed Brown       requires: !single
696c4762a1bSJed Brown 
697c4762a1bSJed Brown    test:
698c4762a1bSJed Brown       suffix: 18
699798534f6SMatthew G. Knepley       args: -snes_monitor_ksp draw::draw_lg -ksp_pc_side right
700c4762a1bSJed Brown       requires: x !single
701c4762a1bSJed Brown 
702c4762a1bSJed Brown    test:
703c4762a1bSJed Brown       suffix: 2
704c4762a1bSJed Brown       nsize: 4
705c4762a1bSJed Brown       args: -da_refine 3 -snes_converged_reason -pc_type mg -mat_fd_type ds
706c4762a1bSJed Brown       requires: !single
707c4762a1bSJed Brown 
708c4762a1bSJed Brown    test:
709c4762a1bSJed Brown       suffix: 2_bcols1
710c4762a1bSJed Brown       nsize: 4
711c4762a1bSJed Brown       args: -da_refine 3 -snes_converged_reason -pc_type mg -mat_fd_type ds -mat_fd_coloring_bcols
712c4762a1bSJed Brown       output_file: output/ex19_2.out
713c4762a1bSJed Brown       requires: !single
714c4762a1bSJed Brown 
715c4762a1bSJed Brown    test:
716c4762a1bSJed Brown       suffix: 3
717c4762a1bSJed Brown       nsize: 4
718c4762a1bSJed Brown       requires: mumps
719c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type redundant -dm_mat_type mpiaij -redundant_ksp_type preonly -redundant_pc_factor_mat_solver_type mumps -pc_redundant_number 2
720c4762a1bSJed Brown 
721c4762a1bSJed Brown    test:
722c4762a1bSJed Brown       suffix: 4
723c4762a1bSJed Brown       nsize: 12
724c4762a1bSJed Brown       requires: mumps
725c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type redundant -dm_mat_type mpiaij -redundant_ksp_type preonly -redundant_pc_factor_mat_solver_type mumps -pc_redundant_number 5
726c4762a1bSJed Brown       output_file: output/ex19_3.out
727c4762a1bSJed Brown 
728c4762a1bSJed Brown    test:
729c4762a1bSJed Brown       suffix: 6
730c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -snes_view -ksp_type fgmres -da_refine 1
731c4762a1bSJed Brown       requires: !single
732c4762a1bSJed Brown 
733c4762a1bSJed Brown    test:
734c4762a1bSJed Brown       suffix: 7
735c4762a1bSJed Brown       nsize: 3
736c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -snes_view -da_refine 1 -ksp_type fgmres
737c4762a1bSJed Brown 
738c4762a1bSJed Brown       requires: !single
739c4762a1bSJed Brown    test:
740c4762a1bSJed Brown       suffix: 8
741c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -pc_fieldsplit_block_size 2 -pc_fieldsplit_0_fields 0,1 -pc_fieldsplit_1_fields 0,1 -pc_fieldsplit_type multiplicative -snes_view -fieldsplit_pc_type lu -da_refine 1 -ksp_type fgmres
742c4762a1bSJed Brown       requires: !single
743c4762a1bSJed Brown 
744c4762a1bSJed Brown    test:
745c4762a1bSJed Brown       suffix: 9
746c4762a1bSJed Brown       nsize: 3
747c4762a1bSJed Brown       args: -snes_monitor_short -ksp_monitor_short -pc_type fieldsplit -pc_fieldsplit_type multiplicative -snes_view -da_refine 1 -ksp_type fgmres
748c4762a1bSJed Brown       requires: !single
749c4762a1bSJed Brown 
750c4762a1bSJed Brown    test:
751c4762a1bSJed Brown       suffix: aspin
752c4762a1bSJed Brown       nsize: 4
753c4762a1bSJed Brown       args: -da_refine 3 -da_overlap 2 -snes_monitor_short -snes_type aspin -grashof 4e4 -lidvelocity 100 -ksp_monitor_short
754c4762a1bSJed Brown       requires: !single
755c4762a1bSJed Brown 
756c4762a1bSJed Brown    test:
757c4762a1bSJed Brown       suffix: bcgsl
758c4762a1bSJed Brown       nsize: 2
759c4762a1bSJed Brown       args: -ksp_type bcgsl -ksp_monitor_short -da_refine 2 -ksp_bcgsl_ell 3 -snes_view
760c4762a1bSJed Brown       requires: !single
761c4762a1bSJed Brown 
762c4762a1bSJed Brown    test:
763c4762a1bSJed Brown       suffix: bcols1
764c4762a1bSJed Brown       nsize: 2
765c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type mg -ksp_type fgmres -pc_mg_type full -mat_fd_coloring_bcols 1
766c4762a1bSJed Brown       output_file: output/ex19_1.out
767c4762a1bSJed Brown       requires: !single
768c4762a1bSJed Brown 
769c4762a1bSJed Brown    test:
770c4762a1bSJed Brown       suffix: bjacobi
771c4762a1bSJed Brown       nsize: 4
772c4762a1bSJed Brown       args: -da_refine 4 -ksp_type fgmres -pc_type bjacobi -pc_bjacobi_blocks 2 -sub_ksp_type gmres -sub_ksp_max_it 2 -sub_pc_type bjacobi -sub_sub_ksp_type preonly -sub_sub_pc_type ilu -snes_monitor_short
773c4762a1bSJed Brown       requires: !single
774c4762a1bSJed Brown 
775c4762a1bSJed Brown    test:
776c4762a1bSJed Brown       suffix: cgne
777c4762a1bSJed Brown       args: -da_refine 2 -pc_type lu -ksp_type cgne -ksp_monitor_short -ksp_converged_reason -ksp_view -ksp_norm_type unpreconditioned
778c4762a1bSJed Brown       filter: grep -v HERMITIAN
779c4762a1bSJed Brown       requires: !single
780c4762a1bSJed Brown 
781c4762a1bSJed Brown    test:
782c4762a1bSJed Brown       suffix: cgs
783c4762a1bSJed Brown       args: -da_refine 1 -ksp_monitor_short -ksp_type cgs
784c4762a1bSJed Brown       requires: !single
785c4762a1bSJed Brown 
786c4762a1bSJed Brown    test:
787c4762a1bSJed Brown       suffix: composite_fieldsplit
788c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type composite -pc_composite_type MULTIPLICATIVE -pc_composite_pcs fieldsplit,none -sub_0_pc_fieldsplit_block_size 4 -sub_0_pc_fieldsplit_type additive -sub_0_pc_fieldsplit_0_fields 0,1,2 -sub_0_pc_fieldsplit_1_fields 3 -snes_monitor_short -ksp_monitor_short
789c4762a1bSJed Brown       requires: !single
790c4762a1bSJed Brown 
791c4762a1bSJed Brown    test:
792c4762a1bSJed Brown       suffix: composite_fieldsplit_bjacobi
793c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type composite -pc_composite_type MULTIPLICATIVE -pc_composite_pcs fieldsplit,bjacobi -sub_0_pc_fieldsplit_block_size 4 -sub_0_pc_fieldsplit_type additive -sub_0_pc_fieldsplit_0_fields 0,1,2 -sub_0_pc_fieldsplit_1_fields 3 -sub_1_pc_bjacobi_blocks 16 -sub_1_sub_pc_type lu -snes_monitor_short -ksp_monitor_short
794c4762a1bSJed Brown       requires: !single
795c4762a1bSJed Brown 
796c4762a1bSJed Brown    test:
797c4762a1bSJed Brown       suffix: composite_fieldsplit_bjacobi_2
798c4762a1bSJed Brown       nsize: 4
799c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type composite -pc_composite_type MULTIPLICATIVE -pc_composite_pcs fieldsplit,bjacobi -sub_0_pc_fieldsplit_block_size 4 -sub_0_pc_fieldsplit_type additive -sub_0_pc_fieldsplit_0_fields 0,1,2 -sub_0_pc_fieldsplit_1_fields 3 -sub_1_pc_bjacobi_blocks 16 -sub_1_sub_pc_type lu -snes_monitor_short -ksp_monitor_short
800c4762a1bSJed Brown       requires: !single
801c4762a1bSJed Brown 
802c4762a1bSJed Brown    test:
803c4762a1bSJed Brown       suffix: composite_gs_newton
804c4762a1bSJed Brown       nsize: 2
805c4762a1bSJed Brown       args: -da_refine 3 -grashof 4e4 -lidvelocity 100 -snes_monitor_short -snes_type composite -snes_composite_type additiveoptimal -snes_composite_sneses ngs,newtonls -sub_0_snes_max_it 20 -sub_1_pc_type mg
806c4762a1bSJed Brown       requires: !single
807c4762a1bSJed Brown 
808c4762a1bSJed Brown    test:
809c4762a1bSJed Brown       suffix: cuda
810c4762a1bSJed Brown       requires: cuda !single
811c4762a1bSJed Brown       args: -dm_vec_type cuda -dm_mat_type aijcusparse -pc_type none -ksp_type fgmres -snes_monitor_short -snes_rtol 1.e-5
812c4762a1bSJed Brown 
813c4762a1bSJed Brown    test:
814c4762a1bSJed Brown       suffix: draw
815c4762a1bSJed Brown       args: -pc_type fieldsplit -snes_view draw -fieldsplit_x_velocity_pc_type mg -fieldsplit_x_velocity_pc_mg_galerkin pmat -fieldsplit_x_velocity_pc_mg_levels 2 -da_refine 1 -fieldsplit_x_velocity_mg_coarse_pc_type svd
816c4762a1bSJed Brown       requires: x !single
817c4762a1bSJed Brown 
818c4762a1bSJed Brown    test:
819c4762a1bSJed Brown       suffix: drawports
820c4762a1bSJed Brown       args: -snes_monitor_solution draw::draw_ports -da_refine 1
821c4762a1bSJed Brown       output_file: output/ex19_draw.out
822c4762a1bSJed Brown       requires: x !single
823c4762a1bSJed Brown 
824c4762a1bSJed Brown    test:
825c4762a1bSJed Brown       suffix: fas
826c4762a1bSJed Brown       args: -da_refine 4 -snes_monitor_short -snes_type fas -fas_levels_snes_type ngs -fas_levels_snes_ngs_sweeps 3 -fas_levels_snes_ngs_atol 0.0 -fas_levels_snes_ngs_stol 0.0 -grashof 4e4 -snes_fas_smoothup 6 -snes_fas_smoothdown 6 -lidvelocity 100
827c4762a1bSJed Brown       requires: !single
828c4762a1bSJed Brown 
829c4762a1bSJed Brown    test:
830c4762a1bSJed Brown       suffix: fas_full
831c4762a1bSJed Brown       args: -da_refine 4 -snes_monitor_short -snes_type fas -snes_fas_type full -snes_fas_full_downsweep -fas_levels_snes_type ngs -fas_levels_snes_ngs_sweeps 3 -fas_levels_snes_ngs_atol 0.0 -fas_levels_snes_ngs_stol 0.0 -grashof 4e4 -snes_fas_smoothup 6 -snes_fas_smoothdown 6 -lidvelocity 100
832c4762a1bSJed Brown       requires: !single
833c4762a1bSJed Brown 
834c4762a1bSJed Brown    test:
835c4762a1bSJed Brown       suffix: fdcoloring_ds
836c4762a1bSJed Brown       args: -da_refine 3 -snes_converged_reason -pc_type mg -mat_fd_type ds
837c4762a1bSJed Brown       output_file: output/ex19_2.out
838c4762a1bSJed Brown       requires: !single
839c4762a1bSJed Brown 
840c4762a1bSJed Brown    test:
841c4762a1bSJed Brown       suffix: fdcoloring_ds_baij
842c4762a1bSJed Brown       args: -da_refine 3 -snes_converged_reason -pc_type mg -mat_fd_type ds -dm_mat_type baij
843c4762a1bSJed Brown       output_file: output/ex19_2.out
844c4762a1bSJed Brown       requires: !single
845c4762a1bSJed Brown 
846c4762a1bSJed Brown    test:
847c4762a1bSJed Brown       suffix: fdcoloring_ds_bcols1
848c4762a1bSJed Brown       args: -da_refine 3 -snes_converged_reason -pc_type mg -mat_fd_type ds -mat_fd_coloring_bcols 1
849c4762a1bSJed Brown       output_file: output/ex19_2.out
850c4762a1bSJed Brown       requires: !single
851c4762a1bSJed Brown 
852c4762a1bSJed Brown    test:
853c4762a1bSJed Brown       suffix: fdcoloring_wp
854c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type mg
855c4762a1bSJed Brown       requires: !single
856c4762a1bSJed Brown 
857c4762a1bSJed Brown    test:
858c4762a1bSJed Brown       suffix: fdcoloring_wp_baij
859c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type mg -dm_mat_type baij
860c4762a1bSJed Brown       output_file: output/ex19_fdcoloring_wp.out
861c4762a1bSJed Brown       requires: !single
862c4762a1bSJed Brown 
863c4762a1bSJed Brown    test:
864c4762a1bSJed Brown       suffix: fdcoloring_wp_bcols1
865c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type mg -mat_fd_coloring_bcols 1
866c4762a1bSJed Brown       output_file: output/ex19_fdcoloring_wp.out
867c4762a1bSJed Brown       requires: !single
868c4762a1bSJed Brown 
869c4762a1bSJed Brown    test:
870c4762a1bSJed Brown       suffix: fieldsplit_2
871c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type fieldsplit -pc_fieldsplit_block_size 4 -pc_fieldsplit_type additive -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 -snes_monitor_short -ksp_monitor_short
872c4762a1bSJed Brown       requires: !single
873c4762a1bSJed Brown 
874c4762a1bSJed Brown    test:
875c4762a1bSJed Brown       suffix: fieldsplit_3
876c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type fieldsplit -pc_fieldsplit_block_size 4 -pc_fieldsplit_type additive -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 -fieldsplit_0_pc_type lu -fieldsplit_1_pc_type lu -snes_monitor_short -ksp_monitor_short
877c4762a1bSJed Brown       requires: !single
878c4762a1bSJed Brown 
879c4762a1bSJed Brown    test:
880c4762a1bSJed Brown       suffix: fieldsplit_4
881c4762a1bSJed Brown       args: -ksp_type fgmres -pc_type fieldsplit -pc_fieldsplit_block_size 4 -pc_fieldsplit_type SCHUR -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 -fieldsplit_0_pc_type lu -fieldsplit_1_pc_type lu -snes_monitor_short -ksp_monitor_short
882c4762a1bSJed Brown       requires: !single
883c4762a1bSJed Brown 
884c4762a1bSJed Brown    # HYPRE PtAP broken with complex numbers
885c4762a1bSJed Brown    test:
886c4762a1bSJed Brown       suffix: fieldsplit_hypre
887c4762a1bSJed Brown       nsize: 2
888c4762a1bSJed Brown       requires: hypre mumps !complex
889c4762a1bSJed Brown       args: -pc_type fieldsplit -pc_fieldsplit_block_size 4 -pc_fieldsplit_type SCHUR -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 -fieldsplit_0_pc_type lu -fieldsplit_0_pc_factor_mat_solver_type mumps -fieldsplit_1_pc_type hypre -fieldsplit_1_pc_hypre_type boomeramg -snes_monitor_short -ksp_monitor_short
890c4762a1bSJed Brown 
891c4762a1bSJed Brown    test:
892c4762a1bSJed Brown       suffix: fieldsplit_mumps
893c4762a1bSJed Brown       nsize: 2
894c4762a1bSJed Brown       requires: mumps
895c4762a1bSJed Brown       args: -pc_type fieldsplit -pc_fieldsplit_block_size 4 -pc_fieldsplit_type SCHUR -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 -fieldsplit_0_pc_type lu -fieldsplit_1_pc_type lu -snes_monitor_short -ksp_monitor_short -fieldsplit_0_pc_factor_mat_solver_type mumps -fieldsplit_1_pc_factor_mat_solver_type mumps
896c4762a1bSJed Brown       output_file: output/ex19_fieldsplit_5.out
897c4762a1bSJed Brown 
898c4762a1bSJed Brown    test:
899c4762a1bSJed Brown       suffix: greedy_coloring
900c4762a1bSJed Brown       nsize: 2
901c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -snes_fd_color -snes_fd_color_use_mat -mat_coloring_type greedy -mat_coloring_weight_type lf -mat_coloring_view> ex19_greedy_coloring.tmp 2>&1
902c4762a1bSJed Brown       requires: !single
903c4762a1bSJed Brown 
904c4762a1bSJed Brown    # HYPRE PtAP broken with complex numbers
905c4762a1bSJed Brown    test:
906c4762a1bSJed Brown       suffix: hypre
907c4762a1bSJed Brown       nsize: 2
908c4762a1bSJed Brown       requires: hypre !complex
909c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type hypre
910c4762a1bSJed Brown 
911c4762a1bSJed Brown    test:
912c4762a1bSJed Brown       suffix: ibcgs
913c4762a1bSJed Brown       nsize: 2
914c4762a1bSJed Brown       args: -ksp_type ibcgs -ksp_monitor_short -da_refine 2 -snes_view
915c4762a1bSJed Brown       requires: !complex !single
916c4762a1bSJed Brown 
917c4762a1bSJed Brown    test:
918c4762a1bSJed Brown       suffix: kaczmarz
919c4762a1bSJed Brown       nsize: 2
920c4762a1bSJed Brown       args: -pc_type kaczmarz -ksp_monitor_short -snes_monitor_short -snes_view
921c4762a1bSJed Brown       requires: !single
922c4762a1bSJed Brown 
923c4762a1bSJed Brown    test:
924c4762a1bSJed Brown       suffix: klu
925c4762a1bSJed Brown       requires: suitesparse
926c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type klu
927c4762a1bSJed Brown       output_file: output/ex19_superlu.out
928c4762a1bSJed Brown 
929c4762a1bSJed Brown    test:
930c4762a1bSJed Brown       suffix: klu_2
931c4762a1bSJed Brown       requires: suitesparse
9324ac6704cSBarry Smith       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type klu -pc_factor_mat_ordering_type nd
933c4762a1bSJed Brown       output_file: output/ex19_superlu.out
934c4762a1bSJed Brown 
935c4762a1bSJed Brown    test:
936c4762a1bSJed Brown       suffix: klu_3
937c4762a1bSJed Brown       requires: suitesparse
938c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type klu -mat_klu_use_btf 0
939c4762a1bSJed Brown       output_file: output/ex19_superlu.out
940c4762a1bSJed Brown 
941c4762a1bSJed Brown    test:
942c4762a1bSJed Brown       suffix: ml
943c4762a1bSJed Brown       nsize: 2
944c4762a1bSJed Brown       requires: ml
945c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -pc_type ml
946c4762a1bSJed Brown 
947c4762a1bSJed Brown    test:
948c4762a1bSJed Brown       suffix: ngmres_fas
949c4762a1bSJed Brown       args: -da_refine 4 -snes_monitor_short -snes_type ngmres -npc_fas_levels_snes_type ngs -npc_fas_levels_snes_ngs_sweeps 3 -npc_fas_levels_snes_ngs_atol 0.0 -npc_fas_levels_snes_ngs_stol 0.0 -npc_snes_type fas -npc_fas_levels_snes_type ngs -npc_snes_max_it 1 -npc_snes_fas_smoothup 6 -npc_snes_fas_smoothdown 6 -lidvelocity 100 -grashof 4e4
950c4762a1bSJed Brown       requires: !single
951c4762a1bSJed Brown 
952c4762a1bSJed Brown    test:
953c4762a1bSJed Brown       suffix: ngmres_fas_gssecant
954c4762a1bSJed Brown       args: -da_refine 3 -snes_monitor_short -snes_type ngmres -npc_snes_type fas -npc_fas_levels_snes_type ngs -npc_fas_levels_snes_max_it 6 -npc_fas_levels_snes_ngs_secant -npc_fas_levels_snes_ngs_max_it 1 -npc_fas_coarse_snes_max_it 1 -lidvelocity 100 -grashof 4e4
955c4762a1bSJed Brown       requires: !single
956c4762a1bSJed Brown 
957c4762a1bSJed Brown    test:
958c4762a1bSJed Brown       suffix: ngmres_fas_ms
959c4762a1bSJed Brown       nsize: 2
960c4762a1bSJed Brown       args: -snes_grid_sequence 2 -lidvelocity 200 -grashof 1e4 -snes_monitor_short -snes_view -snes_converged_reason -snes_type ngmres -npc_snes_type fas -npc_fas_coarse_snes_type newtonls -npc_fas_coarse_ksp_type preonly -npc_snes_max_it 1
961c4762a1bSJed Brown       requires: !single
962c4762a1bSJed Brown 
963c4762a1bSJed Brown    test:
964c4762a1bSJed Brown       suffix: ngmres_nasm
965c4762a1bSJed Brown       nsize: 4
966c4762a1bSJed Brown       args: -da_refine 4 -da_overlap 2 -snes_monitor_short -snes_type ngmres -snes_max_it 10 -npc_snes_type nasm -npc_snes_nasm_type basic -grashof 4e4 -lidvelocity 100
967c4762a1bSJed Brown       requires: !single
968c4762a1bSJed Brown 
969c4762a1bSJed Brown    test:
970c4762a1bSJed Brown       suffix: ngs
971c4762a1bSJed Brown       args: -snes_type ngs -snes_view -snes_monitor -snes_rtol 1e-4
972c4762a1bSJed Brown       requires: !single
973c4762a1bSJed Brown 
974c4762a1bSJed Brown    test:
975c4762a1bSJed Brown       suffix: ngs_fd
976c4762a1bSJed Brown       args: -snes_type ngs -snes_ngs_secant -snes_view -snes_monitor -snes_rtol 1e-4
977c4762a1bSJed Brown       requires: !single
978c4762a1bSJed Brown 
979c4762a1bSJed Brown    test:
980c4762a1bSJed Brown       suffix: parms
981c4762a1bSJed Brown       nsize: 2
982c4762a1bSJed Brown       requires: parms
983c4762a1bSJed Brown       args: -pc_type parms -ksp_monitor_short -snes_view
984c4762a1bSJed Brown 
985c4762a1bSJed Brown    test:
986c4762a1bSJed Brown       suffix: superlu
987c4762a1bSJed Brown       requires: superlu
988c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type superlu
989c4762a1bSJed Brown 
990c4762a1bSJed Brown    test:
991c4762a1bSJed Brown       suffix: superlu_sell
992c4762a1bSJed Brown       requires: superlu
993c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type superlu -dm_mat_type sell -pc_factor_mat_ordering_type natural
994c4762a1bSJed Brown       output_file: output/ex19_superlu.out
995c4762a1bSJed Brown 
996c4762a1bSJed Brown    test:
997c4762a1bSJed Brown       suffix: superlu_dist
998c4762a1bSJed Brown       requires: superlu_dist
999c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type superlu_dist
1000c4762a1bSJed Brown       output_file: output/ex19_superlu.out
1001c4762a1bSJed Brown 
1002c4762a1bSJed Brown    test:
1003c4762a1bSJed Brown       suffix: superlu_dist_2
1004c4762a1bSJed Brown       nsize: 2
1005c4762a1bSJed Brown       requires: superlu_dist
1006c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -pc_type lu -pc_factor_mat_solver_type superlu_dist
1007c4762a1bSJed Brown       output_file: output/ex19_superlu.out
1008c4762a1bSJed Brown 
1009c4762a1bSJed Brown    test:
1010c4762a1bSJed Brown       suffix: superlu_equil
1011c4762a1bSJed Brown       requires: superlu
1012c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -{snes,ksp}_monitor_short -pc_type lu -pc_factor_mat_solver_type superlu -mat_superlu_equil
1013c4762a1bSJed Brown 
1014c4762a1bSJed Brown    test:
1015c4762a1bSJed Brown       suffix: superlu_equil_sell
1016c4762a1bSJed Brown       requires: superlu
1017c4762a1bSJed Brown       args: -da_grid_x 20 -da_grid_y 20 -{snes,ksp}_monitor_short -pc_type lu -pc_factor_mat_solver_type superlu -mat_superlu_equil -dm_mat_type sell -pc_factor_mat_ordering_type natural
1018c4762a1bSJed Brown       output_file: output/ex19_superlu_equil.out
1019c4762a1bSJed Brown 
1020c4762a1bSJed Brown    test:
1021c4762a1bSJed Brown       suffix: tcqmr
1022c4762a1bSJed Brown       args: -da_refine 1 -ksp_monitor_short -ksp_type tcqmr
1023c4762a1bSJed Brown       requires: !single
1024c4762a1bSJed Brown 
1025c4762a1bSJed Brown    test:
1026c4762a1bSJed Brown       suffix: tfqmr
1027c4762a1bSJed Brown       args: -da_refine 1 -ksp_monitor_short -ksp_type tfqmr
1028c4762a1bSJed Brown       requires: !single
1029c4762a1bSJed Brown 
1030c4762a1bSJed Brown    test:
1031c4762a1bSJed Brown       suffix: umfpack
1032c4762a1bSJed Brown       requires: suitesparse
10332c7c0729SBarry Smith       args: -da_refine 2 -pc_type lu -pc_factor_mat_solver_type umfpack -snes_view -snes_monitor_short -ksp_monitor_short -pc_factor_mat_ordering_type external
1034c4762a1bSJed Brown 
1035c4762a1bSJed Brown    test:
1036c4762a1bSJed Brown       suffix: tut_1
1037c4762a1bSJed Brown       nsize: 4
1038c4762a1bSJed Brown       requires: !single
1039c4762a1bSJed Brown       args: -da_refine 5 -snes_monitor -ksp_monitor -snes_view
1040c4762a1bSJed Brown 
1041c4762a1bSJed Brown    test:
1042c4762a1bSJed Brown       suffix: tut_2
1043c4762a1bSJed Brown       nsize: 4
1044c4762a1bSJed Brown       requires: !single
1045c4762a1bSJed Brown       args: -da_refine 5 -snes_monitor -ksp_monitor -snes_view -pc_type mg
1046c4762a1bSJed Brown 
1047c4762a1bSJed Brown    # HYPRE PtAP broken with complex numbers
1048c4762a1bSJed Brown    test:
1049c4762a1bSJed Brown       suffix: tut_3
1050c4762a1bSJed Brown       nsize: 4
1051c4762a1bSJed Brown       requires: hypre !single !complex
1052c4762a1bSJed Brown       args: -da_refine 5 -snes_monitor -ksp_monitor -snes_view -pc_type hypre
1053c4762a1bSJed Brown 
1054c4762a1bSJed Brown    test:
1055c4762a1bSJed Brown       suffix: tut_8
1056c4762a1bSJed Brown       nsize: 4
1057c4762a1bSJed Brown       requires: ml !single
1058c4762a1bSJed Brown       args: -da_refine 5 -snes_monitor -ksp_monitor -snes_view -pc_type ml
1059c4762a1bSJed Brown 
1060c4762a1bSJed Brown    test:
1061c4762a1bSJed Brown       suffix: tut_4
1062c4762a1bSJed Brown       nsize: 1
1063c4762a1bSJed Brown       requires: !single
1064c4762a1bSJed Brown       args: -da_refine 5 -log_view
1065c4762a1bSJed Brown       filter: head -n 2
1066c4762a1bSJed Brown       filter_output: head -n 2
1067c4762a1bSJed Brown 
1068c4762a1bSJed Brown    test:
1069c4762a1bSJed Brown       suffix: tut_5
1070c4762a1bSJed Brown       nsize: 1
1071c4762a1bSJed Brown       requires: !single
1072c4762a1bSJed Brown       args: -da_refine 5 -log_view -pc_type mg
1073c4762a1bSJed Brown       filter: head -n 2
1074c4762a1bSJed Brown       filter_output: head -n 2
1075c4762a1bSJed Brown 
1076c4762a1bSJed Brown    test:
1077c4762a1bSJed Brown       suffix: tut_6
1078c4762a1bSJed Brown       nsize: 4
1079c4762a1bSJed Brown       requires: !single
1080c4762a1bSJed Brown       args: -da_refine 5 -log_view
1081c4762a1bSJed Brown       filter: head -n 2
1082c4762a1bSJed Brown       filter_output: head -n 2
1083c4762a1bSJed Brown 
1084c4762a1bSJed Brown    test:
1085c4762a1bSJed Brown       suffix: tut_7
1086c4762a1bSJed Brown       nsize: 4
1087c4762a1bSJed Brown       requires: !single
1088c4762a1bSJed Brown       args: -da_refine 5 -log_view -pc_type mg
1089c4762a1bSJed Brown       filter: head -n 2
1090c4762a1bSJed Brown       filter_output: head -n 2
1091c4762a1bSJed Brown 
1092c4762a1bSJed Brown    test:
1093c4762a1bSJed Brown       suffix: cuda_1
1094c4762a1bSJed Brown       nsize: 1
1095c4762a1bSJed Brown       requires: cuda
1096c4762a1bSJed Brown       args: -snes_monitor -dm_mat_type seqaijcusparse -dm_vec_type seqcuda -pc_type gamg -ksp_monitor -mg_levels_ksp_max_it 3
1097c4762a1bSJed Brown 
1098c4762a1bSJed Brown    test:
1099c4762a1bSJed Brown       suffix: cuda_2
1100c4762a1bSJed Brown       nsize: 3
1101c4762a1bSJed Brown       requires: cuda !single
1102c4762a1bSJed Brown       args: -snes_monitor -dm_mat_type mpiaijcusparse -dm_vec_type mpicuda -pc_type gamg -ksp_monitor  -mg_levels_ksp_max_it 3
1103c4762a1bSJed Brown 
1104c4762a1bSJed Brown    test:
1105c4762a1bSJed Brown       suffix: seqbaijmkl
1106c4762a1bSJed Brown       nsize: 1
1107*dfd57a17SPierre Jolivet       requires: defined(PETSC_HAVE_MKL_SPARSE_OPTIMIZE)
1108c4762a1bSJed Brown       args: -dm_mat_type baij -snes_monitor -ksp_monitor -snes_view
1109c4762a1bSJed Brown 
1110c4762a1bSJed Brown    test:
1111c4762a1bSJed Brown       suffix: mpibaijmkl
1112c4762a1bSJed Brown       nsize: 2
1113*dfd57a17SPierre Jolivet       requires:  defined(PETSC_HAVE_MKL_SPARSE_OPTIMIZE)
1114c4762a1bSJed Brown       args: -dm_mat_type baij -snes_monitor -ksp_monitor -snes_view
1115c4762a1bSJed Brown 
1116c4762a1bSJed Brown    test:
1117c4762a1bSJed Brown      suffix: cpardiso
1118c4762a1bSJed Brown      nsize: 4
1119c4762a1bSJed Brown      requires: mkl_cpardiso
1120c4762a1bSJed Brown      args: -pc_type lu -pc_factor_mat_solver_type mkl_cpardiso -ksp_monitor
1121c4762a1bSJed Brown 
1122c4762a1bSJed Brown    test:
1123c4762a1bSJed Brown      suffix: logviewmemory
1124*dfd57a17SPierre Jolivet      requires: defined(PETSC_USE_LOG) !defined(PETSCTEST_VALGRIND)
1125c4762a1bSJed Brown      args: -log_view -log_view_memory -da_refine 4
1126c4762a1bSJed Brown      filter: grep MatFDColorSetUp | wc -w | xargs  -I % sh -c "expr % \> 21"
1127c4762a1bSJed Brown 
1128534f0846SBarry Smith    test:
1129534f0846SBarry Smith      suffix: fs
1130534f0846SBarry Smith      args: -pc_type fieldsplit -da_refine 3  -all_ksp_monitor -fieldsplit_y_velocity_pc_type lu  -fieldsplit_temperature_pc_type lu -fieldsplit_x_velocity_pc_type lu  -snes_view
1131534f0846SBarry Smith 
113271f558e3SSatish Balay    test:
1133a8e42557SLawrence Mitchell      suffix: asm_matconvert
1134a8e42557SLawrence Mitchell      args: -mat_type aij -pc_type asm -pc_asm_sub_mat_type dense -snes_view
1135a8e42557SLawrence Mitchell 
11368bf83915SBarry Smith    test:
11378bf83915SBarry Smith       suffix: euclid
11388bf83915SBarry Smith       nsize: 2
1139*dfd57a17SPierre Jolivet       requires: hypre !single !complex !defined(PETSC_HAVE_HYPRE_MIXEDINT)
11408bf83915SBarry Smith       args: -da_refine 2 -ksp_monitor -snes_monitor -snes_view -pc_type hypre -pc_hypre_type euclid
11418bf83915SBarry Smith 
11428bf83915SBarry Smith    test:
11438bf83915SBarry Smith       suffix: euclid_bj
11448bf83915SBarry Smith       nsize: 2
1145*dfd57a17SPierre Jolivet       requires: hypre !single !complex !defined(PETSC_HAVE_HYPRE_MIXEDINT)
11468bf83915SBarry Smith       args: -da_refine 2 -ksp_monitor -snes_monitor -snes_view -pc_type hypre -pc_hypre_type euclid -pc_hypre_euclid_bj
11478bf83915SBarry Smith 
11488bf83915SBarry Smith    test:
11498bf83915SBarry Smith       suffix: euclid_droptolerance
11508bf83915SBarry Smith       nsize: 1
1151*dfd57a17SPierre Jolivet       requires: hypre !single !complex !defined(PETSC_HAVE_HYPRE_MIXEDINT)
11528bf83915SBarry Smith       args: -da_refine 2 -ksp_monitor -snes_monitor -snes_view -pc_type hypre -pc_hypre_type euclid -pc_hypre_euclid_droptolerance .1
11538bf83915SBarry Smith 
1154c4762a1bSJed Brown TEST*/
1155