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