static char help[] = "Demonstrate HDF5/XDMF load-save-reload cycle\n\n"; #include #include #define EX "ex5.c" typedef struct { char infile[PETSC_MAX_PATH_LEN]; /* Input mesh filename */ char outfile[PETSC_MAX_PATH_LEN]; /* Dump/reload mesh filename */ PetscViewerFormat informat; /* Input mesh format */ PetscViewerFormat outformat; /* Dump/reload mesh format */ PetscBool redistribute; /* Redistribute the mesh */ PetscInt ntimes; /* How many times do the cycle */ } AppCtx; static PetscErrorCode ProcessOptions(MPI_Comm comm, AppCtx *options) { PetscBool flg; PetscErrorCode ierr; PetscFunctionBeginUser; options->infile[0] = '\0'; options->outfile[0] = '\0'; options->informat = PETSC_VIEWER_HDF5_XDMF; options->outformat = PETSC_VIEWER_HDF5_XDMF; options->redistribute = PETSC_TRUE; options->ntimes = 2; ierr = PetscOptionsBegin(comm, "", "Meshing Problem Options", "DMPLEX");CHKERRQ(ierr); ierr = PetscOptionsString("-infile", "The input mesh file", EX, options->infile, options->infile, sizeof(options->infile), &flg);CHKERRQ(ierr); if (!flg) SETERRQ(comm, PETSC_ERR_USER_INPUT, "-infile needs to be specified"); ierr = PetscOptionsString("-outfile", "The output mesh file (by default it's the same as infile)", EX, options->outfile, options->outfile, sizeof(options->outfile), &flg);CHKERRQ(ierr); if (!flg) SETERRQ(comm, PETSC_ERR_USER_INPUT, "-outfile needs to be specified"); ierr = PetscOptionsEnum("-informat", "Input mesh format", EX, PetscViewerFormats, (PetscEnum)options->informat, (PetscEnum*)&options->informat, NULL);CHKERRQ(ierr); ierr = PetscOptionsEnum("-outformat", "Dump/reload mesh format", EX, PetscViewerFormats, (PetscEnum)options->outformat, (PetscEnum*)&options->outformat, NULL);CHKERRQ(ierr); ierr = PetscOptionsBool("-redistribute", "Redistribute the mesh", EX, options->redistribute, &options->redistribute, NULL);CHKERRQ(ierr); ierr = PetscOptionsInt("-ntimes", "How many times do the cycle", EX, options->ntimes, &options->ntimes, NULL);CHKERRQ(ierr); ierr = PetscOptionsEnd(); PetscFunctionReturn(0); }; //TODO test DMLabel I/O (not yet working for PETSC_VIEWER_HDF5_XDMF) int main(int argc, char **argv) { AppCtx user; PetscInt i; PetscBool flg; MPI_Comm comm; PetscMPIInt size; PetscErrorCode ierr; const char *filename; PetscViewerFormat format; ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr; comm = PETSC_COMM_WORLD; ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); ierr = ProcessOptions(comm, &user);CHKERRQ(ierr); /* Use infile for the initial load */ filename = user.infile; format = user.informat; for (i=0; i