Actual source code: dmglvis.c

      1: /* Routines to visualize DMs through GLVis */

      3: #include <petsc/private/dmimpl.h>
      4: #include <petsc/private/glvisviewerimpl.h>

      6: PetscErrorCode DMView_GLVis(DM dm, PetscViewer viewer, PetscErrorCode (*DMView_GLVis_ASCII)(DM,PetscViewer))
      7: {
      8:   PetscBool      isglvis,isascii;

     12:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERGLVIS,&isglvis);
     13:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
     15:   if (isglvis) {
     16:     PetscViewerGLVisType type;
     17:     PetscViewer          view;

     19:     PetscViewerGLVisGetType_Private(viewer,&type);
     20:     PetscViewerGLVisGetDMWindow_Private(viewer,&view);
     21:     if (!view) return 0; /* socket window has been closed */
     22:     if (type == PETSC_VIEWER_GLVIS_SOCKET) {
     23:       PetscMPIInt size,rank;
     24:       PetscInt    sdim;
     25:       const char* name;

     27:       MPI_Comm_size(PetscObjectComm((PetscObject)dm),&size);
     28:       MPI_Comm_rank(PetscObjectComm((PetscObject)dm),&rank);
     29:       DMGetCoordinateDim(dm,&sdim);
     30:       PetscObjectGetName((PetscObject)dm,&name);

     32:       PetscGLVisCollectiveBegin(PetscObjectComm((PetscObject)dm),&view);
     33:       PetscViewerASCIIPrintf(view,"parallel %d %d\nmesh\n",size,rank);
     34:       DMView_GLVis_ASCII(dm,view);
     35:       PetscViewerGLVisInitWindow_Private(view,PETSC_TRUE,sdim,name);
     36:       PetscGLVisCollectiveEnd(PetscObjectComm((PetscObject)dm),&view);
     37:     } else {
     38:       DMView_GLVis_ASCII(dm,view);
     39:     }
     40:     PetscViewerGLVisRestoreDMWindow_Private(viewer,&view);
     41:   } else {
     42:     DMView_GLVis_ASCII(dm,viewer);
     43:   }
     44:   return 0;
     45: }