xref: /petsc/src/snes/tutorials/ex12.c (revision 24ded41b4e3afbef0dd5eaa1b3d8dd0172f6dba2)
1 static char help[] = "Poisson Problem in 2d and 3d with simplicial finite elements.\n\
2 We solve the Poisson problem in a rectangular\n\
3 domain, using a parallel unstructured mesh (DMPLEX) to discretize it.\n\
4 This example supports discretized auxiliary fields (conductivity) as well as\n\
5 multilevel nonlinear solvers.\n\n\n";
6 
7 /*
8 A visualization of the adaptation can be accomplished using:
9 
10   -dm_adapt_view hdf5:$PWD/adapt.h5 -sol_adapt_view hdf5:$PWD/adapt.h5::append -dm_adapt_pre_view hdf5:$PWD/orig.h5 -sol_adapt_pre_view hdf5:$PWD/orig.h5::append
11 
12 Information on refinement:
13 
14    -info :~sys,vec,is,mat,ksp,snes,ts
15 */
16 
17 #include <petscdmplex.h>
18 #include <petscdmadaptor.h>
19 #include <petscsnes.h>
20 #include <petscds.h>
21 #include <petscviewerhdf5.h>
22 
23 typedef enum {NEUMANN, DIRICHLET, NONE} BCType;
24 typedef enum {RUN_FULL, RUN_EXACT, RUN_TEST, RUN_PERF} RunType;
25 typedef enum {COEFF_NONE, COEFF_ANALYTIC, COEFF_FIELD, COEFF_NONLINEAR, COEFF_BALL, COEFF_CROSS, COEFF_CHECKERBOARD_0, COEFF_CHECKERBOARD_1} CoeffType;
26 
27 typedef struct {
28   RunType        runType;           /* Whether to run tests, or solve the full problem */
29   PetscBool      jacobianMF;        /* Whether to calculate the Jacobian action on the fly */
30   PetscBool      showInitial, showSolution, restart, quiet, nonzInit;
31   /* Problem definition */
32   BCType         bcType;
33   CoeffType      variableCoefficient;
34   PetscErrorCode (**exactFuncs)(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx);
35   PetscBool      fieldBC;
36   void           (**exactFields)(PetscInt, PetscInt, PetscInt,
37                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
38                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
39                                  PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]);
40   PetscBool      bdIntegral;        /* Compute the integral of the solution on the boundary */
41   /* Reproducing tests from SISC 40(3), pp. A1473-A1493, 2018 */
42   PetscInt       div;               /* Number of divisions */
43   PetscInt       k;                 /* Parameter for checkerboard coefficient */
44   PetscInt      *kgrid;             /* Random parameter grid */
45   PetscBool      rand;              /* Make random assignments */
46   /* Solver */
47   PC             pcmg;              /* This is needed for error monitoring */
48   PetscBool      checkksp;          /* Whether to check the KSPSolve for runType == RUN_TEST */
49 } AppCtx;
50 
51 static PetscErrorCode zero(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
52 {
53   u[0] = 0.0;
54   return 0;
55 }
56 
57 static PetscErrorCode ecks(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
58 {
59   u[0] = x[0];
60   return 0;
61 }
62 
63 /*
64   In 2D for Dirichlet conditions, we use exact solution:
65 
66     u = x^2 + y^2
67     f = 4
68 
69   so that
70 
71     -\Delta u + f = -4 + 4 = 0
72 
73   For Neumann conditions, we have
74 
75     -\nabla u \cdot -\hat y |_{y=0} =  (2y)|_{y=0} =  0 (bottom)
76     -\nabla u \cdot  \hat y |_{y=1} = -(2y)|_{y=1} = -2 (top)
77     -\nabla u \cdot -\hat x |_{x=0} =  (2x)|_{x=0} =  0 (left)
78     -\nabla u \cdot  \hat x |_{x=1} = -(2x)|_{x=1} = -2 (right)
79 
80   Which we can express as
81 
82     \nabla u \cdot  \hat n|_\Gamma = {2 x, 2 y} \cdot \hat n = 2 (x + y)
83 
84   The boundary integral of this solution is (assuming we are not orienting the edges)
85 
86     \int^1_0 x^2 dx + \int^1_0 (1 + y^2) dy + \int^1_0 (x^2 + 1) dx + \int^1_0 y^2 dy = 1/3 + 4/3 + 4/3 + 1/3 = 3 1/3
87 */
88 static PetscErrorCode quadratic_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
89 {
90   *u = x[0]*x[0] + x[1]*x[1];
91   return 0;
92 }
93 
94 static void quadratic_u_field_2d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
95                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
96                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
97                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uexact[])
98 {
99   uexact[0] = a[0];
100 }
101 
102 static PetscErrorCode ball_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
103 {
104   const PetscReal alpha   = 500.;
105   const PetscReal radius2 = PetscSqr(0.15);
106   const PetscReal r2      = PetscSqr(x[0] - 0.5) + PetscSqr(x[1] - 0.5);
107   const PetscReal xi      = alpha*(radius2 - r2);
108 
109   *u = PetscTanhScalar(xi) + 1.0;
110   return 0;
111 }
112 
113 static PetscErrorCode cross_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
114 {
115   const PetscReal alpha = 50*4;
116   const PetscReal xy    = (x[0]-0.5)*(x[1]-0.5);
117 
118   *u = PetscSinReal(alpha*xy) * (alpha*PetscAbsReal(xy) < 2*PETSC_PI ? 1 : 0.01);
119   return 0;
120 }
121 
122 static void f0_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
123                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
124                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
125                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
126 {
127   f0[0] = 4.0;
128 }
129 
130 static void f0_ball_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
131                       const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
132                       const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133                       PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
134 {
135   PetscInt        d;
136   const PetscReal alpha = 500., radius2 = PetscSqr(0.15);
137   PetscReal       r2, xi;
138 
139   for (d = 0, r2 = 0.0; d < dim; ++d) r2 += PetscSqr(x[d] - 0.5);
140   xi = alpha*(radius2 - r2);
141   f0[0] = (-2.0*dim*alpha - 8.0*PetscSqr(alpha)*r2*PetscTanhReal(xi)) * PetscSqr(1.0/PetscCoshReal(xi));
142 }
143 
144 static void f0_cross_u_2d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
145                           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
146                           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
147                           PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
148 {
149   const PetscReal alpha = 50*4;
150   const PetscReal xy    = (x[0]-0.5)*(x[1]-0.5);
151 
152   f0[0] = PetscSinReal(alpha*xy) * (alpha*PetscAbsReal(xy) < 2*PETSC_PI ? 1 : 0.01);
153 }
154 
155 static void f0_checkerboard_0_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
156                                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
157                                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
158                                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
159 {
160   f0[0] = -20.0*PetscExpReal(-(PetscSqr(x[0] - 0.5) + PetscSqr(x[1] - 0.5)));
161 }
162 
163 static void f0_bd_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
164                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
165                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
166                     PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
167 {
168   PetscInt d;
169   for (d = 0, f0[0] = 0.0; d < dim; ++d) f0[0] += -n[d]*2.0*x[d];
170 }
171 
172 /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
173 static void f1_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
174                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
175                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
176                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
177 {
178   PetscInt d;
179   for (d = 0; d < dim; ++d) f1[d] = u_x[d];
180 }
181 
182 /* < \nabla v, \nabla u + {\nabla u}^T >
183    This just gives \nabla u, give the perdiagonal for the transpose */
184 static void g3_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
185                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
186                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
187                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
188 {
189   PetscInt d;
190   for (d = 0; d < dim; ++d) g3[d*dim+d] = 1.0;
191 }
192 
193 /*
194   In 2D for x periodicity and y Dirichlet conditions, we use exact solution:
195 
196     u = sin(2 pi x)
197     f = -4 pi^2 sin(2 pi x)
198 
199   so that
200 
201     -\Delta u + f = 4 pi^2 sin(2 pi x) - 4 pi^2 sin(2 pi x) = 0
202 */
203 static PetscErrorCode xtrig_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
204 {
205   *u = PetscSinReal(2.0*PETSC_PI*x[0]);
206   return 0;
207 }
208 
209 static void f0_xtrig_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
210                        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
211                        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212                        PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
213 {
214   f0[0] = -4.0*PetscSqr(PETSC_PI)*PetscSinReal(2.0*PETSC_PI*x[0]);
215 }
216 
217 /*
218   In 2D for x-y periodicity, we use exact solution:
219 
220     u = sin(2 pi x) sin(2 pi y)
221     f = -8 pi^2 sin(2 pi x)
222 
223   so that
224 
225     -\Delta u + f = 4 pi^2 sin(2 pi x) sin(2 pi y) + 4 pi^2 sin(2 pi x) sin(2 pi y) - 8 pi^2 sin(2 pi x) = 0
226 */
227 static PetscErrorCode xytrig_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
228 {
229   *u = PetscSinReal(2.0*PETSC_PI*x[0])*PetscSinReal(2.0*PETSC_PI*x[1]);
230   return 0;
231 }
232 
233 static void f0_xytrig_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
234                         const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
235                         const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236                         PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
237 {
238   f0[0] = -8.0*PetscSqr(PETSC_PI)*PetscSinReal(2.0*PETSC_PI*x[0]);
239 }
240 
241 /*
242   In 2D for Dirichlet conditions with a variable coefficient, we use exact solution:
243 
244     u  = x^2 + y^2
245     f  = 6 (x + y)
246     nu = (x + y)
247 
248   so that
249 
250     -\div \nu \grad u + f = -6 (x + y) + 6 (x + y) = 0
251 */
252 static PetscErrorCode nu_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
253 {
254   *u = x[0] + x[1];
255   return 0;
256 }
257 
258 static PetscErrorCode checkerboardCoeff(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
259 {
260   AppCtx  *user = (AppCtx *) ctx;
261   PetscInt div  = user->div;
262   PetscInt k    = user->k;
263   PetscInt mask = 0, ind = 0, d;
264 
265   PetscFunctionBeginUser;
266   for (d = 0; d < dim; ++d) mask = (mask + (PetscInt) (x[d]*div)) % 2;
267   if (user->kgrid) {
268     for (d = 0; d < dim; ++d) {
269       if (d > 0) ind *= dim;
270       ind += (PetscInt) (x[d]*div);
271     }
272     k = user->kgrid[ind];
273   }
274   u[0] = mask ? 1.0 : PetscPowRealInt(10.0, -k);
275   PetscFunctionReturn(0);
276 }
277 
278 void f0_analytic_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
279                    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
280                    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
281                    PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
282 {
283   f0[0] = 6.0*(x[0] + x[1]);
284 }
285 
286 /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
287 void f1_analytic_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
288                    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
289                    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
290                    PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
291 {
292   PetscInt d;
293   for (d = 0; d < dim; ++d) f1[d] = (x[0] + x[1])*u_x[d];
294 }
295 
296 void f1_field_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
297                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
298                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
299                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
300 {
301   PetscInt d;
302   for (d = 0; d < dim; ++d) f1[d] = a[0]*u_x[d];
303 }
304 
305 /* < \nabla v, \nabla u + {\nabla u}^T >
306    This just gives \nabla u, give the perdiagonal for the transpose */
307 void g3_analytic_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
308                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
309                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
310                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
311 {
312   PetscInt d;
313   for (d = 0; d < dim; ++d) g3[d*dim+d] = x[0] + x[1];
314 }
315 
316 void g3_field_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
317                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
318                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
319                  PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
320 {
321   PetscInt d;
322   for (d = 0; d < dim; ++d) g3[d*dim+d] = a[0];
323 }
324 
325 /*
326   In 2D for Dirichlet conditions with a nonlinear coefficient (p-Laplacian with p = 4), we use exact solution:
327 
328     u  = x^2 + y^2
329     f  = 16 (x^2 + y^2)
330     nu = 1/2 |grad u|^2
331 
332   so that
333 
334     -\div \nu \grad u + f = -16 (x^2 + y^2) + 16 (x^2 + y^2) = 0
335 */
336 void f0_analytic_nonlinear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
337                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
338                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
339                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
340 {
341   f0[0] = 16.0*(x[0]*x[0] + x[1]*x[1]);
342 }
343 
344 /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
345 void f1_analytic_nonlinear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
346                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
347                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
348                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
349 {
350   PetscScalar nu = 0.0;
351   PetscInt    d;
352   for (d = 0; d < dim; ++d) nu += u_x[d]*u_x[d];
353   for (d = 0; d < dim; ++d) f1[d] = 0.5*nu*u_x[d];
354 }
355 
356 /*
357   grad (u + eps w) - grad u = eps grad w
358 
359   1/2 |grad (u + eps w)|^2 grad (u + eps w) - 1/2 |grad u|^2 grad u
360 = 1/2 (|grad u|^2 + 2 eps <grad u,grad w>) (grad u + eps grad w) - 1/2 |grad u|^2 grad u
361 = 1/2 (eps |grad u|^2 grad w + 2 eps <grad u,grad w> grad u)
362 = eps (1/2 |grad u|^2 grad w + grad u <grad u,grad w>)
363 */
364 void g3_analytic_nonlinear_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
365                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
366                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
367                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
368 {
369   PetscScalar nu = 0.0;
370   PetscInt    d, e;
371   for (d = 0; d < dim; ++d) nu += u_x[d]*u_x[d];
372   for (d = 0; d < dim; ++d) {
373     g3[d*dim+d] = 0.5*nu;
374     for (e = 0; e < dim; ++e) {
375       g3[d*dim+e] += u_x[d]*u_x[e];
376     }
377   }
378 }
379 
380 /*
381   In 3D for Dirichlet conditions we use exact solution:
382 
383     u = 2/3 (x^2 + y^2 + z^2)
384     f = 4
385 
386   so that
387 
388     -\Delta u + f = -2/3 * 6 + 4 = 0
389 
390   For Neumann conditions, we have
391 
392     -\nabla u \cdot -\hat z |_{z=0} =  (2z)|_{z=0} =  0 (bottom)
393     -\nabla u \cdot  \hat z |_{z=1} = -(2z)|_{z=1} = -2 (top)
394     -\nabla u \cdot -\hat y |_{y=0} =  (2y)|_{y=0} =  0 (front)
395     -\nabla u \cdot  \hat y |_{y=1} = -(2y)|_{y=1} = -2 (back)
396     -\nabla u \cdot -\hat x |_{x=0} =  (2x)|_{x=0} =  0 (left)
397     -\nabla u \cdot  \hat x |_{x=1} = -(2x)|_{x=1} = -2 (right)
398 
399   Which we can express as
400 
401     \nabla u \cdot  \hat n|_\Gamma = {2 x, 2 y, 2z} \cdot \hat n = 2 (x + y + z)
402 */
403 static PetscErrorCode quadratic_u_3d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
404 {
405   *u = 2.0*(x[0]*x[0] + x[1]*x[1] + x[2]*x[2])/3.0;
406   return 0;
407 }
408 
409 static PetscErrorCode ball_u_3d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
410 {
411   const PetscReal alpha   = 500.;
412   const PetscReal radius2 = PetscSqr(0.15);
413   const PetscReal r2      = PetscSqr(x[0] - 0.5) + PetscSqr(x[1] - 0.5) + PetscSqr(x[2] - 0.5);
414   const PetscReal xi      = alpha*(radius2 - r2);
415 
416   *u = PetscTanhScalar(xi) + 1.0;
417   return 0;
418 }
419 
420 static void quadratic_u_field_3d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
421                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
422                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
423                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uexact[])
424 {
425   uexact[0] = a[0];
426 }
427 
428 static PetscErrorCode cross_u_3d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
429 {
430   const PetscReal alpha = 50*4;
431   const PetscReal xyz   = (x[0]-0.5)*(x[1]-0.5)*(x[2]-0.5);
432 
433   *u = PetscSinReal(alpha*xyz) * (alpha*PetscAbsReal(xyz) < 2*PETSC_PI ? (alpha*PetscAbsReal(xyz) > -2*PETSC_PI ? 1.0 : 0.01) : 0.01);
434   return 0;
435 }
436 
437 static void f0_cross_u_3d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
438                           const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
439                           const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
440                           PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
441 {
442   const PetscReal alpha = 50*4;
443   const PetscReal xyz   = (x[0]-0.5)*(x[1]-0.5)*(x[2]-0.5);
444 
445   f0[0] = PetscSinReal(alpha*xyz) * (alpha*PetscAbsReal(xyz) < 2*PETSC_PI ? (alpha*PetscAbsReal(xyz) > -2*PETSC_PI ? 1.0 : 0.01) : 0.01);
446 }
447 
448 static void bd_integral_2d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
449                            const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
450                            const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
451                            PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar *uint)
452 {
453   uint[0] = u[0];
454 }
455 
456 static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
457 {
458   const char    *bcTypes[3]  = {"neumann", "dirichlet", "none"};
459   const char    *runTypes[4] = {"full", "exact", "test", "perf"};
460   const char    *coeffTypes[8] = {"none", "analytic", "field", "nonlinear", "ball", "cross", "checkerboard_0", "checkerboard_1"};
461   PetscInt       bc, run, coeff;
462 
463   PetscFunctionBeginUser;
464   options->runType             = RUN_FULL;
465   options->bcType              = DIRICHLET;
466   options->variableCoefficient = COEFF_NONE;
467   options->fieldBC             = PETSC_FALSE;
468   options->jacobianMF          = PETSC_FALSE;
469   options->showInitial         = PETSC_FALSE;
470   options->showSolution        = PETSC_FALSE;
471   options->restart             = PETSC_FALSE;
472   options->quiet               = PETSC_FALSE;
473   options->nonzInit            = PETSC_FALSE;
474   options->bdIntegral          = PETSC_FALSE;
475   options->checkksp            = PETSC_FALSE;
476   options->div                 = 4;
477   options->k                   = 1;
478   options->kgrid               = NULL;
479   options->rand                = PETSC_FALSE;
480 
481   PetscOptionsBegin(comm, "", "Poisson Problem Options", "DMPLEX");
482   run  = options->runType;
483   PetscCall(PetscOptionsEList("-run_type", "The run type", "ex12.c", runTypes, 4, runTypes[options->runType], &run, NULL));
484   options->runType = (RunType) run;
485   bc   = options->bcType;
486   PetscCall(PetscOptionsEList("-bc_type","Type of boundary condition","ex12.c",bcTypes,3,bcTypes[options->bcType],&bc,NULL));
487   options->bcType = (BCType) bc;
488   coeff = options->variableCoefficient;
489   PetscCall(PetscOptionsEList("-variable_coefficient","Type of variable coefficent","ex12.c",coeffTypes,8,coeffTypes[options->variableCoefficient],&coeff,NULL));
490   options->variableCoefficient = (CoeffType) coeff;
491 
492   PetscCall(PetscOptionsBool("-field_bc", "Use a field representation for the BC", "ex12.c", options->fieldBC, &options->fieldBC, NULL));
493   PetscCall(PetscOptionsBool("-jacobian_mf", "Calculate the action of the Jacobian on the fly", "ex12.c", options->jacobianMF, &options->jacobianMF, NULL));
494   PetscCall(PetscOptionsBool("-show_initial", "Output the initial guess for verification", "ex12.c", options->showInitial, &options->showInitial, NULL));
495   PetscCall(PetscOptionsBool("-show_solution", "Output the solution for verification", "ex12.c", options->showSolution, &options->showSolution, NULL));
496   PetscCall(PetscOptionsBool("-restart", "Read in the mesh and solution from a file", "ex12.c", options->restart, &options->restart, NULL));
497   PetscCall(PetscOptionsBool("-quiet", "Don't print any vecs", "ex12.c", options->quiet, &options->quiet, NULL));
498   PetscCall(PetscOptionsBool("-nonzero_initial_guess", "nonzero initial guess", "ex12.c", options->nonzInit, &options->nonzInit, NULL));
499   PetscCall(PetscOptionsBool("-bd_integral", "Compute the integral of the solution on the boundary", "ex12.c", options->bdIntegral, &options->bdIntegral, NULL));
500   if (options->runType == RUN_TEST) {
501     PetscCall(PetscOptionsBool("-run_test_check_ksp", "Check solution of KSP", "ex12.c", options->checkksp, &options->checkksp, NULL));
502   }
503   PetscCall(PetscOptionsInt("-div", "The number of division for the checkerboard coefficient", "ex12.c", options->div, &options->div, NULL));
504   PetscCall(PetscOptionsInt("-k", "The exponent for the checkerboard coefficient", "ex12.c", options->k, &options->k, NULL));
505   PetscCall(PetscOptionsBool("-k_random", "Assign random k values to checkerboard", "ex12.c", options->rand, &options->rand, NULL));
506   PetscOptionsEnd();
507   PetscFunctionReturn(0);
508 }
509 
510 static PetscErrorCode CreateBCLabel(DM dm, const char name[])
511 {
512   DM             plex;
513   DMLabel        label;
514 
515   PetscFunctionBeginUser;
516   PetscCall(DMCreateLabel(dm, name));
517   PetscCall(DMGetLabel(dm, name, &label));
518   PetscCall(DMConvert(dm, DMPLEX, &plex));
519   PetscCall(DMPlexMarkBoundaryFaces(plex, 1, label));
520   PetscCall(DMDestroy(&plex));
521   PetscFunctionReturn(0);
522 }
523 
524 static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm)
525 {
526   PetscFunctionBeginUser;
527   PetscCall(DMCreate(comm, dm));
528   PetscCall(DMSetType(*dm, DMPLEX));
529   PetscCall(DMSetFromOptions(*dm));
530   {
531     char      convType[256];
532     PetscBool flg;
533 
534     PetscOptionsBegin(comm, "", "Mesh conversion options", "DMPLEX");
535     PetscCall(PetscOptionsFList("-dm_plex_convert_type","Convert DMPlex to another format","ex12",DMList,DMPLEX,convType,256,&flg));
536     PetscOptionsEnd();
537     if (flg) {
538       DM dmConv;
539 
540       PetscCall(DMConvert(*dm,convType,&dmConv));
541       if (dmConv) {
542         PetscCall(DMDestroy(dm));
543         *dm  = dmConv;
544       }
545       PetscCall(DMSetFromOptions(*dm));
546       PetscCall(DMSetUp(*dm));
547     }
548   }
549   PetscCall(DMViewFromOptions(*dm, NULL, "-dm_view"));
550   if (user->rand) {
551     PetscRandom r;
552     PetscReal   val;
553     PetscInt    dim, N, i;
554 
555     PetscCall(DMGetDimension(*dm, &dim));
556     N    = PetscPowInt(user->div, dim);
557     PetscCall(PetscMalloc1(N, &user->kgrid));
558     PetscCall(PetscRandomCreate(PETSC_COMM_SELF, &r));
559     PetscCall(PetscRandomSetFromOptions(r));
560     PetscCall(PetscRandomSetInterval(r, 0.0, user->k));
561     PetscCall(PetscRandomSetSeed(r, 1973));
562     PetscCall(PetscRandomSeed(r));
563     for (i = 0; i < N; ++i) {
564       PetscCall(PetscRandomGetValueReal(r, &val));
565       user->kgrid[i] = 1 + (PetscInt) val;
566     }
567     PetscCall(PetscRandomDestroy(&r));
568   }
569   PetscFunctionReturn(0);
570 }
571 
572 static PetscErrorCode SetupProblem(DM dm, AppCtx *user)
573 {
574   PetscDS          ds;
575   DMLabel          label;
576   PetscWeakForm    wf;
577   const PetscReal *L;
578   const PetscInt   id = 1;
579   PetscInt         bd, dim;
580 
581   PetscFunctionBeginUser;
582   PetscCall(DMGetDS(dm, &ds));
583   PetscCall(DMGetDimension(dm, &dim));
584   PetscCall(DMGetPeriodicity(dm, NULL, NULL, &L));
585   switch (user->variableCoefficient) {
586   case COEFF_NONE:
587     if (L && L[0]) {
588       if (L && L[1]) {
589         PetscCall(PetscDSSetResidual(ds, 0, f0_xytrig_u, f1_u));
590         PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_uu));
591       } else {
592         PetscCall(PetscDSSetResidual(ds, 0, f0_xtrig_u,  f1_u));
593         PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_uu));
594       }
595     } else {
596       PetscCall(PetscDSSetResidual(ds, 0, f0_u, f1_u));
597       PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_uu));
598     }
599     break;
600   case COEFF_ANALYTIC:
601     PetscCall(PetscDSSetResidual(ds, 0, f0_analytic_u, f1_analytic_u));
602     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_analytic_uu));
603     break;
604   case COEFF_FIELD:
605     PetscCall(PetscDSSetResidual(ds, 0, f0_analytic_u, f1_field_u));
606     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_field_uu));
607     break;
608   case COEFF_NONLINEAR:
609     PetscCall(PetscDSSetResidual(ds, 0, f0_analytic_nonlinear_u, f1_analytic_nonlinear_u));
610     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_analytic_nonlinear_uu));
611     break;
612   case COEFF_BALL:
613     PetscCall(PetscDSSetResidual(ds, 0, f0_ball_u, f1_u));
614     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_uu));
615     break;
616   case COEFF_CROSS:
617     switch (dim) {
618     case 2:
619       PetscCall(PetscDSSetResidual(ds, 0, f0_cross_u_2d, f1_u));
620       break;
621     case 3:
622       PetscCall(PetscDSSetResidual(ds, 0, f0_cross_u_3d, f1_u));
623       break;
624     default:
625       SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %" PetscInt_FMT, dim);
626     }
627     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_uu));
628     break;
629   case COEFF_CHECKERBOARD_0:
630     PetscCall(PetscDSSetResidual(ds, 0, f0_checkerboard_0_u, f1_field_u));
631     PetscCall(PetscDSSetJacobian(ds, 0, 0, NULL, NULL, NULL, g3_field_uu));
632     break;
633   default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid variable coefficient type %d", user->variableCoefficient);
634   }
635   switch (dim) {
636   case 2:
637     switch (user->variableCoefficient) {
638     case COEFF_BALL:
639       user->exactFuncs[0]  = ball_u_2d;break;
640     case COEFF_CROSS:
641       user->exactFuncs[0]  = cross_u_2d;break;
642     case COEFF_CHECKERBOARD_0:
643       user->exactFuncs[0]  = zero;break;
644     default:
645       if (L && L[0]) {
646         if (L && L[1]) {
647           user->exactFuncs[0] = xytrig_u_2d;
648         } else {
649           user->exactFuncs[0] = xtrig_u_2d;
650         }
651       } else {
652         user->exactFuncs[0]  = quadratic_u_2d;
653         user->exactFields[0] = quadratic_u_field_2d;
654       }
655     }
656     if (user->bcType == NEUMANN) {
657       PetscCall(DMGetLabel(dm, "boundary", &label));
658       PetscCall(DMAddBoundary(dm, DM_BC_NATURAL, "wall", label, 1, &id, 0, 0, NULL, NULL, NULL, user, &bd));
659       PetscCall(PetscDSGetBoundary(ds, bd, &wf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
660       PetscCall(PetscWeakFormSetIndexBdResidual(wf, label, id, 0, 0, 0, f0_bd_u, 0, NULL));
661     }
662     break;
663   case 3:
664     switch (user->variableCoefficient) {
665     case COEFF_BALL:
666       user->exactFuncs[0]  = ball_u_3d;break;
667     case COEFF_CROSS:
668       user->exactFuncs[0]  = cross_u_3d;break;
669     default:
670       user->exactFuncs[0]  = quadratic_u_3d;
671       user->exactFields[0] = quadratic_u_field_3d;
672     }
673     if (user->bcType == NEUMANN) {
674       PetscCall(DMGetLabel(dm, "boundary", &label));
675       PetscCall(DMAddBoundary(dm, DM_BC_NATURAL, "wall", label, 1, &id, 0, 0, NULL, NULL, NULL, user, &bd));
676       PetscCall(PetscDSGetBoundary(ds, bd, &wf, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
677       PetscCall(PetscWeakFormSetIndexBdResidual(wf, label, id, 0, 0, 0, f0_bd_u, 0, NULL));
678     }
679     break;
680   default:
681     SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %" PetscInt_FMT, dim);
682   }
683   /* Setup constants */
684   switch (user->variableCoefficient) {
685   case COEFF_CHECKERBOARD_0:
686   {
687     PetscScalar constants[2];
688 
689     constants[0] = user->div;
690     constants[1] = user->k;
691     PetscCall(PetscDSSetConstants(ds, 2, constants));
692   }
693   break;
694   default: break;
695   }
696   PetscCall(PetscDSSetExactSolution(ds, 0, user->exactFuncs[0], user));
697   /* Setup Boundary Conditions */
698   if (user->bcType == DIRICHLET) {
699     PetscCall(DMGetLabel(dm, "marker", &label));
700     if (!label) {
701       /* Right now, p4est cannot create labels immediately */
702       PetscCall(PetscDSAddBoundaryByName(ds, user->fieldBC ? DM_BC_ESSENTIAL_FIELD : DM_BC_ESSENTIAL, "wall", "marker", 1, &id, 0, 0, NULL, user->fieldBC ? (void (*)(void)) user->exactFields[0] : (void (*)(void)) user->exactFuncs[0], NULL, user, NULL));
703     } else {
704       PetscCall(DMAddBoundary(dm, user->fieldBC ? DM_BC_ESSENTIAL_FIELD : DM_BC_ESSENTIAL, "wall", label, 1, &id, 0, 0, NULL, user->fieldBC ? (void (*)(void)) user->exactFields[0] : (void (*)(void)) user->exactFuncs[0], NULL, user, NULL));
705     }
706   }
707   PetscFunctionReturn(0);
708 }
709 
710 static PetscErrorCode SetupMaterial(DM dm, DM dmAux, AppCtx *user)
711 {
712   PetscErrorCode (*matFuncs[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) = {nu_2d};
713   void            *ctx[1];
714   Vec              nu;
715 
716   PetscFunctionBegin;
717   ctx[0] = user;
718   if (user->variableCoefficient == COEFF_CHECKERBOARD_0) {matFuncs[0] = checkerboardCoeff;}
719   PetscCall(DMCreateLocalVector(dmAux, &nu));
720   PetscCall(PetscObjectSetName((PetscObject) nu, "Coefficient"));
721   PetscCall(DMProjectFunctionLocal(dmAux, 0.0, matFuncs, ctx, INSERT_ALL_VALUES, nu));
722   PetscCall(DMSetAuxiliaryVec(dm, NULL, 0, 0, nu));
723   PetscCall(VecDestroy(&nu));
724   PetscFunctionReturn(0);
725 }
726 
727 static PetscErrorCode SetupBC(DM dm, DM dmAux, AppCtx *user)
728 {
729   PetscErrorCode (*bcFuncs[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx);
730   Vec            uexact;
731   PetscInt       dim;
732 
733   PetscFunctionBegin;
734   PetscCall(DMGetDimension(dm, &dim));
735   if (dim == 2) bcFuncs[0] = quadratic_u_2d;
736   else          bcFuncs[0] = quadratic_u_3d;
737   PetscCall(DMCreateLocalVector(dmAux, &uexact));
738   PetscCall(DMProjectFunctionLocal(dmAux, 0.0, bcFuncs, NULL, INSERT_ALL_VALUES, uexact));
739   PetscCall(DMSetAuxiliaryVec(dm, NULL, 0, 0, uexact));
740   PetscCall(VecDestroy(&uexact));
741   PetscFunctionReturn(0);
742 }
743 
744 static PetscErrorCode SetupAuxDM(DM dm, PetscFE feAux, AppCtx *user)
745 {
746   DM             dmAux, coordDM;
747 
748   PetscFunctionBegin;
749   /* MUST call DMGetCoordinateDM() in order to get p4est setup if present */
750   PetscCall(DMGetCoordinateDM(dm, &coordDM));
751   if (!feAux) PetscFunctionReturn(0);
752   PetscCall(DMClone(dm, &dmAux));
753   PetscCall(DMSetCoordinateDM(dmAux, coordDM));
754   PetscCall(DMSetField(dmAux, 0, NULL, (PetscObject) feAux));
755   PetscCall(DMCreateDS(dmAux));
756   if (user->fieldBC) PetscCall(SetupBC(dm, dmAux, user));
757   else               PetscCall(SetupMaterial(dm, dmAux, user));
758   PetscCall(DMDestroy(&dmAux));
759   PetscFunctionReturn(0);
760 }
761 
762 static PetscErrorCode SetupDiscretization(DM dm, AppCtx *user)
763 {
764   DM             plex, cdm = dm;
765   PetscFE        fe, feAux = NULL;
766   PetscBool      simplex;
767   PetscInt       dim;
768   MPI_Comm       comm;
769 
770   PetscFunctionBeginUser;
771   PetscCall(DMGetDimension(dm, &dim));
772   PetscCall(DMConvert(dm, DMPLEX, &plex));
773   PetscCall(DMPlexIsSimplex(plex, &simplex));
774   PetscCall(DMDestroy(&plex));
775   PetscCall(PetscObjectGetComm((PetscObject) dm, &comm));
776   PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, 1, simplex, NULL, -1, &fe));
777   PetscCall(PetscObjectSetName((PetscObject) fe, "potential"));
778   if (user->variableCoefficient == COEFF_FIELD || user->variableCoefficient == COEFF_CHECKERBOARD_0) {
779     PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, 1, simplex, "mat_", -1, &feAux));
780     PetscCall(PetscObjectSetName((PetscObject) feAux, "coefficient"));
781     PetscCall(PetscFECopyQuadrature(fe, feAux));
782   } else if (user->fieldBC) {
783     PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, 1, simplex, "bc_", -1, &feAux));
784     PetscCall(PetscFECopyQuadrature(fe, feAux));
785   }
786   /* Set discretization and boundary conditions for each mesh */
787   PetscCall(DMSetField(dm, 0, NULL, (PetscObject) fe));
788   PetscCall(DMCreateDS(dm));
789   PetscCall(SetupProblem(dm, user));
790   while (cdm) {
791     PetscCall(SetupAuxDM(cdm, feAux, user));
792     if (user->bcType == DIRICHLET) {
793       PetscBool hasLabel;
794 
795       PetscCall(DMHasLabel(cdm, "marker", &hasLabel));
796       if (!hasLabel) PetscCall(CreateBCLabel(cdm, "marker"));
797     }
798     PetscCall(DMCopyDisc(dm, cdm));
799     PetscCall(DMGetCoarseDM(cdm, &cdm));
800   }
801   PetscCall(PetscFEDestroy(&fe));
802   PetscCall(PetscFEDestroy(&feAux));
803   PetscFunctionReturn(0);
804 }
805 
806 int main(int argc, char **argv)
807 {
808   DM             dm;          /* Problem specification */
809   SNES           snes;        /* nonlinear solver */
810   Vec            u;           /* solution vector */
811   Mat            A,J;         /* Jacobian matrix */
812   MatNullSpace   nullSpace;   /* May be necessary for Neumann conditions */
813   AppCtx         user;        /* user-defined work context */
814   JacActionCtx   userJ;       /* context for Jacobian MF action */
815   PetscReal      error = 0.0; /* L_2 error in the solution */
816 
817   PetscCall(PetscInitialize(&argc, &argv, NULL,help));
818   PetscCall(ProcessOptions(PETSC_COMM_WORLD, &user));
819   PetscCall(SNESCreate(PETSC_COMM_WORLD, &snes));
820   PetscCall(CreateMesh(PETSC_COMM_WORLD, &user, &dm));
821   PetscCall(SNESSetDM(snes, dm));
822   PetscCall(DMSetApplicationContext(dm, &user));
823 
824   PetscCall(PetscMalloc2(1, &user.exactFuncs, 1, &user.exactFields));
825   PetscCall(SetupDiscretization(dm, &user));
826 
827   PetscCall(DMCreateGlobalVector(dm, &u));
828   PetscCall(PetscObjectSetName((PetscObject) u, "potential"));
829 
830   PetscCall(DMCreateMatrix(dm, &J));
831   if (user.jacobianMF) {
832     PetscInt M, m, N, n;
833 
834     PetscCall(MatGetSize(J, &M, &N));
835     PetscCall(MatGetLocalSize(J, &m, &n));
836     PetscCall(MatCreate(PETSC_COMM_WORLD, &A));
837     PetscCall(MatSetSizes(A, m, n, M, N));
838     PetscCall(MatSetType(A, MATSHELL));
839     PetscCall(MatSetUp(A));
840 #if 0
841     PetscCall(MatShellSetOperation(A, MATOP_MULT, (void (*)(void))FormJacobianAction));
842 #endif
843 
844     userJ.dm   = dm;
845     userJ.J    = J;
846     userJ.user = &user;
847 
848     PetscCall(DMCreateLocalVector(dm, &userJ.u));
849     if (user.fieldBC) PetscCall(DMProjectFieldLocal(dm, 0.0, userJ.u, user.exactFields, INSERT_BC_VALUES, userJ.u));
850     else              PetscCall(DMProjectFunctionLocal(dm, 0.0, user.exactFuncs, NULL, INSERT_BC_VALUES, userJ.u));
851     PetscCall(MatShellSetContext(A, &userJ));
852   } else {
853     A = J;
854   }
855 
856   nullSpace = NULL;
857   if (user.bcType != DIRICHLET) {
858     PetscCall(MatNullSpaceCreate(PetscObjectComm((PetscObject) dm), PETSC_TRUE, 0, NULL, &nullSpace));
859     PetscCall(MatSetNullSpace(A, nullSpace));
860   }
861 
862   PetscCall(DMPlexSetSNESLocalFEM(dm,&user,&user,&user));
863   PetscCall(SNESSetJacobian(snes, A, J, NULL, NULL));
864 
865   PetscCall(SNESSetFromOptions(snes));
866 
867   if (user.fieldBC) PetscCall(DMProjectField(dm, 0.0, u, user.exactFields, INSERT_ALL_VALUES, u));
868   else              PetscCall(DMProjectFunction(dm, 0.0, user.exactFuncs, NULL, INSERT_ALL_VALUES, u));
869   if (user.restart) {
870 #if defined(PETSC_HAVE_HDF5)
871     PetscViewer viewer;
872     char        filename[PETSC_MAX_PATH_LEN];
873 
874     PetscCall(PetscOptionsGetString(NULL, NULL, "-dm_plex_filename", filename, sizeof(filename), NULL));
875     PetscCall(PetscViewerCreate(PETSC_COMM_WORLD, &viewer));
876     PetscCall(PetscViewerSetType(viewer, PETSCVIEWERHDF5));
877     PetscCall(PetscViewerFileSetMode(viewer, FILE_MODE_READ));
878     PetscCall(PetscViewerFileSetName(viewer, filename));
879     PetscCall(PetscViewerHDF5PushGroup(viewer, "/fields"));
880     PetscCall(VecLoad(u, viewer));
881     PetscCall(PetscViewerHDF5PopGroup(viewer));
882     PetscCall(PetscViewerDestroy(&viewer));
883 #endif
884   }
885   if (user.showInitial) {
886     Vec lv;
887     PetscCall(DMGetLocalVector(dm, &lv));
888     PetscCall(DMGlobalToLocalBegin(dm, u, INSERT_VALUES, lv));
889     PetscCall(DMGlobalToLocalEnd(dm, u, INSERT_VALUES, lv));
890     PetscCall(DMPrintLocalVec(dm, "Local function", 1.0e-10, lv));
891     PetscCall(DMRestoreLocalVector(dm, &lv));
892   }
893   if (user.runType == RUN_FULL || user.runType == RUN_EXACT) {
894     PetscErrorCode (*initialGuess[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) = {zero};
895 
896     if (user.nonzInit) initialGuess[0] = ecks;
897     if (user.runType == RUN_FULL) {
898       PetscCall(DMProjectFunction(dm, 0.0, initialGuess, NULL, INSERT_VALUES, u));
899     }
900     PetscCall(VecViewFromOptions(u, NULL, "-guess_vec_view"));
901     PetscCall(SNESSolve(snes, NULL, u));
902     PetscCall(SNESGetSolution(snes, &u));
903     PetscCall(SNESGetDM(snes, &dm));
904 
905     if (user.showSolution) {
906       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Solution\n"));
907       PetscCall(VecChop(u, 3.0e-9));
908       PetscCall(VecView(u, PETSC_VIEWER_STDOUT_WORLD));
909     }
910   } else if (user.runType == RUN_PERF) {
911     Vec       r;
912     PetscReal res = 0.0;
913 
914     PetscCall(SNESGetFunction(snes, &r, NULL, NULL));
915     PetscCall(SNESComputeFunction(snes, u, r));
916     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Initial Residual\n"));
917     PetscCall(VecChop(r, 1.0e-10));
918     PetscCall(VecNorm(r, NORM_2, &res));
919     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "L_2 Residual: %g\n", (double)res));
920   } else {
921     Vec       r;
922     PetscReal res = 0.0, tol = 1.0e-11;
923 
924     /* Check discretization error */
925     PetscCall(SNESGetFunction(snes, &r, NULL, NULL));
926     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Initial guess\n"));
927     if (!user.quiet) PetscCall(VecView(u, PETSC_VIEWER_STDOUT_WORLD));
928     PetscCall(DMComputeL2Diff(dm, 0.0, user.exactFuncs, NULL, u, &error));
929     if (error < tol) PetscCall(PetscPrintf(PETSC_COMM_WORLD, "L_2 Error: < %2.1e\n", (double)tol));
930     else             PetscCall(PetscPrintf(PETSC_COMM_WORLD, "L_2 Error: %g\n", (double)error));
931     /* Check residual */
932     PetscCall(SNESComputeFunction(snes, u, r));
933     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Initial Residual\n"));
934     PetscCall(VecChop(r, 1.0e-10));
935     if (!user.quiet) PetscCall(VecView(r, PETSC_VIEWER_STDOUT_WORLD));
936     PetscCall(VecNorm(r, NORM_2, &res));
937     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "L_2 Residual: %g\n", (double)res));
938     /* Check Jacobian */
939     {
940       Vec b;
941 
942       PetscCall(SNESComputeJacobian(snes, u, A, A));
943       PetscCall(VecDuplicate(u, &b));
944       PetscCall(VecSet(r, 0.0));
945       PetscCall(SNESComputeFunction(snes, r, b));
946       PetscCall(MatMult(A, u, r));
947       PetscCall(VecAXPY(r, 1.0, b));
948       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Au - b = Au + F(0)\n"));
949       PetscCall(VecChop(r, 1.0e-10));
950       if (!user.quiet) PetscCall(VecView(r, PETSC_VIEWER_STDOUT_WORLD));
951       PetscCall(VecNorm(r, NORM_2, &res));
952       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Linear L_2 Residual: %g\n", (double)res));
953       /* check solver */
954       if (user.checkksp) {
955         KSP ksp;
956 
957         if (nullSpace) PetscCall(MatNullSpaceRemove(nullSpace, u));
958         PetscCall(SNESComputeJacobian(snes, u, A, J));
959         PetscCall(MatMult(A, u, b));
960         PetscCall(SNESGetKSP(snes, &ksp));
961         PetscCall(KSPSetOperators(ksp, A, J));
962         PetscCall(KSPSolve(ksp, b, r));
963         PetscCall(VecAXPY(r, -1.0, u));
964         PetscCall(VecNorm(r, NORM_2, &res));
965         PetscCall(PetscPrintf(PETSC_COMM_WORLD, "KSP Error: %g\n", (double)res));
966       }
967       PetscCall(VecDestroy(&b));
968     }
969   }
970   PetscCall(VecViewFromOptions(u, NULL, "-vec_view"));
971   {
972     Vec nu;
973 
974     PetscCall(DMGetAuxiliaryVec(dm, NULL, 0, 0, &nu));
975     if (nu) PetscCall(VecViewFromOptions(nu, NULL, "-coeff_view"));
976   }
977 
978   if (user.bdIntegral) {
979     DMLabel   label;
980     PetscInt  id = 1;
981     PetscScalar bdInt = 0.0;
982     PetscReal   exact = 3.3333333333;
983 
984     PetscCall(DMGetLabel(dm, "marker", &label));
985     PetscCall(DMPlexComputeBdIntegral(dm, u, label, 1, &id, bd_integral_2d, &bdInt, NULL));
986     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Solution boundary integral: %.4g\n", (double) PetscAbsScalar(bdInt)));
987     PetscCheck(PetscAbsReal(PetscAbsScalar(bdInt) - exact) <= PETSC_SQRT_MACHINE_EPSILON,PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Invalid boundary integral %g != %g", (double) PetscAbsScalar(bdInt), (double)exact);
988   }
989 
990   PetscCall(MatNullSpaceDestroy(&nullSpace));
991   if (user.jacobianMF) PetscCall(VecDestroy(&userJ.u));
992   if (A != J) PetscCall(MatDestroy(&A));
993   PetscCall(MatDestroy(&J));
994   PetscCall(VecDestroy(&u));
995   PetscCall(SNESDestroy(&snes));
996   PetscCall(DMDestroy(&dm));
997   PetscCall(PetscFree2(user.exactFuncs, user.exactFields));
998   PetscCall(PetscFree(user.kgrid));
999   PetscCall(PetscFinalize());
1000   return 0;
1001 }
1002 
1003 /*TEST
1004   # 2D serial P1 test 0-4
1005   test:
1006     suffix: 2d_p1_0
1007     requires: triangle
1008     args: -run_type test -bc_type dirichlet -dm_plex_interpolate 0 -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1009 
1010   test:
1011     suffix: 2d_p1_1
1012     requires: triangle
1013     args: -run_type test -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1014 
1015   test:
1016     suffix: 2d_p1_2
1017     requires: triangle
1018     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1019 
1020   test:
1021     suffix: 2d_p1_neumann_0
1022     requires: triangle
1023     args: -dm_coord_space 0 -run_type test -bc_type neumann -dm_plex_boundary_label boundary -petscspace_degree 1 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail
1024 
1025   test:
1026     suffix: 2d_p1_neumann_1
1027     requires: triangle
1028     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -bc_type neumann -dm_plex_boundary_label boundary -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1029 
1030   # 2D serial P2 test 5-8
1031   test:
1032     suffix: 2d_p2_0
1033     requires: triangle
1034     args: -run_type test -bc_type dirichlet -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1035 
1036   test:
1037     suffix: 2d_p2_1
1038     requires: triangle
1039     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -bc_type dirichlet -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1040 
1041   test:
1042     suffix: 2d_p2_neumann_0
1043     requires: triangle
1044     args: -dm_coord_space 0 -run_type test -bc_type neumann -dm_plex_boundary_label boundary -petscspace_degree 2 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail
1045 
1046   test:
1047     suffix: 2d_p2_neumann_1
1048     requires: triangle
1049     args: -dm_coord_space 0 -run_type test -dm_refine_volume_limit_pre 0.0625 -bc_type neumann -dm_plex_boundary_label boundary -petscspace_degree 2 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail
1050 
1051   test:
1052     suffix: bd_int_0
1053     requires: triangle
1054     args: -run_type test -bc_type dirichlet -petscspace_degree 2 -bd_integral -dm_view -quiet
1055 
1056   test:
1057     suffix: bd_int_1
1058     requires: triangle
1059     args: -run_type test -dm_refine 2 -bc_type dirichlet -petscspace_degree 2 -bd_integral -dm_view -quiet
1060 
1061   # 3D serial P1 test 9-12
1062   test:
1063     suffix: 3d_p1_0
1064     requires: ctetgen
1065     args: -run_type test -dm_plex_dim 3 -bc_type dirichlet -dm_plex_interpolate 0 -petscspace_degree 1 -show_initial -dm_plex_print_fem 1 -dm_view
1066 
1067   test:
1068     suffix: 3d_p1_1
1069     requires: ctetgen
1070     args: -run_type test -dm_plex_dim 3 -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1 -dm_view
1071 
1072   test:
1073     suffix: 3d_p1_2
1074     requires: ctetgen
1075     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1 -dm_view
1076 
1077   test:
1078     suffix: 3d_p1_neumann_0
1079     requires: ctetgen
1080     args: -run_type test -dm_plex_dim 3 -bc_type neumann -dm_plex_boundary_label boundary -petscspace_degree 1 -snes_fd -show_initial -dm_plex_print_fem 1 -dm_view
1081 
1082   # Analytic variable coefficient 13-20
1083   test:
1084     suffix: 13
1085     requires: triangle
1086     args: -run_type test -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1087   test:
1088     suffix: 14
1089     requires: triangle
1090     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1091   test:
1092     suffix: 15
1093     requires: triangle
1094     args: -run_type test -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1095   test:
1096     suffix: 16
1097     requires: triangle
1098     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1099   test:
1100     suffix: 17
1101     requires: ctetgen
1102     args: -run_type test -dm_plex_dim 3 -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1103 
1104   test:
1105     suffix: 18
1106     requires: ctetgen
1107     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1108 
1109   test:
1110     suffix: 19
1111     requires: ctetgen
1112     args: -run_type test -dm_plex_dim 3 -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1113 
1114   test:
1115     suffix: 20
1116     requires: ctetgen
1117     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1118 
1119   # P1 variable coefficient 21-28
1120   test:
1121     suffix: 21
1122     requires: triangle
1123     args: -run_type test -variable_coefficient field -petscspace_degree 1 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1124 
1125   test:
1126     suffix: 22
1127     requires: triangle
1128     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient field -petscspace_degree 1 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1129 
1130   test:
1131     suffix: 23
1132     requires: triangle
1133     args: -run_type test -variable_coefficient field -petscspace_degree 2 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1134 
1135   test:
1136     suffix: 24
1137     requires: triangle
1138     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient field -petscspace_degree 2 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1139 
1140   test:
1141     suffix: 25
1142     requires: ctetgen
1143     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 1 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1144 
1145   test:
1146     suffix: 26
1147     requires: ctetgen
1148     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient field -petscspace_degree 1 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1149 
1150   test:
1151     suffix: 27
1152     requires: ctetgen
1153     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 2 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1154 
1155   test:
1156     suffix: 28
1157     requires: ctetgen
1158     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient field -petscspace_degree 2 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1159 
1160   # P0 variable coefficient 29-36
1161   test:
1162     suffix: 29
1163     requires: triangle
1164     args: -run_type test -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1165 
1166   test:
1167     suffix: 30
1168     requires: triangle
1169     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1170 
1171   test:
1172     suffix: 31
1173     requires: triangle
1174     args: -run_type test -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1175 
1176   test:
1177     requires: triangle
1178     suffix: 32
1179     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1180 
1181   test:
1182     requires: ctetgen
1183     suffix: 33
1184     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1185 
1186   test:
1187     suffix: 34
1188     requires: ctetgen
1189     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1190 
1191   test:
1192     suffix: 35
1193     requires: ctetgen
1194     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1195 
1196   test:
1197     suffix: 36
1198     requires: ctetgen
1199     args: -run_type test -dm_plex_dim 3 -dm_refine_volume_limit_pre 0.0125 -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1200 
1201   # Full solve 39-44
1202   test:
1203     suffix: 39
1204     requires: triangle !single
1205     args: -run_type full -dm_refine_volume_limit_pre 0.015625 -petscspace_degree 2 -pc_type gamg -pc_gamg_esteig_ksp_type cg -pc_gamg_esteig_ksp_max_it 10 -snes_rtol 1.0e-6 -ksp_rtol 1.0e-7 -ksp_monitor -ksp_converged_reason -snes_monitor_short -snes_converged_reason ::ascii_info_detail
1206   test:
1207     suffix: 40
1208     requires: triangle !single
1209     args: -run_type full -dm_refine_volume_limit_pre 0.015625 -variable_coefficient nonlinear -petscspace_degree 2 -pc_type svd -ksp_rtol 1.0e-10 -snes_monitor_short -snes_converged_reason ::ascii_info_detail
1210   test:
1211     suffix: 41
1212     requires: triangle !single
1213     args: -run_type full -dm_refine_volume_limit_pre 0.03125 -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 2 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 1 -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short
1214   test:
1215     suffix: 42
1216     requires: triangle !single
1217     args: -run_type full -dm_refine_volume_limit_pre 0.0625 -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 2 -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short -fas_levels_2_snes_type newtonls -fas_levels_2_pc_type svd -fas_levels_2_ksp_rtol 1.0e-10 -fas_levels_2_snes_atol 1.0e-11 -fas_levels_2_snes_monitor_short
1218   test:
1219     suffix: 43
1220     requires: triangle !single
1221     nsize: 2
1222     args: -run_type full -dm_refine_volume_limit_pre 0.03125 -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 2 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 1 -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short
1223 
1224   test:
1225     suffix: 44
1226     requires: triangle !single
1227     nsize: 2
1228     args: -run_type full -dm_refine_volume_limit_pre 0.0625 -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short  -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 2 -dm_plex_print_fem 0 -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short -fas_levels_2_snes_type newtonls -fas_levels_2_pc_type svd -fas_levels_2_ksp_rtol 1.0e-10 -fas_levels_2_snes_atol 1.0e-11 -fas_levels_2_snes_monitor_short
1229 
1230   # These tests use a loose tolerance just to exercise the PtAP operations for MATIS and multiple PCBDDC setup calls inside PCMG
1231   testset:
1232     requires: triangle !single
1233     nsize: 3
1234     args: -run_type full -petscspace_degree 1 -dm_mat_type is -pc_type mg -mg_coarse_pc_type bddc -pc_mg_galerkin pmat -ksp_rtol 1.0e-2 -snes_converged_reason -dm_refine_hierarchy 2 -snes_max_it 4
1235     test:
1236       suffix: gmg_bddc
1237       filter: sed -e "s/CONVERGED_FNORM_RELATIVE iterations 3/CONVERGED_FNORM_RELATIVE iterations 4/g"
1238       args: -mg_levels_pc_type jacobi
1239     test:
1240       filter: sed -e "s/iterations [0-4]/iterations 4/g"
1241       suffix: gmg_bddc_lev
1242       args: -mg_levels_pc_type bddc
1243 
1244   # Restarting
1245   testset:
1246     suffix: restart
1247     requires: hdf5 triangle !complex
1248     args: -run_type test -bc_type dirichlet -petscspace_degree 1
1249     test:
1250       args: -dm_view hdf5:sol.h5 -vec_view hdf5:sol.h5::append
1251     test:
1252       args: -dm_plex_filename sol.h5 -dm_plex_name box -restart
1253 
1254   # Periodicity
1255   test:
1256     suffix: periodic_0
1257     requires: triangle
1258     args: -run_type full -bc_type dirichlet -petscspace_degree 1 -snes_converged_reason ::ascii_info_detail
1259 
1260   test:
1261     requires: !complex
1262     suffix: periodic_1
1263     args: -quiet -run_type test -dm_plex_simplex 0 -dm_plex_box_faces 3,3 -dm_plex_box_bd periodic,periodic -vec_view vtk:test.vtu:vtk_vtu -petscspace_degree 1 -dm_refine 1
1264 
1265   # 2D serial P1 test with field bc
1266   test:
1267     suffix: field_bc_2d_p1_0
1268     requires: triangle
1269     args: -run_type test -bc_type dirichlet -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1270 
1271   test:
1272     suffix: field_bc_2d_p1_1
1273     requires: triangle
1274     args: -run_type test -dm_refine 1 -bc_type dirichlet -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1275 
1276   test:
1277     suffix: field_bc_2d_p1_neumann_0
1278     requires: triangle
1279     args: -run_type test -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1280 
1281   test:
1282     suffix: field_bc_2d_p1_neumann_1
1283     requires: triangle
1284     args: -run_type test -dm_refine 1 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1285 
1286   # 3D serial P1 test with field bc
1287   test:
1288     suffix: field_bc_3d_p1_0
1289     requires: ctetgen
1290     args: -run_type test -dm_plex_dim 3 -bc_type dirichlet -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1291 
1292   test:
1293     suffix: field_bc_3d_p1_1
1294     requires: ctetgen
1295     args: -run_type test -dm_plex_dim 3 -dm_refine 1 -bc_type dirichlet -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1296 
1297   test:
1298     suffix: field_bc_3d_p1_neumann_0
1299     requires: ctetgen
1300     args: -run_type test -dm_plex_dim 3 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1301 
1302   test:
1303     suffix: field_bc_3d_p1_neumann_1
1304     requires: ctetgen
1305     args: -run_type test -dm_plex_dim 3 -dm_refine 1 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1306 
1307   # 2D serial P2 test with field bc
1308   test:
1309     suffix: field_bc_2d_p2_0
1310     requires: triangle
1311     args: -run_type test -bc_type dirichlet -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1312 
1313   test:
1314     suffix: field_bc_2d_p2_1
1315     requires: triangle
1316     args: -run_type test -dm_refine 1 -bc_type dirichlet -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1317 
1318   test:
1319     suffix: field_bc_2d_p2_neumann_0
1320     requires: triangle
1321     args: -run_type test -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1322 
1323   test:
1324     suffix: field_bc_2d_p2_neumann_1
1325     requires: triangle
1326     args: -run_type test -dm_refine 1 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1327 
1328   # 3D serial P2 test with field bc
1329   test:
1330     suffix: field_bc_3d_p2_0
1331     requires: ctetgen
1332     args: -run_type test -dm_plex_dim 3 -bc_type dirichlet -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1333 
1334   test:
1335     suffix: field_bc_3d_p2_1
1336     requires: ctetgen
1337     args: -run_type test -dm_plex_dim 3 -dm_refine 1 -bc_type dirichlet -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1338 
1339   test:
1340     suffix: field_bc_3d_p2_neumann_0
1341     requires: ctetgen
1342     args: -run_type test -dm_plex_dim 3 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1343 
1344   test:
1345     suffix: field_bc_3d_p2_neumann_1
1346     requires: ctetgen
1347     args: -run_type test -dm_plex_dim 3 -dm_refine 1 -bc_type neumann -dm_plex_boundary_label boundary -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1348 
1349   # Full solve simplex: Convergence
1350   test:
1351     suffix: 3d_p1_conv
1352     requires: ctetgen
1353     args: -run_type full -dm_plex_dim 3 -dm_refine 1 -bc_type dirichlet -petscspace_degree 1 \
1354       -snes_convergence_estimate -convest_num_refine 1 -pc_type lu
1355 
1356   # Full solve simplex: PCBDDC
1357   test:
1358     suffix: tri_bddc
1359     requires: triangle !single
1360     nsize: 5
1361     args: -run_type full -petscpartitioner_type simple -dm_refine 2 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -dm_mat_type is -pc_type bddc -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1362 
1363   # Full solve simplex: PCBDDC
1364   test:
1365     suffix: tri_parmetis_bddc
1366     requires: triangle !single parmetis
1367     nsize: 4
1368     args: -run_type full -petscpartitioner_type parmetis -dm_refine 2 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -dm_mat_type is -pc_type bddc -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1369 
1370   testset:
1371     args: -run_type full -dm_plex_simplex 0 -dm_plex_box_faces 3,3 -petscpartitioner_type simple -dm_refine 2 -bc_type dirichlet -petscspace_degree 2 -dm_mat_type is -pc_type bddc -ksp_type gmres -snes_monitor_short -ksp_monitor_short -snes_view -petscspace_poly_tensor -pc_bddc_corner_selection -ksp_rtol 1.e-9 -pc_bddc_use_edges 0
1372     nsize: 5
1373     output_file: output/ex12_quad_bddc.out
1374     filter: sed -e "s/aijcusparse/aij/g" -e "s/aijviennacl/aij/g" -e "s/factorization: cusparse/factorization: petsc/g"
1375     test:
1376       requires: !single
1377       suffix: quad_bddc
1378     test:
1379       requires: !single cuda
1380       suffix: quad_bddc_cuda
1381       args: -matis_localmat_type aijcusparse -pc_bddc_dirichlet_pc_factor_mat_solver_type cusparse -pc_bddc_neumann_pc_factor_mat_solver_type cusparse
1382     test:
1383       requires: !single viennacl
1384       suffix: quad_bddc_viennacl
1385       args: -matis_localmat_type aijviennacl
1386 
1387   # Full solve simplex: ASM
1388   test:
1389     suffix: tri_q2q1_asm_lu
1390     requires: triangle !single
1391     args: -run_type full -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -pc_type asm -pc_asm_type restrict -pc_asm_blocks 4 -sub_pc_type lu -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1392 
1393   test:
1394     suffix: tri_q2q1_msm_lu
1395     requires: triangle !single
1396     args: -run_type full -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -pc_type asm -pc_asm_type restrict -pc_asm_local_type multiplicative -pc_asm_blocks 4 -sub_pc_type lu -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1397 
1398   test:
1399     suffix: tri_q2q1_asm_sor
1400     requires: triangle !single
1401     args: -run_type full -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -pc_type asm -pc_asm_type restrict -pc_asm_blocks 4 -sub_pc_type sor -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1402 
1403   test:
1404     suffix: tri_q2q1_msm_sor
1405     requires: triangle !single
1406     args: -run_type full -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -ksp_rtol 1.0e-9 -pc_type asm -pc_asm_type restrict -pc_asm_local_type multiplicative -pc_asm_blocks 4 -sub_pc_type sor -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0
1407 
1408   # Full solve simplex: FAS
1409   test:
1410     suffix: fas_newton_0
1411     requires: triangle !single
1412     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 2 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 1 -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short
1413 
1414   test:
1415     suffix: fas_newton_1
1416     requires: triangle !single
1417     args: -run_type full -dm_refine_hierarchy 3 -petscspace_degree 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type lu -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_snes_linesearch_type basic -fas_levels_ksp_rtol 1.0e-10 -fas_levels_snes_monitor_short
1418     filter: sed -e "s/total number of linear solver iterations=14/total number of linear solver iterations=15/g"
1419 
1420   test:
1421     suffix: fas_ngs_0
1422     requires: triangle !single
1423     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 2 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 1 -snes_view -fas_levels_1_snes_type ngs -fas_levels_1_snes_monitor_short
1424 
1425   # These two tests are broken because DMPlexComputeInjectorFEM() only works for regularly refined meshes
1426   test:
1427     suffix: fas_newton_coarse_0
1428     requires: pragmatic triangle
1429     TODO: broken
1430     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 1 \
1431           -dm_refine 2 -dm_coarsen_hierarchy 1 -dm_plex_hash_location -dm_adaptor pragmatic \
1432           -snes_type fas -snes_fas_levels 2 -snes_converged_reason ::ascii_info_detail -snes_monitor_short -snes_view \
1433             -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -fas_coarse_snes_linesearch_type basic \
1434             -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short
1435 
1436   test:
1437     suffix: mg_newton_coarse_0
1438     requires: triangle pragmatic
1439     TODO: broken
1440     args: -run_type full -petscspace_degree 1 \
1441           -dm_refine 3 -dm_coarsen_hierarchy 3 -dm_plex_hash_location -dm_adaptor pragmatic \
1442           -snes_atol 1.0e-8 -snes_rtol 0.0 -snes_monitor_short -snes_converged_reason ::ascii_info_detail -snes_view \
1443             -ksp_type richardson -ksp_atol 1.0e-8 -ksp_rtol 0.0 -ksp_norm_type unpreconditioned -ksp_monitor_true_residual \
1444               -pc_type mg -pc_mg_levels 4 \
1445               -mg_levels_ksp_type gmres -mg_levels_pc_type ilu -mg_levels_ksp_max_it 10
1446 
1447   # Full solve tensor
1448   test:
1449     suffix: tensor_plex_2d
1450     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_refine_hierarchy 2
1451 
1452   test:
1453     suffix: tensor_p4est_2d
1454     requires: p4est
1455     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_forest_initial_refinement 2 -dm_forest_minimum_refinement 0 -dm_plex_convert_type p4est
1456 
1457   test:
1458     suffix: tensor_plex_3d
1459     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_plex_dim 3 -dm_refine_hierarchy 1 -dm_plex_box_faces 2,2,2
1460 
1461   test:
1462     suffix: tensor_p4est_3d
1463     requires: p4est
1464     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_forest_initial_refinement 1 -dm_forest_minimum_refinement 0 -dm_plex_dim 3 -dm_plex_convert_type p8est -dm_plex_box_faces 2,2,2
1465 
1466   test:
1467     suffix: p4est_test_q2_conformal_serial
1468     requires: p4est
1469     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2
1470 
1471   test:
1472     suffix: p4est_test_q2_conformal_parallel
1473     requires: p4est
1474     nsize: 7
1475     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type simple
1476 
1477   test:
1478     suffix: p4est_test_q2_conformal_parallel_parmetis
1479     requires: parmetis p4est
1480     nsize: 4
1481     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type parmetis
1482 
1483   test:
1484     suffix: p4est_test_q2_nonconformal_serial
1485     requires: p4est
1486     filter: grep -v "CG or CGNE: variant"
1487     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1488 
1489   test:
1490     suffix: p4est_test_q2_nonconformal_parallel
1491     requires: p4est
1492     filter: grep -v "CG or CGNE: variant"
1493     nsize: 7
1494     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple
1495 
1496   test:
1497     suffix: p4est_test_q2_nonconformal_parallel_parmetis
1498     requires: parmetis p4est
1499     nsize: 4
1500     args: -run_type test -petscspace_degree 2 -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type parmetis
1501 
1502   test:
1503     suffix: p4est_exact_q2_conformal_serial
1504     requires: p4est !single !complex !__float128
1505     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2
1506 
1507   test:
1508     suffix: p4est_exact_q2_conformal_parallel
1509     requires: p4est !single !complex !__float128
1510     nsize: 4
1511     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2
1512 
1513   test:
1514     suffix: p4est_exact_q2_conformal_parallel_parmetis
1515     requires: parmetis p4est !single
1516     nsize: 4
1517     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type parmetis
1518 
1519   test:
1520     suffix: p4est_exact_q2_nonconformal_serial
1521     requires: p4est
1522     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1523 
1524   test:
1525     suffix: p4est_exact_q2_nonconformal_parallel
1526     requires: p4est
1527     nsize: 7
1528     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple
1529 
1530   test:
1531     suffix: p4est_exact_q2_nonconformal_parallel_parmetis
1532     requires: parmetis p4est
1533     nsize: 4
1534     args: -run_type exact -petscspace_degree 2 -fas_levels_snes_atol 1.e-10 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type none -fas_levels_ksp_type preonly -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type parmetis
1535 
1536   test:
1537     suffix: p4est_full_q2_nonconformal_serial
1538     requires: p4est !single
1539     filter: grep -v "variant HERMITIAN"
1540     args: -run_type full -petscspace_degree 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type jacobi -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type jacobi -fas_levels_ksp_type cg -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1541 
1542   test:
1543     suffix: p4est_full_q2_nonconformal_parallel
1544     requires: p4est !single
1545     filter: grep -v "variant HERMITIAN"
1546     nsize: 7
1547     args: -run_type full -petscspace_degree 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -fas_coarse_pc_type jacobi -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type jacobi -fas_levels_ksp_type cg -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple
1548 
1549   test:
1550     suffix: p4est_full_q2_nonconformal_parallel_bddcfas
1551     requires: p4est !single
1552     filter: grep -v "variant HERMITIAN"
1553     nsize: 7
1554     args: -run_type full -petscspace_degree 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -dm_mat_type is -fas_coarse_pc_type bddc -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type bddc -fas_levels_ksp_type cg -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple
1555 
1556   test:
1557     suffix: p4est_full_q2_nonconformal_parallel_bddc
1558     requires: p4est !single
1559     filter: grep -v "variant HERMITIAN"
1560     nsize: 7
1561     args: -run_type full -petscspace_degree 2 -snes_max_it 20 -snes_type newtonls -dm_mat_type is -pc_type bddc -ksp_type cg -snes_monitor_short -snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple
1562 
1563   test:
1564     TODO: broken
1565     suffix: p4est_fas_q2_conformal_serial
1566     requires: p4est !complex !__float128
1567     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -pc_type jacobi -ksp_type gmres -fas_coarse_pc_type svd -fas_coarse_ksp_type gmres -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type svd -fas_levels_ksp_type gmres -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_refine_hierarchy 3
1568 
1569   test:
1570     TODO: broken
1571     suffix: p4est_fas_q2_nonconformal_serial
1572     requires: p4est
1573     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -pc_type jacobi -ksp_type gmres -fas_coarse_pc_type jacobi -fas_coarse_ksp_type gmres -fas_coarse_ksp_monitor_true_residual -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_snes_type newtonls -fas_levels_pc_type jacobi -fas_levels_ksp_type gmres -fas_levels_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1574 
1575   test:
1576     suffix: fas_newton_0_p4est
1577     requires: p4est !single !__float128
1578     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 1 -snes_type fas -snes_fas_levels 2 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -snes_view -fas_levels_1_snes_type newtonls -fas_levels_1_pc_type svd -fas_levels_1_ksp_rtol 1.0e-10 -fas_levels_1_snes_monitor_short -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1579 
1580   # Full solve simplicial AMR
1581   test:
1582     suffix: tri_p1_adapt_init_pragmatic
1583     requires: pragmatic
1584     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_initial 1 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor pragmatic
1585 
1586   test:
1587     suffix: tri_p2_adapt_init_pragmatic
1588     requires: pragmatic
1589     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_initial 1 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor pragmatic
1590 
1591   test:
1592     suffix: tri_p1_adapt_init_mmg
1593     requires: mmg
1594     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_initial 1 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1595 
1596   test:
1597     suffix: tri_p2_adapt_init_mmg
1598     requires: mmg
1599     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_initial 1 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1600 
1601   test:
1602     suffix: tri_p1_adapt_seq_pragmatic
1603     requires: pragmatic
1604     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_sequence 2 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor pragmatic
1605 
1606   test:
1607     suffix: tri_p2_adapt_seq_pragmatic
1608     requires: pragmatic
1609     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_sequence 2 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor pragmatic
1610 
1611   test:
1612     suffix: tri_p1_adapt_seq_mmg
1613     requires: mmg
1614     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_sequence 2 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1615 
1616   test:
1617     suffix: tri_p2_adapt_seq_mmg
1618     requires: mmg
1619     args: -run_type exact -dm_refine 5 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -snes_adapt_sequence 2 -adaptor_target_num 4000 -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1620 
1621   test:
1622     suffix: tri_p1_adapt_analytic_pragmatic
1623     requires: pragmatic
1624     args: -run_type exact -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient cross -snes_adapt_initial 4 -adaptor_target_num 500 -adaptor_monitor -dm_plex_metric_h_min 0.0001 -dm_plex_metric_h_max 0.05 -dm_adaptor pragmatic
1625 
1626   test:
1627     suffix: tri_p2_adapt_analytic_pragmatic
1628     requires: pragmatic
1629     args: -run_type exact -dm_refine 3 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient cross -snes_adapt_initial 4 -adaptor_target_num 500 -adaptor_monitor -dm_plex_metric_h_min 0.0001 -dm_plex_metric_h_max 0.05 -dm_adaptor pragmatic
1630 
1631   test:
1632     suffix: tri_p1_adapt_analytic_mmg
1633     requires: mmg
1634     args: -run_type exact -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient cross -snes_adapt_initial 4 -adaptor_target_num 500 -adaptor_monitor -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1635 
1636   test:
1637     suffix: tri_p2_adapt_analytic_mmg
1638     requires: mmg
1639     args: -run_type exact -dm_refine 3 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient cross -snes_adapt_initial 4 -adaptor_target_num 500 -adaptor_monitor -dm_plex_metric_h_max 0.5 -dm_adaptor mmg
1640 
1641   test:
1642     suffix: tri_p1_adapt_uniform_pragmatic
1643     requires: pragmatic tetgen
1644     nsize: 2
1645     args: -run_type full -dm_plex_box_faces 8,8,8 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 3 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor pragmatic
1646     timeoutfactor: 2
1647 
1648   test:
1649     suffix: tri_p2_adapt_uniform_pragmatic
1650     requires: pragmatic tetgen
1651     nsize: 2
1652     args: -run_type full -dm_plex_box_faces 8,8,8 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 1 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor pragmatic
1653     timeoutfactor: 1
1654 
1655   test:
1656     suffix: tri_p1_adapt_uniform_mmg
1657     requires: mmg tetgen
1658     args: -run_type full -dm_plex_box_faces 4,4,4 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 3 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor mmg
1659     timeoutfactor: 2
1660 
1661   test:
1662     suffix: tri_p2_adapt_uniform_mmg
1663     requires: mmg tetgen
1664     args: -run_type full -dm_plex_box_faces 4,4,4 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 1 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor mmg
1665     timeoutfactor: 1
1666 
1667   test:
1668     suffix: tri_p1_adapt_uniform_parmmg
1669     requires: parmmg tetgen
1670     nsize: 2
1671     args: -run_type full -dm_plex_box_faces 8,8,8 -bc_type dirichlet -petscspace_degree 1 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 3 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor parmmg
1672     timeoutfactor: 2
1673 
1674   test:
1675     suffix: tri_p2_adapt_uniform_parmmg
1676     requires: parmmg tetgen
1677     nsize: 2
1678     args: -run_type full -dm_plex_box_faces 8,8,8 -bc_type dirichlet -petscspace_degree 2 -variable_coefficient none -snes_converged_reason ::ascii_info_detail -ksp_type cg -pc_type sor -snes_adapt_sequence 1 -adaptor_target_num 400 -dm_plex_metric_h_max 0.5 -dm_plex_dim 3 -dm_adaptor parmmg
1679     timeoutfactor: 1
1680 
1681   # Full solve tensor AMR
1682   test:
1683     suffix: quad_q1_adapt_0
1684     requires: p4est
1685     args: -run_type exact -dm_plex_simplex 0 -dm_plex_convert_type p4est -bc_type dirichlet -petscspace_degree 1 -variable_coefficient ball -snes_converged_reason ::ascii_info_detail -pc_type lu -dm_forest_initial_refinement 4 -snes_adapt_initial 1 -dm_view
1686     filter: grep -v DM_
1687 
1688   test:
1689     suffix: amr_0
1690     nsize: 5
1691     args: -run_type test -petscpartitioner_type simple -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_refine 1
1692 
1693   test:
1694     suffix: amr_1
1695     requires: p4est !complex
1696     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_plex_convert_type p4est -dm_p4est_refine_pattern center -dm_forest_maximum_refinement 5 -dm_view vtk:amr.vtu:vtk_vtu -vec_view vtk:amr.vtu:vtk_vtu:append
1697 
1698   test:
1699     suffix: p4est_solve_bddc
1700     requires: p4est !complex
1701     args: -run_type full -variable_coefficient nonlinear -nonzero_initial_guess 1 -petscspace_degree 2 -snes_max_it 20 -snes_type newtonls -dm_mat_type is -pc_type bddc -ksp_type cg -snes_monitor_short -ksp_monitor -snes_linesearch_type bt -snes_converged_reason -snes_view -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -petscpartitioner_type simple -pc_bddc_detect_disconnected
1702     nsize: 4
1703 
1704   test:
1705     suffix: p4est_solve_fas
1706     requires: p4est
1707     args: -run_type full -variable_coefficient nonlinear -nonzero_initial_guess 1 -petscspace_degree 2 -snes_max_it 10 -snes_type fas -snes_linesearch_type bt -snes_fas_levels 3 -fas_coarse_snes_type newtonls -fas_coarse_snes_linesearch_type basic -fas_coarse_ksp_type cg -fas_coarse_pc_type jacobi -fas_coarse_snes_monitor_short -fas_levels_snes_max_it 4 -fas_levels_snes_type newtonls -fas_levels_snes_linesearch_type bt -fas_levels_ksp_type cg -fas_levels_pc_type jacobi -fas_levels_snes_monitor_short -fas_levels_cycle_snes_linesearch_type bt -snes_monitor_short -snes_converged_reason -snes_view -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1708     nsize: 4
1709     TODO: identical machine two runs produce slightly different solver trackers
1710 
1711   test:
1712     suffix: p4est_convergence_test_1
1713     requires: p4est
1714     args:  -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 2 -dm_forest_initial_refinement 2 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash
1715     nsize: 4
1716 
1717   test:
1718     suffix: p4est_convergence_test_2
1719     requires: p4est
1720     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 3 -dm_forest_initial_refinement 3 -dm_forest_maximum_refinement 5 -dm_p4est_refine_pattern hash
1721 
1722   test:
1723     suffix: p4est_convergence_test_3
1724     requires: p4est
1725     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 4 -dm_forest_initial_refinement 4 -dm_forest_maximum_refinement 6 -dm_p4est_refine_pattern hash
1726 
1727   test:
1728     suffix: p4est_convergence_test_4
1729     requires: p4est
1730     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 5 -dm_forest_initial_refinement 5 -dm_forest_maximum_refinement 7 -dm_p4est_refine_pattern hash
1731     timeoutfactor: 5
1732 
1733   # Serial tests with GLVis visualization
1734   test:
1735     suffix: glvis_2d_tet_p1
1736     args: -quiet -run_type test -bc_type dirichlet -petscspace_degree 1 -vec_view glvis: -dm_plex_filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh -dm_plex_boundary_label marker -dm_plex_gmsh_periodic 0 -dm_coord_space 0
1737   test:
1738     suffix: glvis_2d_tet_p2
1739     args: -quiet -run_type test -bc_type dirichlet -petscspace_degree 2 -vec_view glvis: -dm_plex_filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh -dm_plex_boundary_label marker -dm_plex_gmsh_periodic 0 -dm_coord_space 0
1740   test:
1741     suffix: glvis_2d_hex_p1
1742     args: -quiet -run_type test -bc_type dirichlet -petscspace_degree 1 -vec_view glvis: -dm_plex_simplex 0 -dm_refine 1 -dm_coord_space 0
1743   test:
1744     suffix: glvis_2d_hex_p2
1745     args: -quiet -run_type test -bc_type dirichlet -petscspace_degree 2 -vec_view glvis: -dm_plex_simplex 0 -dm_refine 1 -dm_coord_space 0
1746   test:
1747     suffix: glvis_2d_hex_p2_p4est
1748     requires: p4est
1749     args: -quiet -run_type test -bc_type dirichlet -petscspace_degree 2 -vec_view glvis: -dm_plex_simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 1 -dm_forest_maximum_refinement 4 -dm_p4est_refine_pattern hash -viewer_glvis_dm_plex_enable_ncmesh
1750   test:
1751     suffix: glvis_2d_tet_p0
1752     args: -run_type exact -guess_vec_view glvis: -nonzero_initial_guess 1 -dm_plex_filename ${wPETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh -dm_plex_boundary_label marker -petscspace_degree 0 -dm_coord_space 0
1753   test:
1754     suffix: glvis_2d_hex_p0
1755     args: -run_type exact -guess_vec_view glvis: -nonzero_initial_guess 1 -dm_plex_box_faces 5,7 -dm_plex_simplex 0 -petscspace_degree 0 -dm_coord_space 0
1756 
1757   # PCHPDDM tests
1758   testset:
1759     nsize: 4
1760     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1761     args: -run_type test -run_test_check_ksp -quiet -petscspace_degree 1 -petscpartitioner_type simple -bc_type none -dm_plex_simplex 0 -pc_type hpddm -pc_hpddm_levels_1_sub_pc_type lu -pc_hpddm_levels_1_eps_nev 2 -pc_hpddm_coarse_p 1 -pc_hpddm_coarse_pc_type svd -ksp_rtol 1.e-10 -pc_hpddm_levels_1_st_pc_factor_shift_type INBLOCKS -ksp_converged_reason
1762     test:
1763       suffix: quad_singular_hpddm
1764       args: -dm_plex_box_faces 6,7
1765     test:
1766       requires: p4est
1767       suffix: p4est_singular_2d_hpddm
1768       args: -dm_plex_convert_type p4est -dm_forest_minimum_refinement 1 -dm_forest_initial_refinement 3 -dm_forest_maximum_refinement 3
1769     test:
1770       requires: p4est
1771       suffix: p4est_nc_singular_2d_hpddm
1772       args: -dm_plex_convert_type p4est -dm_forest_minimum_refinement 1 -dm_forest_initial_refinement 1 -dm_forest_maximum_refinement 3 -dm_p4est_refine_pattern hash
1773   testset:
1774     nsize: 4
1775     requires: hpddm slepc triangle !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1776     args: -run_type full -petscpartitioner_type simple -dm_refine 2 -bc_type dirichlet -petscspace_degree 2 -ksp_type gmres -ksp_gmres_restart 100 -pc_type hpddm -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0 -pc_type hpddm -pc_hpddm_levels_1_sub_pc_type lu -pc_hpddm_levels_1_eps_nev 4 -pc_hpddm_coarse_p 2 -pc_hpddm_coarse_pc_type redundant -ksp_rtol 1.e-1
1777     test:
1778       args: -pc_hpddm_coarse_mat_type baij -options_left no
1779       suffix: tri_hpddm_reuse_baij
1780     test:
1781       requires: !complex
1782       suffix: tri_hpddm_reuse
1783   testset:
1784     nsize: 4
1785     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1786     args: -run_type full -petscpartitioner_type simple -dm_plex_box_faces 7,5 -dm_refine 2 -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 2 -ksp_type gmres -ksp_gmres_restart 100 -pc_type hpddm -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0 -pc_type hpddm -pc_hpddm_levels_1_sub_pc_type lu -pc_hpddm_levels_1_eps_nev 4 -pc_hpddm_coarse_p 2 -pc_hpddm_coarse_pc_type redundant -ksp_rtol 1.e-1
1787     test:
1788       args: -pc_hpddm_coarse_mat_type baij -options_left no
1789       suffix: quad_hpddm_reuse_baij
1790     test:
1791       requires: !complex
1792       suffix: quad_hpddm_reuse
1793   testset:
1794     nsize: 4
1795     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1796     args: -run_type full -petscpartitioner_type simple -dm_plex_box_faces 7,5 -dm_refine 2 -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -pc_type hpddm -snes_monitor_short -ksp_monitor_short -snes_converged_reason ::ascii_info_detail -ksp_converged_reason -snes_view -show_solution 0 -pc_type hpddm -pc_hpddm_levels_1_sub_pc_type lu -pc_hpddm_levels_1_eps_threshold 0.1 -pc_hpddm_coarse_p 2 -pc_hpddm_coarse_pc_type redundant -ksp_rtol 1.e-1
1797     test:
1798       args: -pc_hpddm_coarse_mat_type baij -options_left no
1799       suffix: quad_hpddm_reuse_threshold_baij
1800     test:
1801       requires: !complex
1802       suffix: quad_hpddm_reuse_threshold
1803   testset:
1804     nsize: 4
1805     requires: hpddm slepc parmetis !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1806     filter: sed -e "s/linear solver iterations=17/linear solver iterations=16/g"
1807     args: -run_type full -petscpartitioner_type parmetis -dm_refine 3 -bc_type dirichlet -petscspace_degree 1 -ksp_type gmres -ksp_gmres_restart 100 -pc_type hpddm -snes_monitor_short -snes_converged_reason ::ascii_info_detail -snes_view -show_solution 0 -pc_type hpddm -pc_hpddm_levels_1_sub_pc_type icc -pc_hpddm_levels_1_eps_nev 20 -pc_hpddm_coarse_p 2 -pc_hpddm_coarse_pc_type redundant -ksp_rtol 1.e-10 -dm_plex_filename ${PETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh -dm_plex_boundary_label marker -pc_hpddm_levels_1_sub_pc_factor_levels 3 -variable_coefficient ball -dm_plex_gmsh_periodic 0
1808     test:
1809       args: -pc_hpddm_coarse_mat_type baij -options_left no
1810       filter: grep -v "      total: nonzeros=" | grep -v "      rows=" | sed -e "s/total number of linear solver iterations=1[5-7]/total number of linear solver iterations=16/g"
1811       suffix: tri_parmetis_hpddm_baij
1812     test:
1813       filter: grep -v "      total: nonzeros=" | grep -v "      rows=" | sed -e "s/total number of linear solver iterations=1[5-7]/total number of linear solver iterations=16/g"
1814       requires: !complex
1815       suffix: tri_parmetis_hpddm
1816 
1817   # 2D serial P1 tests for adaptive MG
1818   test:
1819     suffix: 2d_p1_adaptmg_0
1820     requires: triangle
1821     args: -petscpartitioner_type simple -dm_refine_hierarchy 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1822           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1823           -snes_max_it 1 -ksp_converged_reason \
1824           -ksp_rtol 1e-8 -pc_type mg
1825   test:
1826     suffix: 2d_p1_adaptmg_1
1827     requires: triangle bamg todo
1828     args: -petscpartitioner_type simple -dm_refine_hierarchy 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1829           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1830           -snes_max_it 1 -ksp_converged_reason \
1831           -ksp_rtol 1e-8 -pc_type mg -pc_mg_galerkin -pc_mg_adapt_interp_coarse_space eigenvector -pc_mg_adapt_interp_n 1 \
1832             -pc_mg_mesp_ksp_type richardson -pc_mg_mesp_ksp_richardson_self_scale -pc_mg_mesp_ksp_max_it 100 -pc_mg_mesp_pc_type none
1833   test:
1834     suffix: 2d_p1_adaptmg_gdsw
1835     requires: triangle
1836     nsize: 4
1837     args: -petscpartitioner_type simple -dm_refine 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1838           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1839           -snes_max_it 1 -ksp_converged_reason \
1840           -ksp_rtol 1e-8 -pc_type mg -pc_mg_galerkin -pc_mg_adapt_interp_coarse_space gdsw -pc_mg_levels 2 -mg_levels_pc_type asm -dm_mat_type {{aij is}}
1841 
1842   test:
1843     suffix: 2d_p1_adaptmg_agdsw
1844     requires: triangle mumps
1845     nsize: 4
1846     args: -petscpartitioner_type simple -dm_refine 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1847           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1848           -snes_max_it 1 -ksp_converged_reason \
1849           -ksp_rtol 1e-8 -pc_type mg -pc_mg_galerkin -pc_mg_adapt_interp_coarse_space gdsw -pc_mg_levels 2 -mg_levels_pc_type asm -dm_mat_type is -mg_levels_gdsw_tolerance 0.1 -mg_levels_gdsw_pseudo_pc_type qr
1850 
1851 TEST*/
1852