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