program testDMView implicit none #include 'finclude/petsc.h90' DM :: dm DM :: auxDM PetscErrorCode :: ierr MPI_Comm :: comm PetscBool :: interpolate integer :: ic,tdim,numFields,numBC integer, pointer :: numComp(:),numDof(:) integer, pointer :: bcField(:) IS,pointer :: bcPointIS(:) PetscSection :: section Vec :: X character(len=10) :: fileName PetscViewer :: viewer ! Begin program call PetscInitialize(PETSC_NULL_CHARACTER, ierr) comm = PETSC_COMM_SELF tdim = 2 interpolate = PETSC_TRUE call DMPlexCreateBoxMesh(comm, tdim, interpolate, dm,ierr) ! Create a scalar field u, a vector field v, and a surface vector field w numFields = 1 allocate(numComp(numFields),numDof((tdim+1)*numFields)) numComp(1) = tdim numDof = 0 ! Let u be defined on cell numDof(0*(tdim+1)+tdim+1) = 1 ! Setup boundary conditions numBC = 0 ! Create a PetscSection with this data layout call DMPlexClone(dm,auxDM,ierr) call DMPlexCreateSection(auxdm, tdim, numFields, numComp, & numDof, numBC, bcField, bcPointIS, section,& ierr) CHKERRQ(ierr) ! Name the Field variables call PetscSectionSetFieldName(section, 0, "u", ierr) CHKERRQ(ierr) call PetscSectionView(section, PETSC_VIEWER_STDOUT_WORLD, ierr) CHKERRQ(ierr) ! Tell the DM to use this data layout call DMSetDefaultSection(auxdm, section, ierr) CHKERRQ(ierr) ! Cleanup call PetscSectionDestroy(section, ierr) CHKERRQ(ierr) fileName='Xview.vtu' call PetscObjectGetComm(auxdm, comm, ierr) call DMGetLocalVector(auxdm,X,ierr) call VecSet(X,1.0D0,ierr) call PetscViewerCreate(comm, viewer, ierr) call PetscViewerSetType(viewer,PETSCVIEWERVTK,ierr) call PetscViewerFileSetName(viewer,trim(fileName),ierr) call VecView(X,viewer,ierr) call PetscViewerDestroy(viewer,ierr) call DMRestoreLocalVector(auxdm,X,ierr) call PetscFinalize(ierr) end program testDMView