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