1 static char help[] = "Test section ordering for FEM discretizations\n\n"; 2 3 #include <petscdmplex.h> 4 #include <petscds.h> 5 6 static PetscErrorCode CreateMesh(MPI_Comm comm, DM *dm) 7 { 8 PetscFunctionBegin; 9 PetscCall(DMCreate(comm, dm)); 10 PetscCall(DMSetType(*dm, DMPLEX)); 11 PetscCall(DMSetFromOptions(*dm)); 12 PetscCall(DMViewFromOptions(*dm, NULL, "-dm_view")); 13 PetscFunctionReturn(0); 14 } 15 16 static PetscErrorCode TestLocalDofOrder(DM dm) 17 { 18 PetscFE fe[3]; 19 PetscSection s; 20 PetscBool simplex; 21 PetscInt dim, Nf, f; 22 23 PetscFunctionBegin; 24 PetscCall(DMGetDimension(dm, &dim)); 25 PetscCall(DMPlexIsSimplex(dm, &simplex)); 26 PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, dim, simplex, "field0_", -1, &fe[0])); 27 PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, 1, simplex, "field1_", -1, &fe[1])); 28 PetscCall(PetscFECreateDefault(PETSC_COMM_SELF, dim, 1, simplex, "field2_", -1, &fe[2])); 29 30 PetscCall(DMSetField(dm, 0, NULL, (PetscObject) fe[0])); 31 PetscCall(DMSetField(dm, 1, NULL, (PetscObject) fe[1])); 32 PetscCall(DMSetField(dm, 2, NULL, (PetscObject) fe[2])); 33 PetscCall(DMCreateDS(dm)); 34 PetscCall(DMGetLocalSection(dm, &s)); 35 PetscCall(PetscObjectViewFromOptions((PetscObject) s, NULL, "-dof_view")); 36 37 PetscCall(DMGetNumFields(dm, &Nf)); 38 for (f = 0; f < Nf; ++f) PetscCall(PetscFEDestroy(&fe[f])); 39 PetscFunctionReturn(0); 40 } 41 42 int main(int argc, char **argv) 43 { 44 DM dm; 45 46 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 47 PetscCall(CreateMesh(PETSC_COMM_WORLD, &dm)); 48 PetscCall(TestLocalDofOrder(dm)); 49 PetscCall(DMDestroy(&dm)); 50 PetscCall(PetscFinalize()); 51 return 0; 52 } 53 54 /*TEST 55 56 test: 57 suffix: tri_pm 58 requires: triangle 59 args: -dm_plex_box_faces 1,1 -field0_petscspace_degree 2 -field1_petscspace_degree 1 -field2_petscspace_degree 1 -dm_view -dof_view 60 61 test: 62 suffix: quad_pm 63 requires: 64 args: -dm_plex_simplex 0 -dm_plex_box_faces 1,1 -field0_petscspace_degree 2 -field1_petscspace_degree 1 -field2_petscspace_degree 1 -dm_view -dof_view 65 66 test: 67 suffix: tri_fm 68 requires: triangle 69 args: -dm_coord_space 0 -dm_plex_box_faces 1,1 -field0_petscspace_degree 2 -field1_petscspace_degree 1 -field2_petscspace_degree 1 -petscsection_point_major 0 -dm_view -dof_view 70 71 test: 72 suffix: quad_fm 73 requires: 74 args: -dm_coord_space 0 -dm_plex_simplex 0 -dm_plex_box_faces 1,1 -field0_petscspace_degree 2 -field1_petscspace_degree 1 -field2_petscspace_degree 1 -petscsection_point_major 0 -dm_view -dof_view 75 76 TEST*/ 77