Actual source code: ex12.c

  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";

  7: /*
  8: A visualization of the adaptation can be accomplished using:

 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

 12: Information on refinement:

 14:    -info :~sys,vec,is,mat,ksp,snes,ts
 15: */

 17: #include <petscdmplex.h>
 18: #include <petscdmadaptor.h>
 19: #include <petscsnes.h>
 20: #include <petscds.h>
 21: #include <petscviewerhdf5.h>

 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;

 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;

 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: }

 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: }

 78: /*
 79:   In 2D for Dirichlet conditions, we use exact solution:

 81:     u = x^2 + y^2
 82:     f = 4

 84:   so that

 86:     -\Delta u + f = -4 + 4 = 0

 88:   For Neumann conditions, we have

 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)

 95:   Which we can express as

 97:     \nabla u \cdot  \hat n|_\Gamma = {2 x, 2 y} \cdot \hat n = 2 (x + y)

 99:   The boundary integral of this solution is (assuming we are not orienting the edges)

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: }

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: }

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);

121:   *u = PetscTanhScalar(xi) + 1.0;
122:   return PETSC_SUCCESS;
123: }

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);

130:   *u = PetscSinReal(alpha * xy) * (alpha * PetscAbsReal(xy) < 2 * PETSC_PI ? 1 : 0.01);
131:   return PETSC_SUCCESS;
132: }

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: }

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;

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: }

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);

155:   f0[0] = PetscSinReal(alpha * xy) * (alpha * PetscAbsReal(xy) < 2 * PETSC_PI ? 1 : 0.01);
156: }

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: }

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: }

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: }

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: }

184: /*
185:   In 2D for x periodicity and y Dirichlet conditions, we use exact solution:

187:     u = sin(2 pi x)
188:     f = -4 pi^2 sin(2 pi x)

190:   so that

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: }

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: }

205: /*
206:   In 2D for x-y periodicity, we use exact solution:

208:     u = sin(2 pi x) sin(2 pi y)
209:     f = -8 pi^2 sin(2 pi x)

211:   so that

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: }

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: }

226: /*
227:   In 2D for Dirichlet conditions with a variable coefficient, we use exact solution:

229:     u  = x^2 + y^2
230:     f  = 6 (x + y)
231:     nu = (x + y)

233:   so that

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: }

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;

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: }

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: }

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: }

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: }

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: }

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: }

295: /*
296:   In 2D for Dirichlet conditions with a nonlinear coefficient (p-Laplacian with p = 4), we use exact solution:

298:     u  = x^2 + y^2
299:     f  = 16 (x^2 + y^2)
300:     nu = 1/2 |grad u|^2

302:   so that

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: }

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: }

320: /*
321:   grad (u + eps w) - grad u = eps grad w

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: }

339: /*
340:   In 3D for Dirichlet conditions we use exact solution:

342:     u = 2/3 (x^2 + y^2 + z^2)
343:     f = 4

345:   so that

347:     -\Delta u + f = -2/3 * 6 + 4 = 0

349:   For Neumann conditions, we have

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)

358:   Which we can express as

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: }

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);

375:   *u = PetscTanhScalar(xi) + 1.0;
376:   return PETSC_SUCCESS;
377: }

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: }

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);

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: }

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);

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: }

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: }

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;

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;

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;

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: }

458: static PetscErrorCode CreateBCLabel(DM dm, const char name[])
459: {
460:   DM      plex;
461:   DMLabel label;

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: }

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;

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;

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;

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: }

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;

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];

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: }

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;

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: }

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;

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: }

697: static PetscErrorCode SetupAuxDM(DM dm, PetscFE feAux, AppCtx *user)
698: {
699:   DM dmAux, coordDM;

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: }

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;

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;

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: }

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 */

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));

776:   PetscCall(PetscMalloc2(1, &user.exactFuncs, 1, &user.exactFields));
777:   PetscCall(SetupDiscretization(dm, &user));

779:   PetscCall(DMCreateGlobalVector(dm, &u));
780:   PetscCall(PetscObjectSetName((PetscObject)u, "potential"));

782:   PetscCall(DMCreateMatrix(dm, &J));
783:   if (user.jacobianMF) {
784:     PetscInt M, m, N, n;

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

796:     userJ.dm   = dm;
797:     userJ.J    = J;
798:     userJ.user = &user;

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:   }

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:   }

814:   PetscCall(DMPlexSetSNESLocalFEM(dm, &user, &user, &user));
815:   PetscCall(SNESSetJacobian(snes, A, J, NULL, NULL));

817:   PetscCall(SNESSetFromOptions(snes));

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];

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};

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));

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;

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;

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;

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;

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;

924:     PetscCall(DMGetAuxiliaryVec(dm, NULL, 0, 0, &nu));
925:     if (nu) PetscCall(VecViewFromOptions(nu, NULL, "-coeff_view"));
926:   }

928:   if (user.bdIntegral) {
929:     DMLabel     label;
930:     PetscInt    id    = 1;
931:     PetscScalar bdInt = 0.0;
932:     PetscReal   exact = 3.3333333333;

934:     PetscCall(DMGetLabel(dm, "marker", &label));
935:     PetscCall(DMPlexComputeBdIntegral(dm, u, label, 1, &id, bd_integral_2d, &bdInt, NULL));
936:     PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Solution boundary integral: %.4g\n", (double)PetscAbsScalar(bdInt)));
937:     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);
938:   }

940:   PetscCall(MatNullSpaceDestroy(&nullSpace));
941:   if (user.jacobianMF) PetscCall(VecDestroy(&userJ.u));
942:   if (A != J) PetscCall(MatDestroy(&A));
943:   PetscCall(MatDestroy(&J));
944:   PetscCall(VecDestroy(&u));
945:   PetscCall(SNESDestroy(&snes));
946:   PetscCall(DMDestroy(&dm));
947:   PetscCall(PetscFree2(user.exactFuncs, user.exactFields));
948:   PetscCall(PetscFree(user.kgrid));
949:   PetscCall(PetscFinalize());
950:   return 0;
951: }

953: /*TEST
954:   # 2D serial P1 test 0-4
955:   test:
956:     suffix: 2d_p1_0
957:     requires: triangle
958:     args: -run_type test -bc_type dirichlet -dm_plex_interpolate 0 -petscspace_degree 1 -show_initial -dm_plex_print_fem 1

960:   test:
961:     suffix: 2d_p1_1
962:     requires: triangle
963:     args: -run_type test -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1

965:   test:
966:     suffix: 2d_p1_2
967:     requires: triangle
968:     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:   test:
971:     suffix: 2d_p1_neumann_0
972:     requires: triangle
973:     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:   test:
976:     suffix: 2d_p1_neumann_1
977:     requires: triangle
978:     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:   # 2D serial P2 test 5-8
981:   test:
982:     suffix: 2d_p2_0
983:     requires: triangle
984:     args: -run_type test -bc_type dirichlet -petscspace_degree 2 -show_initial -dm_plex_print_fem 1

986:   test:
987:     suffix: 2d_p2_1
988:     requires: triangle
989:     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:   test:
992:     suffix: 2d_p2_neumann_0
993:     requires: triangle
994:     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:   test:
997:     suffix: 2d_p2_neumann_1
998:     requires: triangle
999:     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:   test:
1002:     suffix: bd_int_0
1003:     requires: triangle
1004:     args: -run_type test -bc_type dirichlet -petscspace_degree 2 -bd_integral -dm_view -quiet

1006:   test:
1007:     suffix: bd_int_1
1008:     requires: triangle
1009:     args: -run_type test -dm_refine 2 -bc_type dirichlet -petscspace_degree 2 -bd_integral -dm_view -quiet

1011:   # 3D serial P1 test 9-12
1012:   test:
1013:     suffix: 3d_p1_0
1014:     requires: ctetgen
1015:     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:   test:
1018:     suffix: 3d_p1_1
1019:     requires: ctetgen
1020:     args: -run_type test -dm_plex_dim 3 -bc_type dirichlet -petscspace_degree 1 -show_initial -dm_plex_print_fem 1 -dm_view

1022:   test:
1023:     suffix: 3d_p1_2
1024:     requires: ctetgen
1025:     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:   test:
1028:     suffix: 3d_p1_neumann_0
1029:     requires: ctetgen
1030:     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:   # Analytic variable coefficient 13-20
1033:   test:
1034:     suffix: 13
1035:     requires: triangle
1036:     args: -run_type test -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1037:   test:
1038:     suffix: 14
1039:     requires: triangle
1040:     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1
1041:   test:
1042:     suffix: 15
1043:     requires: triangle
1044:     args: -run_type test -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1045:   test:
1046:     suffix: 16
1047:     requires: triangle
1048:     args: -run_type test -dm_refine_volume_limit_pre 0.0625 -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1
1049:   test:
1050:     suffix: 17
1051:     requires: ctetgen
1052:     args: -run_type test -dm_plex_dim 3 -variable_coefficient analytic -petscspace_degree 1 -show_initial -dm_plex_print_fem 1

1054:   test:
1055:     suffix: 18
1056:     requires: ctetgen
1057:     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:   test:
1060:     suffix: 19
1061:     requires: ctetgen
1062:     args: -run_type test -dm_plex_dim 3 -variable_coefficient analytic -petscspace_degree 2 -show_initial -dm_plex_print_fem 1

1064:   test:
1065:     suffix: 20
1066:     requires: ctetgen
1067:     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:   # P1 variable coefficient 21-28
1070:   test:
1071:     suffix: 21
1072:     requires: triangle
1073:     args: -run_type test -variable_coefficient field -petscspace_degree 1 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1

1075:   test:
1076:     suffix: 22
1077:     requires: triangle
1078:     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:   test:
1081:     suffix: 23
1082:     requires: triangle
1083:     args: -run_type test -variable_coefficient field -petscspace_degree 2 -mat_petscspace_degree 1 -show_initial -dm_plex_print_fem 1

1085:   test:
1086:     suffix: 24
1087:     requires: triangle
1088:     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:   test:
1091:     suffix: 25
1092:     requires: ctetgen
1093:     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:   test:
1096:     suffix: 26
1097:     requires: ctetgen
1098:     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:   test:
1101:     suffix: 27
1102:     requires: ctetgen
1103:     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:   test:
1106:     suffix: 28
1107:     requires: ctetgen
1108:     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:   # P0 variable coefficient 29-36
1111:   test:
1112:     suffix: 29
1113:     requires: triangle
1114:     args: -run_type test -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1

1116:   test:
1117:     suffix: 30
1118:     requires: triangle
1119:     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:   test:
1122:     suffix: 31
1123:     requires: triangle
1124:     args: -run_type test -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1

1126:   test:
1127:     requires: triangle
1128:     suffix: 32
1129:     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:   test:
1132:     requires: ctetgen
1133:     suffix: 33
1134:     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 1 -show_initial -dm_plex_print_fem 1

1136:   test:
1137:     suffix: 34
1138:     requires: ctetgen
1139:     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:   test:
1142:     suffix: 35
1143:     requires: ctetgen
1144:     args: -run_type test -dm_plex_dim 3 -variable_coefficient field -petscspace_degree 2 -show_initial -dm_plex_print_fem 1

1146:   test:
1147:     suffix: 36
1148:     requires: ctetgen
1149:     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:   # Full solve 39-44
1152:   test:
1153:     suffix: 39
1154:     requires: triangle !single
1155:     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
1156:   test:
1157:     suffix: 40
1158:     requires: triangle !single
1159:     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
1160:   test:
1161:     suffix: 41
1162:     requires: triangle !single
1163:     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
1164:   test:
1165:     suffix: 42
1166:     requires: triangle !single
1167:     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
1168:   test:
1169:     suffix: 43
1170:     requires: triangle !single
1171:     nsize: 2
1172:     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:   test:
1175:     suffix: 44
1176:     requires: triangle !single
1177:     nsize: 2
1178:     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:   # These tests use a loose tolerance just to exercise the PtAP operations for MATIS and multiple PCBDDC setup calls inside PCMG
1181:   testset:
1182:     requires: triangle !single
1183:     nsize: 3
1184:     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
1185:     test:
1186:       suffix: gmg_bddc
1187:       filter: sed -e "s/CONVERGED_FNORM_RELATIVE iterations 3/CONVERGED_FNORM_RELATIVE iterations 4/g"
1188:       args: -mg_levels_pc_type jacobi
1189:     test:
1190:       filter: sed -e "s/iterations [0-4]/iterations 4/g"
1191:       suffix: gmg_bddc_lev
1192:       args: -mg_levels_pc_type bddc

1194:   # Restarting
1195:   testset:
1196:     suffix: restart
1197:     requires: hdf5 triangle !complex
1198:     args: -run_type test -bc_type dirichlet -petscspace_degree 1
1199:     test:
1200:       args: -dm_view hdf5:sol.h5 -vec_view hdf5:sol.h5::append
1201:     test:
1202:       args: -dm_plex_filename sol.h5 -dm_plex_name box -restart

1204:   # Periodicity
1205:   test:
1206:     suffix: periodic_0
1207:     requires: triangle
1208:     args: -run_type full -bc_type dirichlet -petscspace_degree 1 -snes_converged_reason ::ascii_info_detail

1210:   test:
1211:     requires: !complex
1212:     suffix: periodic_1
1213:     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:   # 2D serial P1 test with field bc
1216:   test:
1217:     suffix: field_bc_2d_p1_0
1218:     requires: triangle
1219:     args: -run_type test -bc_type dirichlet -field_bc -petscspace_degree 1 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1

1221:   test:
1222:     suffix: field_bc_2d_p1_1
1223:     requires: triangle
1224:     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:   test:
1227:     suffix: field_bc_2d_p1_neumann_0
1228:     requires: triangle
1229:     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:   test:
1232:     suffix: field_bc_2d_p1_neumann_1
1233:     requires: triangle
1234:     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:   # 3D serial P1 test with field bc
1237:   test:
1238:     suffix: field_bc_3d_p1_0
1239:     requires: ctetgen
1240:     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:   test:
1243:     suffix: field_bc_3d_p1_1
1244:     requires: ctetgen
1245:     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:   test:
1248:     suffix: field_bc_3d_p1_neumann_0
1249:     requires: ctetgen
1250:     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:   test:
1253:     suffix: field_bc_3d_p1_neumann_1
1254:     requires: ctetgen
1255:     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:   # 2D serial P2 test with field bc
1258:   test:
1259:     suffix: field_bc_2d_p2_0
1260:     requires: triangle
1261:     args: -run_type test -bc_type dirichlet -field_bc -petscspace_degree 2 -bc_petscspace_degree 2 -show_initial -dm_plex_print_fem 1

1263:   test:
1264:     suffix: field_bc_2d_p2_1
1265:     requires: triangle
1266:     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:   test:
1269:     suffix: field_bc_2d_p2_neumann_0
1270:     requires: triangle
1271:     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:   test:
1274:     suffix: field_bc_2d_p2_neumann_1
1275:     requires: triangle
1276:     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:   # 3D serial P2 test with field bc
1279:   test:
1280:     suffix: field_bc_3d_p2_0
1281:     requires: ctetgen
1282:     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:   test:
1285:     suffix: field_bc_3d_p2_1
1286:     requires: ctetgen
1287:     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:   test:
1290:     suffix: field_bc_3d_p2_neumann_0
1291:     requires: ctetgen
1292:     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:   test:
1295:     suffix: field_bc_3d_p2_neumann_1
1296:     requires: ctetgen
1297:     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:   # Full solve simplex: Convergence
1300:   test:
1301:     suffix: 3d_p1_conv
1302:     requires: ctetgen
1303:     args: -run_type full -dm_plex_dim 3 -dm_refine 1 -bc_type dirichlet -petscspace_degree 1 \
1304:       -snes_convergence_estimate -convest_num_refine 1 -pc_type lu

1306:   # Full solve simplex: PCBDDC
1307:   test:
1308:     suffix: tri_bddc
1309:     requires: triangle !single
1310:     nsize: 5
1311:     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:   # Full solve simplex: PCBDDC
1314:   test:
1315:     suffix: tri_parmetis_bddc
1316:     requires: triangle !single parmetis
1317:     nsize: 4
1318:     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:   testset:
1321:     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
1322:     nsize: 5
1323:     output_file: output/ex12_quad_bddc.out
1324:     filter: sed -e "s/aijcusparse/aij/g" -e "s/aijviennacl/aij/g" -e "s/factorization: cusparse/factorization: petsc/g"
1325:     test:
1326:       requires: !single
1327:       suffix: quad_bddc
1328:     test:
1329:       requires: !single cuda
1330:       suffix: quad_bddc_cuda
1331:       args: -matis_localmat_type aijcusparse -pc_bddc_dirichlet_pc_factor_mat_solver_type cusparse -pc_bddc_neumann_pc_factor_mat_solver_type cusparse
1332:     test:
1333:       requires: !single viennacl
1334:       suffix: quad_bddc_viennacl
1335:       args: -matis_localmat_type aijviennacl

1337:   # Full solve simplex: ASM
1338:   test:
1339:     suffix: tri_q2q1_asm_lu
1340:     requires: triangle !single
1341:     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:   test:
1344:     suffix: tri_q2q1_msm_lu
1345:     requires: triangle !single
1346:     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:   test:
1349:     suffix: tri_q2q1_asm_sor
1350:     requires: triangle !single
1351:     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:   test:
1354:     suffix: tri_q2q1_msm_sor
1355:     requires: triangle !single
1356:     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:   # Full solve simplex: FAS
1359:   test:
1360:     suffix: fas_newton_0
1361:     requires: triangle !single
1362:     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:   test:
1365:     suffix: fas_newton_1
1366:     requires: triangle !single
1367:     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
1368:     filter: sed -e "s/total number of linear solver iterations=14/total number of linear solver iterations=15/g"

1370:   test:
1371:     suffix: fas_ngs_0
1372:     requires: triangle !single
1373:     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:   # These two tests are broken because DMPlexComputeInjectorFEM() only works for regularly refined meshes
1376:   test:
1377:     suffix: fas_newton_coarse_0
1378:     requires: pragmatic triangle
1379:     TODO: broken
1380:     args: -run_type full -variable_coefficient nonlinear -petscspace_degree 1 \
1381:           -dm_refine 2 -dm_coarsen_hierarchy 1 -dm_plex_hash_location -dm_adaptor pragmatic \
1382:           -snes_type fas -snes_fas_levels 2 -snes_converged_reason ::ascii_info_detail -snes_monitor_short -snes_view \
1383:             -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -fas_coarse_snes_linesearch_type basic \
1384:             -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:   test:
1387:     suffix: mg_newton_coarse_0
1388:     requires: triangle pragmatic
1389:     TODO: broken
1390:     args: -run_type full -petscspace_degree 1 \
1391:           -dm_refine 3 -dm_coarsen_hierarchy 3 -dm_plex_hash_location -dm_adaptor pragmatic \
1392:           -snes_atol 1.0e-8 -snes_rtol 0.0 -snes_monitor_short -snes_converged_reason ::ascii_info_detail -snes_view \
1393:             -ksp_type richardson -ksp_atol 1.0e-8 -ksp_rtol 0.0 -ksp_norm_type unpreconditioned -ksp_monitor_true_residual \
1394:               -pc_type mg -pc_mg_levels 4 \
1395:               -mg_levels_ksp_type gmres -mg_levels_pc_type ilu -mg_levels_ksp_max_it 10

1397:   # Full solve tensor
1398:   test:
1399:     suffix: tensor_plex_2d
1400:     args: -run_type test -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_refine_hierarchy 2

1402:   test:
1403:     suffix: tensor_p4est_2d
1404:     requires: p4est
1405:     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:   test:
1408:     suffix: tensor_plex_3d
1409:     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:   test:
1412:     suffix: tensor_p4est_3d
1413:     requires: p4est
1414:     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:   test:
1417:     suffix: p4est_test_q2_conformal_serial
1418:     requires: p4est
1419:     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:   test:
1422:     suffix: p4est_test_q2_conformal_parallel
1423:     requires: p4est
1424:     nsize: 7
1425:     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:   test:
1428:     suffix: p4est_test_q2_conformal_parallel_parmetis
1429:     requires: parmetis p4est
1430:     nsize: 4
1431:     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:   test:
1434:     suffix: p4est_test_q2_nonconformal_serial
1435:     requires: p4est
1436:     filter: grep -v "CG or CGNE: variant"
1437:     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:   test:
1440:     suffix: p4est_test_q2_nonconformal_parallel
1441:     requires: p4est
1442:     filter: grep -v "CG or CGNE: variant"
1443:     nsize: 7
1444:     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:   test:
1447:     suffix: p4est_test_q2_nonconformal_parallel_parmetis
1448:     requires: parmetis p4est
1449:     nsize: 4
1450:     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:   test:
1453:     suffix: p4est_exact_q2_conformal_serial
1454:     requires: p4est !single !complex !__float128
1455:     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:   test:
1458:     suffix: p4est_exact_q2_conformal_parallel
1459:     requires: p4est !single !complex !__float128
1460:     nsize: 4
1461:     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:   test:
1464:     suffix: p4est_exact_q2_conformal_parallel_parmetis
1465:     requires: parmetis p4est !single
1466:     nsize: 4
1467:     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:   test:
1470:     suffix: p4est_exact_q2_nonconformal_serial
1471:     requires: p4est
1472:     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:   test:
1475:     suffix: p4est_exact_q2_nonconformal_parallel
1476:     requires: p4est
1477:     nsize: 7
1478:     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:   test:
1481:     suffix: p4est_exact_q2_nonconformal_parallel_parmetis
1482:     requires: parmetis p4est
1483:     nsize: 4
1484:     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:   test:
1487:     suffix: p4est_full_q2_nonconformal_serial
1488:     requires: p4est !single
1489:     filter: grep -v "variant HERMITIAN"
1490:     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:   test:
1493:     suffix: p4est_full_q2_nonconformal_parallel
1494:     requires: p4est !single
1495:     filter: grep -v "variant HERMITIAN"
1496:     nsize: 7
1497:     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:   test:
1500:     suffix: p4est_full_q2_nonconformal_parallel_bddcfas
1501:     requires: p4est !single
1502:     filter: grep -v "variant HERMITIAN"
1503:     nsize: 7
1504:     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:   test:
1507:     suffix: p4est_full_q2_nonconformal_parallel_bddc
1508:     requires: p4est !single
1509:     filter: grep -v "variant HERMITIAN"
1510:     nsize: 7
1511:     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:   test:
1514:     TODO: broken
1515:     suffix: p4est_fas_q2_conformal_serial
1516:     requires: p4est !complex !__float128
1517:     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:   test:
1520:     TODO: broken
1521:     suffix: p4est_fas_q2_nonconformal_serial
1522:     requires: p4est
1523:     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:   test:
1526:     suffix: fas_newton_0_p4est
1527:     requires: p4est !single !__float128
1528:     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:   # Full solve simplicial AMR
1531:   test:
1532:     suffix: tri_p1_adapt_init_pragmatic
1533:     requires: pragmatic
1534:     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:   test:
1537:     suffix: tri_p2_adapt_init_pragmatic
1538:     requires: pragmatic
1539:     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:   test:
1542:     suffix: tri_p1_adapt_init_mmg
1543:     requires: mmg
1544:     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:   test:
1547:     suffix: tri_p2_adapt_init_mmg
1548:     requires: mmg
1549:     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:   test:
1552:     suffix: tri_p1_adapt_seq_pragmatic
1553:     requires: pragmatic
1554:     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:   test:
1557:     suffix: tri_p2_adapt_seq_pragmatic
1558:     requires: pragmatic
1559:     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:   test:
1562:     suffix: tri_p1_adapt_seq_mmg
1563:     requires: mmg
1564:     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:   test:
1567:     suffix: tri_p2_adapt_seq_mmg
1568:     requires: mmg
1569:     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:   test:
1572:     suffix: tri_p1_adapt_analytic_pragmatic
1573:     requires: pragmatic
1574:     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:   test:
1577:     suffix: tri_p2_adapt_analytic_pragmatic
1578:     requires: pragmatic
1579:     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:   test:
1582:     suffix: tri_p1_adapt_analytic_mmg
1583:     requires: mmg
1584:     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:   test:
1587:     suffix: tri_p2_adapt_analytic_mmg
1588:     requires: mmg
1589:     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:   test:
1592:     suffix: tri_p1_adapt_uniform_pragmatic
1593:     requires: pragmatic tetgen
1594:     nsize: 2
1595:     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
1596:     timeoutfactor: 2

1598:   test:
1599:     suffix: tri_p2_adapt_uniform_pragmatic
1600:     requires: pragmatic tetgen
1601:     nsize: 2
1602:     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
1603:     timeoutfactor: 1

1605:   test:
1606:     suffix: tri_p1_adapt_uniform_mmg
1607:     requires: mmg tetgen
1608:     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
1609:     timeoutfactor: 2

1611:   test:
1612:     suffix: tri_p2_adapt_uniform_mmg
1613:     requires: mmg tetgen broken
1614:     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
1615:     timeoutfactor: 1

1617:   test:
1618:     suffix: tri_p1_adapt_uniform_parmmg
1619:     requires: parmmg tetgen
1620:     nsize: 2
1621:     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
1622:     timeoutfactor: 2

1624:   test:
1625:     suffix: tri_p2_adapt_uniform_parmmg
1626:     requires: parmmg tetgen
1627:     nsize: 2
1628:     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
1629:     timeoutfactor: 1

1631:   # Full solve tensor AMR
1632:   test:
1633:     suffix: quad_q1_adapt_0
1634:     requires: p4est
1635:     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
1636:     filter: grep -v DM_

1638:   test:
1639:     suffix: amr_0
1640:     nsize: 5
1641:     args: -run_type test -petscpartitioner_type simple -dm_plex_simplex 0 -bc_type dirichlet -petscspace_degree 1 -dm_refine 1

1643:   test:
1644:     suffix: amr_1
1645:     requires: p4est !complex
1646:     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:   test:
1649:     suffix: p4est_solve_bddc
1650:     requires: p4est !complex
1651:     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
1652:     nsize: 4

1654:   test:
1655:     suffix: p4est_solve_fas
1656:     requires: p4est
1657:     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
1658:     nsize: 4
1659:     TODO: identical machine two runs produce slightly different solver trackers

1661:   test:
1662:     suffix: p4est_convergence_test_1
1663:     requires: p4est
1664:     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
1665:     nsize: 4

1667:   test:
1668:     suffix: p4est_convergence_test_2
1669:     requires: p4est
1670:     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 3 -dm_forest_initial_refinement 3 -dm_forest_maximum_refinement 5 -dm_p4est_refine_pattern hash

1672:   test:
1673:     suffix: p4est_convergence_test_3
1674:     requires: p4est
1675:     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 4 -dm_forest_initial_refinement 4 -dm_forest_maximum_refinement 6 -dm_p4est_refine_pattern hash

1677:   test:
1678:     suffix: p4est_convergence_test_4
1679:     requires: p4est
1680:     args: -quiet -run_type test -petscspace_degree 1 -dm_plex_simplex 0 -petscspace_poly_tensor -dm_plex_convert_type p4est -dm_forest_minimum_refinement 5 -dm_forest_initial_refinement 5 -dm_forest_maximum_refinement 7 -dm_p4est_refine_pattern hash
1681:     timeoutfactor: 5

1683:   # Serial tests with GLVis visualization
1684:   test:
1685:     suffix: glvis_2d_tet_p1
1686:     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
1687:   test:
1688:     suffix: glvis_2d_tet_p2
1689:     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
1690:   test:
1691:     suffix: glvis_2d_hex_p1
1692:     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
1693:   test:
1694:     suffix: glvis_2d_hex_p2
1695:     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
1696:   test:
1697:     suffix: glvis_2d_hex_p2_p4est
1698:     requires: p4est
1699:     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
1700:   test:
1701:     suffix: glvis_2d_tet_p0
1702:     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
1703:   test:
1704:     suffix: glvis_2d_hex_p0
1705:     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

1707:   # PCHPDDM tests
1708:   testset:
1709:     nsize: 4
1710:     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1711:     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
1712:     test:
1713:       suffix: quad_singular_hpddm
1714:       args: -dm_plex_box_faces 6,7
1715:     test:
1716:       requires: p4est
1717:       suffix: p4est_singular_2d_hpddm
1718:       args: -dm_plex_convert_type p4est -dm_forest_minimum_refinement 1 -dm_forest_initial_refinement 3 -dm_forest_maximum_refinement 3
1719:     test:
1720:       requires: p4est
1721:       suffix: p4est_nc_singular_2d_hpddm
1722:       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
1723:   testset:
1724:     nsize: 4
1725:     requires: hpddm slepc triangle !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1726:     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
1727:     test:
1728:       args: -pc_hpddm_coarse_mat_type baij -options_left no
1729:       suffix: tri_hpddm_reuse_baij
1730:     test:
1731:       requires: !complex
1732:       suffix: tri_hpddm_reuse
1733:   testset:
1734:     nsize: 4
1735:     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1736:     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
1737:     test:
1738:       args: -pc_hpddm_coarse_mat_type baij -options_left no
1739:       suffix: quad_hpddm_reuse_baij
1740:     test:
1741:       requires: !complex
1742:       suffix: quad_hpddm_reuse
1743:   testset:
1744:     nsize: 4
1745:     requires: hpddm slepc !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1746:     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
1747:     test:
1748:       args: -pc_hpddm_coarse_mat_type baij -options_left no
1749:       suffix: quad_hpddm_reuse_threshold_baij
1750:     test:
1751:       requires: !complex
1752:       suffix: quad_hpddm_reuse_threshold
1753:   testset:
1754:     nsize: 4
1755:     requires: hpddm slepc parmetis !single defined(PETSC_HAVE_DYNAMIC_LIBRARIES) defined(PETSC_USE_SHARED_LIBRARIES)
1756:     filter: sed -e "s/linear solver iterations=17/linear solver iterations=16/g"
1757:     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
1758:     test:
1759:       args: -pc_hpddm_coarse_mat_type baij -options_left no
1760:       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"
1761:       suffix: tri_parmetis_hpddm_baij
1762:     test:
1763:       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"
1764:       requires: !complex
1765:       suffix: tri_parmetis_hpddm

1767:   # 2D serial P1 tests for adaptive MG
1768:   test:
1769:     suffix: 2d_p1_adaptmg_0
1770:     requires: triangle
1771:     args: -petscpartitioner_type simple -dm_refine_hierarchy 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1772:           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1773:           -snes_max_it 1 -ksp_converged_reason \
1774:           -ksp_rtol 1e-8 -pc_type mg
1775:   test:
1776:     suffix: 2d_p1_adaptmg_1
1777:     requires: triangle bamg todo
1778:     args: -petscpartitioner_type simple -dm_refine_hierarchy 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1779:           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1780:           -snes_max_it 1 -ksp_converged_reason \
1781:           -ksp_rtol 1e-8 -pc_type mg -pc_mg_galerkin -pc_mg_adapt_interp_coarse_space eigenvector -pc_mg_adapt_interp_n 1 \
1782:             -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
1783:   test:
1784:     suffix: 2d_p1_adaptmg_gdsw
1785:     requires: triangle
1786:     nsize: 4
1787:     args: -petscpartitioner_type simple -dm_refine 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1788:           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1789:           -snes_max_it 1 -ksp_converged_reason \
1790:           -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}}

1792:   test:
1793:     suffix: 2d_p1_adaptmg_agdsw
1794:     requires: triangle mumps
1795:     nsize: 4
1796:     args: -petscpartitioner_type simple -dm_refine 3 -dm_plex_box_faces 4,4 -bc_type dirichlet -petscspace_degree 1 \
1797:           -variable_coefficient checkerboard_0 -mat_petscspace_degree 0 -div 16 -k 3 \
1798:           -snes_max_it 1 -ksp_converged_reason \
1799:           -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

1801: TEST*/