1 #include <petsc/private/dmmbimpl.h> /*I "petscdmmoab.h" I*/ 2 #include <petscdmmoab.h> 3 4 static PetscErrorCode DMMoab_GetWriteOptions_Private(PetscInt fsetid, PetscInt numproc, PetscInt dim, MoabWriteMode mode, PetscInt dbglevel, const char *dm_opts, const char *extra_opts, const char **write_opts) { 5 char *wopts; 6 char wopts_par[PETSC_MAX_PATH_LEN]; 7 char wopts_parid[PETSC_MAX_PATH_LEN]; 8 char wopts_dbg[PETSC_MAX_PATH_LEN]; 9 PetscFunctionBegin; 10 11 PetscCall(PetscMalloc1(PETSC_MAX_PATH_LEN, &wopts)); 12 PetscCall(PetscMemzero(&wopts_par, PETSC_MAX_PATH_LEN)); 13 PetscCall(PetscMemzero(&wopts_parid, PETSC_MAX_PATH_LEN)); 14 PetscCall(PetscMemzero(&wopts_dbg, PETSC_MAX_PATH_LEN)); 15 16 // do parallel read unless only one processor 17 if (numproc > 1) { 18 PetscCall(PetscSNPrintf(wopts_par, PETSC_MAX_PATH_LEN, "PARALLEL=%s;", MoabWriteModes[mode])); 19 if (fsetid >= 0) { PetscCall(PetscSNPrintf(wopts_parid, PETSC_MAX_PATH_LEN, "PARALLEL_COMM=%d;", fsetid)); } 20 } 21 22 if (dbglevel) { PetscCall(PetscSNPrintf(wopts_dbg, PETSC_MAX_PATH_LEN, "CPUTIME;DEBUG_IO=%d;", dbglevel)); } 23 24 PetscCall(PetscSNPrintf(wopts, PETSC_MAX_PATH_LEN, "%s%s%s%s%s", wopts_par, wopts_parid, wopts_dbg, (extra_opts ? extra_opts : ""), (dm_opts ? dm_opts : ""))); 25 *write_opts = wopts; 26 PetscFunctionReturn(0); 27 } 28 29 /*@C 30 DMMoabOutput - Output the solution vectors that are stored in the DMMoab object as tags 31 along with the complete mesh data structure in the native H5M or VTK format. The H5M output file 32 can be visualized directly with Paraview (if compiled with appropriate plugin) or converted 33 with MOAB/tools/mbconvert to a VTK or Exodus file. 34 35 This routine can also be used for check-pointing purposes to store a complete history of 36 the solution along with any other necessary data to restart computations. 37 38 Collective 39 40 Input Parameters: 41 + dm - the discretization manager object containing solution in MOAB tags. 42 . filename - the name of the output file: e.g., poisson.h5m 43 - usrwriteopts - the parallel write options needed for serializing a MOAB mesh database. Can be NULL. 44 Reference (Parallel Mesh Initialization: http://ftp.mcs.anl.gov/pub/fathom/moab-docs/contents.html#fivetwo) 45 46 Level: intermediate 47 48 .seealso: `DMMoabLoadFromFile()`, `DMMoabSetGlobalFieldVector()` 49 @*/ 50 PetscErrorCode DMMoabOutput(DM dm, const char *filename, const char *usrwriteopts) { 51 DM_Moab *dmmoab; 52 const char *writeopts; 53 PetscBool isftype; 54 moab::ErrorCode merr; 55 56 PetscFunctionBegin; 57 PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 58 dmmoab = (DM_Moab *)(dm)->data; 59 60 PetscCall(PetscStrendswith(filename, "h5m", &isftype)); 61 62 /* add mesh loading options specific to the DM */ 63 if (isftype) { 64 #ifdef MOAB_HAVE_MPI 65 PetscCall(DMMoab_GetWriteOptions_Private(dmmoab->pcomm->get_id(), dmmoab->pcomm->size(), dmmoab->dim, dmmoab->write_mode, dmmoab->rw_dbglevel, dmmoab->extra_write_options, usrwriteopts, &writeopts)); 66 #else 67 PetscCall(DMMoab_GetWriteOptions_Private(0, 1, dmmoab->dim, dmmoab->write_mode, dmmoab->rw_dbglevel, dmmoab->extra_write_options, usrwriteopts, &writeopts)); 68 #endif 69 PetscCall(PetscInfo(dm, "Writing file %s with options: %s\n", filename, writeopts)); 70 } else { 71 writeopts = NULL; 72 } 73 74 /* output file, using parallel write */ 75 merr = dmmoab->mbiface->write_file(filename, NULL, writeopts, &dmmoab->fileset, 1); 76 MBERRVM(dmmoab->mbiface, "Writing output of DMMoab failed.", merr); 77 PetscCall(PetscFree(writeopts)); 78 PetscFunctionReturn(0); 79 } 80