1c4762a1bSJed Brown static char help[] = "Tests for point location\n\n"; 2c4762a1bSJed Brown 3c4762a1bSJed Brown #include <petscsf.h> 4c4762a1bSJed Brown #include <petscdmplex.h> 5c4762a1bSJed Brown 630602db0SMatthew G. Knepley static PetscErrorCode CreateMesh(MPI_Comm comm, DM *dm) 7c4762a1bSJed Brown { 8c4762a1bSJed Brown PetscErrorCode ierr; 9c4762a1bSJed Brown 10c4762a1bSJed Brown PetscFunctionBeginUser; 1130602db0SMatthew G. Knepley ierr = DMCreate(comm, dm);CHKERRQ(ierr); 1230602db0SMatthew G. Knepley ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr); 1330602db0SMatthew G. Knepley ierr = DMSetFromOptions(*dm);CHKERRQ(ierr); 14c4762a1bSJed Brown ierr = DMViewFromOptions(*dm, NULL, "-dm_view");CHKERRQ(ierr); 15c4762a1bSJed Brown PetscFunctionReturn(0); 16c4762a1bSJed Brown } 17c4762a1bSJed Brown 1830602db0SMatthew G. Knepley static PetscErrorCode TestLocation(DM dm) 19c4762a1bSJed Brown { 203285882aSMatthew G. Knepley Vec points; 213285882aSMatthew G. Knepley PetscSF cellSF = NULL; 223285882aSMatthew G. Knepley const PetscSFNode *cells; 233285882aSMatthew G. Knepley PetscScalar *a; 243285882aSMatthew G. Knepley PetscInt cdim, n; 25c4762a1bSJed Brown PetscInt cStart, cEnd, c; 26c4762a1bSJed Brown PetscErrorCode ierr; 27c4762a1bSJed Brown 28c4762a1bSJed Brown PetscFunctionBeginUser; 293285882aSMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &cdim);CHKERRQ(ierr); 30c4762a1bSJed Brown ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); 31c4762a1bSJed Brown /* Locate all centroids */ 323285882aSMatthew G. Knepley ierr = VecCreateSeq(PETSC_COMM_SELF, (cEnd - cStart)*cdim, &points);CHKERRQ(ierr); 333285882aSMatthew G. Knepley ierr = VecSetBlockSize(points, cdim);CHKERRQ(ierr); 343285882aSMatthew G. Knepley ierr = VecGetArray(points, &a);CHKERRQ(ierr); 35c4762a1bSJed Brown for (c = cStart; c < cEnd; ++c) { 36c4762a1bSJed Brown PetscReal centroid[3]; 373285882aSMatthew G. Knepley PetscInt off = (c - cStart)*cdim, d; 38c4762a1bSJed Brown 39c4762a1bSJed Brown ierr = DMPlexComputeCellGeometryFVM(dm, c, NULL, centroid, NULL);CHKERRQ(ierr); 403285882aSMatthew G. Knepley for (d = 0; d < cdim; ++d) a[off+d] = centroid[d]; 41c4762a1bSJed Brown } 423285882aSMatthew G. Knepley ierr = VecRestoreArray(points, &a);CHKERRQ(ierr); 433285882aSMatthew G. Knepley ierr = DMLocatePoints(dm, points, DM_POINTLOCATION_NONE, &cellSF);CHKERRQ(ierr); 443285882aSMatthew G. Knepley ierr = VecDestroy(&points);CHKERRQ(ierr); 453285882aSMatthew G. Knepley ierr = PetscSFGetGraph(cellSF, NULL, &n, NULL, &cells);CHKERRQ(ierr); 463285882aSMatthew G. Knepley if (n != (cEnd - cStart)) { 473285882aSMatthew G. Knepley for (c = 0; c < n; ++c) { 483285882aSMatthew G. Knepley if (cells[c].index != c+cStart) {ierr = PetscPrintf(PETSC_COMM_SELF, "Could not locate centroid of cell %D, error %D\n", c+cStart, cells[c].index);CHKERRQ(ierr);} 493285882aSMatthew G. Knepley } 50*98921bdaSJacob Faibussowitsch SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Located %D points instead of %D", n, cEnd - cStart); 513285882aSMatthew G. Knepley } 523285882aSMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 53*98921bdaSJacob Faibussowitsch if (cells[c - cStart].index != c) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Could not locate centroid of cell %D, instead found %D", c, cells[c - cStart].index); 543285882aSMatthew G. Knepley } 553285882aSMatthew G. Knepley ierr = PetscSFDestroy(&cellSF);CHKERRQ(ierr); 56c4762a1bSJed Brown PetscFunctionReturn(0); 57c4762a1bSJed Brown } 58c4762a1bSJed Brown 59c4762a1bSJed Brown int main(int argc, char **argv) 60c4762a1bSJed Brown { 61c4762a1bSJed Brown DM dm; 62c4762a1bSJed Brown PetscErrorCode ierr; 63c4762a1bSJed Brown 64c4762a1bSJed Brown ierr = PetscInitialize(&argc, &argv, NULL, help);if (ierr) return ierr; 6530602db0SMatthew G. Knepley ierr = CreateMesh(PETSC_COMM_WORLD, &dm);CHKERRQ(ierr); 6630602db0SMatthew G. Knepley ierr = TestLocation(dm);CHKERRQ(ierr); 67c4762a1bSJed Brown ierr = DMDestroy(&dm);CHKERRQ(ierr); 68c4762a1bSJed Brown ierr = PetscFinalize(); 69c4762a1bSJed Brown return ierr; 70c4762a1bSJed Brown } 71c4762a1bSJed Brown 72c4762a1bSJed Brown /*TEST 73c4762a1bSJed Brown 74b26b5bf9SMatthew G. Knepley testset: 75b26b5bf9SMatthew G. Knepley args: -dm_plex_dim 1 -dm_plex_box_faces 10 76b26b5bf9SMatthew G. Knepley 77c4762a1bSJed Brown test: 781af33867SMatthew G. Knepley suffix: seg 79b26b5bf9SMatthew G. Knepley 80b26b5bf9SMatthew G. Knepley test: 81b26b5bf9SMatthew G. Knepley suffix: seg_hash 82b26b5bf9SMatthew G. Knepley args: -dm_refine 2 -dm_plex_hash_location 831af33867SMatthew G. Knepley 843285882aSMatthew G. Knepley testset: 853285882aSMatthew G. Knepley args: -dm_plex_box_faces 5,5 863285882aSMatthew G. Knepley 871af33867SMatthew G. Knepley test: 881af33867SMatthew G. Knepley suffix: tri 89c4762a1bSJed Brown requires: triangle 903285882aSMatthew G. Knepley 913285882aSMatthew G. Knepley test: 923285882aSMatthew G. Knepley suffix: tri_hash 933285882aSMatthew G. Knepley requires: triangle 943285882aSMatthew G. Knepley args: -dm_refine 2 -dm_plex_hash_location 951af33867SMatthew G. Knepley 961af33867SMatthew G. Knepley test: 971af33867SMatthew G. Knepley suffix: quad 983285882aSMatthew G. Knepley args: -dm_plex_simplex 0 993285882aSMatthew G. Knepley 1003285882aSMatthew G. Knepley test: 1013285882aSMatthew G. Knepley suffix: quad_hash 1023285882aSMatthew G. Knepley args: -dm_plex_simplex 0 -dm_refine 2 -dm_plex_hash_location 1033285882aSMatthew G. Knepley 1043285882aSMatthew G. Knepley testset: 1053285882aSMatthew G. Knepley args: -dm_plex_dim 3 -dm_plex_box_faces 3,3,3 1061af33867SMatthew G. Knepley 1071af33867SMatthew G. Knepley test: 1081af33867SMatthew G. Knepley suffix: tet 1091af33867SMatthew G. Knepley requires: ctetgen 1103285882aSMatthew G. Knepley 1113285882aSMatthew G. Knepley test: 1123285882aSMatthew G. Knepley suffix: tet_hash 1133285882aSMatthew G. Knepley requires: ctetgen 1143285882aSMatthew G. Knepley args: -dm_refine 1 -dm_plex_hash_location 1151af33867SMatthew G. Knepley 1161af33867SMatthew G. Knepley test: 1171af33867SMatthew G. Knepley suffix: hex 1183285882aSMatthew G. Knepley args: -dm_plex_simplex 0 1193285882aSMatthew G. Knepley 1203285882aSMatthew G. Knepley test: 1213285882aSMatthew G. Knepley suffix: hex_hash 1223285882aSMatthew G. Knepley args: -dm_plex_simplex 0 -dm_refine 1 -dm_plex_hash_location 123c4762a1bSJed Brown 124c4762a1bSJed Brown TEST*/ 125