1*0a5cf5d8SBlaise Bourdin #include "petscsystypes.h" 249c89c76SBlaise Bourdin static char help[] = "Test PetscViewer_ExodusII\n\n"; 349c89c76SBlaise Bourdin 449c89c76SBlaise Bourdin #include <petsc.h> 549c89c76SBlaise Bourdin #include <exodusII.h> 649c89c76SBlaise Bourdin 749c89c76SBlaise Bourdin int main(int argc, char **argv) 849c89c76SBlaise Bourdin { 949c89c76SBlaise Bourdin DM dm, pdm; 1049c89c76SBlaise Bourdin PetscInt ovlp = 0; 1149c89c76SBlaise Bourdin char ifilename[PETSC_MAX_PATH_LEN], ofilename[PETSC_MAX_PATH_LEN]; 12*0a5cf5d8SBlaise Bourdin PetscExodusIIInt numZVars, numNVars; 13*0a5cf5d8SBlaise Bourdin PetscExodusIIInt nNodalVar = 4; 14*0a5cf5d8SBlaise Bourdin PetscExodusIIInt nZonalVar = 3; 15*0a5cf5d8SBlaise Bourdin PetscInt order = 1; 1649c89c76SBlaise Bourdin PetscViewer viewer; 17*0a5cf5d8SBlaise Bourdin PetscExodusIIInt index = -1; 1849c89c76SBlaise Bourdin const char *nodalVarName[4] = {"U_x", "U_y", "Alpha", "Beta"}; 1949c89c76SBlaise Bourdin const char *zonalVarName[3] = {"Sigma_11", "Sigma_12", "Sigma_22"}; 2049c89c76SBlaise Bourdin const char *testNames[3] = {"U", "Sigma", "Gamma"}; 2149c89c76SBlaise Bourdin const char *varName = NULL; 2249c89c76SBlaise Bourdin 2349c89c76SBlaise Bourdin PetscFunctionBeginUser; 2449c89c76SBlaise Bourdin PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 2549c89c76SBlaise Bourdin PetscOptionsBegin(PETSC_COMM_WORLD, NULL, "PetscViewer_ExodusII test", "ex95"); 2649c89c76SBlaise Bourdin PetscCall(PetscOptionsString("-i", "Filename to read", "ex95", ifilename, ifilename, sizeof(ifilename), NULL)); 2749c89c76SBlaise Bourdin PetscCall(PetscOptionsString("-o", "Filename to write", "ex95", ofilename, ofilename, sizeof(ofilename), NULL)); 2849c89c76SBlaise Bourdin PetscOptionsEnd(); 2949c89c76SBlaise Bourdin 3049c89c76SBlaise Bourdin #ifdef PETSC_USE_DEBUG 3149c89c76SBlaise Bourdin PetscCallExternal(ex_opts, EX_VERBOSE + EX_DEBUG); 3249c89c76SBlaise Bourdin #endif 3349c89c76SBlaise Bourdin 3449c89c76SBlaise Bourdin PetscCall(DMPlexCreateFromFile(PETSC_COMM_WORLD, ifilename, NULL, PETSC_TRUE, &dm)); 3549c89c76SBlaise Bourdin PetscCall(DMPlexDistributeSetDefault(dm, PETSC_FALSE)); 3649c89c76SBlaise Bourdin PetscCall(DMSetFromOptions(dm)); 3749c89c76SBlaise Bourdin PetscCall(PetscObjectSetName((PetscObject)dm, "ex95")); 3849c89c76SBlaise Bourdin PetscCall(DMViewFromOptions(dm, NULL, "-dm_view")); 3949c89c76SBlaise Bourdin 4049c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIOpen(PETSC_COMM_WORLD, ofilename, FILE_MODE_WRITE, &viewer)); 4149c89c76SBlaise Bourdin 4249c89c76SBlaise Bourdin /* Save the geometry to the file, erasing all previous content */ 4349c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIISetOrder(viewer, order)); 4449c89c76SBlaise Bourdin PetscCall(DMView(dm, viewer)); 4549c89c76SBlaise Bourdin PetscCall(PetscViewerView(viewer, PETSC_VIEWER_STDOUT_WORLD)); 4649c89c76SBlaise Bourdin PetscCall(PetscViewerFlush(viewer)); 4749c89c76SBlaise Bourdin 4849c89c76SBlaise Bourdin PetscCall(DMPlexDistribute(dm, ovlp, NULL, &pdm)); 4949c89c76SBlaise Bourdin if (!pdm) pdm = dm; 5049c89c76SBlaise Bourdin 5149c89c76SBlaise Bourdin /* Testing Variable Number*/ 5249c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIISetZonalVariable(viewer, nZonalVar)); 5349c89c76SBlaise Bourdin nZonalVar = -1; 5449c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetZonalVariable(viewer, &nZonalVar)); 5549c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Number of zonal variables: %d\n", nZonalVar)); 5649c89c76SBlaise Bourdin 5749c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIISetNodalVariable(viewer, nNodalVar)); 5849c89c76SBlaise Bourdin nNodalVar = -1; 5949c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetNodalVariable(viewer, &nNodalVar)); 6049c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Number of nodal variables: %d\n", nNodalVar)); 6149c89c76SBlaise Bourdin PetscCall(PetscViewerView(viewer, PETSC_VIEWER_STDOUT_WORLD)); 6249c89c76SBlaise Bourdin 6349c89c76SBlaise Bourdin /* 6449c89c76SBlaise Bourdin Test of PetscViewerExodusIISet[Nodal/Zonal]VariableName 6549c89c76SBlaise Bourdin */ 6649c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Testing PetscViewerExodusIISet[Nodal/Zonal]VariableName\n")); 67*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < nNodalVar; i++) { PetscCall(PetscViewerExodusIISetNodalVariableName(viewer, i, nodalVarName[i])); } 68*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < nZonalVar; i++) { PetscCall(PetscViewerExodusIISetZonalVariableName(viewer, i, zonalVarName[i])); } 6949c89c76SBlaise Bourdin PetscCall(PetscViewerView(viewer, PETSC_VIEWER_STDOUT_WORLD)); 7049c89c76SBlaise Bourdin PetscCall(PetscViewerDestroy(&viewer)); 7149c89c76SBlaise Bourdin 7249c89c76SBlaise Bourdin /* 7349c89c76SBlaise Bourdin Test of PetscViewerExodusIIGet[Nodal/Zonal]VariableName 7449c89c76SBlaise Bourdin */ 7549c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\n\nReopenning the output file in Read-only mode\n")); 7649c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Testing PetscViewerExodusIIGet[Nodal/Zonal]VariableName\n")); 7749c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIOpen(PETSC_COMM_WORLD, ofilename, FILE_MODE_APPEND, &viewer)); 7849c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIISetOrder(viewer, order)); 7949c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetZonalVariable(viewer, &numZVars)); 8049c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetNodalVariable(viewer, &numNVars)); 8149c89c76SBlaise Bourdin 82*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < numNVars; i++) { 8349c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetNodalVariableName(viewer, i, &varName)); 8449c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetNodalVariableIndex(viewer, varName, &index)); 8549c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, " Nodal variable %d: %s, index in file %d\n", i, varName, index)); 8649c89c76SBlaise Bourdin } 87*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < 3; i++) { 8849c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetNodalVariableIndex(viewer, testNames[i], &index)); 8949c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, " Nodal variable %d: %s, index in file %d\n", i, testNames[i], index)); 9049c89c76SBlaise Bourdin } 9149c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\n")); 9249c89c76SBlaise Bourdin 93*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < numZVars; i++) { 9449c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetZonalVariableName(viewer, i, &varName)); 9549c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetZonalVariableIndex(viewer, varName, &index)); 9649c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, " Zonal variable %d: %s, index in file %d\n", i, varName, index)); 9749c89c76SBlaise Bourdin } 98*0a5cf5d8SBlaise Bourdin for (PetscExodusIIInt i = 0; i < 3; i++) { 9949c89c76SBlaise Bourdin PetscCall(PetscViewerExodusIIGetZonalVariableIndex(viewer, testNames[i], &index)); 10049c89c76SBlaise Bourdin PetscCall(PetscPrintf(PETSC_COMM_WORLD, " Zonal variable %d: %s, index in file %d\n", i, testNames[i], index)); 10149c89c76SBlaise Bourdin } 10249c89c76SBlaise Bourdin 10349c89c76SBlaise Bourdin PetscCall(PetscViewerDestroy(&viewer)); 10449c89c76SBlaise Bourdin PetscCall(DMDestroy(&dm)); 10549c89c76SBlaise Bourdin PetscCall(PetscFinalize()); 10649c89c76SBlaise Bourdin return 0; 10749c89c76SBlaise Bourdin } 10849c89c76SBlaise Bourdin 10949c89c76SBlaise Bourdin /*TEST 11049c89c76SBlaise Bourdin 11149c89c76SBlaise Bourdin build: 11249c89c76SBlaise Bourdin requires: exodusii pnetcdf !complex 11349c89c76SBlaise Bourdin test: 11449c89c76SBlaise Bourdin suffix: 0 11549c89c76SBlaise Bourdin nsize: 1 11649c89c76SBlaise Bourdin args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareT-large.exo -o FourSquareT-large_out.exo 11749c89c76SBlaise Bourdin 11849c89c76SBlaise Bourdin TEST*/ 119