1c4762a1bSJed Brown static char help[] = "Check that a DM can accurately represent and interpolate functions of a given polynomial order\n\n"; 2c4762a1bSJed Brown 3c4762a1bSJed Brown #include <petscdmplex.h> 4c4762a1bSJed Brown #include <petscdm.h> 5c4762a1bSJed Brown #include <petscdmda.h> 6c4762a1bSJed Brown #include <petscfe.h> 7c4762a1bSJed Brown #include <petscds.h> 8c4762a1bSJed Brown #include <petscksp.h> 9c4762a1bSJed Brown #include <petscsnes.h> 10c4762a1bSJed Brown 11c4762a1bSJed Brown typedef struct { 12c4762a1bSJed Brown /* Domain and mesh definition */ 13c4762a1bSJed Brown PetscBool useDA; /* Flag DMDA tensor product mesh */ 14c4762a1bSJed Brown PetscBool shearCoords; /* Flag for shear transform */ 15c4762a1bSJed Brown PetscBool nonaffineCoords; /* Flag for non-affine transform */ 16c4762a1bSJed Brown /* Element definition */ 17c4762a1bSJed Brown PetscInt qorder; /* Order of the quadrature */ 18c4762a1bSJed Brown PetscInt numComponents; /* Number of field components */ 19c4762a1bSJed Brown PetscFE fe; /* The finite element */ 20c4762a1bSJed Brown /* Testing space */ 21c4762a1bSJed Brown PetscInt porder; /* Order of polynomials to test */ 22c4762a1bSJed Brown PetscBool convergence; /* Test for order of convergence */ 23c4762a1bSJed Brown PetscBool convRefine; /* Test for convergence using refinement, otherwise use coarsening */ 24c4762a1bSJed Brown PetscBool constraints; /* Test local constraints */ 25c4762a1bSJed Brown PetscBool tree; /* Test tree routines */ 26c4762a1bSJed Brown PetscBool testFEjacobian; /* Test finite element Jacobian assembly */ 27c4762a1bSJed Brown PetscBool testFVgrad; /* Test finite difference gradient routine */ 28c4762a1bSJed Brown PetscBool testInjector; /* Test finite element injection routines */ 29c4762a1bSJed Brown PetscInt treeCell; /* Cell to refine in tree test */ 30c4762a1bSJed Brown PetscReal constants[3]; /* Constant values for each dimension */ 31c4762a1bSJed Brown } AppCtx; 32c4762a1bSJed Brown 33c4762a1bSJed Brown /* u = 1 */ 34c4762a1bSJed Brown PetscErrorCode constant(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt Nf, PetscScalar *u, void *ctx) 35c4762a1bSJed Brown { 36c4762a1bSJed Brown AppCtx *user = (AppCtx *) ctx; 37c4762a1bSJed Brown PetscInt d; 3830602db0SMatthew G. Knepley for (d = 0; d < dim; ++d) u[d] = user->constants[d]; 39c4762a1bSJed Brown return 0; 40c4762a1bSJed Brown } 41c4762a1bSJed Brown PetscErrorCode constantDer(PetscInt dim, PetscReal time, const PetscReal coords[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) 42c4762a1bSJed Brown { 43c4762a1bSJed Brown PetscInt d; 4430602db0SMatthew G. Knepley for (d = 0; d < dim; ++d) u[d] = 0.0; 45c4762a1bSJed Brown return 0; 46c4762a1bSJed Brown } 47c4762a1bSJed Brown 48c4762a1bSJed Brown /* u = x */ 49c4762a1bSJed Brown PetscErrorCode linear(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt Nf, PetscScalar *u, void *ctx) 50c4762a1bSJed Brown { 51c4762a1bSJed Brown PetscInt d; 52c4762a1bSJed Brown for (d = 0; d < dim; ++d) u[d] = coords[d]; 53c4762a1bSJed Brown return 0; 54c4762a1bSJed Brown } 55c4762a1bSJed Brown PetscErrorCode linearDer(PetscInt dim, PetscReal time, const PetscReal coords[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) 56c4762a1bSJed Brown { 57c4762a1bSJed Brown PetscInt d, e; 58c4762a1bSJed Brown for (d = 0; d < dim; ++d) { 59c4762a1bSJed Brown u[d] = 0.0; 60c4762a1bSJed Brown for (e = 0; e < dim; ++e) u[d] += (d == e ? 1.0 : 0.0) * n[e]; 61c4762a1bSJed Brown } 62c4762a1bSJed Brown return 0; 63c4762a1bSJed Brown } 64c4762a1bSJed Brown 65c4762a1bSJed Brown /* u = x^2 or u = (x^2, xy) or u = (xy, yz, zx) */ 66c4762a1bSJed Brown PetscErrorCode quadratic(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt Nf, PetscScalar *u, void *ctx) 67c4762a1bSJed Brown { 6830602db0SMatthew G. Knepley if (dim > 2) {u[0] = coords[0]*coords[1]; u[1] = coords[1]*coords[2]; u[2] = coords[2]*coords[0];} 6930602db0SMatthew G. Knepley else if (dim > 1) {u[0] = coords[0]*coords[0]; u[1] = coords[0]*coords[1];} 7030602db0SMatthew G. Knepley else if (dim > 0) {u[0] = coords[0]*coords[0];} 71c4762a1bSJed Brown return 0; 72c4762a1bSJed Brown } 73c4762a1bSJed Brown PetscErrorCode quadraticDer(PetscInt dim, PetscReal time, const PetscReal coords[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) 74c4762a1bSJed Brown { 7530602db0SMatthew G. Knepley if (dim > 2) {u[0] = coords[1]*n[0] + coords[0]*n[1]; u[1] = coords[2]*n[1] + coords[1]*n[2]; u[2] = coords[2]*n[0] + coords[0]*n[2];} 7630602db0SMatthew G. Knepley else if (dim > 1) {u[0] = 2.0*coords[0]*n[0]; u[1] = coords[1]*n[0] + coords[0]*n[1];} 7730602db0SMatthew G. Knepley else if (dim > 0) {u[0] = 2.0*coords[0]*n[0];} 78c4762a1bSJed Brown return 0; 79c4762a1bSJed Brown } 80c4762a1bSJed Brown 81c4762a1bSJed Brown /* u = x^3 or u = (x^3, x^2y) or u = (x^2y, y^2z, z^2x) */ 82c4762a1bSJed Brown PetscErrorCode cubic(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt Nf, PetscScalar *u, void *ctx) 83c4762a1bSJed Brown { 8430602db0SMatthew G. Knepley if (dim > 2) {u[0] = coords[0]*coords[0]*coords[1]; u[1] = coords[1]*coords[1]*coords[2]; u[2] = coords[2]*coords[2]*coords[0];} 8530602db0SMatthew G. Knepley else if (dim > 1) {u[0] = coords[0]*coords[0]*coords[0]; u[1] = coords[0]*coords[0]*coords[1];} 8630602db0SMatthew G. Knepley else if (dim > 0) {u[0] = coords[0]*coords[0]*coords[0];} 87c4762a1bSJed Brown return 0; 88c4762a1bSJed Brown } 89c4762a1bSJed Brown PetscErrorCode cubicDer(PetscInt dim, PetscReal time, const PetscReal coords[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) 90c4762a1bSJed Brown { 9130602db0SMatthew G. Knepley if (dim > 2) {u[0] = 2.0*coords[0]*coords[1]*n[0] + coords[0]*coords[0]*n[1]; u[1] = 2.0*coords[1]*coords[2]*n[1] + coords[1]*coords[1]*n[2]; u[2] = 2.0*coords[2]*coords[0]*n[2] + coords[2]*coords[2]*n[0];} 9230602db0SMatthew G. Knepley else if (dim > 1) {u[0] = 3.0*coords[0]*coords[0]*n[0]; u[1] = 2.0*coords[0]*coords[1]*n[0] + coords[0]*coords[0]*n[1];} 9330602db0SMatthew G. Knepley else if (dim > 0) {u[0] = 3.0*coords[0]*coords[0]*n[0];} 94c4762a1bSJed Brown return 0; 95c4762a1bSJed Brown } 96c4762a1bSJed Brown 97c4762a1bSJed Brown /* u = tanh(x) */ 98c4762a1bSJed Brown PetscErrorCode trig(PetscInt dim, PetscReal time, const PetscReal coords[], PetscInt Nf, PetscScalar *u, void *ctx) 99c4762a1bSJed Brown { 100c4762a1bSJed Brown PetscInt d; 10130602db0SMatthew G. Knepley for (d = 0; d < dim; ++d) u[d] = PetscTanhReal(coords[d] - 0.5); 102c4762a1bSJed Brown return 0; 103c4762a1bSJed Brown } 104c4762a1bSJed Brown PetscErrorCode trigDer(PetscInt dim, PetscReal time, const PetscReal coords[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) 105c4762a1bSJed Brown { 106c4762a1bSJed Brown PetscInt d; 10730602db0SMatthew G. Knepley for (d = 0; d < dim; ++d) u[d] = 1.0/PetscSqr(PetscCoshReal(coords[d] - 0.5)) * n[d]; 108c4762a1bSJed Brown return 0; 109c4762a1bSJed Brown } 110c4762a1bSJed Brown 111c4762a1bSJed Brown static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options) 112c4762a1bSJed Brown { 113c4762a1bSJed Brown PetscInt n = 3; 114c4762a1bSJed Brown PetscErrorCode ierr; 115c4762a1bSJed Brown 116c4762a1bSJed Brown PetscFunctionBeginUser; 11730602db0SMatthew G. Knepley options->useDA = PETSC_FALSE; 118c4762a1bSJed Brown options->shearCoords = PETSC_FALSE; 119c4762a1bSJed Brown options->nonaffineCoords = PETSC_FALSE; 120c4762a1bSJed Brown options->qorder = 0; 121c4762a1bSJed Brown options->numComponents = PETSC_DEFAULT; 122c4762a1bSJed Brown options->porder = 0; 123c4762a1bSJed Brown options->convergence = PETSC_FALSE; 124c4762a1bSJed Brown options->convRefine = PETSC_TRUE; 125c4762a1bSJed Brown options->constraints = PETSC_FALSE; 126c4762a1bSJed Brown options->tree = PETSC_FALSE; 127c4762a1bSJed Brown options->treeCell = 0; 128c4762a1bSJed Brown options->testFEjacobian = PETSC_FALSE; 129c4762a1bSJed Brown options->testFVgrad = PETSC_FALSE; 130c4762a1bSJed Brown options->testInjector = PETSC_FALSE; 131c4762a1bSJed Brown options->constants[0] = 1.0; 132c4762a1bSJed Brown options->constants[1] = 2.0; 133c4762a1bSJed Brown options->constants[2] = 3.0; 134c4762a1bSJed Brown 1359566063dSJacob Faibussowitsch ierr = PetscOptionsBegin(comm, "", "Projection Test Options", "DMPlex");PetscCall(ierr); 1369566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-use_da", "Flag for DMDA mesh", "ex3.c", options->useDA, &options->useDA, NULL)); 1379566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-shear_coords", "Transform coordinates with a shear", "ex3.c", options->shearCoords, &options->shearCoords, NULL)); 1389566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-non_affine_coords", "Transform coordinates with a non-affine transform", "ex3.c", options->nonaffineCoords, &options->nonaffineCoords, NULL)); 1399566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-qorder", "The quadrature order", "ex3.c", options->qorder, &options->qorder, NULL,0)); 1409566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-num_comp", "The number of field components", "ex3.c", options->numComponents, &options->numComponents, NULL,PETSC_DEFAULT)); 1419566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-porder", "The order of polynomials to test", "ex3.c", options->porder, &options->porder, NULL,0)); 1429566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-convergence", "Check the convergence rate", "ex3.c", options->convergence, &options->convergence, NULL)); 1439566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-conv_refine", "Use refinement for the convergence rate", "ex3.c", options->convRefine, &options->convRefine, NULL)); 1449566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-constraints", "Test local constraints (serial only)", "ex3.c", options->constraints, &options->constraints, NULL)); 1459566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-tree", "Test tree routines", "ex3.c", options->tree, &options->tree, NULL)); 1469566063dSJacob Faibussowitsch PetscCall(PetscOptionsBoundedInt("-tree_cell", "cell to refine in tree test", "ex3.c", options->treeCell, &options->treeCell, NULL,0)); 1479566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-test_fe_jacobian", "Test finite element Jacobian assembly", "ex3.c", options->testFEjacobian, &options->testFEjacobian, NULL)); 1489566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-test_fv_grad", "Test finite volume gradient reconstruction", "ex3.c", options->testFVgrad, &options->testFVgrad, NULL)); 1499566063dSJacob Faibussowitsch PetscCall(PetscOptionsBool("-test_injector","Test finite element injection", "ex3.c", options->testInjector, &options->testInjector,NULL)); 1509566063dSJacob Faibussowitsch PetscCall(PetscOptionsRealArray("-constants","Set the constant values", "ex3.c", options->constants, &n,NULL)); 1519566063dSJacob Faibussowitsch ierr = PetscOptionsEnd();PetscCall(ierr); 152c4762a1bSJed Brown 153c4762a1bSJed Brown PetscFunctionReturn(0); 154c4762a1bSJed Brown } 155c4762a1bSJed Brown 156c4762a1bSJed Brown static PetscErrorCode TransformCoordinates(DM dm, AppCtx *user) 157c4762a1bSJed Brown { 158c4762a1bSJed Brown PetscSection coordSection; 159c4762a1bSJed Brown Vec coordinates; 160c4762a1bSJed Brown PetscScalar *coords; 161c4762a1bSJed Brown PetscInt vStart, vEnd, v; 162c4762a1bSJed Brown 163c4762a1bSJed Brown PetscFunctionBeginUser; 164c4762a1bSJed Brown if (user->nonaffineCoords) { 165c4762a1bSJed Brown /* x' = r^(1/p) (x/r), y' = r^(1/p) (y/r), z' = z */ 1669566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(dm, &coordSection)); 1679566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(dm, &coordinates)); 1689566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd)); 1699566063dSJacob Faibussowitsch PetscCall(VecGetArray(coordinates, &coords)); 170c4762a1bSJed Brown for (v = vStart; v < vEnd; ++v) { 171c4762a1bSJed Brown PetscInt dof, off; 172c4762a1bSJed Brown PetscReal p = 4.0, r; 173c4762a1bSJed Brown 1749566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(coordSection, v, &dof)); 1759566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(coordSection, v, &off)); 176c4762a1bSJed Brown switch (dof) { 177c4762a1bSJed Brown case 2: 178c4762a1bSJed Brown r = PetscSqr(PetscRealPart(coords[off+0])) + PetscSqr(PetscRealPart(coords[off+1])); 179c4762a1bSJed Brown coords[off+0] = r == 0.0 ? 0.0 : PetscPowReal(r, (1 - p)/(2*p))*coords[off+0]; 180c4762a1bSJed Brown coords[off+1] = r == 0.0 ? 0.0 : PetscPowReal(r, (1 - p)/(2*p))*coords[off+1]; 181c4762a1bSJed Brown break; 182c4762a1bSJed Brown case 3: 183c4762a1bSJed Brown r = PetscSqr(PetscRealPart(coords[off+0])) + PetscSqr(PetscRealPart(coords[off+1])); 184c4762a1bSJed Brown coords[off+0] = r == 0.0 ? 0.0 : PetscPowReal(r, (1 - p)/(2*p))*coords[off+0]; 185c4762a1bSJed Brown coords[off+1] = r == 0.0 ? 0.0 : PetscPowReal(r, (1 - p)/(2*p))*coords[off+1]; 186c4762a1bSJed Brown coords[off+2] = coords[off+2]; 187c4762a1bSJed Brown break; 188c4762a1bSJed Brown } 189c4762a1bSJed Brown } 1909566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(coordinates, &coords)); 191c4762a1bSJed Brown } 192c4762a1bSJed Brown if (user->shearCoords) { 193c4762a1bSJed Brown /* x' = x + m y + m z, y' = y + m z, z' = z */ 1949566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateSection(dm, &coordSection)); 1959566063dSJacob Faibussowitsch PetscCall(DMGetCoordinatesLocal(dm, &coordinates)); 1969566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd)); 1979566063dSJacob Faibussowitsch PetscCall(VecGetArray(coordinates, &coords)); 198c4762a1bSJed Brown for (v = vStart; v < vEnd; ++v) { 199c4762a1bSJed Brown PetscInt dof, off; 200c4762a1bSJed Brown PetscReal m = 1.0; 201c4762a1bSJed Brown 2029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(coordSection, v, &dof)); 2039566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(coordSection, v, &off)); 204c4762a1bSJed Brown switch (dof) { 205c4762a1bSJed Brown case 2: 206c4762a1bSJed Brown coords[off+0] = coords[off+0] + m*coords[off+1]; 207c4762a1bSJed Brown coords[off+1] = coords[off+1]; 208c4762a1bSJed Brown break; 209c4762a1bSJed Brown case 3: 210c4762a1bSJed Brown coords[off+0] = coords[off+0] + m*coords[off+1] + m*coords[off+2]; 211c4762a1bSJed Brown coords[off+1] = coords[off+1] + m*coords[off+2]; 212c4762a1bSJed Brown coords[off+2] = coords[off+2]; 213c4762a1bSJed Brown break; 214c4762a1bSJed Brown } 215c4762a1bSJed Brown } 2169566063dSJacob Faibussowitsch PetscCall(VecRestoreArray(coordinates, &coords)); 217c4762a1bSJed Brown } 218c4762a1bSJed Brown PetscFunctionReturn(0); 219c4762a1bSJed Brown } 220c4762a1bSJed Brown 221c4762a1bSJed Brown static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm) 222c4762a1bSJed Brown { 22330602db0SMatthew G. Knepley PetscInt dim = 2; 22430602db0SMatthew G. Knepley PetscBool simplex; 225c4762a1bSJed Brown 226c4762a1bSJed Brown PetscFunctionBeginUser; 22730602db0SMatthew G. Knepley if (user->useDA) { 22830602db0SMatthew G. Knepley switch (dim) { 229c4762a1bSJed Brown case 2: 2309566063dSJacob Faibussowitsch PetscCall(DMDACreate2d(comm, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_BOX, 2, 2, PETSC_DETERMINE, PETSC_DETERMINE, 1, 1, NULL, NULL, dm)); 2319566063dSJacob Faibussowitsch PetscCall(DMSetFromOptions(*dm)); 2329566063dSJacob Faibussowitsch PetscCall(DMSetUp(*dm)); 2339566063dSJacob Faibussowitsch PetscCall(DMDASetVertexCoordinates(*dm, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)); 234c4762a1bSJed Brown break; 235c4762a1bSJed Brown default: 23698921bdaSJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot create structured mesh of dimension %d", dim); 237c4762a1bSJed Brown } 2389566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject) *dm, "Hexahedral Mesh")); 23930602db0SMatthew G. Knepley } else { 2409566063dSJacob Faibussowitsch PetscCall(DMCreate(comm, dm)); 2419566063dSJacob Faibussowitsch PetscCall(DMSetType(*dm, DMPLEX)); 2429566063dSJacob Faibussowitsch PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE)); 2439566063dSJacob Faibussowitsch PetscCall(DMSetFromOptions(*dm)); 244c4762a1bSJed Brown 2459566063dSJacob Faibussowitsch PetscCall(DMGetDimension(*dm, &dim)); 2469566063dSJacob Faibussowitsch PetscCall(DMPlexIsSimplex(*dm, &simplex)); 2479566063dSJacob Faibussowitsch PetscCallMPI(MPI_Bcast(&simplex, 1, MPIU_BOOL, 0, comm)); 248c4762a1bSJed Brown if (user->tree) { 24930602db0SMatthew G. Knepley DM refTree, ncdm = NULL; 250c4762a1bSJed Brown 2519566063dSJacob Faibussowitsch PetscCall(DMPlexCreateDefaultReferenceTree(comm,dim,simplex,&refTree)); 2529566063dSJacob Faibussowitsch PetscCall(DMViewFromOptions(refTree,NULL,"-reftree_dm_view")); 2539566063dSJacob Faibussowitsch PetscCall(DMPlexSetReferenceTree(*dm,refTree)); 2549566063dSJacob Faibussowitsch PetscCall(DMDestroy(&refTree)); 2559566063dSJacob Faibussowitsch PetscCall(DMPlexTreeRefineCell(*dm,user->treeCell,&ncdm)); 256c4762a1bSJed Brown if (ncdm) { 2579566063dSJacob Faibussowitsch PetscCall(DMDestroy(dm)); 258c4762a1bSJed Brown *dm = ncdm; 2599566063dSJacob Faibussowitsch PetscCall(DMPlexSetRefinementUniform(*dm, PETSC_FALSE)); 260c4762a1bSJed Brown } 2619566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) *dm, "tree_")); 2629566063dSJacob Faibussowitsch PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE)); 2639566063dSJacob Faibussowitsch PetscCall(DMSetFromOptions(*dm)); 2649566063dSJacob Faibussowitsch PetscCall(DMViewFromOptions(*dm,NULL,"-dm_view")); 265c4762a1bSJed Brown } else { 2669566063dSJacob Faibussowitsch PetscCall(DMPlexSetRefinementUniform(*dm, PETSC_TRUE)); 267c4762a1bSJed Brown } 2689566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) *dm, "dist_")); 2699566063dSJacob Faibussowitsch PetscCall(DMPlexDistributeSetDefault(*dm, PETSC_FALSE)); 2709566063dSJacob Faibussowitsch PetscCall(DMSetFromOptions(*dm)); 2719566063dSJacob Faibussowitsch PetscCall(PetscObjectSetOptionsPrefix((PetscObject) *dm, NULL)); 2729566063dSJacob Faibussowitsch if (simplex) PetscCall(PetscObjectSetName((PetscObject) *dm, "Simplicial Mesh")); 2739566063dSJacob Faibussowitsch else PetscCall(PetscObjectSetName((PetscObject) *dm, "Hexahedral Mesh")); 274c4762a1bSJed Brown } 2759566063dSJacob Faibussowitsch PetscCall(DMSetFromOptions(*dm)); 2769566063dSJacob Faibussowitsch PetscCall(TransformCoordinates(*dm, user)); 2779566063dSJacob Faibussowitsch PetscCall(DMViewFromOptions(*dm,NULL,"-dm_view")); 278c4762a1bSJed Brown PetscFunctionReturn(0); 279c4762a1bSJed Brown } 280c4762a1bSJed Brown 281c4762a1bSJed Brown static void simple_mass(PetscInt dim, PetscInt Nf, PetscInt NfAux, 282c4762a1bSJed Brown const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 283c4762a1bSJed Brown const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 284c4762a1bSJed Brown PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar g0[]) 285c4762a1bSJed Brown { 286c4762a1bSJed Brown PetscInt d, e; 287c4762a1bSJed Brown for (d = 0, e = 0; d < dim; d++, e+=dim+1) { 288c4762a1bSJed Brown g0[e] = 1.; 289c4762a1bSJed Brown } 290c4762a1bSJed Brown } 291c4762a1bSJed Brown 292c4762a1bSJed Brown /* < \nabla v, 1/2(\nabla u + {\nabla u}^T) > */ 293c4762a1bSJed Brown static void symmetric_gradient_inner_product(PetscInt dim, PetscInt Nf, PetscInt NfAux, 294c4762a1bSJed Brown const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar u[], const PetscScalar u_t[], const PetscScalar u_x[], 295c4762a1bSJed Brown const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar a[], const PetscScalar a_t[], const PetscScalar a_x[], 296c4762a1bSJed Brown PetscReal t, PetscReal u_tShift, const PetscReal x[], PetscInt numConstants, const PetscScalar constants[], PetscScalar C[]) 297c4762a1bSJed Brown { 298c4762a1bSJed Brown PetscInt compI, compJ, d, e; 299c4762a1bSJed Brown 300c4762a1bSJed Brown for (compI = 0; compI < dim; ++compI) { 301c4762a1bSJed Brown for (compJ = 0; compJ < dim; ++compJ) { 302c4762a1bSJed Brown for (d = 0; d < dim; ++d) { 303c4762a1bSJed Brown for (e = 0; e < dim; e++) { 304c4762a1bSJed Brown if (d == e && d == compI && d == compJ) { 305c4762a1bSJed Brown C[((compI*dim+compJ)*dim+d)*dim+e] = 1.0; 306c4762a1bSJed Brown } else if ((d == compJ && e == compI) || (d == e && compI == compJ)) { 307c4762a1bSJed Brown C[((compI*dim+compJ)*dim+d)*dim+e] = 0.5; 308c4762a1bSJed Brown } else { 309c4762a1bSJed Brown C[((compI*dim+compJ)*dim+d)*dim+e] = 0.0; 310c4762a1bSJed Brown } 311c4762a1bSJed Brown } 312c4762a1bSJed Brown } 313c4762a1bSJed Brown } 314c4762a1bSJed Brown } 315c4762a1bSJed Brown } 316c4762a1bSJed Brown 317c4762a1bSJed Brown static PetscErrorCode SetupSection(DM dm, AppCtx *user) 318c4762a1bSJed Brown { 319c4762a1bSJed Brown PetscFunctionBeginUser; 32030602db0SMatthew G. Knepley if (user->constraints) { 321c4762a1bSJed Brown /* test local constraints */ 322c4762a1bSJed Brown DM coordDM; 323c4762a1bSJed Brown PetscInt fStart, fEnd, f, vStart, vEnd, v; 324c4762a1bSJed Brown PetscInt edgesx = 2, vertsx; 325c4762a1bSJed Brown PetscInt edgesy = 2, vertsy; 326c4762a1bSJed Brown PetscMPIInt size; 327c4762a1bSJed Brown PetscInt numConst; 328c4762a1bSJed Brown PetscSection aSec; 329c4762a1bSJed Brown PetscInt *anchors; 330c4762a1bSJed Brown PetscInt offset; 331c4762a1bSJed Brown IS aIS; 332c4762a1bSJed Brown MPI_Comm comm = PetscObjectComm((PetscObject)dm); 333c4762a1bSJed Brown 3349566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm,&size)); 335*08401ef6SPierre Jolivet PetscCheck(size <= 1,comm,PETSC_ERR_SUP,"Local constraint test can only be performed in serial"); 336c4762a1bSJed Brown 337c4762a1bSJed Brown /* we are going to test constraints by using them to enforce periodicity 338c4762a1bSJed Brown * in one direction, and comparing to the existing method of enforcing 339c4762a1bSJed Brown * periodicity */ 340c4762a1bSJed Brown 341c4762a1bSJed Brown /* first create the coordinate section so that it does not clone the 342c4762a1bSJed Brown * constraints */ 3439566063dSJacob Faibussowitsch PetscCall(DMGetCoordinateDM(dm,&coordDM)); 344c4762a1bSJed Brown 345c4762a1bSJed Brown /* create the constrained-to-anchor section */ 3469566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm,0,&vStart,&vEnd)); 3479566063dSJacob Faibussowitsch PetscCall(DMPlexGetDepthStratum(dm,1,&fStart,&fEnd)); 3489566063dSJacob Faibussowitsch PetscCall(PetscSectionCreate(PETSC_COMM_SELF,&aSec)); 3499566063dSJacob Faibussowitsch PetscCall(PetscSectionSetChart(aSec,PetscMin(fStart,vStart),PetscMax(fEnd,vEnd))); 350c4762a1bSJed Brown 351c4762a1bSJed Brown /* define the constraints */ 3529566063dSJacob Faibussowitsch PetscCall(PetscOptionsGetInt(NULL,NULL,"-da_grid_x",&edgesx,NULL)); 3539566063dSJacob Faibussowitsch PetscCall(PetscOptionsGetInt(NULL,NULL,"-da_grid_y",&edgesy,NULL)); 354c4762a1bSJed Brown vertsx = edgesx + 1; 355c4762a1bSJed Brown vertsy = edgesy + 1; 356c4762a1bSJed Brown numConst = vertsy + edgesy; 3579566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(numConst,&anchors)); 358c4762a1bSJed Brown offset = 0; 359c4762a1bSJed Brown for (v = vStart + edgesx; v < vEnd; v+= vertsx) { 3609566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(aSec,v,1)); 361c4762a1bSJed Brown anchors[offset++] = v - edgesx; 362c4762a1bSJed Brown } 363c4762a1bSJed Brown for (f = fStart + edgesx * vertsy + edgesx * edgesy; f < fEnd; f++) { 3649566063dSJacob Faibussowitsch PetscCall(PetscSectionSetDof(aSec,f,1)); 365c4762a1bSJed Brown anchors[offset++] = f - edgesx * edgesy; 366c4762a1bSJed Brown } 3679566063dSJacob Faibussowitsch PetscCall(PetscSectionSetUp(aSec)); 3689566063dSJacob Faibussowitsch PetscCall(ISCreateGeneral(PETSC_COMM_SELF,numConst,anchors,PETSC_OWN_POINTER,&aIS)); 369c4762a1bSJed Brown 3709566063dSJacob Faibussowitsch PetscCall(DMPlexSetAnchors(dm,aSec,aIS)); 3719566063dSJacob Faibussowitsch PetscCall(PetscSectionDestroy(&aSec)); 3729566063dSJacob Faibussowitsch PetscCall(ISDestroy(&aIS)); 373c4762a1bSJed Brown } 3749566063dSJacob Faibussowitsch PetscCall(DMSetNumFields(dm, 1)); 3759566063dSJacob Faibussowitsch PetscCall(DMSetField(dm, 0, NULL, (PetscObject) user->fe)); 3769566063dSJacob Faibussowitsch PetscCall(DMCreateDS(dm)); 37730602db0SMatthew G. Knepley if (user->constraints) { 378c4762a1bSJed Brown /* test getting local constraint matrix that matches section */ 379c4762a1bSJed Brown PetscSection aSec; 380c4762a1bSJed Brown IS aIS; 381c4762a1bSJed Brown 3829566063dSJacob Faibussowitsch PetscCall(DMPlexGetAnchors(dm,&aSec,&aIS)); 383c4762a1bSJed Brown if (aSec) { 384c4762a1bSJed Brown PetscDS ds; 385c4762a1bSJed Brown PetscSection cSec, section; 386c4762a1bSJed Brown PetscInt cStart, cEnd, c, numComp; 387c4762a1bSJed Brown Mat cMat, mass; 388c4762a1bSJed Brown Vec local; 389c4762a1bSJed Brown const PetscInt *anchors; 390c4762a1bSJed Brown 3919566063dSJacob Faibussowitsch PetscCall(DMGetLocalSection(dm,§ion)); 392c4762a1bSJed Brown /* this creates the matrix and preallocates the matrix structure: we 393c4762a1bSJed Brown * just have to fill in the values */ 3949566063dSJacob Faibussowitsch PetscCall(DMGetDefaultConstraints(dm,&cSec,&cMat,NULL)); 3959566063dSJacob Faibussowitsch PetscCall(PetscSectionGetChart(cSec,&cStart,&cEnd)); 3969566063dSJacob Faibussowitsch PetscCall(ISGetIndices(aIS,&anchors)); 3979566063dSJacob Faibussowitsch PetscCall(PetscFEGetNumComponents(user->fe, &numComp)); 398c4762a1bSJed Brown for (c = cStart; c < cEnd; c++) { 399c4762a1bSJed Brown PetscInt cDof; 400c4762a1bSJed Brown 401c4762a1bSJed Brown /* is this point constrained? (does it have an anchor?) */ 4029566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(aSec,c,&cDof)); 403c4762a1bSJed Brown if (cDof) { 404c4762a1bSJed Brown PetscInt cOff, a, aDof, aOff, j; 405*08401ef6SPierre Jolivet PetscCheck(cDof == 1,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Found %d anchor points: should be just one",cDof); 406c4762a1bSJed Brown 407c4762a1bSJed Brown /* find the anchor point */ 4089566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(aSec,c,&cOff)); 409c4762a1bSJed Brown a = anchors[cOff]; 410c4762a1bSJed Brown 411c4762a1bSJed Brown /* find the constrained dofs (row in constraint matrix) */ 4129566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(cSec,c,&cDof)); 4139566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(cSec,c,&cOff)); 414c4762a1bSJed Brown 415c4762a1bSJed Brown /* find the anchor dofs (column in constraint matrix) */ 4169566063dSJacob Faibussowitsch PetscCall(PetscSectionGetDof(section,a,&aDof)); 4179566063dSJacob Faibussowitsch PetscCall(PetscSectionGetOffset(section,a,&aOff)); 418c4762a1bSJed Brown 419*08401ef6SPierre Jolivet PetscCheck(cDof == aDof,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Point and anchor have different number of dofs: %d, %d",cDof,aDof); 420*08401ef6SPierre Jolivet PetscCheck(cDof % numComp == 0,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Point dofs not divisible by field components: %d, %d",cDof,numComp); 421c4762a1bSJed Brown 422c4762a1bSJed Brown /* put in a simple equality constraint */ 423c4762a1bSJed Brown for (j = 0; j < cDof; j++) { 4249566063dSJacob Faibussowitsch PetscCall(MatSetValue(cMat,cOff+j,aOff+j,1.,INSERT_VALUES)); 425c4762a1bSJed Brown } 426c4762a1bSJed Brown } 427c4762a1bSJed Brown } 4289566063dSJacob Faibussowitsch PetscCall(MatAssemblyBegin(cMat,MAT_FINAL_ASSEMBLY)); 4299566063dSJacob Faibussowitsch PetscCall(MatAssemblyEnd(cMat,MAT_FINAL_ASSEMBLY)); 4309566063dSJacob Faibussowitsch PetscCall(ISRestoreIndices(aIS,&anchors)); 431c4762a1bSJed Brown 432c4762a1bSJed Brown /* Now that we have constructed the constraint matrix, any FE matrix 433c4762a1bSJed Brown * that we construct will apply the constraints during construction */ 434c4762a1bSJed Brown 4359566063dSJacob Faibussowitsch PetscCall(DMCreateMatrix(dm,&mass)); 436c4762a1bSJed Brown /* get a dummy local variable to serve as the solution */ 4379566063dSJacob Faibussowitsch PetscCall(DMGetLocalVector(dm,&local)); 4389566063dSJacob Faibussowitsch PetscCall(DMGetDS(dm,&ds)); 439c4762a1bSJed Brown /* set the jacobian to be the mass matrix */ 4409566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobian(ds, 0, 0, simple_mass, NULL, NULL, NULL)); 441c4762a1bSJed Brown /* build the mass matrix */ 4429566063dSJacob Faibussowitsch PetscCall(DMPlexSNESComputeJacobianFEM(dm,local,mass,mass,NULL)); 4439566063dSJacob Faibussowitsch PetscCall(MatView(mass,PETSC_VIEWER_STDOUT_WORLD)); 4449566063dSJacob Faibussowitsch PetscCall(MatDestroy(&mass)); 4459566063dSJacob Faibussowitsch PetscCall(DMRestoreLocalVector(dm,&local)); 446c4762a1bSJed Brown } 447c4762a1bSJed Brown } 448c4762a1bSJed Brown PetscFunctionReturn(0); 449c4762a1bSJed Brown } 450c4762a1bSJed Brown 451c4762a1bSJed Brown static PetscErrorCode TestFEJacobian(DM dm, AppCtx *user) 452c4762a1bSJed Brown { 453c4762a1bSJed Brown PetscFunctionBeginUser; 45430602db0SMatthew G. Knepley if (!user->useDA) { 455c4762a1bSJed Brown Vec local; 456c4762a1bSJed Brown const Vec *vecs; 457c4762a1bSJed Brown Mat E; 458c4762a1bSJed Brown MatNullSpace sp; 459c4762a1bSJed Brown PetscBool isNullSpace, hasConst; 46030602db0SMatthew G. Knepley PetscInt dim, n, i; 461c4762a1bSJed Brown Vec res = NULL, localX, localRes; 462c4762a1bSJed Brown PetscDS ds; 463c4762a1bSJed Brown 4649566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 465*08401ef6SPierre Jolivet PetscCheck(user->numComponents == dim,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "The number of components %d must be equal to the dimension %d for this test", user->numComponents, dim); 4669566063dSJacob Faibussowitsch PetscCall(DMGetDS(dm,&ds)); 4679566063dSJacob Faibussowitsch PetscCall(PetscDSSetJacobian(ds,0,0,NULL,NULL,NULL,symmetric_gradient_inner_product)); 4689566063dSJacob Faibussowitsch PetscCall(DMCreateMatrix(dm,&E)); 4699566063dSJacob Faibussowitsch PetscCall(DMGetLocalVector(dm,&local)); 4709566063dSJacob Faibussowitsch PetscCall(DMPlexSNESComputeJacobianFEM(dm,local,E,E,NULL)); 4719566063dSJacob Faibussowitsch PetscCall(DMPlexCreateRigidBody(dm,0,&sp)); 4729566063dSJacob Faibussowitsch PetscCall(MatNullSpaceGetVecs(sp,&hasConst,&n,&vecs)); 4739566063dSJacob Faibussowitsch if (n) PetscCall(VecDuplicate(vecs[0],&res)); 4749566063dSJacob Faibussowitsch PetscCall(DMCreateLocalVector(dm,&localX)); 4759566063dSJacob Faibussowitsch PetscCall(DMCreateLocalVector(dm,&localRes)); 476c4762a1bSJed Brown for (i = 0; i < n; i++) { /* also test via matrix-free Jacobian application */ 477c4762a1bSJed Brown PetscReal resNorm; 478c4762a1bSJed Brown 4799566063dSJacob Faibussowitsch PetscCall(VecSet(localRes,0.)); 4809566063dSJacob Faibussowitsch PetscCall(VecSet(localX,0.)); 4819566063dSJacob Faibussowitsch PetscCall(VecSet(local,0.)); 4829566063dSJacob Faibussowitsch PetscCall(VecSet(res,0.)); 4839566063dSJacob Faibussowitsch PetscCall(DMGlobalToLocalBegin(dm,vecs[i],INSERT_VALUES,localX)); 4849566063dSJacob Faibussowitsch PetscCall(DMGlobalToLocalEnd(dm,vecs[i],INSERT_VALUES,localX)); 4859566063dSJacob Faibussowitsch PetscCall(DMSNESComputeJacobianAction(dm,local,localX,localRes,NULL)); 4869566063dSJacob Faibussowitsch PetscCall(DMLocalToGlobalBegin(dm,localRes,ADD_VALUES,res)); 4879566063dSJacob Faibussowitsch PetscCall(DMLocalToGlobalEnd(dm,localRes,ADD_VALUES,res)); 4889566063dSJacob Faibussowitsch PetscCall(VecNorm(res,NORM_2,&resNorm)); 489c4762a1bSJed Brown if (resNorm > PETSC_SMALL) { 4909566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject)dm),"Symmetric gradient action null space vector %D residual: %E\n",i,resNorm)); 491c4762a1bSJed Brown } 492c4762a1bSJed Brown } 4939566063dSJacob Faibussowitsch PetscCall(VecDestroy(&localRes)); 4949566063dSJacob Faibussowitsch PetscCall(VecDestroy(&localX)); 4959566063dSJacob Faibussowitsch PetscCall(VecDestroy(&res)); 4969566063dSJacob Faibussowitsch PetscCall(MatNullSpaceTest(sp,E,&isNullSpace)); 497c4762a1bSJed Brown if (isNullSpace) { 4989566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject)dm),"Symmetric gradient null space: PASS\n")); 499c4762a1bSJed Brown } else { 5009566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject)dm),"Symmetric gradient null space: FAIL\n")); 501c4762a1bSJed Brown } 5029566063dSJacob Faibussowitsch PetscCall(MatNullSpaceDestroy(&sp)); 5039566063dSJacob Faibussowitsch PetscCall(MatDestroy(&E)); 5049566063dSJacob Faibussowitsch PetscCall(DMRestoreLocalVector(dm,&local)); 505c4762a1bSJed Brown } 506c4762a1bSJed Brown PetscFunctionReturn(0); 507c4762a1bSJed Brown } 508c4762a1bSJed Brown 509c4762a1bSJed Brown static PetscErrorCode TestInjector(DM dm, AppCtx *user) 510c4762a1bSJed Brown { 511c4762a1bSJed Brown DM refTree; 512c4762a1bSJed Brown PetscMPIInt rank; 513c4762a1bSJed Brown 514c4762a1bSJed Brown PetscFunctionBegin; 5159566063dSJacob Faibussowitsch PetscCall(DMPlexGetReferenceTree(dm,&refTree)); 516c4762a1bSJed Brown if (refTree) { 517c4762a1bSJed Brown Mat inj; 518c4762a1bSJed Brown 5199566063dSJacob Faibussowitsch PetscCall(DMPlexComputeInjectorReferenceTree(refTree,&inj)); 5209566063dSJacob Faibussowitsch PetscCall(PetscObjectSetName((PetscObject)inj,"Reference Tree Injector")); 5219566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); 522dd400576SPatrick Sanan if (rank == 0) { 5239566063dSJacob Faibussowitsch PetscCall(MatView(inj,PETSC_VIEWER_STDOUT_SELF)); 524c4762a1bSJed Brown } 5259566063dSJacob Faibussowitsch PetscCall(MatDestroy(&inj)); 526c4762a1bSJed Brown } 527c4762a1bSJed Brown PetscFunctionReturn(0); 528c4762a1bSJed Brown } 529c4762a1bSJed Brown 530c4762a1bSJed Brown static PetscErrorCode TestFVGrad(DM dm, AppCtx *user) 531c4762a1bSJed Brown { 532c4762a1bSJed Brown MPI_Comm comm; 533c4762a1bSJed Brown DM dmRedist, dmfv, dmgrad, dmCell, refTree; 534c4762a1bSJed Brown PetscFV fv; 53530602db0SMatthew G. Knepley PetscInt dim, nvecs, v, cStart, cEnd, cEndInterior; 536c4762a1bSJed Brown PetscMPIInt size; 537c4762a1bSJed Brown Vec cellgeom, grad, locGrad; 538c4762a1bSJed Brown const PetscScalar *cgeom; 539c4762a1bSJed Brown PetscReal allVecMaxDiff = 0., fvTol = 100. * PETSC_MACHINE_EPSILON; 540c4762a1bSJed Brown 541c4762a1bSJed Brown PetscFunctionBeginUser; 542c4762a1bSJed Brown comm = PetscObjectComm((PetscObject)dm); 5439566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 544c4762a1bSJed Brown /* duplicate DM, give dup. a FV discretization */ 5459566063dSJacob Faibussowitsch PetscCall(DMSetBasicAdjacency(dm,PETSC_TRUE,PETSC_FALSE)); 5469566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm,&size)); 547c4762a1bSJed Brown dmRedist = NULL; 548c4762a1bSJed Brown if (size > 1) { 5499566063dSJacob Faibussowitsch PetscCall(DMPlexDistributeOverlap(dm,1,NULL,&dmRedist)); 550c4762a1bSJed Brown } 551c4762a1bSJed Brown if (!dmRedist) { 552c4762a1bSJed Brown dmRedist = dm; 5539566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)dmRedist)); 554c4762a1bSJed Brown } 5559566063dSJacob Faibussowitsch PetscCall(PetscFVCreate(comm,&fv)); 5569566063dSJacob Faibussowitsch PetscCall(PetscFVSetType(fv,PETSCFVLEASTSQUARES)); 5579566063dSJacob Faibussowitsch PetscCall(PetscFVSetNumComponents(fv,user->numComponents)); 5589566063dSJacob Faibussowitsch PetscCall(PetscFVSetSpatialDimension(fv,dim)); 5599566063dSJacob Faibussowitsch PetscCall(PetscFVSetFromOptions(fv)); 5609566063dSJacob Faibussowitsch PetscCall(PetscFVSetUp(fv)); 5619566063dSJacob Faibussowitsch PetscCall(DMPlexConstructGhostCells(dmRedist,NULL,NULL,&dmfv)); 5629566063dSJacob Faibussowitsch PetscCall(DMDestroy(&dmRedist)); 5639566063dSJacob Faibussowitsch PetscCall(DMSetNumFields(dmfv,1)); 5649566063dSJacob Faibussowitsch PetscCall(DMSetField(dmfv, 0, NULL, (PetscObject) fv)); 5659566063dSJacob Faibussowitsch PetscCall(DMCreateDS(dmfv)); 5669566063dSJacob Faibussowitsch PetscCall(DMPlexGetReferenceTree(dm,&refTree)); 5679566063dSJacob Faibussowitsch if (refTree) PetscCall(DMCopyDisc(dmfv,refTree)); 5689566063dSJacob Faibussowitsch PetscCall(DMPlexGetGradientDM(dmfv, fv, &dmgrad)); 5699566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(dmfv,0,&cStart,&cEnd)); 57030602db0SMatthew G. Knepley nvecs = dim * (dim+1) / 2; 5719566063dSJacob Faibussowitsch PetscCall(DMPlexGetGeometryFVM(dmfv,NULL,&cellgeom,NULL)); 5729566063dSJacob Faibussowitsch PetscCall(VecGetDM(cellgeom,&dmCell)); 5739566063dSJacob Faibussowitsch PetscCall(VecGetArrayRead(cellgeom,&cgeom)); 5749566063dSJacob Faibussowitsch PetscCall(DMGetGlobalVector(dmgrad,&grad)); 5759566063dSJacob Faibussowitsch PetscCall(DMGetLocalVector(dmgrad,&locGrad)); 5769566063dSJacob Faibussowitsch PetscCall(DMPlexGetGhostCellStratum(dmgrad,&cEndInterior,NULL)); 577c4762a1bSJed Brown cEndInterior = (cEndInterior < 0) ? cEnd: cEndInterior; 578c4762a1bSJed Brown for (v = 0; v < nvecs; v++) { 579c4762a1bSJed Brown Vec locX; 580c4762a1bSJed Brown PetscInt c; 581c4762a1bSJed Brown PetscScalar trueGrad[3][3] = {{0.}}; 582c4762a1bSJed Brown const PetscScalar *gradArray; 583c4762a1bSJed Brown PetscReal maxDiff, maxDiffGlob; 584c4762a1bSJed Brown 5859566063dSJacob Faibussowitsch PetscCall(DMGetLocalVector(dmfv,&locX)); 586c4762a1bSJed Brown /* get the local projection of the rigid body mode */ 587c4762a1bSJed Brown for (c = cStart; c < cEnd; c++) { 588c4762a1bSJed Brown PetscFVCellGeom *cg; 589c4762a1bSJed Brown PetscScalar cx[3] = {0.,0.,0.}; 590c4762a1bSJed Brown 5919566063dSJacob Faibussowitsch PetscCall(DMPlexPointLocalRead(dmCell, c, cgeom, &cg)); 59230602db0SMatthew G. Knepley if (v < dim) { 593c4762a1bSJed Brown cx[v] = 1.; 594c4762a1bSJed Brown } else { 59530602db0SMatthew G. Knepley PetscInt w = v - dim; 596c4762a1bSJed Brown 59730602db0SMatthew G. Knepley cx[(w + 1) % dim] = cg->centroid[(w + 2) % dim]; 59830602db0SMatthew G. Knepley cx[(w + 2) % dim] = -cg->centroid[(w + 1) % dim]; 599c4762a1bSJed Brown } 6009566063dSJacob Faibussowitsch PetscCall(DMPlexVecSetClosure(dmfv,NULL,locX,c,cx,INSERT_ALL_VALUES)); 601c4762a1bSJed Brown } 602c4762a1bSJed Brown /* TODO: this isn't in any header */ 6039566063dSJacob Faibussowitsch PetscCall(DMPlexReconstructGradientsFVM(dmfv,locX,grad)); 6049566063dSJacob Faibussowitsch PetscCall(DMGlobalToLocalBegin(dmgrad,grad,INSERT_VALUES,locGrad)); 6059566063dSJacob Faibussowitsch PetscCall(DMGlobalToLocalEnd(dmgrad,grad,INSERT_VALUES,locGrad)); 6069566063dSJacob Faibussowitsch PetscCall(VecGetArrayRead(locGrad,&gradArray)); 607c4762a1bSJed Brown /* compare computed gradient to exact gradient */ 60830602db0SMatthew G. Knepley if (v >= dim) { 60930602db0SMatthew G. Knepley PetscInt w = v - dim; 610c4762a1bSJed Brown 61130602db0SMatthew G. Knepley trueGrad[(w + 1) % dim][(w + 2) % dim] = 1.; 61230602db0SMatthew G. Knepley trueGrad[(w + 2) % dim][(w + 1) % dim] = -1.; 613c4762a1bSJed Brown } 614c4762a1bSJed Brown maxDiff = 0.; 615c4762a1bSJed Brown for (c = cStart; c < cEndInterior; c++) { 616c4762a1bSJed Brown PetscScalar *compGrad; 617c4762a1bSJed Brown PetscInt i, j, k; 618c4762a1bSJed Brown PetscReal FrobDiff = 0.; 619c4762a1bSJed Brown 6209566063dSJacob Faibussowitsch PetscCall(DMPlexPointLocalRead(dmgrad, c, gradArray, &compGrad)); 621c4762a1bSJed Brown 62230602db0SMatthew G. Knepley for (i = 0, k = 0; i < dim; i++) { 62330602db0SMatthew G. Knepley for (j = 0; j < dim; j++, k++) { 624c4762a1bSJed Brown PetscScalar diff = compGrad[k] - trueGrad[i][j]; 625c4762a1bSJed Brown FrobDiff += PetscRealPart(diff * PetscConj(diff)); 626c4762a1bSJed Brown } 627c4762a1bSJed Brown } 628c4762a1bSJed Brown FrobDiff = PetscSqrtReal(FrobDiff); 629c4762a1bSJed Brown maxDiff = PetscMax(maxDiff,FrobDiff); 630c4762a1bSJed Brown } 6319566063dSJacob Faibussowitsch PetscCallMPI(MPI_Allreduce(&maxDiff,&maxDiffGlob,1,MPIU_REAL,MPIU_MAX,comm)); 632c4762a1bSJed Brown allVecMaxDiff = PetscMax(allVecMaxDiff,maxDiffGlob); 6339566063dSJacob Faibussowitsch PetscCall(VecRestoreArrayRead(locGrad,&gradArray)); 6349566063dSJacob Faibussowitsch PetscCall(DMRestoreLocalVector(dmfv,&locX)); 635c4762a1bSJed Brown } 636c4762a1bSJed Brown if (allVecMaxDiff < fvTol) { 6379566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject)dm),"Finite volume gradient reconstruction: PASS\n")); 638c4762a1bSJed Brown } else { 6399566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject)dm),"Finite volume gradient reconstruction: FAIL at tolerance %g with max difference %g\n",fvTol,allVecMaxDiff)); 640c4762a1bSJed Brown } 6419566063dSJacob Faibussowitsch PetscCall(DMRestoreLocalVector(dmgrad,&locGrad)); 6429566063dSJacob Faibussowitsch PetscCall(DMRestoreGlobalVector(dmgrad,&grad)); 6439566063dSJacob Faibussowitsch PetscCall(VecRestoreArrayRead(cellgeom,&cgeom)); 6449566063dSJacob Faibussowitsch PetscCall(DMDestroy(&dmfv)); 6459566063dSJacob Faibussowitsch PetscCall(PetscFVDestroy(&fv)); 646c4762a1bSJed Brown PetscFunctionReturn(0); 647c4762a1bSJed Brown } 648c4762a1bSJed Brown 649c4762a1bSJed Brown static PetscErrorCode ComputeError(DM dm, PetscErrorCode (**exactFuncs)(PetscInt, PetscReal, const PetscReal[], PetscInt, PetscScalar *, void *), 650c4762a1bSJed Brown PetscErrorCode (**exactFuncDers)(PetscInt, PetscReal, const PetscReal[], const PetscReal[], PetscInt, PetscScalar *, void *), 651c4762a1bSJed Brown void **exactCtxs, PetscReal *error, PetscReal *errorDer, AppCtx *user) 652c4762a1bSJed Brown { 653c4762a1bSJed Brown Vec u; 654c4762a1bSJed Brown PetscReal n[3] = {1.0, 1.0, 1.0}; 655c4762a1bSJed Brown 656c4762a1bSJed Brown PetscFunctionBeginUser; 6579566063dSJacob Faibussowitsch PetscCall(DMGetGlobalVector(dm, &u)); 658c4762a1bSJed Brown /* Project function into FE function space */ 6599566063dSJacob Faibussowitsch PetscCall(DMProjectFunction(dm, 0.0, exactFuncs, exactCtxs, INSERT_ALL_VALUES, u)); 6609566063dSJacob Faibussowitsch PetscCall(VecViewFromOptions(u, NULL, "-projection_view")); 661c4762a1bSJed Brown /* Compare approximation to exact in L_2 */ 6629566063dSJacob Faibussowitsch PetscCall(DMComputeL2Diff(dm, 0.0, exactFuncs, exactCtxs, u, error)); 6639566063dSJacob Faibussowitsch PetscCall(DMComputeL2GradientDiff(dm, 0.0, exactFuncDers, exactCtxs, u, n, errorDer)); 6649566063dSJacob Faibussowitsch PetscCall(DMRestoreGlobalVector(dm, &u)); 665c4762a1bSJed Brown PetscFunctionReturn(0); 666c4762a1bSJed Brown } 667c4762a1bSJed Brown 668c4762a1bSJed Brown static PetscErrorCode CheckFunctions(DM dm, PetscInt order, AppCtx *user) 669c4762a1bSJed Brown { 670c4762a1bSJed Brown PetscErrorCode (*exactFuncs[1]) (PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar *u, void *ctx); 671c4762a1bSJed Brown PetscErrorCode (*exactFuncDers[1]) (PetscInt dim, PetscReal time, const PetscReal x[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx); 672c4762a1bSJed Brown void *exactCtxs[3]; 673c4762a1bSJed Brown MPI_Comm comm; 674c4762a1bSJed Brown PetscReal error, errorDer, tol = PETSC_SMALL; 675c4762a1bSJed Brown 676c4762a1bSJed Brown PetscFunctionBeginUser; 677c4762a1bSJed Brown exactCtxs[0] = user; 678c4762a1bSJed Brown exactCtxs[1] = user; 679c4762a1bSJed Brown exactCtxs[2] = user; 6809566063dSJacob Faibussowitsch PetscCall(PetscObjectGetComm((PetscObject)dm, &comm)); 681c4762a1bSJed Brown /* Setup functions to approximate */ 682c4762a1bSJed Brown switch (order) { 683c4762a1bSJed Brown case 0: 684c4762a1bSJed Brown exactFuncs[0] = constant; 685c4762a1bSJed Brown exactFuncDers[0] = constantDer; 686c4762a1bSJed Brown break; 687c4762a1bSJed Brown case 1: 688c4762a1bSJed Brown exactFuncs[0] = linear; 689c4762a1bSJed Brown exactFuncDers[0] = linearDer; 690c4762a1bSJed Brown break; 691c4762a1bSJed Brown case 2: 692c4762a1bSJed Brown exactFuncs[0] = quadratic; 693c4762a1bSJed Brown exactFuncDers[0] = quadraticDer; 694c4762a1bSJed Brown break; 695c4762a1bSJed Brown case 3: 696c4762a1bSJed Brown exactFuncs[0] = cubic; 697c4762a1bSJed Brown exactFuncDers[0] = cubicDer; 698c4762a1bSJed Brown break; 699c4762a1bSJed Brown default: 70098921bdaSJacob Faibussowitsch SETERRQ(comm, PETSC_ERR_ARG_OUTOFRANGE, "Could not determine functions to test for order %d", order); 701c4762a1bSJed Brown } 7029566063dSJacob Faibussowitsch PetscCall(ComputeError(dm, exactFuncs, exactFuncDers, exactCtxs, &error, &errorDer, user)); 703c4762a1bSJed Brown /* Report result */ 7049566063dSJacob Faibussowitsch if (error > tol) PetscCall(PetscPrintf(comm, "Function tests FAIL for order %D at tolerance %g error %g\n", order, (double)tol,(double) error)); 7059566063dSJacob Faibussowitsch else PetscCall(PetscPrintf(comm, "Function tests pass for order %D at tolerance %g\n", order, (double)tol)); 7069566063dSJacob Faibussowitsch if (errorDer > tol) PetscCall(PetscPrintf(comm, "Function tests FAIL for order %D derivatives at tolerance %g error %g\n", order, (double)tol, (double)errorDer)); 7079566063dSJacob Faibussowitsch else PetscCall(PetscPrintf(comm, "Function tests pass for order %D derivatives at tolerance %g\n", order, (double)tol)); 708c4762a1bSJed Brown PetscFunctionReturn(0); 709c4762a1bSJed Brown } 710c4762a1bSJed Brown 711c4762a1bSJed Brown static PetscErrorCode CheckInterpolation(DM dm, PetscBool checkRestrict, PetscInt order, AppCtx *user) 712c4762a1bSJed Brown { 713c4762a1bSJed Brown PetscErrorCode (*exactFuncs[1]) (PetscInt, PetscReal, const PetscReal x[], PetscInt, PetscScalar *u, void *ctx); 714c4762a1bSJed Brown PetscErrorCode (*exactFuncDers[1]) (PetscInt, PetscReal, const PetscReal x[], const PetscReal n[], PetscInt, PetscScalar *u, void *ctx); 715c4762a1bSJed Brown PetscReal n[3] = {1.0, 1.0, 1.0}; 716c4762a1bSJed Brown void *exactCtxs[3]; 717c4762a1bSJed Brown DM rdm, idm, fdm; 718c4762a1bSJed Brown Mat Interp; 719c4762a1bSJed Brown Vec iu, fu, scaling; 720c4762a1bSJed Brown MPI_Comm comm; 72130602db0SMatthew G. Knepley PetscInt dim; 722c4762a1bSJed Brown PetscReal error, errorDer, tol = PETSC_SMALL; 723c4762a1bSJed Brown 724c4762a1bSJed Brown PetscFunctionBeginUser; 725c4762a1bSJed Brown exactCtxs[0] = user; 726c4762a1bSJed Brown exactCtxs[1] = user; 727c4762a1bSJed Brown exactCtxs[2] = user; 7289566063dSJacob Faibussowitsch PetscCall(PetscObjectGetComm((PetscObject)dm,&comm)); 7299566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 7309566063dSJacob Faibussowitsch PetscCall(DMRefine(dm, comm, &rdm)); 7319566063dSJacob Faibussowitsch PetscCall(DMSetCoarseDM(rdm, dm)); 7329566063dSJacob Faibussowitsch PetscCall(DMPlexSetRegularRefinement(rdm, user->convRefine)); 73330602db0SMatthew G. Knepley if (user->tree) { 734c4762a1bSJed Brown DM refTree; 7359566063dSJacob Faibussowitsch PetscCall(DMPlexGetReferenceTree(dm,&refTree)); 7369566063dSJacob Faibussowitsch PetscCall(DMPlexSetReferenceTree(rdm,refTree)); 737c4762a1bSJed Brown } 7389566063dSJacob Faibussowitsch if (user->useDA) PetscCall(DMDASetVertexCoordinates(rdm, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)); 7399566063dSJacob Faibussowitsch PetscCall(SetupSection(rdm, user)); 740c4762a1bSJed Brown /* Setup functions to approximate */ 741c4762a1bSJed Brown switch (order) { 742c4762a1bSJed Brown case 0: 743c4762a1bSJed Brown exactFuncs[0] = constant; 744c4762a1bSJed Brown exactFuncDers[0] = constantDer; 745c4762a1bSJed Brown break; 746c4762a1bSJed Brown case 1: 747c4762a1bSJed Brown exactFuncs[0] = linear; 748c4762a1bSJed Brown exactFuncDers[0] = linearDer; 749c4762a1bSJed Brown break; 750c4762a1bSJed Brown case 2: 751c4762a1bSJed Brown exactFuncs[0] = quadratic; 752c4762a1bSJed Brown exactFuncDers[0] = quadraticDer; 753c4762a1bSJed Brown break; 754c4762a1bSJed Brown case 3: 755c4762a1bSJed Brown exactFuncs[0] = cubic; 756c4762a1bSJed Brown exactFuncDers[0] = cubicDer; 757c4762a1bSJed Brown break; 758c4762a1bSJed Brown default: 75998921bdaSJacob Faibussowitsch SETERRQ(comm, PETSC_ERR_ARG_OUTOFRANGE, "Could not determine functions to test for dimension %D order %D", dim, order); 760c4762a1bSJed Brown } 761c4762a1bSJed Brown idm = checkRestrict ? rdm : dm; 762c4762a1bSJed Brown fdm = checkRestrict ? dm : rdm; 7639566063dSJacob Faibussowitsch PetscCall(DMGetGlobalVector(idm, &iu)); 7649566063dSJacob Faibussowitsch PetscCall(DMGetGlobalVector(fdm, &fu)); 7659566063dSJacob Faibussowitsch PetscCall(DMSetApplicationContext(dm, user)); 7669566063dSJacob Faibussowitsch PetscCall(DMSetApplicationContext(rdm, user)); 7679566063dSJacob Faibussowitsch PetscCall(DMCreateInterpolation(dm, rdm, &Interp, &scaling)); 768c4762a1bSJed Brown /* Project function into initial FE function space */ 7699566063dSJacob Faibussowitsch PetscCall(DMProjectFunction(idm, 0.0, exactFuncs, exactCtxs, INSERT_ALL_VALUES, iu)); 770c4762a1bSJed Brown /* Interpolate function into final FE function space */ 7719566063dSJacob Faibussowitsch if (checkRestrict) {PetscCall(MatRestrict(Interp, iu, fu));PetscCall(VecPointwiseMult(fu, scaling, fu));} 7729566063dSJacob Faibussowitsch else PetscCall(MatInterpolate(Interp, iu, fu)); 773c4762a1bSJed Brown /* Compare approximation to exact in L_2 */ 7749566063dSJacob Faibussowitsch PetscCall(DMComputeL2Diff(fdm, 0.0, exactFuncs, exactCtxs, fu, &error)); 7759566063dSJacob Faibussowitsch PetscCall(DMComputeL2GradientDiff(fdm, 0.0, exactFuncDers, exactCtxs, fu, n, &errorDer)); 776c4762a1bSJed Brown /* Report result */ 7779566063dSJacob Faibussowitsch if (error > tol) PetscCall(PetscPrintf(comm, "Interpolation tests FAIL for order %D at tolerance %g error %g\n", order, (double)tol, (double)error)); 7789566063dSJacob Faibussowitsch else PetscCall(PetscPrintf(comm, "Interpolation tests pass for order %D at tolerance %g\n", order, (double)tol)); 7799566063dSJacob Faibussowitsch if (errorDer > tol) PetscCall(PetscPrintf(comm, "Interpolation tests FAIL for order %D derivatives at tolerance %g error %g\n", order, (double)tol, (double)errorDer)); 7809566063dSJacob Faibussowitsch else PetscCall(PetscPrintf(comm, "Interpolation tests pass for order %D derivatives at tolerance %g\n", order, (double)tol)); 7819566063dSJacob Faibussowitsch PetscCall(DMRestoreGlobalVector(idm, &iu)); 7829566063dSJacob Faibussowitsch PetscCall(DMRestoreGlobalVector(fdm, &fu)); 7839566063dSJacob Faibussowitsch PetscCall(MatDestroy(&Interp)); 7849566063dSJacob Faibussowitsch PetscCall(VecDestroy(&scaling)); 7859566063dSJacob Faibussowitsch PetscCall(DMDestroy(&rdm)); 786c4762a1bSJed Brown PetscFunctionReturn(0); 787c4762a1bSJed Brown } 788c4762a1bSJed Brown 789c4762a1bSJed Brown static PetscErrorCode CheckConvergence(DM dm, PetscInt Nr, AppCtx *user) 790c4762a1bSJed Brown { 791c4762a1bSJed Brown DM odm = dm, rdm = NULL, cdm = NULL; 792c4762a1bSJed Brown PetscErrorCode (*exactFuncs[1]) (PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar *u, void *ctx) = {trig}; 793c4762a1bSJed Brown PetscErrorCode (*exactFuncDers[1]) (PetscInt dim, PetscReal time, const PetscReal x[], const PetscReal n[], PetscInt Nf, PetscScalar *u, void *ctx) = {trigDer}; 794c4762a1bSJed Brown void *exactCtxs[3]; 795c4762a1bSJed Brown PetscInt r, c, cStart, cEnd; 796c4762a1bSJed Brown PetscReal errorOld, errorDerOld, error, errorDer, rel, len, lenOld; 797c4762a1bSJed Brown double p; 798c4762a1bSJed Brown 799c4762a1bSJed Brown PetscFunctionBeginUser; 800c4762a1bSJed Brown if (!user->convergence) PetscFunctionReturn(0); 801c4762a1bSJed Brown exactCtxs[0] = user; 802c4762a1bSJed Brown exactCtxs[1] = user; 803c4762a1bSJed Brown exactCtxs[2] = user; 8049566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject) odm)); 805c4762a1bSJed Brown if (!user->convRefine) { 806c4762a1bSJed Brown for (r = 0; r < Nr; ++r) { 8079566063dSJacob Faibussowitsch PetscCall(DMRefine(odm, PetscObjectComm((PetscObject) dm), &rdm)); 8089566063dSJacob Faibussowitsch PetscCall(DMDestroy(&odm)); 809c4762a1bSJed Brown odm = rdm; 810c4762a1bSJed Brown } 8119566063dSJacob Faibussowitsch PetscCall(SetupSection(odm, user)); 812c4762a1bSJed Brown } 8139566063dSJacob Faibussowitsch PetscCall(ComputeError(odm, exactFuncs, exactFuncDers, exactCtxs, &errorOld, &errorDerOld, user)); 814c4762a1bSJed Brown if (user->convRefine) { 815c4762a1bSJed Brown for (r = 0; r < Nr; ++r) { 8169566063dSJacob Faibussowitsch PetscCall(DMRefine(odm, PetscObjectComm((PetscObject) dm), &rdm)); 8179566063dSJacob Faibussowitsch if (user->useDA) PetscCall(DMDASetVertexCoordinates(rdm, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)); 8189566063dSJacob Faibussowitsch PetscCall(SetupSection(rdm, user)); 8199566063dSJacob Faibussowitsch PetscCall(ComputeError(rdm, exactFuncs, exactFuncDers, exactCtxs, &error, &errorDer, user)); 820c4762a1bSJed Brown p = PetscLog2Real(errorOld/error); 8219566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject) dm), "Function convergence rate at refinement %D: %.2f\n", r, (double)p)); 822c4762a1bSJed Brown p = PetscLog2Real(errorDerOld/errorDer); 8239566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject) dm), "Derivative convergence rate at refinement %D: %.2f\n", r, (double)p)); 8249566063dSJacob Faibussowitsch PetscCall(DMDestroy(&odm)); 825c4762a1bSJed Brown odm = rdm; 826c4762a1bSJed Brown errorOld = error; 827c4762a1bSJed Brown errorDerOld = errorDer; 828c4762a1bSJed Brown } 829c4762a1bSJed Brown } else { 8309566063dSJacob Faibussowitsch /* PetscCall(ComputeLongestEdge(dm, &lenOld)); */ 8319566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(odm, 0, &cStart, &cEnd)); 832c4762a1bSJed Brown lenOld = cEnd - cStart; 833c4762a1bSJed Brown for (c = 0; c < Nr; ++c) { 8349566063dSJacob Faibussowitsch PetscCall(DMCoarsen(odm, PetscObjectComm((PetscObject) dm), &cdm)); 8359566063dSJacob Faibussowitsch if (user->useDA) PetscCall(DMDASetVertexCoordinates(cdm, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0)); 8369566063dSJacob Faibussowitsch PetscCall(SetupSection(cdm, user)); 8379566063dSJacob Faibussowitsch PetscCall(ComputeError(cdm, exactFuncs, exactFuncDers, exactCtxs, &error, &errorDer, user)); 8389566063dSJacob Faibussowitsch /* PetscCall(ComputeLongestEdge(cdm, &len)); */ 8399566063dSJacob Faibussowitsch PetscCall(DMPlexGetHeightStratum(cdm, 0, &cStart, &cEnd)); 840c4762a1bSJed Brown len = cEnd - cStart; 841c4762a1bSJed Brown rel = error/errorOld; 842c4762a1bSJed Brown p = PetscLogReal(rel) / PetscLogReal(lenOld / len); 8439566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject) dm), "Function convergence rate at coarsening %D: %.2f\n", c, (double)p)); 844c4762a1bSJed Brown rel = errorDer/errorDerOld; 845c4762a1bSJed Brown p = PetscLogReal(rel) / PetscLogReal(lenOld / len); 8469566063dSJacob Faibussowitsch PetscCall(PetscPrintf(PetscObjectComm((PetscObject) dm), "Derivative convergence rate at coarsening %D: %.2f\n", c, (double)p)); 8479566063dSJacob Faibussowitsch PetscCall(DMDestroy(&odm)); 848c4762a1bSJed Brown odm = cdm; 849c4762a1bSJed Brown errorOld = error; 850c4762a1bSJed Brown errorDerOld = errorDer; 851c4762a1bSJed Brown lenOld = len; 852c4762a1bSJed Brown } 853c4762a1bSJed Brown } 8549566063dSJacob Faibussowitsch PetscCall(DMDestroy(&odm)); 855c4762a1bSJed Brown PetscFunctionReturn(0); 856c4762a1bSJed Brown } 857c4762a1bSJed Brown 858c4762a1bSJed Brown int main(int argc, char **argv) 859c4762a1bSJed Brown { 860c4762a1bSJed Brown DM dm; 861c4762a1bSJed Brown AppCtx user; /* user-defined work context */ 86230602db0SMatthew G. Knepley PetscInt dim = 2; 86330602db0SMatthew G. Knepley PetscBool simplex = PETSC_FALSE; 864c4762a1bSJed Brown 8659566063dSJacob Faibussowitsch PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 8669566063dSJacob Faibussowitsch PetscCall(ProcessOptions(PETSC_COMM_WORLD, &user)); 8679566063dSJacob Faibussowitsch PetscCall(CreateMesh(PETSC_COMM_WORLD, &user, &dm)); 86830602db0SMatthew G. Knepley if (!user.useDA) { 8699566063dSJacob Faibussowitsch PetscCall(DMGetDimension(dm, &dim)); 8709566063dSJacob Faibussowitsch PetscCall(DMPlexIsSimplex(dm, &simplex)); 87130602db0SMatthew G. Knepley } 8729566063dSJacob Faibussowitsch PetscCall(DMPlexMetricSetFromOptions(dm)); 87330602db0SMatthew G. Knepley user.numComponents = user.numComponents < 0 ? dim : user.numComponents; 8749566063dSJacob Faibussowitsch PetscCall(PetscFECreateDefault(PETSC_COMM_WORLD, dim, user.numComponents, simplex, NULL, user.qorder, &user.fe)); 8759566063dSJacob Faibussowitsch PetscCall(SetupSection(dm, &user)); 8769566063dSJacob Faibussowitsch if (user.testFEjacobian) PetscCall(TestFEJacobian(dm, &user)); 8779566063dSJacob Faibussowitsch if (user.testFVgrad) PetscCall(TestFVGrad(dm, &user)); 8789566063dSJacob Faibussowitsch if (user.testInjector) PetscCall(TestInjector(dm, &user)); 8799566063dSJacob Faibussowitsch PetscCall(CheckFunctions(dm, user.porder, &user)); 880c4762a1bSJed Brown { 881c4762a1bSJed Brown PetscDualSpace dsp; 882c4762a1bSJed Brown PetscInt k; 883c4762a1bSJed Brown 8849566063dSJacob Faibussowitsch PetscCall(PetscFEGetDualSpace(user.fe, &dsp)); 8859566063dSJacob Faibussowitsch PetscCall(PetscDualSpaceGetDeRahm(dsp, &k)); 88630602db0SMatthew G. Knepley if (dim == 2 && simplex == PETSC_TRUE && user.tree == PETSC_FALSE && k == 0) { 8879566063dSJacob Faibussowitsch PetscCall(CheckInterpolation(dm, PETSC_FALSE, user.porder, &user)); 8889566063dSJacob Faibussowitsch PetscCall(CheckInterpolation(dm, PETSC_TRUE, user.porder, &user)); 889c4762a1bSJed Brown } 890c4762a1bSJed Brown } 8919566063dSJacob Faibussowitsch PetscCall(CheckConvergence(dm, 3, &user)); 8929566063dSJacob Faibussowitsch PetscCall(PetscFEDestroy(&user.fe)); 8939566063dSJacob Faibussowitsch PetscCall(DMDestroy(&dm)); 8949566063dSJacob Faibussowitsch PetscCall(PetscFinalize()); 895b122ec5aSJacob Faibussowitsch return 0; 896c4762a1bSJed Brown } 897c4762a1bSJed Brown 898c4762a1bSJed Brown /*TEST 899c4762a1bSJed Brown 900c4762a1bSJed Brown test: 901c4762a1bSJed Brown suffix: 1 902c4762a1bSJed Brown requires: triangle 903c4762a1bSJed Brown 904c4762a1bSJed Brown # 2D P_1 on a triangle 905c4762a1bSJed Brown test: 906c4762a1bSJed Brown suffix: p1_2d_0 907c4762a1bSJed Brown requires: triangle 908c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -convergence 909c4762a1bSJed Brown test: 910c4762a1bSJed Brown suffix: p1_2d_1 911c4762a1bSJed Brown requires: triangle 912c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -porder 1 913c4762a1bSJed Brown test: 914c4762a1bSJed Brown suffix: p1_2d_2 915c4762a1bSJed Brown requires: triangle 916c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -porder 2 917c4762a1bSJed Brown test: 918c4762a1bSJed Brown suffix: p1_2d_3 919e788613bSJoe Wallwork requires: triangle mmg 920c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -convergence -conv_refine 0 921c4762a1bSJed Brown test: 922c4762a1bSJed Brown suffix: p1_2d_4 923e788613bSJoe Wallwork requires: triangle mmg 924c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 1 -conv_refine 0 925c4762a1bSJed Brown test: 926c4762a1bSJed Brown suffix: p1_2d_5 927e788613bSJoe Wallwork requires: triangle mmg 928c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 2 -conv_refine 0 929c4762a1bSJed Brown 930c4762a1bSJed Brown # 3D P_1 on a tetrahedron 931c4762a1bSJed Brown test: 932c4762a1bSJed Brown suffix: p1_3d_0 933c4762a1bSJed Brown requires: ctetgen 93430602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -convergence 935c4762a1bSJed Brown test: 936c4762a1bSJed Brown suffix: p1_3d_1 937c4762a1bSJed Brown requires: ctetgen 93830602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -porder 1 939c4762a1bSJed Brown test: 940c4762a1bSJed Brown suffix: p1_3d_2 941c4762a1bSJed Brown requires: ctetgen 94230602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -porder 2 943c4762a1bSJed Brown test: 944c4762a1bSJed Brown suffix: p1_3d_3 945e788613bSJoe Wallwork requires: ctetgen mmg 94630602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -convergence -conv_refine 0 947c4762a1bSJed Brown test: 948c4762a1bSJed Brown suffix: p1_3d_4 949e788613bSJoe Wallwork requires: ctetgen mmg 95030602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 1 -conv_refine 0 951c4762a1bSJed Brown test: 952c4762a1bSJed Brown suffix: p1_3d_5 953e788613bSJoe Wallwork requires: ctetgen mmg 95430602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 2 -conv_refine 0 955c4762a1bSJed Brown 956c4762a1bSJed Brown # 2D P_2 on a triangle 957c4762a1bSJed Brown test: 958c4762a1bSJed Brown suffix: p2_2d_0 959c4762a1bSJed Brown requires: triangle 960c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -convergence 961c4762a1bSJed Brown test: 962c4762a1bSJed Brown suffix: p2_2d_1 963c4762a1bSJed Brown requires: triangle 964c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -porder 1 965c4762a1bSJed Brown test: 966c4762a1bSJed Brown suffix: p2_2d_2 967c4762a1bSJed Brown requires: triangle 968c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -porder 2 969c4762a1bSJed Brown test: 970c4762a1bSJed Brown suffix: p2_2d_3 971e788613bSJoe Wallwork requires: triangle mmg 972c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -convergence -conv_refine 0 973c4762a1bSJed Brown test: 974c4762a1bSJed Brown suffix: p2_2d_4 975e788613bSJoe Wallwork requires: triangle mmg 976c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -porder 1 -conv_refine 0 977c4762a1bSJed Brown test: 978c4762a1bSJed Brown suffix: p2_2d_5 979e788613bSJoe Wallwork requires: triangle mmg 980c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -porder 2 -conv_refine 0 981c4762a1bSJed Brown 982c4762a1bSJed Brown # 3D P_2 on a tetrahedron 983c4762a1bSJed Brown test: 984c4762a1bSJed Brown suffix: p2_3d_0 985c4762a1bSJed Brown requires: ctetgen 98630602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -convergence 987c4762a1bSJed Brown test: 988c4762a1bSJed Brown suffix: p2_3d_1 989c4762a1bSJed Brown requires: ctetgen 99030602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -porder 1 991c4762a1bSJed Brown test: 992c4762a1bSJed Brown suffix: p2_3d_2 993c4762a1bSJed Brown requires: ctetgen 99430602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -porder 2 995c4762a1bSJed Brown test: 996c4762a1bSJed Brown suffix: p2_3d_3 997e788613bSJoe Wallwork requires: ctetgen mmg 99830602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -convergence -conv_refine 0 999c4762a1bSJed Brown test: 1000c4762a1bSJed Brown suffix: p2_3d_4 1001e788613bSJoe Wallwork requires: ctetgen mmg 100230602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -porder 1 -conv_refine 0 1003c4762a1bSJed Brown test: 1004c4762a1bSJed Brown suffix: p2_3d_5 1005e788613bSJoe Wallwork requires: ctetgen mmg 100630602db0SMatthew G. Knepley args: -dm_plex_dim 3 -petscspace_degree 2 -qorder 2 -dm_plex_hash_location -porder 2 -conv_refine 0 1007c4762a1bSJed Brown 1008c4762a1bSJed Brown # 2D Q_1 on a quadrilaterial DA 1009c4762a1bSJed Brown test: 1010c4762a1bSJed Brown suffix: q1_2d_da_0 101199a192c5SJunchao Zhang requires: broken 101230602db0SMatthew G. Knepley args: -use_da 1 -petscspace_degree 1 -qorder 1 -convergence 1013c4762a1bSJed Brown test: 1014c4762a1bSJed Brown suffix: q1_2d_da_1 101599a192c5SJunchao Zhang requires: broken 101630602db0SMatthew G. Knepley args: -use_da 1 -petscspace_degree 1 -qorder 1 -porder 1 1017c4762a1bSJed Brown test: 1018c4762a1bSJed Brown suffix: q1_2d_da_2 101999a192c5SJunchao Zhang requires: broken 102030602db0SMatthew G. Knepley args: -use_da 1 -petscspace_degree 1 -qorder 1 -porder 2 1021c4762a1bSJed Brown 1022c4762a1bSJed Brown # 2D Q_1 on a quadrilaterial Plex 1023c4762a1bSJed Brown test: 1024c4762a1bSJed Brown suffix: q1_2d_plex_0 102530602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 1 -convergence 1026c4762a1bSJed Brown test: 1027c4762a1bSJed Brown suffix: q1_2d_plex_1 102830602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 1 -porder 1 1029c4762a1bSJed Brown test: 1030c4762a1bSJed Brown suffix: q1_2d_plex_2 103130602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 1 -porder 2 1032c4762a1bSJed Brown test: 1033c4762a1bSJed Brown suffix: q1_2d_plex_3 103430602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 1 -porder 1 -shear_coords 1035c4762a1bSJed Brown test: 1036c4762a1bSJed Brown suffix: q1_2d_plex_4 103730602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 1 -porder 2 -shear_coords 1038c4762a1bSJed Brown test: 1039c4762a1bSJed Brown suffix: q1_2d_plex_5 104030602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscspace_type tensor -qorder 1 -porder 0 -non_affine_coords -convergence 1041c4762a1bSJed Brown test: 1042c4762a1bSJed Brown suffix: q1_2d_plex_6 104330602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscspace_type tensor -qorder 1 -porder 1 -non_affine_coords -convergence 1044c4762a1bSJed Brown test: 1045c4762a1bSJed Brown suffix: q1_2d_plex_7 104630602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscspace_type tensor -qorder 1 -porder 2 -non_affine_coords -convergence 1047c4762a1bSJed Brown 1048c4762a1bSJed Brown # 2D Q_2 on a quadrilaterial 1049c4762a1bSJed Brown test: 1050c4762a1bSJed Brown suffix: q2_2d_plex_0 105130602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -convergence 1052c4762a1bSJed Brown test: 1053c4762a1bSJed Brown suffix: q2_2d_plex_1 105430602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 1 1055c4762a1bSJed Brown test: 1056c4762a1bSJed Brown suffix: q2_2d_plex_2 105730602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 2 1058c4762a1bSJed Brown test: 1059c4762a1bSJed Brown suffix: q2_2d_plex_3 106030602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 1 -shear_coords 1061c4762a1bSJed Brown test: 1062c4762a1bSJed Brown suffix: q2_2d_plex_4 106330602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 2 -shear_coords 1064c4762a1bSJed Brown test: 1065c4762a1bSJed Brown suffix: q2_2d_plex_5 106630602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_type tensor -qorder 2 -porder 0 -non_affine_coords -convergence 1067c4762a1bSJed Brown test: 1068c4762a1bSJed Brown suffix: q2_2d_plex_6 106930602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_type tensor -qorder 2 -porder 1 -non_affine_coords -convergence 1070c4762a1bSJed Brown test: 1071c4762a1bSJed Brown suffix: q2_2d_plex_7 107230602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_type tensor -qorder 2 -porder 2 -non_affine_coords -convergence 1073c4762a1bSJed Brown 1074c4762a1bSJed Brown # 2D P_3 on a triangle 1075c4762a1bSJed Brown test: 1076c4762a1bSJed Brown suffix: p3_2d_0 1077c4762a1bSJed Brown requires: triangle !single 1078c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -convergence 1079c4762a1bSJed Brown test: 1080c4762a1bSJed Brown suffix: p3_2d_1 1081c4762a1bSJed Brown requires: triangle !single 1082c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -porder 1 1083c4762a1bSJed Brown test: 1084c4762a1bSJed Brown suffix: p3_2d_2 1085c4762a1bSJed Brown requires: triangle !single 1086c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -porder 2 1087c4762a1bSJed Brown test: 1088c4762a1bSJed Brown suffix: p3_2d_3 1089c4762a1bSJed Brown requires: triangle !single 1090c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -porder 3 1091c4762a1bSJed Brown test: 1092c4762a1bSJed Brown suffix: p3_2d_4 1093e788613bSJoe Wallwork requires: triangle mmg 1094c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -dm_plex_hash_location -convergence -conv_refine 0 1095c4762a1bSJed Brown test: 1096c4762a1bSJed Brown suffix: p3_2d_5 1097e788613bSJoe Wallwork requires: triangle mmg 1098c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -dm_plex_hash_location -porder 1 -conv_refine 0 1099c4762a1bSJed Brown test: 1100c4762a1bSJed Brown suffix: p3_2d_6 1101e788613bSJoe Wallwork requires: triangle mmg 1102c4762a1bSJed Brown args: -petscspace_degree 3 -qorder 3 -dm_plex_hash_location -porder 3 -conv_refine 0 1103c4762a1bSJed Brown 1104c4762a1bSJed Brown # 2D Q_3 on a quadrilaterial 1105c4762a1bSJed Brown test: 1106c4762a1bSJed Brown suffix: q3_2d_0 110799a192c5SJunchao Zhang requires: !single 110830602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 3 -qorder 3 -convergence 1109c4762a1bSJed Brown test: 1110c4762a1bSJed Brown suffix: q3_2d_1 111199a192c5SJunchao Zhang requires: !single 111230602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 3 -qorder 3 -porder 1 1113c4762a1bSJed Brown test: 1114c4762a1bSJed Brown suffix: q3_2d_2 111599a192c5SJunchao Zhang requires: !single 111630602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 3 -qorder 3 -porder 2 1117c4762a1bSJed Brown test: 1118c4762a1bSJed Brown suffix: q3_2d_3 111999a192c5SJunchao Zhang requires: !single 112030602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 3 -qorder 3 -porder 3 1121c4762a1bSJed Brown 1122c4762a1bSJed Brown # 2D P_1disc on a triangle/quadrilateral 1123c4762a1bSJed Brown test: 1124c4762a1bSJed Brown suffix: p1d_2d_0 1125c4762a1bSJed Brown requires: triangle 1126c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -convergence 1127c4762a1bSJed Brown test: 1128c4762a1bSJed Brown suffix: p1d_2d_1 1129c4762a1bSJed Brown requires: triangle 1130c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -porder 1 1131c4762a1bSJed Brown test: 1132c4762a1bSJed Brown suffix: p1d_2d_2 1133c4762a1bSJed Brown requires: triangle 1134c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -porder 2 1135c4762a1bSJed Brown test: 1136c4762a1bSJed Brown suffix: p1d_2d_3 1137c4762a1bSJed Brown requires: triangle 113830602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -convergence 1139c4762a1bSJed Brown filter: sed -e "s/convergence rate at refinement 0: 2/convergence rate at refinement 0: 1.9/g" 1140c4762a1bSJed Brown test: 1141c4762a1bSJed Brown suffix: p1d_2d_4 1142c4762a1bSJed Brown requires: triangle 114330602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -porder 1 1144c4762a1bSJed Brown test: 1145c4762a1bSJed Brown suffix: p1d_2d_5 1146c4762a1bSJed Brown requires: triangle 114730602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -petscdualspace_lagrange_continuity 0 -qorder 1 -porder 2 1148c4762a1bSJed Brown 1149c4762a1bSJed Brown # 2D BDM_1 on a triangle 1150c4762a1bSJed Brown test: 1151c4762a1bSJed Brown suffix: bdm1_2d_0 1152c4762a1bSJed Brown requires: triangle 1153c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 1154c4762a1bSJed Brown -num_comp 2 -qorder 1 -convergence 1155c4762a1bSJed Brown test: 1156c4762a1bSJed Brown suffix: bdm1_2d_1 1157c4762a1bSJed Brown requires: triangle 1158c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 1159c4762a1bSJed Brown -num_comp 2 -qorder 1 -porder 1 1160c4762a1bSJed Brown test: 1161c4762a1bSJed Brown suffix: bdm1_2d_2 1162c4762a1bSJed Brown requires: triangle 1163c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 1164c4762a1bSJed Brown -num_comp 2 -qorder 1 -porder 2 1165c4762a1bSJed Brown 1166c4762a1bSJed Brown # 2D BDM_1 on a quadrilateral 1167c4762a1bSJed Brown test: 1168c4762a1bSJed Brown suffix: bdm1q_2d_0 1169c4762a1bSJed Brown requires: triangle 1170c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 11713f27d899SToby Isaac -petscdualspace_lagrange_tensor 1 \ 117230602db0SMatthew G. Knepley -dm_plex_simplex 0 -num_comp 2 -qorder 1 -convergence 1173c4762a1bSJed Brown test: 1174c4762a1bSJed Brown suffix: bdm1q_2d_1 1175c4762a1bSJed Brown requires: triangle 1176c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 11773f27d899SToby Isaac -petscdualspace_lagrange_tensor 1 \ 117830602db0SMatthew G. Knepley -dm_plex_simplex 0 -num_comp 2 -qorder 1 -porder 1 1179c4762a1bSJed Brown test: 1180c4762a1bSJed Brown suffix: bdm1q_2d_2 1181c4762a1bSJed Brown requires: triangle 1182c4762a1bSJed Brown args: -petscspace_degree 1 -petscdualspace_type bdm \ 11833f27d899SToby Isaac -petscdualspace_lagrange_tensor 1 \ 118430602db0SMatthew G. Knepley -dm_plex_simplex 0 -num_comp 2 -qorder 1 -porder 2 1185c4762a1bSJed Brown 1186c4762a1bSJed Brown # Test high order quadrature 1187c4762a1bSJed Brown test: 1188c4762a1bSJed Brown suffix: p1_quad_2 1189c4762a1bSJed Brown requires: triangle 1190c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 2 -porder 1 1191c4762a1bSJed Brown test: 1192c4762a1bSJed Brown suffix: p1_quad_5 1193c4762a1bSJed Brown requires: triangle 1194c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 5 -porder 1 1195c4762a1bSJed Brown test: 1196c4762a1bSJed Brown suffix: p2_quad_3 1197c4762a1bSJed Brown requires: triangle 1198c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 3 -porder 2 1199c4762a1bSJed Brown test: 1200c4762a1bSJed Brown suffix: p2_quad_5 1201c4762a1bSJed Brown requires: triangle 1202c4762a1bSJed Brown args: -petscspace_degree 2 -qorder 5 -porder 2 1203c4762a1bSJed Brown test: 1204c4762a1bSJed Brown suffix: q1_quad_2 120530602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 2 -porder 1 1206c4762a1bSJed Brown test: 1207c4762a1bSJed Brown suffix: q1_quad_5 120830602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 1 -qorder 5 -porder 1 1209c4762a1bSJed Brown test: 1210c4762a1bSJed Brown suffix: q2_quad_3 121130602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 3 -porder 1 1212c4762a1bSJed Brown test: 1213c4762a1bSJed Brown suffix: q2_quad_5 121430602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 5 -porder 1 1215c4762a1bSJed Brown 1216c4762a1bSJed Brown # Nonconforming tests 1217c4762a1bSJed Brown test: 1218c4762a1bSJed Brown suffix: constraints 121930602db0SMatthew G. Knepley args: -dm_coord_space 0 -dm_plex_simplex 0 -petscspace_type tensor -petscspace_degree 1 -qorder 0 -constraints 1220c4762a1bSJed Brown test: 1221c4762a1bSJed Brown suffix: nonconforming_tensor_2 1222c4762a1bSJed Brown nsize: 4 122330602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -test_injector -petscpartitioner_type simple -tree -dm_plex_simplex 0 -dm_plex_max_projection_height 1 -petscspace_type tensor -petscspace_degree 2 -qorder 2 -dm_view ascii::ASCII_INFO_DETAIL 1224c4762a1bSJed Brown test: 1225c4762a1bSJed Brown suffix: nonconforming_tensor_3 1226c4762a1bSJed Brown nsize: 4 122730602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -petscpartitioner_type simple -tree -dm_plex_simplex 0 -dm_plex_dim 3 -dm_plex_box_faces 2,2,2 -dm_plex_max_projection_height 2 -petscspace_type tensor -petscspace_degree 1 -qorder 1 -dm_view ascii::ASCII_INFO_DETAIL 1228c4762a1bSJed Brown test: 1229c4762a1bSJed Brown suffix: nonconforming_tensor_2_fv 1230c4762a1bSJed Brown nsize: 4 123130602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fv_grad -test_injector -petsclimiter_type none -petscpartitioner_type simple -tree -dm_plex_simplex 0 -num_comp 2 1232c4762a1bSJed Brown test: 1233c4762a1bSJed Brown suffix: nonconforming_tensor_3_fv 1234c4762a1bSJed Brown nsize: 4 123530602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fv_grad -test_injector -petsclimiter_type none -petscpartitioner_type simple -tree -dm_plex_simplex 0 -dm_plex_dim 3 -dm_plex_box_faces 2,2,2 -num_comp 3 1236c4762a1bSJed Brown test: 1237c4762a1bSJed Brown suffix: nonconforming_tensor_2_hi 1238c4762a1bSJed Brown requires: !single 1239c4762a1bSJed Brown nsize: 4 124030602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -petscpartitioner_type simple -tree -dm_plex_simplex 0 -dm_plex_max_projection_height 1 -petscspace_type tensor -petscspace_degree 4 -qorder 4 1241c4762a1bSJed Brown test: 1242c4762a1bSJed Brown suffix: nonconforming_tensor_3_hi 1243c4762a1bSJed Brown requires: !single skip 1244c4762a1bSJed Brown nsize: 4 124530602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -petscpartitioner_type simple -tree -dm_plex_simplex 0 -dm_plex_dim 3 -dm_plex_box_faces 2,2,2 -dm_plex_max_projection_height 2 -petscspace_type tensor -petscspace_degree 4 -qorder 4 1246c4762a1bSJed Brown test: 1247c4762a1bSJed Brown suffix: nonconforming_simplex_2 1248c4762a1bSJed Brown requires: triangle 1249c4762a1bSJed Brown nsize: 4 125030602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -test_injector -petscpartitioner_type simple -tree -dm_plex_max_projection_height 1 -petscspace_degree 2 -qorder 2 -dm_view ascii::ASCII_INFO_DETAIL 1251c4762a1bSJed Brown test: 1252c4762a1bSJed Brown suffix: nonconforming_simplex_2_hi 1253c4762a1bSJed Brown requires: triangle !single 1254c4762a1bSJed Brown nsize: 4 125530602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -petscpartitioner_type simple -tree -dm_plex_max_projection_height 1 -petscspace_degree 4 -qorder 4 1256c4762a1bSJed Brown test: 1257c4762a1bSJed Brown suffix: nonconforming_simplex_2_fv 1258c4762a1bSJed Brown requires: triangle 1259c4762a1bSJed Brown nsize: 4 126030602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fv_grad -test_injector -petsclimiter_type none -petscpartitioner_type simple -tree -num_comp 2 1261c4762a1bSJed Brown test: 1262c4762a1bSJed Brown suffix: nonconforming_simplex_3 1263c4762a1bSJed Brown requires: ctetgen 1264c4762a1bSJed Brown nsize: 4 126530602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -test_injector -petscpartitioner_type simple -tree -dm_plex_dim 3 -dm_plex_max_projection_height 2 -petscspace_degree 2 -qorder 2 -dm_view ascii::ASCII_INFO_DETAIL 1266c4762a1bSJed Brown test: 1267c4762a1bSJed Brown suffix: nonconforming_simplex_3_hi 1268c4762a1bSJed Brown requires: ctetgen skip 1269c4762a1bSJed Brown nsize: 4 127030602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fe_jacobian -petscpartitioner_type simple -tree -dm_plex_dim 3 -dm_plex_max_projection_height 2 -petscspace_degree 4 -qorder 4 1271c4762a1bSJed Brown test: 1272c4762a1bSJed Brown suffix: nonconforming_simplex_3_fv 1273c4762a1bSJed Brown requires: ctetgen 1274c4762a1bSJed Brown nsize: 4 127530602db0SMatthew G. Knepley args: -dist_dm_distribute -test_fv_grad -test_injector -petsclimiter_type none -petscpartitioner_type simple -tree -dm_plex_dim 3 -num_comp 3 1276c4762a1bSJed Brown 1277d21efd2eSMatthew G. Knepley # 3D WXY on a triangular prism 1278d21efd2eSMatthew G. Knepley test: 1279d21efd2eSMatthew G. Knepley suffix: wxy_0 1280d21efd2eSMatthew G. Knepley args: -dm_plex_reference_cell_domain -dm_plex_cell triangular_prism -qorder 2 -porder 0 \ 1281e239af90SMatthew G. Knepley -petscspace_type sum \ 1282e239af90SMatthew G. Knepley -petscspace_variables 3 \ 1283e239af90SMatthew G. Knepley -petscspace_components 3 \ 1284e239af90SMatthew G. Knepley -petscspace_sum_spaces 2 \ 1285e239af90SMatthew G. Knepley -petscspace_sum_concatenate false \ 1286e239af90SMatthew G. Knepley -sumcomp_0_petscspace_variables 3 \ 1287e239af90SMatthew G. Knepley -sumcomp_0_petscspace_components 3 \ 1288e239af90SMatthew G. Knepley -sumcomp_0_petscspace_degree 1 \ 1289e239af90SMatthew G. Knepley -sumcomp_1_petscspace_variables 3 \ 1290e239af90SMatthew G. Knepley -sumcomp_1_petscspace_components 3 \ 1291e239af90SMatthew G. Knepley -sumcomp_1_petscspace_type wxy \ 1292e239af90SMatthew G. Knepley -petscdualspace_refcell triangular_prism \ 1293e239af90SMatthew G. Knepley -petscdualspace_form_degree 0 \ 1294e239af90SMatthew G. Knepley -petscdualspace_order 1 \ 1295e239af90SMatthew G. Knepley -petscdualspace_components 3 1296d21efd2eSMatthew G. Knepley 1297c4762a1bSJed Brown TEST*/ 1298c4762a1bSJed Brown 1299c4762a1bSJed Brown /* 1300c4762a1bSJed Brown # 2D Q_2 on a quadrilaterial Plex 1301c4762a1bSJed Brown test: 1302c4762a1bSJed Brown suffix: q2_2d_plex_0 130330602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -convergence 1304c4762a1bSJed Brown test: 1305c4762a1bSJed Brown suffix: q2_2d_plex_1 130630602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 1 1307c4762a1bSJed Brown test: 1308c4762a1bSJed Brown suffix: q2_2d_plex_2 130930602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 2 1310c4762a1bSJed Brown test: 1311c4762a1bSJed Brown suffix: q2_2d_plex_3 131230602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 1 -shear_coords 1313c4762a1bSJed Brown test: 1314c4762a1bSJed Brown suffix: q2_2d_plex_4 131530602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -qorder 2 -porder 2 -shear_coords 1316c4762a1bSJed Brown test: 1317c4762a1bSJed Brown suffix: q2_2d_plex_5 131830602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_poly_tensor 1 -qorder 2 -porder 0 -non_affine_coords 1319c4762a1bSJed Brown test: 1320c4762a1bSJed Brown suffix: q2_2d_plex_6 132130602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_poly_tensor 1 -qorder 2 -porder 1 -non_affine_coords 1322c4762a1bSJed Brown test: 1323c4762a1bSJed Brown suffix: q2_2d_plex_7 132430602db0SMatthew G. Knepley args: -dm_plex_simplex 0 -petscspace_degree 2 -petscspace_poly_tensor 1 -qorder 2 -porder 2 -non_affine_coords 1325c4762a1bSJed Brown 1326c4762a1bSJed Brown test: 1327c4762a1bSJed Brown suffix: p1d_2d_6 1328e788613bSJoe Wallwork requires: mmg 1329c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -convergence -conv_refine 0 1330c4762a1bSJed Brown test: 1331c4762a1bSJed Brown suffix: p1d_2d_7 1332e788613bSJoe Wallwork requires: mmg 1333c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 1 -conv_refine 0 1334c4762a1bSJed Brown test: 1335c4762a1bSJed Brown suffix: p1d_2d_8 1336e788613bSJoe Wallwork requires: mmg 1337c4762a1bSJed Brown args: -petscspace_degree 1 -qorder 1 -dm_plex_hash_location -porder 2 -conv_refine 0 1338c4762a1bSJed Brown */ 1339