Actual source code: ex12.c

petsc-master 2018-05-25
Report Typos and Errors
  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 -info_exclude null,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 {NEUMANN, DIRICHLET, NONE} BCType;
 24: typedef enum {RUN_FULL, RUN_EXACT, RUN_TEST, RUN_PERF} RunType;
 25: typedef enum {COEFF_NONE, COEFF_ANALYTIC, COEFF_FIELD, COEFF_NONLINEAR, COEFF_CIRCLE, COEFF_CROSS} CoeffType;

 27: typedef struct {
 28:   PetscInt       debug;             /* The debugging level */
 29:   RunType        runType;           /* Whether to run tests, or solve the full problem */
 30:   PetscBool      jacobianMF;        /* Whether to calculate the Jacobian action on the fly */
 31:   PetscLogEvent  createMeshEvent;
 32:   PetscBool      showInitial, showSolution, restart, check, quiet, nonzInit;
 33:   /* Domain and mesh definition */
 34:   PetscInt       dim;               /* The topological mesh dimension */
 35:   DMBoundaryType periodicity[3];    /* The domain periodicity */
 36:   PetscInt       cells[3];          /* The initial domain division */
 37:   char           filename[2048];    /* The optional mesh file */
 38:   PetscBool      interpolate;       /* Generate intermediate mesh elements */
 39:   PetscReal      refinementLimit;   /* The largest allowable cell volume */
 40:   PetscBool      viewHierarchy;     /* Whether to view the hierarchy */
 41:   PetscBool      simplex;           /* Simplicial mesh */
 42:   /* Problem definition */
 43:   BCType         bcType;
 44:   CoeffType      variableCoefficient;
 45:   PetscErrorCode (**exactFuncs)(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx);
 46:   PetscBool      fieldBC;
 47:   void           (**exactFields)(PetscInt, PetscInt, PetscInt,
 48:                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
 49:                                  const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[],
 50:                                  PetscReal, const PetscReal[], PetscInt, const PetscScalar[], PetscScalar[]);
 51:   /* Solver */
 52:   PC            pcmg;              /* This is needed for error monitoring */
 53: } AppCtx;

 55: static PetscErrorCode zero(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
 56: {
 57:   u[0] = 0.0;
 58:   return 0;
 59: }

 61: static PetscErrorCode ecks(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
 62: {
 63:   u[0] = x[0];
 64:   return 0;
 65: }

 67: /*
 68:   In 2D for Dirichlet conditions, we use exact solution:

 70:     u = x^2 + y^2
 71:     f = 4

 73:   so that

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

 77:   For Neumann conditions, we have

 79:     -\nabla u \cdot -\hat y |_{y=0} =  (2y)|_{y=0} =  0 (bottom)
 80:     -\nabla u \cdot  \hat y |_{y=1} = -(2y)|_{y=1} = -2 (top)
 81:     -\nabla u \cdot -\hat x |_{x=0} =  (2x)|_{x=0} =  0 (left)
 82:     -\nabla u \cdot  \hat x |_{x=1} = -(2x)|_{x=1} = -2 (right)

 84:   Which we can express as

 86:     \nabla u \cdot  \hat n|_\Gamma = {2 x, 2 y} \cdot \hat n = 2 (x + y)
 87: */
 88: static PetscErrorCode quadratic_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
 89: {
 90:   *u = x[0]*x[0] + x[1]*x[1];
 91:   return 0;
 92: }

 94: static void quadratic_u_field_2d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
 95:                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
 96:                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
 97:                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uexact[])
 98: {
 99:   uexact[0] = a[0];
100: }

102: static PetscErrorCode circle_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
103: {
104:   const PetscReal alpha   = 500.;
105:   const PetscReal radius2 = PetscSqr(0.15);
106:   const PetscReal r2      = PetscSqr(x[0] - 0.5) + PetscSqr(x[1] - 0.5);
107:   const PetscReal xi      = alpha*(radius2 - r2);

109:   *u = PetscTanhScalar(xi) + 1.0;
110:   return 0;
111: }

113: static PetscErrorCode cross_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
114: {
115:   const PetscReal alpha = 50*4;
116:   const PetscReal xy    = (x[0]-0.5)*(x[1]-0.5);

118:   *u = PetscSinScalar(alpha*xy) * (alpha*PetscAbsScalar(xy) < 2*PETSC_PI ? 1 : 0.01);
119:   return 0;
120: }

122: static void f0_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
123:                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
124:                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
125:                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
126: {
127:   f0[0] = 4.0;
128: }

130: static void f0_circle_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
131:                         const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
132:                         const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
133:                         PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
134: {
135:   const PetscReal alpha   = 500.;
136:   const PetscReal radius2 = PetscSqr(0.15);
137:   const PetscReal r2      = PetscSqr(x[0] - 0.5) + PetscSqr(x[1] - 0.5);
138:   const PetscReal xi      = alpha*(radius2 - r2);

140:   f0[0] = (-4.0*alpha - 8.0*PetscSqr(alpha)*r2*PetscTanhReal(xi)) * PetscSqr(1.0/PetscCoshReal(xi));
141: }

143: static void f0_cross_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
144:                        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
145:                        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
146:                        PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
147: {
148:   const PetscReal alpha = 50*4;
149:   const PetscReal xy    = (x[0]-0.5)*(x[1]-0.5);

151:   f0[0] = PetscSinScalar(alpha*xy) * (alpha*PetscAbsScalar(xy) < 2*PETSC_PI ? 1 : 0.01);
152: }

154: static void f0_bd_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
155:                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
156:                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
157:                     PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
158: {
159:   PetscInt d;
160:   for (d = 0, f0[0] = 0.0; d < dim; ++d) f0[0] += -n[d]*2.0*x[d];
161: }

163: static void f1_bd_zero(PetscInt dim, PetscInt Nf, PetscInt NfAux,
164:                        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
165:                        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
166:                        PetscReal t, const PetscReal x[], const PetscReal n[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
167: {
168:   PetscInt comp;
169:   for (comp = 0; comp < dim; ++comp) f1[comp] = 0.0;
170: }

172: /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
173: static void f1_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
174:                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
175:                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
176:                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
177: {
178:   PetscInt d;
179:   for (d = 0; d < dim; ++d) f1[d] = u_x[d];
180: }

182: /* < \nabla v, \nabla u + {\nabla u}^T >
183:    This just gives \nabla u, give the perdiagonal for the transpose */
184: static void g3_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
185:                   const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
186:                   const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
187:                   PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
188: {
189:   PetscInt d;
190:   for (d = 0; d < dim; ++d) g3[d*dim+d] = 1.0;
191: }

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

196:     u = sin(2 pi x)
197:     f = -4 pi^2 sin(2 pi x)

199:   so that

201:     -\Delta u + f = 4 pi^2 sin(2 pi x) - 4 pi^2 sin(2 pi x) = 0
202: */
203: static PetscErrorCode xtrig_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
204: {
205:   *u = PetscSinReal(2.0*PETSC_PI*x[0]);
206:   return 0;
207: }

209: static void f0_xtrig_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
210:                        const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
211:                        const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
212:                        PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
213: {
214:   f0[0] = -4.0*PetscSqr(PETSC_PI)*PetscSinReal(2.0*PETSC_PI*x[0]);
215: }

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

220:     u = sin(2 pi x) sin(2 pi y)
221:     f = -8 pi^2 sin(2 pi x)

223:   so that

225:     -\Delta u + f = 4 pi^2 sin(2 pi x) sin(2 pi y) + 4 pi^2 sin(2 pi x) sin(2 pi y) - 8 pi^2 sin(2 pi x) = 0
226: */
227: static PetscErrorCode xytrig_u_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
228: {
229:   *u = PetscSinReal(2.0*PETSC_PI*x[0])*PetscSinReal(2.0*PETSC_PI*x[1]);
230:   return 0;
231: }

233: static void f0_xytrig_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
234:                         const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
235:                         const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
236:                         PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
237: {
238:   f0[0] = -8.0*PetscSqr(PETSC_PI)*PetscSinReal(2.0*PETSC_PI*x[0]);
239: }

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

244:     u  = x^2 + y^2
245:     f  = 6 (x + y)
246:     nu = (x + y)

248:   so that

250:     -\div \nu \grad u + f = -6 (x + y) + 6 (x + y) = 0
251: */
252: static PetscErrorCode nu_2d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
253: {
254:   *u = x[0] + x[1];
255:   return 0;
256: }

258: void f0_analytic_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
259:                    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
260:                    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
261:                    PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
262: {
263:   f0[0] = 6.0*(x[0] + x[1]);
264: }

266: /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
267: void f1_analytic_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
268:                    const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
269:                    const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
270:                    PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
271: {
272:   PetscInt d;
273:   for (d = 0; d < dim; ++d) f1[d] = (x[0] + x[1])*u_x[d];
274: }

276: void f1_field_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
277:                 const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
278:                 const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
279:                 PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
280: {
281:   PetscInt d;
282:   for (d = 0; d < dim; ++d) f1[d] = a[0]*u_x[d];
283: }

285: /* < \nabla v, \nabla u + {\nabla u}^T >
286:    This just gives \nabla u, give the perdiagonal for the transpose */
287: void g3_analytic_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
288:                     const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
289:                     const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
290:                     PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
291: {
292:   PetscInt d;
293:   for (d = 0; d < dim; ++d) g3[d*dim+d] = x[0] + x[1];
294: }

296: void g3_field_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
297:                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
298:                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
299:                  PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
300: {
301:   PetscInt d;
302:   for (d = 0; d < dim; ++d) g3[d*dim+d] = a[0];
303: }

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

308:     u  = x^2 + y^2
309:     f  = 16 (x^2 + y^2)
310:     nu = 1/2 |grad u|^2

312:   so that

314:     -\div \nu \grad u + f = -16 (x^2 + y^2) + 16 (x^2 + y^2) = 0
315: */
316: void f0_analytic_nonlinear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
317:                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
318:                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
319:                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f0[])
320: {
321:   f0[0] = 16.0*(x[0]*x[0] + x[1]*x[1]);
322: }

324: /* gradU[comp*dim+d] = {u_x, u_y} or {u_x, u_y, u_z} */
325: void f1_analytic_nonlinear_u(PetscInt dim, PetscInt Nf, PetscInt NfAux,
326:                              const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
327:                              const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
328:                              PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar f1[])
329: {
330:   PetscScalar nu = 0.0;
331:   PetscInt    d;
332:   for (d = 0; d < dim; ++d) nu += u_x[d]*u_x[d];
333:   for (d = 0; d < dim; ++d) f1[d] = 0.5*nu*u_x[d];
334: }

336: /*
337:   grad (u + eps w) - grad u = eps grad w

339:   1/2 |grad (u + eps w)|^2 grad (u + eps w) - 1/2 |grad u|^2 grad u
340: = 1/2 (|grad u|^2 + 2 eps <grad u,grad w>) (grad u + eps grad w) - 1/2 |grad u|^2 grad u
341: = 1/2 (eps |grad u|^2 grad w + 2 eps <grad u,grad w> grad u)
342: = eps (1/2 |grad u|^2 grad w + grad u <grad u,grad w>)
343: */
344: void g3_analytic_nonlinear_uu(PetscInt dim, PetscInt Nf, PetscInt NfAux,
345:                               const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
346:                               const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
347:                               PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g3[])
348: {
349:   PetscScalar nu = 0.0;
350:   PetscInt    d, e;
351:   for (d = 0; d < dim; ++d) nu += u_x[d]*u_x[d];
352:   for (d = 0; d < dim; ++d) {
353:     g3[d*dim+d] = 0.5*nu;
354:     for (e = 0; e < dim; ++e) {
355:       g3[d*dim+e] += u_x[d]*u_x[e];
356:     }
357:   }
358: }

360: /*
361:   In 3D for Dirichlet conditions we use exact solution:

363:     u = 2/3 (x^2 + y^2 + z^2)
364:     f = 4

366:   so that

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

370:   For Neumann conditions, we have

372:     -\nabla u \cdot -\hat z |_{z=0} =  (2z)|_{z=0} =  0 (bottom)
373:     -\nabla u \cdot  \hat z |_{z=1} = -(2z)|_{z=1} = -2 (top)
374:     -\nabla u \cdot -\hat y |_{y=0} =  (2y)|_{y=0} =  0 (front)
375:     -\nabla u \cdot  \hat y |_{y=1} = -(2y)|_{y=1} = -2 (back)
376:     -\nabla u \cdot -\hat x |_{x=0} =  (2x)|_{x=0} =  0 (left)
377:     -\nabla u \cdot  \hat x |_{x=1} = -(2x)|_{x=1} = -2 (right)

379:   Which we can express as

381:     \nabla u \cdot  \hat n|_\Gamma = {2 x, 2 y, 2z} \cdot \hat n = 2 (x + y + z)
382: */
383: static PetscErrorCode quadratic_u_3d(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar *u, void *ctx)
384: {
385:   *u = 2.0*(x[0]*x[0] + x[1]*x[1] + x[2]*x[2])/3.0;
386:   return 0;
387: }

389: static void quadratic_u_field_3d(PetscInt dim, PetscInt Nf, PetscInt NfAux,
390:                                  const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[],
391:                                  const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[],
392:                                  PetscReal t, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar uexact[])
393: {
394:   uexact[0] = a[0];
395: }

397: static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options)
398: {
399:   const char    *bcTypes[3]  = {"neumann", "dirichlet", "none"};
400:   const char    *runTypes[4] = {"full", "exact", "test", "perf"};
401:   const char    *coeffTypes[6] = {"none", "analytic", "field", "nonlinear", "circle", "cross"};
402:   PetscInt       bd, bc, run, coeff, n;
403:   PetscBool      flg;

407:   options->debug               = 0;
408:   options->runType             = RUN_FULL;
409:   options->dim                 = 2;
410:   options->periodicity[0]      = DM_BOUNDARY_NONE;
411:   options->periodicity[1]      = DM_BOUNDARY_NONE;
412:   options->periodicity[2]      = DM_BOUNDARY_NONE;
413:   options->cells[0]            = 2;
414:   options->cells[1]            = 2;
415:   options->cells[2]            = 2;
416:   options->filename[0]         = '\0';
417:   options->interpolate         = PETSC_FALSE;
418:   options->refinementLimit     = 0.0;
419:   options->bcType              = DIRICHLET;
420:   options->variableCoefficient = COEFF_NONE;
421:   options->fieldBC             = PETSC_FALSE;
422:   options->jacobianMF          = PETSC_FALSE;
423:   options->showInitial         = PETSC_FALSE;
424:   options->showSolution        = PETSC_FALSE;
425:   options->restart             = PETSC_FALSE;
426:   options->check               = PETSC_FALSE;
427:   options->viewHierarchy       = PETSC_FALSE;
428:   options->simplex             = PETSC_TRUE;
429:   options->quiet               = PETSC_FALSE;
430:   options->nonzInit            = PETSC_FALSE;

432:   PetscOptionsBegin(comm, "", "Poisson Problem Options", "DMPLEX");
433:   PetscOptionsInt("-debug", "The debugging level", "ex12.c", options->debug, &options->debug, NULL);
434:   run  = options->runType;
435:   PetscOptionsEList("-run_type", "The run type", "ex12.c", runTypes, 3, runTypes[options->runType], &run, NULL);

437:   options->runType = (RunType) run;

439:   PetscOptionsInt("-dim", "The topological mesh dimension", "ex12.c", options->dim, &options->dim, NULL);
440:   bd = options->periodicity[0];
441:   PetscOptionsEList("-x_periodicity", "The x-boundary periodicity", "ex12.c", DMBoundaryTypes, 5, DMBoundaryTypes[options->periodicity[0]], &bd, NULL);
442:   options->periodicity[0] = (DMBoundaryType) bd;
443:   bd = options->periodicity[1];
444:   PetscOptionsEList("-y_periodicity", "The y-boundary periodicity", "ex12.c", DMBoundaryTypes, 5, DMBoundaryTypes[options->periodicity[1]], &bd, NULL);
445:   options->periodicity[1] = (DMBoundaryType) bd;
446:   bd = options->periodicity[2];
447:   PetscOptionsEList("-z_periodicity", "The z-boundary periodicity", "ex12.c", DMBoundaryTypes, 5, DMBoundaryTypes[options->periodicity[2]], &bd, NULL);
448:   options->periodicity[2] = (DMBoundaryType) bd;
449:   n = 3;
450:   PetscOptionsIntArray("-cells", "The initial mesh division", "ex12.c", options->cells, &n, NULL);
451:   PetscOptionsString("-f", "Mesh filename to read", "ex12.c", options->filename, options->filename, sizeof(options->filename), &flg);
452:   PetscOptionsBool("-interpolate", "Generate intermediate mesh elements", "ex12.c", options->interpolate, &options->interpolate, NULL);
453:   PetscOptionsReal("-refinement_limit", "The largest allowable cell volume", "ex12.c", options->refinementLimit, &options->refinementLimit, NULL);
454:   bc   = options->bcType;
455:   PetscOptionsEList("-bc_type","Type of boundary condition","ex12.c",bcTypes,3,bcTypes[options->bcType],&bc,NULL);
456:   options->bcType = (BCType) bc;
457:   coeff = options->variableCoefficient;
458:   PetscOptionsEList("-variable_coefficient","Type of variable coefficent","ex12.c",coeffTypes,6,coeffTypes[options->variableCoefficient],&coeff,NULL);
459:   options->variableCoefficient = (CoeffType) coeff;

461:   PetscOptionsBool("-field_bc", "Use a field representation for the BC", "ex12.c", options->fieldBC, &options->fieldBC, NULL);
462:   PetscOptionsBool("-jacobian_mf", "Calculate the action of the Jacobian on the fly", "ex12.c", options->jacobianMF, &options->jacobianMF, NULL);
463:   PetscOptionsBool("-show_initial", "Output the initial guess for verification", "ex12.c", options->showInitial, &options->showInitial, NULL);
464:   PetscOptionsBool("-show_solution", "Output the solution for verification", "ex12.c", options->showSolution, &options->showSolution, NULL);
465:   PetscOptionsBool("-restart", "Read in the mesh and solution from a file", "ex12.c", options->restart, &options->restart, NULL);
466:   PetscOptionsBool("-check", "Compare with default integration routines", "ex12.c", options->check, &options->check, NULL);
467:   PetscOptionsBool("-dm_view_hierarchy", "View the coarsened hierarchy", "ex12.c", options->viewHierarchy, &options->viewHierarchy, NULL);
468:   PetscOptionsBool("-simplex", "Simplicial (true) or tensor (false) mesh", "ex12.c", options->simplex, &options->simplex, NULL);
469:   PetscOptionsBool("-quiet", "Don't print any vecs", "ex12.c", options->quiet, &options->quiet, NULL);
470:   PetscOptionsBool("-nonzero_initial_guess", "nonzero intial guess", "ex12.c", options->nonzInit, &options->nonzInit, NULL);
471:   PetscOptionsEnd();
472:   PetscLogEventRegister("CreateMesh", DM_CLASSID, &options->createMeshEvent);
473:   return(0);
474: }

476: static PetscErrorCode CreateBCLabel(DM dm, const char name[])
477: {
478:   DMLabel        label;

482:   DMCreateLabel(dm, name);
483:   DMGetLabel(dm, name, &label);
484:   DMPlexMarkBoundaryFaces(dm, 1, label);
485:   DMPlexLabelComplete(dm, label);
486:   return(0);
487: }

489: static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm)
490: {
491:   PetscInt       dim             = user->dim;
492:   const char    *filename        = user->filename;
493:   PetscBool      interpolate     = user->interpolate;
494:   PetscReal      refinementLimit = user->refinementLimit;
495:   size_t         len;

499:   PetscLogEventBegin(user->createMeshEvent,0,0,0,0);
500:   PetscStrlen(filename, &len);
501:   if (!len) {
502:     PetscInt d;

504:     if (user->periodicity[0] || user->periodicity[1] || user->periodicity[2]) for (d = 0; d < dim; ++d) user->cells[d] = PetscMax(user->cells[d], 3);
505:     DMPlexCreateBoxMesh(comm, dim, user->simplex, user->cells, NULL, NULL, user->periodicity, interpolate, dm);
506:     PetscObjectSetName((PetscObject) *dm, "Mesh");
507:   } else {
508:     DMPlexCreateFromFile(comm, filename, interpolate, dm);
509:     DMPlexSetRefinementUniform(*dm, PETSC_FALSE);
510:   }
511:   {
512:     PetscPartitioner part;
513:     DM               refinedMesh     = NULL;
514:     DM               distributedMesh = NULL;

516:     /* Refine mesh using a volume constraint */
517:     if (refinementLimit > 0.0) {
518:       DMPlexSetRefinementLimit(*dm, refinementLimit);
519:       DMRefine(*dm, comm, &refinedMesh);
520:       if (refinedMesh) {
521:         const char *name;

523:         PetscObjectGetName((PetscObject) *dm,         &name);
524:         PetscObjectSetName((PetscObject) refinedMesh,  name);
525:         DMDestroy(dm);
526:         *dm  = refinedMesh;
527:       }
528:     }
529:     /* Distribute mesh over processes */
530:     DMPlexGetPartitioner(*dm,&part);
531:     PetscPartitionerSetFromOptions(part);
532:     DMPlexDistribute(*dm, 0, NULL, &distributedMesh);
533:     if (distributedMesh) {
534:       DMDestroy(dm);
535:       *dm  = distributedMesh;
536:     }
537:   }
538:   if (user->bcType == NEUMANN) {
539:     DMLabel   label;

541:     DMCreateLabel(*dm, "boundary");
542:     DMGetLabel(*dm, "boundary", &label);
543:     DMPlexMarkBoundaryFaces(*dm, 1, label);
544:   } else if (user->bcType == DIRICHLET) {
545:     PetscBool hasLabel;

547:     DMHasLabel(*dm,"marker",&hasLabel);
548:     if (!hasLabel) {CreateBCLabel(*dm, "marker");}
549:   }
550:   {
551:     char      convType[256];
552:     PetscBool flg;

554:     PetscOptionsBegin(comm, "", "Mesh conversion options", "DMPLEX");
555:     PetscOptionsFList("-dm_plex_convert_type","Convert DMPlex to another format","ex12",DMList,DMPLEX,convType,256,&flg);
556:     PetscOptionsEnd();
557:     if (flg) {
558:       DM dmConv;

560:       DMConvert(*dm,convType,&dmConv);
561:       if (dmConv) {
562:         DMDestroy(dm);
563:         *dm  = dmConv;
564:       }
565:     }
566:   }
567:   DMLocalizeCoordinates(*dm); /* needed for periodic */
568:   DMSetFromOptions(*dm);
569:   DMViewFromOptions(*dm, NULL, "-dm_view");
570:   if (user->viewHierarchy) {
571:     DM       cdm = *dm;
572:     PetscInt i   = 0;
573:     char     buf[256];

575:     while (cdm) {
576:       DMSetUp(cdm);
577:       DMGetCoarseDM(cdm, &cdm);
578:       ++i;
579:     }
580:     cdm = *dm;
581:     while (cdm) {
582:       PetscViewer       viewer;
583:       PetscBool   isHDF5, isVTK;

585:       --i;
586:       PetscViewerCreate(comm,&viewer);
587:       PetscViewerSetType(viewer,PETSCVIEWERHDF5);
588:       PetscViewerSetOptionsPrefix(viewer,"hierarchy_");
589:       PetscViewerSetFromOptions(viewer);
590:       PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&isHDF5);
591:       PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERVTK,&isVTK);
592:       if (isHDF5) {
593:         PetscSNPrintf(buf, 256, "ex12-%d.h5", i);
594:       } else if (isVTK) {
595:         PetscSNPrintf(buf, 256, "ex12-%d.vtu", i);
596:         PetscViewerPushFormat(viewer,PETSC_VIEWER_VTK_VTU);
597:       } else {
598:         PetscSNPrintf(buf, 256, "ex12-%d", i);
599:       }
600:       PetscViewerFileSetMode(viewer,FILE_MODE_WRITE);
601:       PetscViewerFileSetName(viewer,buf);
602:       DMView(cdm, viewer);
603:       PetscViewerDestroy(&viewer);
604:       DMGetCoarseDM(cdm, &cdm);
605:     }
606:   }
607:   PetscLogEventEnd(user->createMeshEvent,0,0,0,0);
608:   return(0);
609: }

611: static PetscErrorCode SetupProblem(PetscDS prob, AppCtx *user)
612: {
613:   const PetscInt id = 1;

617:   switch (user->variableCoefficient) {
618:   case COEFF_NONE:
619:     if (user->periodicity[0]) {
620:       if (user->periodicity[1]) {
621:         PetscDSSetResidual(prob, 0, f0_xytrig_u, f1_u);
622:         PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_uu);
623:       } else {
624:         PetscDSSetResidual(prob, 0, f0_xtrig_u,  f1_u);
625:         PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_uu);
626:       }
627:     } else {
628:       PetscDSSetResidual(prob, 0, f0_u, f1_u);
629:       PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_uu);
630:     }
631:     break;
632:   case COEFF_ANALYTIC:
633:     PetscDSSetResidual(prob, 0, f0_analytic_u, f1_analytic_u);
634:     PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_analytic_uu);
635:     break;
636:   case COEFF_FIELD:
637:     PetscDSSetResidual(prob, 0, f0_analytic_u, f1_field_u);
638:     PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_field_uu);
639:     break;
640:   case COEFF_NONLINEAR:
641:     PetscDSSetResidual(prob, 0, f0_analytic_nonlinear_u, f1_analytic_nonlinear_u);
642:     PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_analytic_nonlinear_uu);
643:     break;
644:   case COEFF_CIRCLE:
645:     PetscDSSetResidual(prob, 0, f0_circle_u, f1_u);
646:     PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_uu);
647:     break;
648:   case COEFF_CROSS:
649:     PetscDSSetResidual(prob, 0, f0_cross_u, f1_u);
650:     PetscDSSetJacobian(prob, 0, 0, NULL, NULL, NULL, g3_uu);
651:     break;
652:   default: SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid variable coefficient type %d", user->variableCoefficient);
653:   }
654:   switch (user->dim) {
655:   case 2:
656:     switch (user->variableCoefficient) {
657:     case COEFF_CIRCLE:
658:       user->exactFuncs[0]  = circle_u_2d;break;
659:     case COEFF_CROSS:
660:       user->exactFuncs[0]  = cross_u_2d;break;
661:     default:
662:       if (user->periodicity[0]) {
663:         if (user->periodicity[1]) {
664:           user->exactFuncs[0] = xytrig_u_2d;
665:         } else {
666:           user->exactFuncs[0] = xtrig_u_2d;
667:         }
668:       } else {
669:         user->exactFuncs[0]  = quadratic_u_2d;
670:         user->exactFields[0] = quadratic_u_field_2d;
671:       }
672:     }
673:     if (user->bcType == NEUMANN) {PetscDSSetBdResidual(prob, 0, f0_bd_u, f1_bd_zero);}
674:     break;
675:   case 3:
676:     user->exactFuncs[0]  = quadratic_u_3d;
677:     user->exactFields[0] = quadratic_u_field_3d;
678:     if (user->bcType == NEUMANN) {PetscDSSetBdResidual(prob, 0, f0_bd_u, f1_bd_zero);}
679:     break;
680:   default:
681:     SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %d", user->dim);
682:   }
683:   PetscDSAddBoundary(prob, user->bcType == DIRICHLET ? (user->fieldBC ? DM_BC_ESSENTIAL_FIELD : DM_BC_ESSENTIAL) : DM_BC_NATURAL,
684:                             "wall", user->bcType == DIRICHLET ? "marker" : "boundary", 0, 0, NULL,
685:                             user->fieldBC ? (void (*)()) user->exactFields[0] : (void (*)()) user->exactFuncs[0], 1, &id, user);
686:   PetscDSSetExactSolution(prob, 0, user->exactFuncs[0]);
687:   PetscDSSetFromOptions(prob);
688:   return(0);
689: }

691: static PetscErrorCode SetupMaterial(DM dm, DM dmAux, AppCtx *user)
692: {
693:   PetscErrorCode (*matFuncs[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) = {nu_2d};
694:   Vec            nu;

698:   DMCreateLocalVector(dmAux, &nu);
699:   DMProjectFunctionLocal(dmAux, 0.0, matFuncs, NULL, INSERT_ALL_VALUES, nu);
700:   PetscObjectCompose((PetscObject) dm, "A", (PetscObject) nu);
701:   VecDestroy(&nu);
702:   return(0);
703: }

705: static PetscErrorCode SetupBC(DM dm, DM dmAux, AppCtx *user)
706: {
707:   PetscErrorCode (*bcFuncs[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx);
708:   Vec            uexact;
709:   PetscInt       dim;

713:   DMGetDimension(dm, &dim);
714:   if (dim == 2) bcFuncs[0] = quadratic_u_2d;
715:   else          bcFuncs[0] = quadratic_u_3d;
716:   DMCreateLocalVector(dmAux, &uexact);
717:   DMProjectFunctionLocal(dmAux, 0.0, bcFuncs, NULL, INSERT_ALL_VALUES, uexact);
718:   PetscObjectCompose((PetscObject) dm, "A", (PetscObject) uexact);
719:   VecDestroy(&uexact);
720:   return(0);
721: }

723: static PetscErrorCode SetupDiscretization(DM dm, AppCtx *user)
724: {
725:   DM             cdm   = dm;
726:   const PetscInt dim   = user->dim;
727:   PetscFE        feAux = NULL;
728:   PetscFE        feCh  = NULL;
729:   PetscFE        fe;
730:   PetscDS        prob, probAux = NULL, probCh = NULL;
731:   PetscBool      simplex = user->simplex;
732:   MPI_Comm       comm;

736:   /* Create finite element */
737:   PetscObjectGetComm((PetscObject) dm, &comm);
738:   PetscFECreateDefault(comm, dim, 1, simplex, NULL, -1, &fe);
739:   PetscObjectSetName((PetscObject) fe, "potential");
740:   if (user->variableCoefficient == COEFF_FIELD) {
741:     PetscQuadrature q;

743:     PetscFECreateDefault(comm, dim, 1, simplex, "mat_", -1, &feAux);
744:     PetscFEGetQuadrature(fe, &q);
745:     PetscFESetQuadrature(feAux, q);
746:     PetscDSCreate(PetscObjectComm((PetscObject)dm),&probAux);
747:     PetscDSSetDiscretization(probAux, 0, (PetscObject) feAux);
748:   } else if (user->fieldBC) {
749:     PetscQuadrature q;

751:     PetscFECreateDefault(comm, dim, 1, simplex, "bc_", -1, &feAux);
752:     PetscFEGetQuadrature(fe, &q);
753:     PetscFESetQuadrature(feAux, q);
754:     PetscDSCreate(PetscObjectComm((PetscObject)dm),&probAux);
755:     PetscDSSetDiscretization(probAux, 0, (PetscObject) feAux);
756:   }
757:   if (user->check) {
758:     PetscFECreateDefault(comm, dim, 1, simplex, "ch_", -1, &feCh);
759:     PetscDSCreate(PetscObjectComm((PetscObject)dm),&probCh);
760:     PetscDSSetDiscretization(probCh, 0, (PetscObject) feCh);
761:   }
762:   /* Set discretization and boundary conditions for each mesh */
763:   DMGetDS(dm, &prob);
764:   PetscDSSetDiscretization(prob, 0, (PetscObject) fe);
765:   SetupProblem(prob, user);
766:   while (cdm) {
767:     DM coordDM;

769:     DMSetDS(cdm,prob);
770:     DMGetCoordinateDM(cdm,&coordDM);
771:     if (feAux) {
772:       DM      dmAux;

774:       DMClone(cdm, &dmAux);
775:       DMSetCoordinateDM(dmAux, coordDM);
776:       DMSetDS(dmAux, probAux);
777:       PetscObjectCompose((PetscObject) dm, "dmAux", (PetscObject) dmAux);
778:       if (user->fieldBC) {SetupBC(cdm, dmAux, user);}
779:       else               {SetupMaterial(cdm, dmAux, user);}
780:       DMDestroy(&dmAux);
781:     }
782:     if (feCh) {
783:       DM      dmCh;

785:       DMClone(cdm, &dmCh);
786:       DMSetCoordinateDM(dmCh, coordDM);
787:       DMSetDS(dmCh, probCh);
788:       PetscObjectCompose((PetscObject) dm, "dmCh", (PetscObject) dmCh);
789:       DMDestroy(&dmCh);
790:     }
791:     if (user->bcType == DIRICHLET) {
792:       PetscBool hasLabel;

794:       DMHasLabel(cdm, "marker", &hasLabel);
795:       if (!hasLabel) {CreateBCLabel(cdm, "marker");}
796:     }
797:     DMGetCoarseDM(cdm, &cdm);
798:   }
799:   PetscFEDestroy(&fe);
800:   PetscFEDestroy(&feAux);
801:   PetscFEDestroy(&feCh);
802:   PetscDSDestroy(&probAux);
803:   PetscDSDestroy(&probCh);
804:   return(0);
805: }

807: #include "petsc/private/petscimpl.h"

809: /*@C
810:   KSPMonitorError - Outputs the error at each iteration of an iterative solver.

812:   Collective on KSP

814:   Input Parameters:
815: + ksp   - the KSP
816: . its   - iteration number
817: . rnorm - 2-norm, preconditioned residual value (may be estimated).
818: - ctx   - monitor context

820:   Level: intermediate

822: .keywords: KSP, default, monitor, residual
823: .seealso: KSPMonitorSet(), KSPMonitorTrueResidualNorm(), KSPMonitorDefault()
824: @*/
825: static PetscErrorCode KSPMonitorError(KSP ksp, PetscInt its, PetscReal rnorm, void *ctx)
826: {
827:   AppCtx        *user = (AppCtx *) ctx;
828:   DM             dm;
829:   Vec            du, r;
830:   PetscInt       level = 0;
831:   PetscBool      hasLevel;
832: #if defined(PETSC_HAVE_HDF5)
833:   PetscViewer    viewer;
834:   char           buf[256];
835: #endif

839:   KSPGetDM(ksp, &dm);
840:   /* Calculate solution */
841:   {
842:     PC        pc = user->pcmg; /* The MG PC */
843:     DM        fdm = NULL,  cdm;
844:     KSP       fksp, cksp;
845:     Vec       fu,   cu;
846:     PetscInt  levels, l;

848:     KSPBuildSolution(ksp, NULL, &du);
849:     PetscObjectComposedDataGetInt((PetscObject) ksp, PetscMGLevelId, level, hasLevel);
850:     PCMGGetLevels(pc, &levels);
851:     PCMGGetSmoother(pc, levels-1, &fksp);
852:     KSPBuildSolution(fksp, NULL, &fu);
853:     for (l = levels-1; l > level; --l) {
854:       Mat R;
855:       Vec s;

857:       PCMGGetSmoother(pc, l-1, &cksp);
858:       KSPGetDM(cksp, &cdm);
859:       DMGetGlobalVector(cdm, &cu);
860:       PCMGGetRestriction(pc, l, &R);
861:       PCMGGetRScale(pc, l, &s);
862:       MatRestrict(R, fu, cu);
863:       VecPointwiseMult(cu, cu, s);
864:       if (l < levels-1) {DMRestoreGlobalVector(fdm, &fu);}
865:       fdm  = cdm;
866:       fu   = cu;
867:     }
868:     if (levels-1 > level) {
869:       VecAXPY(du, 1.0, cu);
870:       DMRestoreGlobalVector(cdm, &cu);
871:     }
872:   }
873:   /* Calculate error */
874:   DMGetGlobalVector(dm, &r);
875:   DMProjectFunction(dm, 0.0, user->exactFuncs, NULL, INSERT_ALL_VALUES, r);
876:   VecAXPY(r,-1.0,du);
877:   PetscObjectSetName((PetscObject) r, "solution error");
878:   /* View error */
879: #if defined(PETSC_HAVE_HDF5)
880:   PetscSNPrintf(buf, 256, "ex12-%D.h5", level);
881:   PetscViewerHDF5Open(PETSC_COMM_WORLD, buf, FILE_MODE_APPEND, &viewer);
882:   VecView(r, viewer);
883:   PetscViewerDestroy(&viewer);
884: #endif
885:   DMRestoreGlobalVector(dm, &r);
886:   return(0);
887: }

889: /*@C
890:   SNESMonitorError - Outputs the error at each iteration of an iterative solver.

892:   Collective on SNES

894:   Input Parameters:
895: + snes  - the SNES
896: . its   - iteration number
897: . rnorm - 2-norm of residual
898: - ctx   - user context

900:   Level: intermediate

902: .keywords: SNES, nonlinear, default, monitor, norm
903: .seealso: SNESMonitorDefault(), SNESMonitorSet(), SNESMonitorSolution()
904: @*/
905: static PetscErrorCode SNESMonitorError(SNES snes, PetscInt its, PetscReal rnorm, void *ctx)
906: {
907:   AppCtx        *user = (AppCtx *) ctx;
908:   DM             dm;
909:   Vec            u, r;
910:   PetscInt       level = -1;
911:   PetscBool      hasLevel;
912: #if defined(PETSC_HAVE_HDF5)
913:   PetscViewer    viewer;
914: #endif
915:   char           buf[256];

919:   SNESGetDM(snes, &dm);
920:   /* Calculate error */
921:   SNESGetSolution(snes, &u);
922:   DMGetGlobalVector(dm, &r);
923:   PetscObjectSetName((PetscObject) r, "solution error");
924:   DMProjectFunction(dm, 0.0, user->exactFuncs, NULL, INSERT_ALL_VALUES, r);
925:   VecAXPY(r, -1.0, u);
926:   /* View error */
927:   PetscObjectComposedDataGetInt((PetscObject) snes, PetscMGLevelId, level, hasLevel);
928:   PetscSNPrintf(buf, 256, "ex12-%D.h5", level);
929: #if defined(PETSC_HAVE_HDF5)
930:   PetscViewerHDF5Open(PETSC_COMM_WORLD, buf, FILE_MODE_APPEND, &viewer);
931:   VecView(r, viewer);
932:   PetscViewerDestroy(&viewer);
933:   /* Cleanup */
934:   DMRestoreGlobalVector(dm, &r);
935:   return(0);
936: #else
937:   SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"You need to configure with --download-hdf5");
938: #endif
939: }

941: int main(int argc, char **argv)
942: {
943:   DM             dm;          /* Problem specification */
944:   SNES           snes;        /* nonlinear solver */
945:   Vec            u;           /* solution vector */
946:   Mat            A,J;         /* Jacobian matrix */
947:   MatNullSpace   nullSpace;   /* May be necessary for Neumann conditions */
948:   AppCtx         user;        /* user-defined work context */
949:   JacActionCtx   userJ;       /* context for Jacobian MF action */
950:   PetscReal      error = 0.0; /* L_2 error in the solution */
951:   PetscBool      isFAS;

954:   PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr;
955:   ProcessOptions(PETSC_COMM_WORLD, &user);
956:   SNESCreate(PETSC_COMM_WORLD, &snes);
957:   CreateMesh(PETSC_COMM_WORLD, &user, &dm);
958:   SNESSetDM(snes, dm);
959:   DMSetApplicationContext(dm, &user);

961:   PetscMalloc2(1, &user.exactFuncs, 1, &user.exactFields);
962:   SetupDiscretization(dm, &user);

964:   DMCreateGlobalVector(dm, &u);
965:   PetscObjectSetName((PetscObject) u, "potential");

967:   DMCreateMatrix(dm, &J);
968:   if (user.jacobianMF) {
969:     PetscInt M, m, N, n;

971:     MatGetSize(J, &M, &N);
972:     MatGetLocalSize(J, &m, &n);
973:     MatCreate(PETSC_COMM_WORLD, &A);
974:     MatSetSizes(A, m, n, M, N);
975:     MatSetType(A, MATSHELL);
976:     MatSetUp(A);
977: #if 0
978:     MatShellSetOperation(A, MATOP_MULT, (void (*)(void))FormJacobianAction);
979: #endif

981:     userJ.dm   = dm;
982:     userJ.J    = J;
983:     userJ.user = &user;

985:     DMCreateLocalVector(dm, &userJ.u);
986:     if (user.fieldBC) {DMProjectFieldLocal(dm, 0.0, userJ.u, user.exactFields, INSERT_BC_VALUES, userJ.u);}
987:     else              {DMProjectFunctionLocal(dm, 0.0, user.exactFuncs, NULL, INSERT_BC_VALUES, userJ.u);}
988:     MatShellSetContext(A, &userJ);
989:   } else {
990:     A = J;
991:   }
992:   if (user.bcType == NEUMANN) {
993:     MatNullSpaceCreate(PetscObjectComm((PetscObject) dm), PETSC_TRUE, 0, NULL, &nullSpace);
994:     MatSetNullSpace(A, nullSpace);
995:   }

997:   DMPlexSetSNESLocalFEM(dm,&user,&user,&user);
998:   SNESSetJacobian(snes, A, J, NULL, NULL);

1000:   SNESSetFromOptions(snes);

1002:   if (user.fieldBC) {DMProjectField(dm, 0.0, u, user.exactFields, INSERT_ALL_VALUES, u);}
1003:   else              {DMProjectFunction(dm, 0.0, user.exactFuncs, NULL, INSERT_ALL_VALUES, u);}
1004:   if (user.restart) {
1005: #if defined(PETSC_HAVE_HDF5)
1006:     PetscViewer viewer;

1008:     PetscViewerCreate(PETSC_COMM_WORLD, &viewer);
1009:     PetscViewerSetType(viewer, PETSCVIEWERHDF5);
1010:     PetscViewerFileSetMode(viewer, FILE_MODE_READ);
1011:     PetscViewerFileSetName(viewer, user.filename);
1012:     PetscViewerHDF5PushGroup(viewer, "/fields");
1013:     VecLoad(u, viewer);
1014:     PetscViewerHDF5PopGroup(viewer);
1015:     PetscViewerDestroy(&viewer);
1016: #endif
1017:   }
1018:   if (user.showInitial) {
1019:     Vec lv;
1020:     DMGetLocalVector(dm, &lv);
1021:     DMGlobalToLocalBegin(dm, u, INSERT_VALUES, lv);
1022:     DMGlobalToLocalEnd(dm, u, INSERT_VALUES, lv);
1023:     DMPrintLocalVec(dm, "Local function", 1.0e-10, lv);
1024:     DMRestoreLocalVector(dm, &lv);
1025:   }
1026:   if (user.viewHierarchy) {
1027:     SNES      lsnes;
1028:     KSP       ksp;
1029:     PC        pc;
1030:     PetscInt  numLevels, l;
1031:     PetscBool isMG;

1033:     PetscObjectTypeCompare((PetscObject) snes, SNESFAS, &isFAS);
1034:     if (isFAS) {
1035:       SNESFASGetLevels(snes, &numLevels);
1036:       for (l = 0; l < numLevels; ++l) {
1037:         SNESFASGetCycleSNES(snes, l, &lsnes);
1038:         SNESMonitorSet(lsnes, SNESMonitorError, &user, NULL);
1039:       }
1040:     } else {
1041:       SNESGetKSP(snes, &ksp);
1042:       KSPGetPC(ksp, &pc);
1043:       PetscObjectTypeCompare((PetscObject) pc, PCMG, &isMG);
1044:       if (isMG) {
1045:         user.pcmg = pc;
1046:         PCMGGetLevels(pc, &numLevels);
1047:         for (l = 0; l < numLevels; ++l) {
1048:           PCMGGetSmootherDown(pc, l, &ksp);
1049:           KSPMonitorSet(ksp, KSPMonitorError, &user, NULL);
1050:         }
1051:       }
1052:     }
1053:   }
1054:   if (user.runType == RUN_FULL || user.runType == RUN_EXACT) {
1055:     PetscErrorCode (*initialGuess[1])(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nc, PetscScalar u[], void *ctx) = {zero};

1057:     if (user.nonzInit) initialGuess[0] = ecks;
1058:     if (user.runType == RUN_FULL) {
1059:       DMProjectFunction(dm, 0.0, initialGuess, NULL, INSERT_VALUES, u);
1060:     }
1061:     if (user.debug) {
1062:       PetscPrintf(PETSC_COMM_WORLD, "Initial guess\n");
1063:       VecView(u, PETSC_VIEWER_STDOUT_WORLD);
1064:     }
1065:     SNESSolve(snes, NULL, u);
1066:     SNESGetSolution(snes, &u);
1067:     SNESGetDM(snes, &dm);

1069:     if (user.showSolution) {
1070:       PetscPrintf(PETSC_COMM_WORLD, "Solution\n");
1071:       VecChop(u, 3.0e-9);
1072:       VecView(u, PETSC_VIEWER_STDOUT_WORLD);
1073:     }
1074:     VecViewFromOptions(u, NULL, "-vec_view");
1075:   } else if (user.runType == RUN_PERF) {
1076:     Vec       r;
1077:     PetscReal res = 0.0;

1079:     SNESGetFunction(snes, &r, NULL, NULL);
1080:     SNESComputeFunction(snes, u, r);
1081:     PetscPrintf(PETSC_COMM_WORLD, "Initial Residual\n");
1082:     VecChop(r, 1.0e-10);
1083:     VecNorm(r, NORM_2, &res);
1084:     PetscPrintf(PETSC_COMM_WORLD, "L_2 Residual: %g\n", res);
1085:   } else {
1086:     Vec       r;
1087:     PetscReal res = 0.0, tol = 1.0e-11;

1089:     /* Check discretization error */
1090:     SNESGetFunction(snes, &r, NULL, NULL);
1091:     PetscPrintf(PETSC_COMM_WORLD, "Initial guess\n");
1092:     if (!user.quiet) {VecView(u, PETSC_VIEWER_STDOUT_WORLD);}
1093:     DMComputeL2Diff(dm, 0.0, user.exactFuncs, NULL, u, &error);
1094:     if (error < tol) {PetscPrintf(PETSC_COMM_WORLD, "L_2 Error: < %2.1e\n", tol);}
1095:     else             {PetscPrintf(PETSC_COMM_WORLD, "L_2 Error: %g\n", error);}
1096:     /* Check residual */
1097:     SNESComputeFunction(snes, u, r);
1098:     PetscPrintf(PETSC_COMM_WORLD, "Initial Residual\n");
1099:     VecChop(r, 1.0e-10);
1100:     if (!user.quiet) {VecView(r, PETSC_VIEWER_STDOUT_WORLD);}
1101:     VecNorm(r, NORM_2, &res);
1102:     PetscPrintf(PETSC_COMM_WORLD, "L_2 Residual: %g\n", res);
1103:     /* Check Jacobian */
1104:     {
1105:       Vec b;

1107:       SNESComputeJacobian(snes, u, A, A);
1108:       VecDuplicate(u, &b);
1109:       VecSet(r, 0.0);
1110:       SNESComputeFunction(snes, r, b);
1111:       MatMult(A, u, r);
1112:       VecAXPY(r, 1.0, b);
1113:       VecDestroy(&b);
1114:       PetscPrintf(PETSC_COMM_WORLD, "Au - b = Au + F(0)\n");
1115:       VecChop(r, 1.0e-10);
1116:       if (!user.quiet) {VecView(r, PETSC_VIEWER_STDOUT_WORLD);}
1117:       VecNorm(r, NORM_2, &res);
1118:       PetscPrintf(PETSC_COMM_WORLD, "Linear L_2 Residual: %g\n", res);
1119:     }
1120:   }
1121:   VecViewFromOptions(u, NULL, "-vec_view");

1123:   if (user.bcType == NEUMANN) {MatNullSpaceDestroy(&nullSpace);}
1124:   if (user.jacobianMF) {VecDestroy(&userJ.u);}
1125:   if (A != J) {MatDestroy(&A);}
1126:   MatDestroy(&J);
1127:   VecDestroy(&u);
1128:   SNESDestroy(&snes);
1129:   DMDestroy(&dm);
1130:   PetscFree2(user.exactFuncs, user.exactFields);
1131:   PetscFinalize();
1132:   return ierr;
1133: }

1135: /*TEST
1136:   build:
1137:     requires: triangle
1138:   # 2D serial P1 test 0-4
1139:   test:
1140:     suffix: 0
1141:     requires: triangle
1142:     args: -run_type test -refinement_limit 0.0    -bc_type dirichlet -interpolate 0 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1144:   test:
1145:     suffix: 1
1146:     requires: triangle
1147:     args: -run_type test -refinement_limit 0.0    -bc_type dirichlet -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1149:   test:
1150:     suffix: 2
1151:     requires: triangle
1152:     args: -run_type test -refinement_limit 0.0625 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1154:   test:
1155:     suffix: 3
1156:     requires: triangle
1157:     args: -run_type test -refinement_limit 0.0    -bc_type neumann   -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail

1159:   test:
1160:     suffix: 4
1161:     requires: triangle
1162:     args: -run_type test -refinement_limit 0.0625 -bc_type neumann   -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1164:   # 2D serial P2 test 5-8
1165:   test:
1166:     suffix: 5
1167:     requires: triangle
1168:     args: -run_type test -refinement_limit 0.0    -bc_type dirichlet -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1

1170:   test:
1171:     suffix: 6
1172:     requires: triangle
1173:     args: -run_type test -refinement_limit 0.0625 -bc_type dirichlet -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1

1175:   test:
1176:     suffix: 7
1177:     requires: triangle
1178:     args: -run_type test -refinement_limit 0.0    -bc_type neumann   -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail

1180:   test:
1181:     suffix: 8
1182:     requires: triangle
1183:     args: -run_type test -refinement_limit 0.0625 -bc_type neumann   -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -dm_view ascii::ascii_info_detail

1185:   # 3D serial P1 test 9-12
1186:   test:
1187:     suffix: 9
1188:     requires: ctetgen
1189:     args: -run_type test -dim 3 -refinement_limit 0.0    -bc_type dirichlet -interpolate 0 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -dm_view -cells 1,1,1

1191:   test:
1192:     suffix: 10
1193:     requires: ctetgen
1194:     args: -run_type test -dim 3 -refinement_limit 0.0    -bc_type dirichlet -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -dm_view -cells 1,1,1

1196:   test:
1197:     suffix: 11
1198:     requires: ctetgen
1199:     args: -run_type test -dim 3 -refinement_limit 0.0125 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -dm_view -cells 1,1,1

1201:   test:
1202:     suffix: 12
1203:     requires: ctetgen
1204:     args: -run_type test -dim 3 -refinement_limit 0.0    -bc_type neumann   -interpolate 1 -petscspace_order 1 -snes_fd -show_initial -dm_plex_print_fem 1 -dm_view -cells 1,1,1

1206:   # Analytic variable coefficient 13-20
1207:   test:
1208:     suffix: 13
1209:     requires: triangle
1210:     args: -run_type test -refinement_limit 0.0    -variable_coefficient analytic -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1
1211:   test:
1212:     suffix: 14
1213:     requires: triangle
1214:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient analytic -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1
1215:   test:
1216:     suffix: 15
1217:     requires: triangle
1218:     args: -run_type test -refinement_limit 0.0    -variable_coefficient analytic -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1
1219:   test:
1220:     suffix: 16
1221:     requires: triangle
1222:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient analytic -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1
1223:   test:
1224:     suffix: 17
1225:     requires: hdf5 ctetgen
1226:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient analytic -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1228:   test:
1229:     suffix: 18
1230:     requires: ctetgen
1231:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient analytic -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1233:   test:
1234:     suffix: 19
1235:     requires: ctetgen
1236:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient analytic -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1238:   test:
1239:     suffix: 20
1240:     requires: ctetgen
1241:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient analytic -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1243:   # P1 variable coefficient 21-28
1244:   test:
1245:     suffix: 21
1246:     requires: triangle
1247:     args: -run_type test -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 1 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1

1249:   test:
1250:     suffix: 22
1251:     requires: triangle
1252:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient field    -interpolate 1 -petscspace_order 1 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1

1254:   test:
1255:     suffix: 23
1256:     requires: triangle
1257:     args: -run_type test -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 2 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1

1259:   test:
1260:     suffix: 24
1261:     requires: triangle
1262:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient field    -interpolate 1 -petscspace_order 2 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1

1264:   test:
1265:     suffix: 25
1266:     requires: ctetgen
1267:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 1 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1269:   test:
1270:     suffix: 26
1271:     requires: ctetgen
1272:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient field    -interpolate 1 -petscspace_order 1 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1274:   test:
1275:     suffix: 27
1276:     requires: ctetgen
1277:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 2 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1279:   test:
1280:     suffix: 28
1281:     requires: ctetgen
1282:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient field    -interpolate 1 -petscspace_order 2 -mat_petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1284:   # P0 variable coefficient 29-36
1285:   test:
1286:     suffix: 29
1287:     requires: triangle
1288:     args: -run_type test -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1290:   test:
1291:     suffix: 30
1292:     requires: triangle
1293:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient field    -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1

1295:   test:
1296:     suffix: 31
1297:     requires: triangle
1298:     args: -run_type test -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1

1300:   test:
1301:     requires: triangle
1302:     suffix: 32
1303:     args: -run_type test -refinement_limit 0.0625 -variable_coefficient field    -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1

1305:   test:
1306:     requires: ctetgen
1307:     suffix: 33
1308:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1310:   test:
1311:     suffix: 34
1312:     requires: ctetgen
1313:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient field    -interpolate 1 -petscspace_order 1 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1315:   test:
1316:     suffix: 35
1317:     requires: ctetgen
1318:     args: -run_type test -dim 3 -refinement_limit 0.0    -variable_coefficient field    -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1320:   test:
1321:     suffix: 36
1322:     requires: ctetgen
1323:     args: -run_type test -dim 3 -refinement_limit 0.0125 -variable_coefficient field    -interpolate 1 -petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1325:   # Full solve 39-44
1326:   test:
1327:     suffix: 39
1328:     requires: triangle !single
1329:     args: -run_type full -refinement_limit 0.015625 -interpolate 1 -petscspace_order 2 -pc_type gamg -ksp_rtol 1.0e-10 -ksp_monitor_short -ksp_converged_reason -snes_monitor_short -snes_converged_reason ::ascii_info_detail
1330:   test:
1331:     suffix: 40
1332:     requires: triangle !single
1333:     args: -run_type full -refinement_limit 0.015625 -variable_coefficient nonlinear -interpolate 1 -petscspace_order 2 -pc_type svd -ksp_rtol 1.0e-10 -snes_monitor_short -snes_converged_reason ::ascii_info_detail
1334:   test:
1335:     suffix: 41
1336:     requires: triangle !single
1337:     args: -run_type full -refinement_limit 0.03125 -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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
1338:   test:
1339:     suffix: 42
1340:     requires: triangle !single
1341:     args: -run_type full -refinement_limit 0.0625 -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 3 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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
1342:   test:
1343:     suffix: 43
1344:     requires: triangle !single
1345:     nsize: 2
1346:     args: -run_type full -refinement_limit 0.03125 -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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

1348:   test:
1349:     suffix: 44
1350:     requires: triangle !single
1351:     nsize: 2
1352:     args: -run_type full -refinement_limit 0.0625 -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 3 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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

1354:   # This test uses a loose tolerance to trigger the PtAP operations for MATIS
1355:   test:
1356:     suffix: gmg_bddc
1357:     requires: triangle !single
1358:     nsize: 3
1359:     args: -interpolate -run_type full -petscspace_order 1 -dm_mat_type is -pc_type mg -pc_mg_levels 2 -mg_levels_pc_type jacobi -mg_coarse_pc_type bddc -pc_mg_galerkin pmat -ksp_rtol 1.0e-2 -ksp_monitor_short -ksp_converged_reason -snes_monitor_short -snes_converged_reason ::ascii_info_detail -dm_refine_hierarchy 2

1361:   # Restarting
1362:   testset:
1363:     suffix: restart
1364:     requires: hdf5 triangle !complex
1365:     args: -run_type test -refinement_limit 0.0    -bc_type dirichlet -interpolate 1 -petscspace_order 1
1366:     test:
1367:       args: -dm_view hdf5:sol.h5 -vec_view hdf5:sol.h5::append
1368:     test:
1369:       args: -f sol.h5 -restart

1371:   # Periodicity
1372:   test:
1373:     suffix: periodic_0
1374:     requires: triangle
1375:     args: -run_type full -refinement_limit 0.0    -bc_type dirichlet -interpolate 1 -petscspace_order 1 -snes_converged_reason ::ascii_info_detail

1377:   # 2D serial P1 test with field bc
1378:   test:
1379:     suffix: field_bc_p1_0
1380:     requires: triangle
1381:     args: -run_type test              -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1383:   test:
1384:     suffix: field_bc_p1_1
1385:     requires: triangle
1386:     args: -run_type test -dm_refine 1 -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1388:   test:
1389:     suffix: field_bc_p1_2
1390:     requires: triangle
1391:     args: -run_type test              -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1393:   test:
1394:     suffix: field_bc_p1_3
1395:     requires: triangle
1396:     args: -run_type test -dm_refine 1 -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1398:   # 3D serial P1 test with field bc
1399:   test:
1400:     suffix: field_bc_p1_4
1401:     requires: ctetgen
1402:     args: -run_type test -dim 3              -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1404:   test:
1405:     suffix: field_bc_p1_5
1406:     requires: ctetgen
1407:     args: -run_type test -dim 3 -dm_refine 1 -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1409:   test:
1410:     suffix: field_bc_p1_6
1411:     requires: ctetgen
1412:     args: -run_type test -dim 3              -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1414:   test:
1415:     suffix: field_bc_p1_7
1416:     requires: ctetgen
1417:     args: -run_type test -dim 3 -dm_refine 1 -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 1 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1419:   # 2D serial P2 test with field bc
1420:   test:
1421:     suffix: field_bc_p2_0
1422:     requires: triangle
1423:     args: -run_type test              -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1425:   test:
1426:     suffix: field_bc_p2_1
1427:     requires: triangle
1428:     args: -run_type test -dm_refine 1 -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1430:   test:
1431:     suffix: field_bc_p2_2
1432:     requires: triangle
1433:     args: -run_type test              -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1435:   test:
1436:     suffix: field_bc_p2_3
1437:     requires: triangle
1438:     args: -run_type test -dm_refine 1 -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1

1440:   # 3D serial P2 test with field bc
1441:   test:
1442:     suffix: field_bc_p2_4
1443:     requires: ctetgen
1444:     args: -run_type test -dim 3              -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1446:   test:
1447:     suffix: field_bc_p2_5
1448:     requires: ctetgen
1449:     args: -run_type test -dim 3 -dm_refine 1 -interpolate 1 -bc_type dirichlet -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1451:   test:
1452:     suffix: field_bc_p2_6
1453:     requires: ctetgen
1454:     args: -run_type test -dim 3              -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1456:   test:
1457:     suffix: field_bc_p2_7
1458:     requires: ctetgen
1459:     args: -run_type test -dim 3 -dm_refine 1 -interpolate 1 -bc_type neumann   -field_bc -petscspace_order 2 -bc_petscspace_order 2 -show_initial -dm_plex_print_fem 1 -cells 1,1,1

1461:   # Full solve simplex: Convergence
1462:   test:
1463:     suffix: tet_conv_p1_r0
1464:     requires: ctetgen
1465:     args: -run_type full -dim 3 -dm_refine 0 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -dm_view -snes_converged_reason ::ascii_info_detail -pc_type lu -cells 1,1,1
1466:   test:
1467:     suffix: tet_conv_p1_r2
1468:     requires: ctetgen
1469:     args: -run_type full -dim 3 -dm_refine 2 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -dm_view -snes_converged_reason ::ascii_info_detail -pc_type lu -cells 1,1,1
1470:   test:
1471:     suffix: tet_conv_p1_r3
1472:     requires: ctetgen
1473:     args: -run_type full -dim 3 -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -dm_view -snes_converged_reason ::ascii_info_detail -pc_type lu -cells 1,1,1
1474:   test:
1475:     suffix: tet_conv_p2_r0
1476:     requires: ctetgen
1477:     args: -run_type full -dim 3 -dm_refine 0 -bc_type dirichlet -interpolate 1 -petscspace_order 2 -dm_view -snes_converged_reason ::ascii_info_detail -pc_type lu -cells 1,1,1
1478:   test:
1479:     suffix: tet_conv_p2_r2
1480:     requires: ctetgen
1481:     args: -run_type full -dim 3 -dm_refine 2 -bc_type dirichlet -interpolate 1 -petscspace_order 2 -dm_view -snes_converged_reason ::ascii_info_detail -pc_type lu -cells 1,1,1

1483:   # Full solve simplex: BDDC
1484:   test:
1485:     suffix: tri_bddc
1486:     requires: triangle !single
1487:     nsize: 5
1488:     args: -run_type full -petscpartitioner_type simple -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1490:   # Full solve simplex: BDDC
1491:   test:
1492:     suffix: tri_bddc_parmetis
1493:     requires: hdf5 triangle !single
1494:     nsize: 4
1495:     args: -run_type full -petscpartitioner_type parmetis -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1497:   test:
1498:     suffix: quad_bddc
1499:     args: -run_type full -petscpartitioner_type simple -dm_refine 2 -bc_type dirichlet -interpolate 1 -petscspace_order 2 -dm_mat_type is -pc_type bddc -ksp_type gmres -snes_monitor_short -ksp_monitor_short -snes_view -simplex 0 -petscspace_poly_tensor -pc_bddc_corner_selection -cells 3,3 -ksp_rtol 1.e-9 -pc_bddc_use_edges 0
1500:     nsize: 9

1502:   # Full solve simplex: ASM
1503:   test:
1504:     suffix: tri_q2q1_asm_lu
1505:     requires: triangle !single
1506:     args: -run_type full -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1508:   test:
1509:     suffix: tri_q2q1_msm_lu
1510:     requires: triangle !single
1511:     args: -run_type full -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1513:   test:
1514:     suffix: tri_q2q1_asm_sor
1515:     requires: triangle !single
1516:     args: -run_type full -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1518:   test:
1519:     suffix: tri_q2q1_msm_sor
1520:     requires: triangle !single
1521:     args: -run_type full -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 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

1523:   # Full solve simplex: FAS
1524:   test:
1525:     suffix: fas_newton_0
1526:     requires: triangle !single
1527:     args: -run_type full -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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

1529:   test:
1530:     suffix: fas_newton_1
1531:     requires: triangle !single
1532:     args: -run_type full -dm_refine_hierarchy 3 -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 3 -ksp_rtol 1.0e-10 -fas_coarse_pc_type lu -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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

1534:   test:
1535:     suffix: fas_ngs_0
1536:     requires: triangle !single
1537:     args: -run_type full -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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

1539:   test:
1540:     suffix: fas_newton_coarse_0
1541:     requires: pragmatic triangle
1542:     TODO: broken
1543:     args: -run_type full -dm_refine 2 -dm_plex_hash_location -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -fas_coarse_snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_coarsen_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

1545:   test:
1546:     suffix: mg_newton_coarse_0
1547:     requires: triangle pragmatic
1548:     args: -run_type full -dm_refine 3 -interpolate 1 -petscspace_order 1 -snes_monitor_short -ksp_monitor_true_residual -snes_linesearch_type basic -snes_converged_reason ::ascii_info_detail -dm_coarsen_hierarchy 3 -dm_plex_hash_location -snes_view -dm_view -ksp_type richardson -pc_type mg  -pc_mg_levels 4 -snes_atol 1.0e-8 -ksp_atol 1.0e-8 -snes_rtol 0.0 -ksp_rtol 0.0 -ksp_norm_type unpreconditioned -mg_levels_ksp_type gmres -mg_levels_pc_type ilu -mg_levels_ksp_max_it 10

1550:   test:
1551:     suffix: mg_newton_coarse_1
1552:     requires: triangle pragmatic
1553:     args: -run_type full -dm_refine 5 -interpolate 1 -petscspace_order 1 -dm_coarsen_hierarchy 5 -dm_plex_hash_location -dm_plex_separate_marker -dm_plex_coarsen_bd_label marker -dm_plex_remesh_bd -ksp_type richardson -ksp_rtol 1.0e-12 -pc_type mg -pc_mg_levels 3 -mg_levels_ksp_max_it 2 -snes_converged_reason ::ascii_info_detail -snes_monitor -ksp_monitor_true_residual -mg_levels_ksp_monitor_true_residual -dm_view -ksp_view

1555:   test:
1556:     suffix: mg_newton_coarse_2
1557:     requires: triangle pragmatic
1558:     args: -run_type full -dm_refine 5 -interpolate 1 -petscspace_order 1 -dm_coarsen_hierarchy 5 -dm_plex_hash_location -dm_plex_separate_marker -dm_plex_remesh_bd -ksp_type richardson -ksp_rtol 1.0e-12 -pc_type mg -pc_mg_levels 3 -mg_levels_ksp_max_it 2 -snes_converged_reason ::ascii_info_detail -snes_monitor -ksp_monitor_true_residual -mg_levels_ksp_monitor_true_residual -dm_view -ksp_view

1560:   # Full solve tensor
1561:   test:
1562:     suffix: tensor_plex_2d
1563:     args: -run_type test -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 1 -dm_refine_hierarchy 2 -cells 2,2

1565:   test:
1566:     suffix: tensor_p4est_2d
1567:     requires: p4est
1568:     args: -run_type test -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 1 -dm_forest_initial_refinement 2 -dm_forest_minimum_refinement 0 -dm_plex_convert_type p4est -cells 2,2

1570:   test:
1571:     suffix: tensor_plex_3d
1572:     args: -run_type test -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 1 -dim 3 -dm_refine_hierarchy 1 -cells 2,2,2

1574:   test:
1575:     suffix: tensor_p4est_3d
1576:     requires: p4est
1577:     args: -run_type test -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 1 -dm_forest_initial_refinement 1 -dm_forest_minimum_refinement 0 -dim 3 -dm_plex_convert_type p8est -cells 2,2,2

1579:   test:
1580:     suffix: p4est_test_q2_conformal_serial
1581:     requires: p4est
1582:     args: -run_type test -interpolate 1 -petscspace_order 2 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -cells 2,2

1584:   test:
1585:     suffix: p4est_test_q2_conformal_parallel
1586:     requires: p4est
1587:     nsize: 7
1588:     args: -run_type test -interpolate 1 -petscspace_order 2 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type simple -cells 2,2

1590:   test:
1591:     suffix: p4est_test_q2_conformal_parallel_parmetis
1592:     requires: hdf5 p4est
1593:     nsize: 4
1594:     args: -run_type test -interpolate 1 -petscspace_order 2 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type parmetis -cells 2,2

1596:   test:
1597:     suffix: p4est_test_q2_nonconformal_serial
1598:     requires: p4est
1599:     filter: grep -v "CG or CGNE: variant"
1600:     args: -run_type test -interpolate 1 -petscspace_order 2 -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 -cells 2,2

1602:   test:
1603:     suffix: p4est_test_q2_nonconformal_parallel
1604:     requires: p4est
1605:     filter: grep -v "CG or CGNE: variant"
1606:     nsize: 7
1607:     args: -run_type test -interpolate 1 -petscspace_order 2 -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 -cells 2,2

1609:   test:
1610:     suffix: p4est_test_q2_nonconformal_parallel_parmetis
1611:     requires: hdf5 p4est
1612:     nsize: 4
1613:     args: -run_type test -interpolate 1 -petscspace_order 2 -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 -cells 2,2

1615:   test:
1616:     suffix: p4est_exact_q2_conformal_serial
1617:     requires: p4est !single
1618:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -cells 2,2

1620:   test:
1621:     suffix: p4est_exact_q2_conformal_parallel
1622:     requires: p4est !single
1623:     nsize: 7
1624:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -cells 2,2

1626:   test:
1627:     suffix: p4est_exact_q2_conformal_parallel_parmetis
1628:     requires: hdf5 p4est !single
1629:     nsize: 4
1630:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -simplex 0 -dm_plex_convert_type p4est -dm_forest_minimum_refinement 0 -dm_forest_initial_refinement 2 -petscpartitioner_type parmetis  -cells 2,2

1632:   test:
1633:     suffix: p4est_exact_q2_nonconformal_serial
1634:     requires: p4est
1635:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1637:   test:
1638:     suffix: p4est_exact_q2_nonconformal_parallel
1639:     requires: p4est
1640:     nsize: 7
1641:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1643:   test:
1644:     suffix: p4est_exact_q2_nonconformal_parallel_parmetis
1645:     requires: hdf5 p4est
1646:     nsize: 4
1647:     args: -run_type exact -interpolate 1 -petscspace_order 2 -snes_max_it 1 -snes_type fas -snes_fas_levels 3 -pc_type none -ksp_type preonly -fas_coarse_pc_type none -fas_coarse_ksp_type preonly -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1649:   test:
1650:     suffix: p4est_full_q2_nonconformal_serial
1651:     requires: p4est !single
1652:     filter: grep -v "variant HERMITIAN"
1653:     args: -run_type full -interpolate 1 -petscspace_order 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -pc_type jacobi -ksp_type cg -fas_coarse_pc_type jacobi -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1655:   test:
1656:     suffix: p4est_full_q2_nonconformal_parallel
1657:     requires: p4est !single
1658:     filter: grep -v "variant HERMITIAN"
1659:     nsize: 7
1660:     args: -run_type full -interpolate 1 -petscspace_order 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -pc_type jacobi -ksp_type cg -fas_coarse_pc_type jacobi -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1662:   test:
1663:     suffix: p4est_full_q2_nonconformal_parallel_bddcfas
1664:     requires: p4est
1665:     filter: grep -v "variant HERMITIAN"
1666:     nsize: 7
1667:     args: -run_type full -interpolate 1 -petscspace_order 2 -snes_max_it 20 -snes_type fas -snes_fas_levels 3 -dm_mat_type is -pc_type bddc -ksp_type cg -fas_coarse_pc_type bddc -fas_coarse_ksp_type cg -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1669:   test:
1670:     suffix: p4est_full_q2_nonconformal_parallel_bddc
1671:     requires: p4est
1672:     filter: grep -v "variant HERMITIAN"
1673:     nsize: 7
1674:     args: -run_type full -interpolate 1 -petscspace_order 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 -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 -cells 2,2

1676:   test:
1677:     suffix: p4est_fas_q2_conformal_serial
1678:     requires: p4est
1679:     args: -run_type full -variable_coefficient nonlinear -interpolate 1 -petscspace_order 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 -snes_linesearch_type basic -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 -simplex 0 -dm_refine_hierarchy 3 -cells 2,2
1680:     TODO: broken

1682:   test:
1683:     suffix: p4est_fas_q2_nonconformal_serial
1684:     requires: p4est broken
1685:     args: -run_type full -variable_coefficient nonlinear -interpolate 1 -petscspace_order 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 -snes_linesearch_type basic -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 -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 -cells 2,2

1687:   test:
1688:     suffix: fas_newton_0_p4est
1689:     requires: p4est !single
1690:     args: -run_type full -variable_coefficient nonlinear -interpolate 1 -petscspace_order 1 -snes_type fas -snes_fas_levels 2 -pc_type svd -ksp_rtol 1.0e-10 -fas_coarse_pc_type svd -fas_coarse_ksp_rtol 1.0e-10 -fas_coarse_snes_monitor_short -snes_monitor_short -snes_linesearch_type basic -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 -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 -cells 2,2

1692:   # Full solve simplicial AMR
1693:   test:
1694:     suffix: tri_p1_adapt_0
1695:     requires: pragmatic
1696:     args: -run_type exact -dim 2 -dm_refine 5 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -variable_coefficient circle -snes_converged_reason ::ascii_info_detail -pc_type lu -adaptor_refinement_factor 1.0 -dm_view -dm_adapt_view -snes_adapt_initial

1698:   test:
1699:     suffix: tri_p1_adapt_1
1700:     requires: pragmatic
1701:     args: -run_type exact -dim 2 -dm_refine 5 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -variable_coefficient circle -snes_converged_reason ::ascii_info_detail -pc_type lu -adaptor_refinement_factor 1.0 -dm_view -dm_adapt_iter_view -dm_adapt_view -snes_adapt_sequence 2

1703:   test:
1704:     suffix: tri_p1_adapt_analytic_0
1705:     requires: pragmatic
1706:     args: -run_type exact -dim 2 -dm_refine 3 -bc_type dirichlet -interpolate 1 -petscspace_order 1 -variable_coefficient cross -snes_adapt_initial 4 -adaptor_target_num 500 -adaptor_monitor -dm_view -dm_adapt_iter_view

1708:   # Full solve tensor AMR
1709:   test:
1710:     suffix: quad_q1_adapt_0
1711:     requires: p4est
1712:     args: -run_type exact -dim 2 -simplex 0 -dm_plex_convert_type p4est -bc_type dirichlet -interpolate 1 -petscspace_order 1 -variable_coefficient circle -snes_converged_reason ::ascii_info_detail -pc_type lu -dm_forest_initial_refinement 4   -snes_adapt_initial -dm_view
1713:     filter: grep -v DM_

1715:   test:
1716:     suffix: amr_0
1717:     nsize: 5
1718:     args: -run_type test -petscpartitioner_type simple -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 1 -dm_refine 1 -cells 2,2

1720:   test:
1721:     suffix: amr_1
1722:     requires: p4est !complex
1723:     args: -run_type test -refinement_limit 0.0 -simplex 0 -interpolate -bc_type dirichlet -petscspace_order 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 -cells 2,2

1725:   test:
1726:     suffix: p4est_solve_bddc
1727:     requires: p4est
1728:     args: -run_type full -variable_coefficient nonlinear -nonzero_initial_guess 1 -interpolate 1 -petscspace_order 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 -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
1729:     nsize: 4

1731:   test:
1732:     suffix: p4est_solve_fas
1733:     requires: p4est
1734:     args: -run_type full -variable_coefficient nonlinear -nonzero_initial_guess 1 -interpolate 1 -petscspace_order 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 -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
1735:     nsize: 4
1736:     TODO: identical machine two runs produce slightly different solver trackers

1738:   test:
1739:     suffix: p4est_convergence_test_1
1740:     requires: p4est
1741:     args:  -quiet -run_type test -interpolate 1 -petscspace_order 1 -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
1742:     nsize: 4

1744:   test:
1745:     suffix: p4est_convergence_test_2
1746:     requires: p4est
1747:     args: -quiet -run_type test -interpolate 1 -petscspace_order 1 -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

1749:   test:
1750:     suffix: p4est_convergence_test_3
1751:     requires: p4est
1752:     args: -quiet -run_type test -interpolate 1 -petscspace_order 1 -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

1754:   test:
1755:     suffix: p4est_convergence_test_4
1756:     requires: p4est
1757:     args: -quiet -run_type test -interpolate 1 -petscspace_order 1 -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
1758:     timeoutfactor: 5

1760:   # Serial tests with GLVis visualization
1761:   test:
1762:     suffix: glvis_2d_tet_p1
1763:     args: -quiet -run_type test -interpolate 1 -bc_type dirichlet -petscspace_order 1 -vec_view glvis: -f ${wPETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh
1764:   test:
1765:     suffix: glvis_2d_tet_p2
1766:     args: -quiet -run_type test -interpolate 1 -bc_type dirichlet -petscspace_order 2 -vec_view glvis: -f ${wPETSC_DIR}/share/petsc/datafiles/meshes/square_periodic.msh
1767:   test:
1768:     suffix: glvis_2d_hex_p1
1769:     args: -quiet -run_type test -interpolate 1 -bc_type dirichlet -petscspace_order 1 -vec_view glvis: -simplex 0 -dm_refine 1
1770:   test:
1771:     suffix: glvis_2d_hex_p2
1772:     args: -quiet -run_type test -interpolate 1 -bc_type dirichlet -petscspace_order 2 -vec_view glvis: -simplex 0 -dm_refine 1
1773:   test:
1774:     suffix: glvis_2d_hex_p2_p4est
1775:     requires: p4est
1776:     args: -quiet -run_type test -interpolate 1 -bc_type dirichlet -petscspace_order 2 -vec_view glvis: -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 -cells 2,2 -viewer_glvis_dm_plex_enable_ncmesh

1778: TEST*/