#include "petsc.h" int main(int argc, char * argv[]) { MPI_Comm comm; PetscReal lower[2] = { 0, 0 }; PetscReal upper[2] = { 1, 1 }; PetscInt faces[2] = { 1, 1 }; DMBoundaryType periodicity[2] = { DM_BOUNDARY_GHOSTED, DM_BOUNDARY_GHOSTED }; DM dm; PetscInt nc[1] = { 1 }; PetscInt n_dofs[3] = { 1, 0, 0 }; PetscSection s; Vec x; PetscViewer viewer; PetscInitialize(&argc, &argv, NULL, NULL); comm = PETSC_COMM_WORLD; DMPlexCreateBoxMesh(comm, 2, PETSC_FALSE, faces, lower, upper, periodicity, PETSC_TRUE, &dm); DMSetUp(dm); DMSetNumFields(dm, 1); DMPlexCreateSection(dm, NULL, nc, n_dofs, 0, NULL, NULL, NULL, NULL, &s); DMSetLocalSection(dm, s); DMCreateGlobalVector(dm, &x); VecSetValue(x, 0, 2, INSERT_VALUES); VecSetValue(x, 1, 3, INSERT_VALUES); VecSetValue(x, 2, 5, INSERT_VALUES); VecSetValue(x, 3, 8, INSERT_VALUES); PetscViewerCreate(comm, &viewer); PetscViewerSetType(viewer, PETSCVIEWEREXODUSII); PetscViewerFileSetMode(viewer, FILE_MODE_WRITE); PetscViewerFileSetName(viewer, "out.exo"); DMView(dm, viewer); VecView(x, viewer); PetscViewerDestroy(&viewer); PetscFinalize(); }