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