1552f7358SJed Brown #define PETSCDM_DLL 2af0996ceSBarry Smith #include <petsc/private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 3*ce78bad3SBarry Smith #include <petsc/private/viewerimpl.h> 4*ce78bad3SBarry Smith 5*ce78bad3SBarry Smith /*@ 6*ce78bad3SBarry Smith PetscViewerExodusIIGetId - Get the file id of the `PETSCVIEWEREXODUSII` file 7*ce78bad3SBarry Smith 8*ce78bad3SBarry Smith Logically Collective 9*ce78bad3SBarry Smith 10*ce78bad3SBarry Smith Input Parameter: 11*ce78bad3SBarry Smith . viewer - the `PetscViewer` 12*ce78bad3SBarry Smith 13*ce78bad3SBarry Smith Output Parameter: 14*ce78bad3SBarry Smith . exoid - The ExodusII file id 15*ce78bad3SBarry Smith 16*ce78bad3SBarry Smith Level: intermediate 17*ce78bad3SBarry Smith 18*ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerFileSetMode()`, `PetscViewerCreate()`, `PetscViewerSetType()`, `PetscViewerBinaryOpen()` 19*ce78bad3SBarry Smith @*/ 20*ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIGetId(PetscViewer viewer, int *exoid) 21*ce78bad3SBarry Smith { 22*ce78bad3SBarry Smith PetscFunctionBegin; 23*ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 24*ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerGetId_C", (PetscViewer, int *), (viewer, exoid)); 25*ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 26*ce78bad3SBarry Smith } 27*ce78bad3SBarry Smith 28*ce78bad3SBarry Smith /*@ 29*ce78bad3SBarry Smith PetscViewerExodusIISetOrder - Set the elements order in the exodusII file. 30*ce78bad3SBarry Smith 31*ce78bad3SBarry Smith Collective 32*ce78bad3SBarry Smith 33*ce78bad3SBarry Smith Input Parameters: 34*ce78bad3SBarry Smith + viewer - the `PETSCVIEWEREXODUSII` viewer 35*ce78bad3SBarry Smith - order - elements order 36*ce78bad3SBarry Smith 37*ce78bad3SBarry Smith Output Parameter: 38*ce78bad3SBarry Smith 39*ce78bad3SBarry Smith Level: beginner 40*ce78bad3SBarry Smith 41*ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerExodusIIGetId()`, `PetscViewerExodusIIGetOrder()` 42*ce78bad3SBarry Smith @*/ 43*ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIISetOrder(PetscViewer viewer, PetscInt order) 44*ce78bad3SBarry Smith { 45*ce78bad3SBarry Smith PetscFunctionBegin; 46*ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 47*ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerSetOrder_C", (PetscViewer, PetscInt), (viewer, order)); 48*ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 49*ce78bad3SBarry Smith } 50*ce78bad3SBarry Smith 51*ce78bad3SBarry Smith /*@ 52*ce78bad3SBarry Smith PetscViewerExodusIIGetOrder - Get the elements order in the exodusII file. 53*ce78bad3SBarry Smith 54*ce78bad3SBarry Smith Collective 55*ce78bad3SBarry Smith 56*ce78bad3SBarry Smith Input Parameters: 57*ce78bad3SBarry Smith + viewer - the `PETSCVIEWEREXODUSII` viewer 58*ce78bad3SBarry Smith - order - elements order 59*ce78bad3SBarry Smith 60*ce78bad3SBarry Smith Output Parameter: 61*ce78bad3SBarry Smith 62*ce78bad3SBarry Smith Level: beginner 63*ce78bad3SBarry Smith 64*ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerExodusIIGetId()`, `PetscViewerExodusIISetOrder()` 65*ce78bad3SBarry Smith @*/ 66*ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIGetOrder(PetscViewer viewer, PetscInt *order) 67*ce78bad3SBarry Smith { 68*ce78bad3SBarry Smith PetscFunctionBegin; 69*ce78bad3SBarry Smith PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1); 70*ce78bad3SBarry Smith PetscTryMethod(viewer, "PetscViewerGetOrder_C", (PetscViewer, PetscInt *), (viewer, order)); 71*ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 72*ce78bad3SBarry Smith } 73*ce78bad3SBarry Smith 74*ce78bad3SBarry Smith /*@ 75*ce78bad3SBarry Smith PetscViewerExodusIIOpen - Opens a file for ExodusII input/output. 76*ce78bad3SBarry Smith 77*ce78bad3SBarry Smith Collective 78*ce78bad3SBarry Smith 79*ce78bad3SBarry Smith Input Parameters: 80*ce78bad3SBarry Smith + comm - MPI communicator 81*ce78bad3SBarry Smith . name - name of file 82*ce78bad3SBarry Smith - type - type of file 83*ce78bad3SBarry Smith .vb 84*ce78bad3SBarry Smith FILE_MODE_WRITE - create new file for binary output 85*ce78bad3SBarry Smith FILE_MODE_READ - open existing file for binary input 86*ce78bad3SBarry Smith FILE_MODE_APPEND - open existing file for binary output 87*ce78bad3SBarry Smith .ve 88*ce78bad3SBarry Smith 89*ce78bad3SBarry Smith Output Parameter: 90*ce78bad3SBarry Smith . exo - `PETSCVIEWEREXODUSII` `PetscViewer` for Exodus II input/output to use with the specified file 91*ce78bad3SBarry Smith 92*ce78bad3SBarry Smith Level: beginner 93*ce78bad3SBarry Smith 94*ce78bad3SBarry Smith .seealso: `PETSCVIEWEREXODUSII`, `PetscViewer`, `PetscViewerPushFormat()`, `PetscViewerDestroy()`, 95*ce78bad3SBarry Smith `DMLoad()`, `PetscFileMode`, `PetscViewerSetType()`, `PetscViewerFileSetMode()`, `PetscViewerFileSetName()` 96*ce78bad3SBarry Smith @*/ 97*ce78bad3SBarry Smith PetscErrorCode PetscViewerExodusIIOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *exo) 98*ce78bad3SBarry Smith { 99*ce78bad3SBarry Smith PetscFunctionBegin; 100*ce78bad3SBarry Smith PetscCall(PetscViewerCreate(comm, exo)); 101*ce78bad3SBarry Smith PetscCall(PetscViewerSetType(*exo, PETSCVIEWEREXODUSII)); 102*ce78bad3SBarry Smith PetscCall(PetscViewerFileSetMode(*exo, type)); 103*ce78bad3SBarry Smith PetscCall(PetscViewerFileSetName(*exo, name)); 104*ce78bad3SBarry Smith PetscCall(PetscViewerSetFromOptions(*exo)); 105*ce78bad3SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 106*ce78bad3SBarry 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