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