xref: /petsc/src/dm/impls/plex/plexexodusii.c (revision 0a5cf5d8aa03b9d37350e0735e3cdfb377381335)
1552f7358SJed Brown #define PETSCDM_DLL
2af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I   "petscdmplex.h"   I*/
3552f7358SJed Brown 
4cc4c1da9SBarry Smith /*@
5a1cb98faSBarry Smith   DMPlexCreateExodusFromFile - Create a `DMPLEX` mesh from an ExodusII file.
633751fbdSMichael Lange 
7d083f849SBarry Smith   Collective
833751fbdSMichael Lange 
933751fbdSMichael Lange   Input Parameters:
1033751fbdSMichael Lange + comm        - The MPI communicator
1133751fbdSMichael Lange . filename    - The name of the ExodusII file
1233751fbdSMichael Lange - interpolate - Create faces and edges in the mesh
1333751fbdSMichael Lange 
1433751fbdSMichael Lange   Output Parameter:
15a1cb98faSBarry Smith . dm - The `DM` object representing the mesh
1633751fbdSMichael Lange 
1733751fbdSMichael Lange   Level: beginner
1833751fbdSMichael Lange 
191cc06b55SBarry Smith .seealso: [](ch_unstructured), `DM`, `PETSCVIEWEREXODUSII`, `DMPLEX`, `DMCreate()`, `DMPlexCreateExodus()`
2033751fbdSMichael Lange @*/
21d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexCreateExodusFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm)
22d71ae5a4SJacob Faibussowitsch {
2349c89c76SBlaise Bourdin   PetscFunctionBegin;
2433751fbdSMichael Lange #if defined(PETSC_HAVE_EXODUSII)
2549c89c76SBlaise Bourdin   PetscMPIInt      rank;
26*0a5cf5d8SBlaise Bourdin   PetscExodusIIInt CPU_word_size = sizeof(PetscReal), IO_word_size = 0, exoid = -1;
2733751fbdSMichael Lange   float            version;
2833751fbdSMichael Lange 
294f572ea9SToby Isaac   PetscAssertPointer(filename, 2);
309566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_rank(comm, &rank));
31dd400576SPatrick Sanan   if (rank == 0) {
3233751fbdSMichael Lange     exoid = ex_open(filename, EX_READ, &CPU_word_size, &IO_word_size, &version);
3308401ef6SPierre Jolivet     PetscCheck(exoid > 0, PETSC_COMM_SELF, PETSC_ERR_LIB, "ex_open(\"%s\",...) did not return a valid file ID", filename);
3433751fbdSMichael Lange   }
359566063dSJacob Faibussowitsch   PetscCall(DMPlexCreateExodus(comm, exoid, interpolate, dm));
3648a46eb9SPierre Jolivet   if (rank == 0) PetscCallExternal(ex_close, exoid);
373ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
3833751fbdSMichael Lange #else
3949c89c76SBlaise Bourdin   SETERRQ(comm, PETSC_ERR_SUP, "Loading meshes requires EXODUSII support. Reconfigure using --with-exodusii-dir or -download-exodusii");
40552f7358SJed Brown #endif
41552f7358SJed Brown }
42