static char help[] = "Define a simple field over the mesh\n\n"; #include int main(int argc, char **argv) { DM dm, dmDist = NULL; PetscInt N = 2, dim = 3; PetscInt size, myrank; PetscInt c, cStart, cEnd; Vec coordinates; PetscSection coordSection; PetscScalar *coords; PetscErrorCode ierr; const PetscInt faces[3] = {N,N,N }; const PetscReal lower[3] = {0.0,0.0,0.0}; const PetscReal upper[3] = {1.0,1.0,1.0}; ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr; ierr = DMPlexCreateBoxMesh(PETSC_COMM_WORLD,dim,PETSC_FALSE,faces,lower,upper, NULL,PETSC_TRUE,&dm); CHKERRQ(ierr); ierr = DMSetUseNatural(dm,PETSC_TRUE); CHKERRQ(ierr); ierr = DMPlexDistribute(dm, 1, NULL, &dmDist);CHKERRQ(ierr); if (dmDist) {ierr = DMDestroy(&dm);CHKERRQ(ierr); dm = dmDist;} ierr = DMSetFromOptions(dm); CHKERRQ(ierr); PetscSection sec; PetscInt pStart, pEnd; // Define 1 DOF on cell center of the mesh ierr = PetscSectionCreate(PETSC_COMM_WORLD, &sec); ierr = PetscSectionSetNumFields(sec,1); ierr = PetscSectionSetFieldName(sec,0,"p"); ierr = PetscSectionSetFieldComponents(sec,0,1); ierr = DMPlexGetChart(dm,&pStart,&pEnd); ierr = PetscSectionSetChart(sec,pStart,pEnd); ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd); CHKERRQ(ierr); for (PetscInt c=cStart; c=0)); } } MPI_Barrier(PETSC_COMM_WORLD); } ierr = VecRestoreArray(coordinates,&coords); CHKERRQ(ierr); ierr = VecRestoreArray(Gvec, &g); CHKERRQ(ierr); ierr = DMDestroy(&dm);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }