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