コード例 #1
0
ファイル: plexgmsh.c プロジェクト: pombredanne/petsc
/*@C
  DMPlexCreateGmshFromFile - Create a DMPlex mesh from a Gmsh file

+ comm        - The MPI communicator
. filename    - Name of the Gmsh file
- interpolate - Create faces and edges in the mesh

  Output Parameter:
. dm  - The DM object representing the mesh

  Level: beginner

.seealso: DMPlexCreateFromFile(), DMPlexCreateGmsh(), DMPlexCreate()
@*/
PetscErrorCode DMPlexCreateGmshFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm)
{
    PetscViewer     viewer, vheader;
    PetscMPIInt     rank;
    PetscViewerType vtype;
    char            line[PETSC_MAX_PATH_LEN];
    int             snum;
    PetscBool       match;
    int             fT;
    PetscInt        fileType;
    float           version;
    PetscErrorCode  ierr;

    PetscFunctionBegin;
    ierr = MPI_Comm_rank(comm, &rank);
    CHKERRQ(ierr);
    /* Determine Gmsh file type (ASCII or binary) from file header */
    ierr = PetscViewerCreate(comm, &vheader);
    CHKERRQ(ierr);
    ierr = PetscViewerSetType(vheader, PETSCVIEWERASCII);
    CHKERRQ(ierr);
    ierr = PetscViewerFileSetMode(vheader, FILE_MODE_READ);
    CHKERRQ(ierr);
    ierr = PetscViewerFileSetName(vheader, filename);
    CHKERRQ(ierr);
    if (!rank) {
        /* Read only the first two lines of the Gmsh file */
        ierr = PetscViewerRead(vheader, line, 1, NULL, PETSC_STRING);
        CHKERRQ(ierr);
        ierr = PetscStrncmp(line, "$MeshFormat", PETSC_MAX_PATH_LEN, &match);
        CHKERRQ(ierr);
        if (!match) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "File is not a valid Gmsh file");
        ierr = PetscViewerRead(vheader, line, 2, NULL, PETSC_STRING);
        CHKERRQ(ierr);
        snum = sscanf(line, "%f %d", &version, &fT);
        fileType = (PetscInt) fT;
        if (snum != 2) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Unable to parse Gmsh file header: %s", line);
        if (version < 2.0) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Gmsh file must be at least version 2.0");
    }
    ierr = MPI_Bcast(&fileType, 1, MPIU_INT, 0, comm);
    CHKERRQ(ierr);
    /* Create appropriate viewer and build plex */
    if (fileType == 0) vtype = PETSCVIEWERASCII;
    else vtype = PETSCVIEWERBINARY;
    ierr = PetscViewerCreate(comm, &viewer);
    CHKERRQ(ierr);
    ierr = PetscViewerSetType(viewer, vtype);
    CHKERRQ(ierr);
    ierr = PetscViewerFileSetMode(viewer, FILE_MODE_READ);
    CHKERRQ(ierr);
    ierr = PetscViewerFileSetName(viewer, filename);
    CHKERRQ(ierr);
    ierr = DMPlexCreateGmsh(comm, viewer, interpolate, dm);
    CHKERRQ(ierr);
    ierr = PetscViewerDestroy(&viewer);
    CHKERRQ(ierr);
    ierr = PetscViewerDestroy(&vheader);
    CHKERRQ(ierr);
    PetscFunctionReturn(0);
}
コード例 #2
0
PETSC_EXTERN void PETSC_STDCALL  dmplexcreategmsh_(MPI_Fint * comm,PetscViewer viewer,PetscBool *interpolate,DM *dm, int *__ierr ){
*__ierr = DMPlexCreateGmsh(
	MPI_Comm_f2c( *(comm) ),
	(PetscViewer)PetscToPointer((viewer) ),*interpolate,dm);
}