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