1552f7358SJed Brown #define PETSCDM_DLL 2af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 3ce78bad3SBarry Smith #include <petsc/private/viewerimpl.h> 4ce78bad3SBarry Smith 5ce78bad3SBarry Smith /*@ 6ce78bad3SBarry Smith PetscViewerExodusIIGetId - Get the file id of the `PETSCVIEWEREXODUSII` file 7ce78bad3SBarry Smith 8ce78bad3SBarry Smith Logically Collective 9ce78bad3SBarry Smith 10ce78bad3SBarry Smith Input Parameter: 11ce78bad3SBarry Smith . viewer - the `PetscViewer` 12ce78bad3SBarry Smith 13ce78bad3SBarry Smith Output Parameter: 14ce78bad3SBarry Smith . exoid - The ExodusII file id 15ce78bad3SBarry Smith 16ce78bad3SBarry Smith Level: intermediate 17ce78bad3SBarry Smith 18ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerFileSetMode()`, `PetscViewerCreate()`, `PetscViewerSetType()`, `PetscViewerBinaryOpen()` 19ce78bad3SBarry Smith @*/ 20ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIGetId(PetscViewer viewer, int *exoid) 21ce78bad3SBarry Smith { 22ce78bad3SBarry Smith PetscFunctionBegin; 23ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 24ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerGetId_C", (PetscViewer, int *), (viewer, exoid)); 25ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 26ce78bad3SBarry Smith } 27ce78bad3SBarry Smith 28ce78bad3SBarry Smith /*@ 29*caff39ffSPierre Jolivet PetscViewerExodusIISetOrder - Set the elements order in the ExodusII file. 30ce78bad3SBarry Smith 31ce78bad3SBarry Smith Collective 32ce78bad3SBarry Smith 33ce78bad3SBarry Smith Input Parameters: 34ce78bad3SBarry Smith + viewer - the `PETSCVIEWEREXODUSII` viewer 35ce78bad3SBarry Smith - order - elements order 36ce78bad3SBarry Smith 37ce78bad3SBarry Smith Output Parameter: 38ce78bad3SBarry Smith 39ce78bad3SBarry Smith Level: beginner 40ce78bad3SBarry Smith 41ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerExodusIIGetId()`, `PetscViewerExodusIIGetOrder()` 42ce78bad3SBarry Smith @*/ 43ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIISetOrder(PetscViewer viewer, PetscInt order) 44ce78bad3SBarry Smith { 45ce78bad3SBarry Smith PetscFunctionBegin; 46ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 47ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerSetOrder_C", (PetscViewer, PetscInt), (viewer, order)); 48ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 49ce78bad3SBarry Smith } 50ce78bad3SBarry Smith 51ce78bad3SBarry Smith /*@ 52*caff39ffSPierre Jolivet PetscViewerExodusIIGetOrder - Get the elements order in the ExodusII file. 53ce78bad3SBarry Smith 54ce78bad3SBarry Smith Collective 55ce78bad3SBarry Smith 56ce78bad3SBarry Smith Input Parameters: 57ce78bad3SBarry Smith + viewer - the `PETSCVIEWEREXODUSII` viewer 58ce78bad3SBarry Smith - order - elements order 59ce78bad3SBarry Smith 60ce78bad3SBarry Smith Output Parameter: 61ce78bad3SBarry Smith 62ce78bad3SBarry Smith Level: beginner 63ce78bad3SBarry Smith 64ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerExodusIIGetId()`, `PetscViewerExodusIISetOrder()` 65ce78bad3SBarry Smith @*/ 66ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIGetOrder(PetscViewer viewer, PetscInt *order) 67ce78bad3SBarry Smith { 68ce78bad3SBarry Smith PetscFunctionBegin; 69ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 70ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerGetOrder_C", (PetscViewer, PetscInt *), (viewer, order)); 71ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 72ce78bad3SBarry Smith } 73ce78bad3SBarry Smith 74ce78bad3SBarry Smith /*@ 75ce78bad3SBarry Smith PetscViewerExodusIIOpen - Opens a file for ExodusII input/output. 76ce78bad3SBarry Smith 77ce78bad3SBarry Smith Collective 78ce78bad3SBarry Smith 79ce78bad3SBarry Smith Input Parameters: 80ce78bad3SBarry Smith + comm - MPI communicator 81ce78bad3SBarry Smith . name - name of file 82ce78bad3SBarry Smith - type - type of file 83ce78bad3SBarry Smith .vb 84ce78bad3SBarry Smith FILE_MODE_WRITE - create new file for binary output 85ce78bad3SBarry Smith FILE_MODE_READ - open existing file for binary input 86ce78bad3SBarry Smith FILE_MODE_APPEND - open existing file for binary output 87ce78bad3SBarry Smith .ve 88ce78bad3SBarry Smith 89ce78bad3SBarry Smith Output Parameter: 90ce78bad3SBarry Smith . exo - `PETSCVIEWEREXODUSII` `PetscViewer` for Exodus II input/output to use with the specified file 91ce78bad3SBarry Smith 92ce78bad3SBarry Smith Level: beginner 93ce78bad3SBarry Smith 94ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerPushFormat()`, `PetscViewerDestroy()`, 95ce78bad3SBarry Smith `DMLoad()`, `PetscFileMode`, `PetscViewerSetType()`, `PetscViewerFileSetMode()`, `PetscViewerFileSetName()` 96ce78bad3SBarry Smith @*/ 97ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *exo) 98ce78bad3SBarry Smith { 99ce78bad3SBarry Smith PetscFunctionBegin; 100ce78bad3SBarry Smith PetscCall(PetscViewerCreate(comm, exo)); 101ce78bad3SBarry Smith PetscCall(PetscViewerSetType(*exo, PETSCVIEWEREXODUSII)); 102ce78bad3SBarry Smith PetscCall(PetscViewerFileSetMode(*exo, type)); 103ce78bad3SBarry Smith PetscCall(PetscViewerFileSetName(*exo, name)); 104ce78bad3SBarry Smith PetscCall(PetscViewerSetFromOptions(*exo)); 105ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 106ce78bad3SBarry Smith } 107552f7358SJed Brown 108cc4c1da9SBarry Smith /*@ 109a1cb98faSBarry Smith DMPlexCreateExodusFromFile - Create a `DMPLEX` mesh from an ExodusII file. 11033751fbdSMichael Lange 111d083f849SBarry Smith Collective 11233751fbdSMichael Lange 11333751fbdSMichael Lange Input Parameters: 11433751fbdSMichael Lange + comm - The MPI communicator 11533751fbdSMichael Lange . filename - The name of the ExodusII file 11633751fbdSMichael Lange - interpolate - Create faces and edges in the mesh 11733751fbdSMichael Lange 11833751fbdSMichael Lange Output Parameter: 119a1cb98faSBarry Smith . dm - The `DM` object representing the mesh 12033751fbdSMichael Lange 12133751fbdSMichael Lange Level: beginner 12233751fbdSMichael Lange 1231cc06b55SBarry Smith .seealso: [](ch_unstructured), `DM`, `PETSCVIEWEREXODUSII`, `DMPLEX`, `DMCreate()`, `DMPlexCreateExodus()` 12433751fbdSMichael Lange @*/ 125d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexCreateExodusFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm) 126d71ae5a4SJacob Faibussowitsch { 12749c89c76SBlaise Bourdin PetscFunctionBegin; 12833751fbdSMichael Lange #if defined(PETSC_HAVE_EXODUSII) 12949c89c76SBlaise Bourdin PetscMPIInt rank; 1300a5cf5d8SBlaise Bourdin PetscExodusIIInt CPU_word_size = sizeof(PetscReal), IO_word_size = 0, exoid = -1; 13133751fbdSMichael Lange float version; 13233751fbdSMichael Lange 1334f572ea9SToby Isaac PetscAssertPointer(filename, 2); 1349566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(comm, &rank)); 135dd400576SPatrick Sanan if (rank == 0) { 13633751fbdSMichael Lange exoid = ex_open(filename, EX_READ, &CPU_word_size, &IO_word_size, &version); 13708401ef6SPierre Jolivet PetscCheck(exoid > 0, PETSC_COMM_SELF, PETSC_ERR_LIB, "ex_open(\"%s\",...) did not return a valid file ID", filename); 13833751fbdSMichael Lange } 1399566063dSJacob Faibussowitsch PetscCall(DMPlexCreateExodus(comm, exoid, interpolate, dm)); 14048a46eb9SPierre Jolivet if (rank == 0) PetscCallExternal(ex_close, exoid); 1413ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 14233751fbdSMichael Lange #else 14349c89c76SBlaise Bourdin SETERRQ(comm, PETSC_ERR_SUP, "Loading meshes requires EXODUSII support. Reconfigure using --with-exodusii-dir or -download-exodusii"); 144552f7358SJed Brown #endif 145552f7358SJed Brown } 146