Actual source code: plexexodusii.c

  1: #define PETSCDM_DLL
  2: #include <petsc/private/dmpleximpl.h>

  4: /*@
  5:   DMPlexCreateExodusFromFile - Create a `DMPLEX` mesh from an ExodusII file.

  7:   Collective

  9:   Input Parameters:
 10: + comm        - The MPI communicator
 11: . filename    - The name of the ExodusII file
 12: - interpolate - Create faces and edges in the mesh

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

 17:   Level: beginner

 19: .seealso: [](ch_unstructured), `DM`, `PETSCVIEWEREXODUSII`, `DMPLEX`, `DMCreate()`, `DMPlexCreateExodus()`
 20: @*/
 21: PetscErrorCode DMPlexCreateExodusFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm)
 22: {
 23:   PetscFunctionBegin;
 24: #if defined(PETSC_HAVE_EXODUSII)
 25:   PetscMPIInt      rank;
 26:   PetscExodusIIInt CPU_word_size = sizeof(PetscReal), IO_word_size = 0, exoid = -1;
 27:   float            version;

 29:   PetscAssertPointer(filename, 2);
 30:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
 31:   if (rank == 0) {
 32:     exoid = ex_open(filename, EX_READ, &CPU_word_size, &IO_word_size, &version);
 33:     PetscCheck(exoid > 0, PETSC_COMM_SELF, PETSC_ERR_LIB, "ex_open(\"%s\",...) did not return a valid file ID", filename);
 34:   }
 35:   PetscCall(DMPlexCreateExodus(comm, exoid, interpolate, dm));
 36:   if (rank == 0) PetscCallExternal(ex_close, exoid);
 37:   PetscFunctionReturn(PETSC_SUCCESS);
 38: #else
 39:   SETERRQ(comm, PETSC_ERR_SUP, "Loading meshes requires EXODUSII support. Reconfigure using --with-exodusii-dir or -download-exodusii");
 40: #endif
 41: }