Hi Matt,

To test the Segmentation Violation problem in my code, I modified the example ex1f90.F to reproduce the problem I have in my own code.

If use DMPlexCreateBoxMesh to generate the mesh, the code works fine. However, if I use DMPlexCreateGmshFromFile, using the same mesh exported from "DMPlexCreateBoxMesh", it gives Segmentation Violation error.

Did I miss something in the input mesh file? My first guess is the label "marker" used in the code, but I couldn't find any place to set this label.

Would you please let me know how to solve this problem. My code is done in a similar way as ex1f90, it reads mesh from external file or creates from cell list, distributes the mesh (these already work), and then creates sections and sets ndof to the nodes.

Thanks,

Danyang


On 18-02-20 10:07 AM, Danyang Su wrote:
On 18-02-20 09:52 AM, Matthew Knepley wrote:
On Tue, Feb 20, 2018 at 12:30 PM, Danyang Su <danyang...@gmail.com <mailto:danyang...@gmail.com>> wrote:

    Hi All,

    I tried to compile the DMPlexCreateSection code but got error
    information as shown below.

    Error: Symbol 'petsc_null_is' at (1) has no IMPLICIT type

    I tried to use PETSC_NULL_OBJECT instead of PETSC_NULL_IS, then
    the code can be compiled but run into Segmentation Violation
    error in DMPlexCreateSection.

From the webpage

http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMPLEX/DMPlexCreateSection.html

The F90 version is DMPlexCreateSectionF90. Doing this with F77 arrays would have been too painful.
Hi Matt,

Sorry, I still cannot compile the code if use DMPlexCreateSectionF90 instead of DMPlexCreateSection. Would you please tell me in more details?

undefined reference to `dmplexcreatesectionf90_'

then I #include <petsc/finclude/petscdmplex.h90>, but this throws more error during compilation.


    Included at /home/dsu/Soft/PETSc/petsc-3.7.5/include/petsc/finclude/petscdmplex.h90:6:
    Included at ../../solver/solver_ddmethod.F90:62:

          PETSCSECTION_HIDE section
          1
Error: Unclassifiable statement at (1)
/home/dsu/Soft/PETSc/petsc-3.7.5/include/petsc/finclude/ftn-custom/petscdmplex.h90:167.10:
    Included at /home/dsu/Soft/PETSc/petsc-3.7.5/include/petsc/finclude/petscdmplex.h90:6:
    Included at ../../solver/solver_ddmethod.F90:62:

          PETSCSECTION_HIDE section
          1
Error: Unclassifiable statement at (1)
/home/dsu/Soft/PETSc/petsc-3.7.5/include/petsc/finclude/ftn-custom/petscdmplex.h90:179.10:
    Included at /home/dsu/Soft/PETSc/petsc-3.7.5/include/petsc/finclude/petscdmplex.h90:6:
    Included at ../../solver/solver_ddmethod.F90:62:


  Thanks,

     Matt

    dmda_flow%da is distributed dm object that works fine.

    The fortran example I follow is
    
http://www.mcs.anl.gov/petsc/petsc-dev/src/dm/impls/plex/examples/tutorials/ex1f90.F90
    
<http://www.mcs.anl.gov/petsc/petsc-dev/src/dm/impls/plex/examples/tutorials/ex1f90.F90>.


    What parameters should I use if passing null to bcField, bcComps,
    bcPoints and perm.

    PetscErrorCode
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscErrorCode.html#PetscErrorCode>
  DMPlexCreateSection
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/DMPLEX/DMPlexCreateSection.html#DMPlexCreateSection>(DM
    <https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/DM/DM.html#DM> 
 dm,PetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  dim,PetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  numFields,constPetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  numComp[],constPetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  numDof[],PetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  numBC,constPetscInt
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/Vec/PetscInt.html#PetscInt>
  bcField[],
    constIS
    <https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/IS/IS.html#IS> 
 bcComps[], constIS
    <https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/IS/IS.html#IS> 
 bcPoints[],IS
    <https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/IS/IS.html#IS> 
 perm,PetscSection
    
<https://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/IS/PetscSection.html#PetscSection>
  *section)

    #include <petsc/finclude/petscis.h>
    #include <petsc/finclude/petscis.h90>
    #include <petsc/finclude/petscdmplex.h>

    ...

    #ifdef USG
            numFields = 1
            numComp(1) = 1
            pNumComp => numComp

            do i = 1, numFields*(dmda_flow%dim+1)
              numDof(i) = 0
            end do
            numDof(0*(dmda_flow%dim+1)+1) = dmda_flow%dof
            pNumDof => numDof

            numBC = 0

            call DMPlexCreateSection(dmda_flow%da,dmda_flow%dim, &
    numFields,pNumComp,pNumDof, &
    numBC,PETSC_NULL_INTEGER, &
    PETSC_NULL_IS,PETSC_NULL_IS, &             !Error here
    PETSC_NULL_IS,section,ierr)
            CHKERRQ(ierr)

            call PetscSectionSetFieldName(section,0,'flow',ierr)
            CHKERRQ(ierr)

            call DMSetDefaultSection(dmda_flow%da,section,ierr)
            CHKERRQ(ierr)

            call PetscSectionDestroy(section,ierr)
            CHKERRQ(ierr)
    #endif

    Thanks,

    Danyang




--
What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/%7Emk51/>


      program DMPlexTestField
      implicit none
#include "petsc/finclude/petsc.h90"
      DM :: dm, dmDist
      DMLabel :: label
      Vec :: u
      PetscViewer :: viewer
      PetscSection :: section
      PetscInt :: dim,numFields,numBC,i,val
      PetscInt, target, dimension(3) ::                                 &
     &     numComp
      PetscInt, pointer :: pNumComp(:)
      PetscInt, target, dimension(12) ::                                &
     &     numDof
      PetscInt, pointer :: pNumDof(:)
      PetscInt, target, dimension(1) ::                                 &
     &     bcField
      PetscInt, pointer :: pBcField(:)
      IS, target, dimension(1) ::                                       &
     &     bcCompIS
      IS, target, dimension(1) ::                                       &
     &     bcPointIS
      IS, pointer :: pBcCompIS(:)
      IS, pointer :: pBcPointIS(:)
      PetscBool :: interpolate
      PetscErrorCode :: ierr

      call PetscInitialize(PETSC_NULL_CHARACTER, ierr)
      CHKERRQ(ierr)
      dim = 2
      call PetscOptionsGetInt(PETSC_NULL_OBJECT,PETSC_NULL_CHARACTER,   &
     &                        '-dim', dim,PETSC_NULL_BOOL, ierr)
      CHKERRQ(ierr)
      interpolate = PETSC_TRUE
!     Create a mesh
!      call DMPlexCreateBoxMesh(PETSC_COMM_WORLD, dim, interpolate, dm,
!     &     ierr)

      call DMPlexCreateGmshFromFile(PETSC_COMM_WORLD,'./sol.msh',       &
     &     interpolate,dm)
      CHKERRQ(ierr)

      call DMPlexDistribute(dm, 0, PETSC_NULL_OBJECT, dmDist,ierr)
      CHKERRQ(ierr)

      if (dmDist /= PETSC_NULL_OBJECT) then
        call DMDestroy(dm,ierr)
        CHKERRQ(ierr)
        dm = dmDist
      end if

!     Create a scalar field u, a vector field v, and a surface vector field w
      numFields  = 3
      numComp(1) = 1
      numComp(2) = dim
      numComp(3) = dim-1
      pNumComp => numComp
      do i = 1, numFields*(dim+1)
         numDof(i) = 0
      end do
!     Let u be defined on vertices
      numDof(0*(dim+1)+1)     = 1
!     Let v be defined on cells
      numDof(1*(dim+1)+dim+1) = dim
!     Let v be defined on faces
      numDof(2*(dim+1)+dim)   = dim-1
      pNumDof => numDof
!     Setup boundary conditions
      numBC = 1
!     Test label retrieval
      call DMGetLabel(dm, 'marker', label, ierr)
      CHKERRQ(ierr)
      call DMLabelGetValue(label, 0, val, ierr)
      CHKERRQ(ierr)
      if (val .ne. -1) then
        CHKERRQ(1)
      endif
      call DMLabelGetValue(label, 8, val, ierr)
      CHKERRQ(ierr)
      if (val .ne. 1) then
        CHKERRQ(1)
      endif
!     Prescribe a Dirichlet condition on u on the boundary
!       Label "marker" is made by the mesh creation routine
      bcField(1) = 0
      pBcField => bcField
      call ISCreateStride(PETSC_COMM_WORLD, 1, 0, 1, bcCompIS(1), ierr)
      CHKERRQ(ierr)
      pBcCompIS => bcCompIS
      call DMGetStratumIS(dm, 'marker', 1, bcPointIS(1),
     &    ierr)
      CHKERRQ(ierr)
      pBcPointIS => bcPointIS
!     Create a PetscSection with this data layout
      call DMPlexCreateSection(dm, dim, numFields, pNumComp,
     &     pNumDof, numBC, pBcField, pBcCompIS, pBcPointIS,
     &     PETSC_NULL_OBJECT, section, ierr)
      CHKERRQ(ierr)
      call ISDestroy(bcCompIS(1), ierr)
      CHKERRQ(ierr)
      call ISDestroy(bcPointIS(1), ierr)
      CHKERRQ(ierr)
!     Name the Field variables
      call PetscSectionSetFieldName(section, 0, 'u', ierr)
      CHKERRQ(ierr)
      call PetscSectionSetFieldName(section, 1, 'v', ierr)
      CHKERRQ(ierr)
      call PetscSectionSetFieldName(section, 2, 'w', ierr)
      CHKERRQ(ierr)
      call PetscSectionView(section, PETSC_VIEWER_STDOUT_WORLD, ierr)
      CHKERRQ(ierr)
!     Tell the DM to use this data layout
      call DMSetDefaultSection(dm, section, ierr)
      CHKERRQ(ierr)
!     Create a Vec with this layout and view it
      call DMGetGlobalVector(dm, u, ierr)
      CHKERRQ(ierr)
      call PetscViewerCreate(PETSC_COMM_WORLD, viewer, ierr)
      CHKERRQ(ierr)
      call PetscViewerSetType(viewer, PETSCVIEWERVTK, ierr)
      CHKERRQ(ierr)
      call PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_VTK, ierr)
      CHKERRQ(ierr)
      call PetscViewerFileSetName(viewer, 'sol.vtk', ierr)
      CHKERRQ(ierr)
      call VecView(u, viewer, ierr)
      CHKERRQ(ierr)
      call PetscViewerDestroy(viewer, ierr)
      CHKERRQ(ierr)
      call DMRestoreGlobalVector(dm, u, ierr)
      CHKERRQ(ierr)
!     Cleanup
      call PetscSectionDestroy(section, ierr)
      CHKERRQ(ierr)
      call DMDestroy(dm, ierr)
      CHKERRQ(ierr)

      call PetscFinalize(ierr)
      end program DMPlexTestField

Attachment: sol.msh
Description: Mesh model

Reply via email to