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