Actual source code: dmglvis.c
petsc-3.13.6 2020-09-29
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: {
9: PetscBool isglvis,isascii;
14: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERGLVIS,&isglvis);
15: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
16: if (!isglvis && !isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Viewer must be of type VIEWERGLVIS or VIEWERASCII");
17: if (isglvis) {
18: PetscViewerGLVisType type;
19: PetscViewer view;
21: PetscViewerGLVisGetType_Private(viewer,&type);
22: PetscViewerGLVisGetDMWindow_Private(viewer,&view);
23: if (!view) return(0); /* socket window has been closed */
24: if (type == PETSC_VIEWER_GLVIS_SOCKET) {
25: PetscMPIInt size,rank;
26: PetscInt sdim;
27: const char* name;
29: MPI_Comm_size(PetscObjectComm((PetscObject)dm),&size);
30: MPI_Comm_rank(PetscObjectComm((PetscObject)dm),&rank);
31: DMGetCoordinateDim(dm,&sdim);
32: PetscObjectGetName((PetscObject)dm,&name);
34: PetscGLVisCollectiveBegin(PetscObjectComm((PetscObject)dm),&view);
35: PetscViewerASCIIPrintf(view,"parallel %d %d\nmesh\n",size,rank);
36: DMView_GLVis_ASCII(dm,view);
37: PetscViewerGLVisInitWindow_Private(view,PETSC_TRUE,sdim,name);
38: PetscGLVisCollectiveEnd(PetscObjectComm((PetscObject)dm),&view);
39: } else {
40: DMView_GLVis_ASCII(dm,view);
41: }
42: PetscViewerGLVisRestoreDMWindow_Private(viewer,&view);
43: } else {
44: DMView_GLVis_ASCII(dm,viewer);
45: }
46: return(0);
47: }