static char help[] ="Use DMDACreatePatchIS to extract a slice from a vector, Command line options :\n\ mx/my/mz - set the dimensions of the parent vector\n\ dim - set the dimensionality of the parent vector (2,3)\n\ sliceaxis - Integer describing the axis along which the sice will be selected (0-X, 1-Y, 2-Z)\n\ sliceid - set the location where the slice will be extraced from the parent vector\n"; /* This test checks the functionality of DMDACreatePatchIS when extracting a 2D vector from a 3D vector and 1D vector from a 2D vector. */ #include #include int main(int argc,char **argv) { PetscMPIInt rank, size; /* MPI rank and size */ PetscInt mx=4,my=4,mz=4; /* Dimensions of parent vector */ PetscInt sliceid=2; /* k (z) index to pick the slice */ PetscInt sliceaxis=2; /* Select axis along which the slice will be extracted */ PetscInt dim=3; /* Dimension of the parent vector */ PetscInt i,j,k; /* Iteration indices */ PetscInt ixs,iys,izs; /* Corner indices for 3D vector */ PetscInt ixm,iym,izm; /* Widths of parent vector */ PetscScalar ***vecdata3d; /* Pointer to access 3d parent vector */ PetscScalar **vecdata2d; /* Pointer to access 2d parent vector */ DM da; /* 2D/3D DMDA object */ Vec vec_full; /* Parent vector */ Vec vec_slice; /* Slice vector */ MatStencil lower, upper; /* Stencils to select slice */ IS selectis; /* IS to select slice and extract subvector */ PetscBool patchis_offproc = PETSC_FALSE; /* flag to DMDACreatePatchIS indicating that off-proc values are to be ignored */ PetscViewer hdf5_viewer; PetscErrorCode ierr; /* error checking */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Initialize program and set problem parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-mx", &mx, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-my", &my, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-mz", &mz, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-dim", &dim, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-sliceid", &sliceid, NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL, NULL, "-sliceaxis", &sliceaxis, NULL);CHKERRQ(ierr); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create DMDA object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ if (dim==3) { ierr = DMDACreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC, DM_BOUNDARY_PERIODIC, DMDA_STENCIL_STAR, mx, my, mz, PETSC_DECIDE, PETSC_DECIDE, 1, 1, 1, NULL, NULL, NULL, &da);CHKERRQ(ierr); ierr = DMSetFromOptions(da);CHKERRQ(ierr); ierr = DMSetUp(da);CHKERRQ(ierr); } else { ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, mx, my, PETSC_DECIDE, PETSC_DECIDE, 1, 1, NULL, NULL, &da);CHKERRQ(ierr); ierr = DMSetFromOptions(da);CHKERRQ(ierr); ierr = DMSetUp(da);CHKERRQ(ierr); } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create the parent vector - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ ierr = DMCreateGlobalVector(da, &vec_full);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) vec_full, "full_vector");CHKERRQ(ierr); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Populate the 3D vector - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ ierr = DMDAGetCorners(da, &ixs, &iys, &izs, &ixm, &iym, &izm);CHKERRQ(ierr); if (dim==3) { ierr = DMDAVecGetArray(da, vec_full, &vecdata3d);CHKERRQ(ierr); for (k=izs; k