Actual source code: vsilo.c

      1: #define PETSC_DLL
      2: /*
      3:         Written by Matt Dorbin, mrdorbin@cs.purdue.edu 3/1/99
      4:         For database format and API from LLNL
      5:         Updated by Matt Knepley, knepley@cs.purdue.edu 11/16/99
      6: */
     7:  #include vsilo.h

     11: static PetscErrorCode PetscViewerDestroy_Silo(PetscViewer viewer)
     12: {
     13:   Viewer_Silo    *silo = (Viewer_Silo *) viewer->data;
     14:   int            rank;

     18:   MPI_Comm_rank(viewer->comm, &rank);
     19:   if(!rank) {
     20:     DBClose(silo->file_pointer);
     21:   }
     22:   return(0);
     23: }

     27: PetscErrorCode PetscViewerFlush_Silo(PetscViewer viewer)
     28: {
     29:   int            rank;

     33:   MPI_Comm_rank(viewer->comm, &rank);
     34:   if (rank) return(0);
     35:   return(0);
     36: }

     38: /*-----------------------------------------Public Functions-----------------------------------------------------------*/
     41: /*@C
     42:   PetscViewerSiloGetFilePointer - Extracts the file pointer from a Silo viewer.

     44:   Input Parameter:
     45: . viewer - viewer context, obtained from PetscViewerSiloOpen()

     47:   Output Parameter:
     48: . fd     - file pointer

     50:   Level: advanced

     52: .keywords: PetscViewer, file, get, pointer
     53: .seealso: PetscViewerSiloOpen()
     54: @*/
     55: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloGetFilePointer(PetscViewer viewer, DBfile **fd)
     56: {
     57:   Viewer_Silo *silo = (Viewer_Silo *) viewer->data;

     62:   *fd = silo->file_pointer;
     63:   return(0);
     64: }

     68: /*@C
     69:   PetscViewerSiloOpen - This routine writes the mesh and the partition in the
     70:   SILO format used by MeshTv, which can be used to create plots and
     71:   MPEG movies.

     73:   Collectiveon MPI_Comm

     75:   Input Parameters:
     76: + comm - The MPI communicator
     77: - name - The name for the Silo files

     79:   Output Parameter:
     80: . viewer  - A viewer

     82:   Notes:
     83:   This viewer is intended to work with the SILO portable database format.
     84:   Details on SILO, MeshTv, and companion software can be obtained by sending
     85:   mail to meshtv@viper.llnl.gov

     87:   Options Database Keys:

     89:   Level: beginner

     91: .keywords: PetscViewer, Silo, open
     92: @*/
     93: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloOpen(MPI_Comm comm, const char name[], PetscViewer *viewer)
     94: {
     95:   PetscViewer    v;
     96:   Viewer_Silo    *silo;
     97:   char           filename[PETSC_MAX_PATH_LEN], filetemp[PETSC_MAX_PATH_LEN];

    101:   PetscHeaderCreate(v, _p_PetscViewer, struct _PetscViewerOps, PETSC_VIEWER_COOKIE, -1, PETSC_VIEWER_SILO, comm, PetscViewerDestroy, 0);
    102:   PetscLogObjectCreate(v);
    103:   silo            = PetscNew(Viewer_Silo); CHKPTRQ(silo);
    104:   v->data         = silo;
    105:   v->ops->destroy = PetscViewerDestroy_Silo;
    106:   v->ops->flush   = PetscViewerFlush_Silo;
    107:   PetscStrallocpy(PETSC_VIEWER_SILO, &v->type_name);

    109:   PetscStrncpy(filetemp, name, 251);
    110:   PetscStrcat(filetemp, ".pdb");
    111:   PetscFixFilename(filetemp, filename);

    113:   silo->file_pointer = DBCreate(filename, DB_CLOBBER, DB_LOCAL, NULL, DB_PDB);
    114:   if (!silo->file_pointer) SETERRQ(PETSC_ERR_FILE_OPEN,"Cannot open Silo viewer file");
    115: #if defined(PETSC_USE_LOG)
    116:   PLogObjectState((PetscObject) v, "Silo File: %s", name);
    117: #endif
    118:   silo->meshName = PETSC_NULL;
    119:   silo->objName  = PETSC_NULL;

    121:   *viewer = v;
    122:   return(0);
    123: }

    127: /*@C
    128:   PetscViewerSiloCheckMesh - This routine checks a Silo viewer to determine whether the
    129:                         mesh has already been put in the .silo file. It also checks for type,
    130:                         and at the moment accepts only UCD_MESH meshes.

    132:   Not collective

    134:   Input Parameters:
    135: + mesh - The mesh that should be in place
    136: . viewer - The viewer that should contain the mesh
    137: - fp - The pointer to the DBFile that should contain the mesh

    139:   Level: intermediate

    141: .keywords: viewer, Silo, mesh
    142: .seealso: PetscViewerSiloOpen()
    143: @*/
    144: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloCheckMesh(PetscViewer viewer, Mesh mesh)
    145: {
    146:   Viewer_Silo    *vsilo = (Viewer_Silo *) viewer->data;
    147:   DBfile         *fp;
    148:   int            mesh_type;

    152:   PetscViewerSiloGetFilePointer(viewer, &fp);
    153:   if (!vsilo->meshName) {
    154:     mesh_type = DBInqMeshtype(fp, "PetscMesh");
    155:   } else {
    156:     mesh_type = DBInqMeshtype(fp, vsilo->meshName);
    157:   }
    158:   if(mesh_type != DB_UCDMESH) {
    159:     /* DBInqMeshType returns -1 if the mesh is not found*/
    160:     MeshView(mesh, viewer);
    161:   }
    162:   return(0);
    163: }

    167: /*@C
    168:   PetscViewerSiloGetName - Retrieve the default name for objects communicated to Silo

    170:   Input Parameter:
    171: . viewer - The Silo viewer

    173:   Output Parameter:
    174: . name   - The name for new objects created in Silo

    176:   Level: intermediate

    178: .keywords PetscViewer, Silo, name
    179: .seealso PetscViewerSiloSetName(), PetscViewerSiloClearName()
    180: @*/
    181: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloGetName(PetscViewer viewer, char **name)
    182: {
    183:   PetscViewer_Silo *vsilo = (PetscViewer_Silo *) viewer->data;

    188:   *name = vsilo->objName;
    189:   return(0);
    190: }

    194: /*@C
    195:   PetscViewerSiloSetName - Override the default name for objects communicated to Silo

    197:   Input Parameters:
    198: . viewer - The Silo viewer
    199: . name   - The name for new objects created in Silo

    201:   Level: intermediate

    203: .keywords PetscViewer, Silo, name
    204: .seealso PetscViewerSiloSetName(), PetscViewerSiloClearName()
    205: @*/
    206: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloSetName(PetscViewer viewer, char *name)
    207: {
    208:   Viewer_Silo *vsilo = (Viewer_Silo *) viewer->data;

    213:   vsilo->objName = name;
    214:   return(0);
    215: }

    219: /*@C
    220:   PetscViewerSiloClearName - Use the default name for objects communicated to Silo

    222:   Input Parameter:
    223: . viewer - The Silo viewer

    225:   Level: intermediate

    227: .keywords PetscViewer, Silo, name
    228: .seealso PetscViewerSiloGetName(), PetscViewerSiloSetName()
    229: @*/
    230: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloClearName(PetscViewer viewer)
    231: {
    232:   Viewer_Silo *vsilo = (Viewer_Silo *) viewer->data;

    236:   vsilo->objName = PETSC_NULL;
    237:   return(0);
    238: }

    242: /*@C
    243:   PetscViewerSiloGetMeshName - Retrieve the default name for the mesh in Silo

    245:   Input Parameter:
    246: . viewer - The Silo viewer

    248:   Output Parameter:
    249: . name   - The name for new objects created in Silo

    251:   Level: intermediate

    253: .keywords PetscViewer, Silo, name, mesh
    254: .seealso PetscViewerSiloSetMeshName(), PetscViewerSiloClearMeshName()
    255: @*/
    256: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloGetMeshName(PetscViewer viewer, char **name)
    257: {
    258:   Viewer_Silo *vsilo = (Viewer_Silo *) viewer->data;

    263:   *name = vsilo->meshName;
    264:   return(0);
    265: }

    269: /*@C
    270:   PetscViewerSiloSetMeshName - Override the default name for the mesh in Silo

    272:   Input Parameters:
    273: + viewer - The Silo viewer
    274: - name   - The name for new objects created in Silo

    276:   Level: intermediate

    278: .keywords PetscViewer, Silo, name, mesh
    279: .seealso PetscViewerSiloSetMeshName(), PetscViewerSiloClearMeshName()
    280: @*/
    281: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloSetMeshName(PetscViewer viewer, char *name)
    282: {
    283:   Viewer_Silo *vsilo = (Viewer_Silo *) viewer->data;

    288:   vsilo->meshName = name;
    289:   return(0);
    290: }

    294: /*@C
    295:   PetscViewerSiloClearMeshName - Use the default name for the mesh in Silo

    297:   Input Parameter:
    298: . viewer - The Silo viewer

    300:   Level: intermediate

    302: .keywords PetscViewer, Silo, name, mesh
    303: .seealso PetscViewerSiloGetMeshName(), PetscViewerSiloSetMeshName()
    304: @*/
    305: PetscErrorCode PETSC_DLLEXPORT PetscViewerSiloClearMeshName(PetscViewer viewer)
    306: {
    307:   Viewer_Silo *vsilo = (Viewer_Silo *) viewer->data;

    311:   vsilo->meshName = PETSC_NULL;
    312:   return(0);
    313: }

    315: