xref: /petsc/src/sys/classes/viewer/impls/draw/drawv.c (revision ce94432eddcd14845bc7e8083b7f8ea723b9bf7d)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith #include <../src/sys/classes/viewer/impls/draw/vdraw.h> /*I "petscdraw.h" I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith #undef __FUNCT__
55c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy_Draw"
65c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_Draw(PetscViewer v)
75c6c1daeSBarry Smith {
85c6c1daeSBarry Smith   PetscErrorCode   ierr;
95c6c1daeSBarry Smith   PetscInt         i;
105c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
115c6c1daeSBarry Smith 
125c6c1daeSBarry Smith   PetscFunctionBegin;
135c6c1daeSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Destroying PetscViewer without first restoring singleton");
145c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
155c6c1daeSBarry Smith     ierr = PetscDrawAxisDestroy(&vdraw->drawaxis[i]);CHKERRQ(ierr);
165c6c1daeSBarry Smith     ierr = PetscDrawLGDestroy(&vdraw->drawlg[i]);CHKERRQ(ierr);
175c6c1daeSBarry Smith     ierr = PetscDrawDestroy(&vdraw->draw[i]);CHKERRQ(ierr);
185c6c1daeSBarry Smith   }
195c6c1daeSBarry Smith 
205c6c1daeSBarry Smith   ierr = PetscFree(vdraw->display);CHKERRQ(ierr);
215c6c1daeSBarry Smith   ierr = PetscFree(vdraw->title);CHKERRQ(ierr);
225c6c1daeSBarry Smith   ierr = PetscFree3(vdraw->draw,vdraw->drawlg,vdraw->drawaxis);CHKERRQ(ierr);
235c6c1daeSBarry Smith   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
245c6c1daeSBarry Smith   ierr = PetscFree(vdraw);CHKERRQ(ierr);
255c6c1daeSBarry Smith   PetscFunctionReturn(0);
265c6c1daeSBarry Smith }
275c6c1daeSBarry Smith 
285c6c1daeSBarry Smith #undef __FUNCT__
295c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFlush_Draw"
305c6c1daeSBarry Smith PetscErrorCode PetscViewerFlush_Draw(PetscViewer v)
315c6c1daeSBarry Smith {
325c6c1daeSBarry Smith   PetscErrorCode   ierr;
335c6c1daeSBarry Smith   PetscInt         i;
345c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
355c6c1daeSBarry Smith 
365c6c1daeSBarry Smith   PetscFunctionBegin;
375c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
385c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawSynchronizedFlush(vdraw->draw[i]);CHKERRQ(ierr);}
395c6c1daeSBarry Smith   }
405c6c1daeSBarry Smith   PetscFunctionReturn(0);
415c6c1daeSBarry Smith }
425c6c1daeSBarry Smith 
435c6c1daeSBarry Smith #undef __FUNCT__
445c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetDraw"
455c6c1daeSBarry Smith /*@C
465c6c1daeSBarry Smith     PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object.
475c6c1daeSBarry Smith     This PetscDraw object may then be used to perform graphics using
485c6c1daeSBarry Smith     PetscDrawXXX() commands.
495c6c1daeSBarry Smith 
505c6c1daeSBarry Smith     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)
515c6c1daeSBarry Smith 
525c6c1daeSBarry Smith     Input Parameters:
535c6c1daeSBarry Smith +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
545c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
555c6c1daeSBarry Smith 
565c6c1daeSBarry Smith     Ouput Parameter:
575c6c1daeSBarry Smith .   draw - the draw object
585c6c1daeSBarry Smith 
595c6c1daeSBarry Smith     Level: intermediate
605c6c1daeSBarry Smith 
615c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
625c6c1daeSBarry Smith    Concepts: graphics
635c6c1daeSBarry Smith 
645c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
655c6c1daeSBarry Smith @*/
665c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt windownumber,PetscDraw *draw)
675c6c1daeSBarry Smith {
685c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
695c6c1daeSBarry Smith   PetscErrorCode   ierr;
705c6c1daeSBarry Smith   PetscBool        isdraw;
715c6c1daeSBarry Smith   char             *title;
725c6c1daeSBarry Smith 
735c6c1daeSBarry Smith   PetscFunctionBegin;
745c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
755c6c1daeSBarry Smith   if (draw) PetscValidPointer(draw,3);
765c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
775c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
785c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
795c6c1daeSBarry Smith   windownumber += vdraw->draw_base;
805c6c1daeSBarry Smith   if (windownumber >= vdraw->draw_max) {
815c6c1daeSBarry Smith     /* allocate twice as many slots as needed */
825c6c1daeSBarry Smith     PetscInt      draw_max  = vdraw->draw_max;
835c6c1daeSBarry Smith     PetscDraw     *tdraw    = vdraw->draw;
845c6c1daeSBarry Smith     PetscDrawLG   *drawlg   = vdraw->drawlg;
855c6c1daeSBarry Smith     PetscDrawAxis *drawaxis = vdraw->drawaxis;
865c6c1daeSBarry Smith 
875c6c1daeSBarry Smith     vdraw->draw_max = 2*windownumber;
88a297a907SKarl Rupp 
895c6c1daeSBarry Smith     ierr = PetscMalloc3(vdraw->draw_max,PetscDraw,&vdraw->draw,vdraw->draw_max,PetscDrawLG,&vdraw->drawlg,vdraw->draw_max,PetscDrawAxis,&vdraw->drawaxis);CHKERRQ(ierr);
905c6c1daeSBarry Smith     ierr = PetscMemzero(vdraw->draw,vdraw->draw_max*sizeof(PetscDraw));CHKERRQ(ierr);
915c6c1daeSBarry Smith     ierr = PetscMemzero(vdraw->drawlg,vdraw->draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr);
925c6c1daeSBarry Smith     ierr = PetscMemzero(vdraw->drawaxis,vdraw->draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr);
935c6c1daeSBarry Smith 
945c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->draw,tdraw,draw_max*sizeof(PetscDraw));CHKERRQ(ierr);
955c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->drawlg,drawlg,draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr);
965c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->drawaxis,drawaxis,draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr);
975c6c1daeSBarry Smith 
985c6c1daeSBarry Smith     ierr = PetscFree3(tdraw,drawlg,drawaxis);CHKERRQ(ierr);
995c6c1daeSBarry Smith   }
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith   if (!vdraw->draw[windownumber]) {
102a297a907SKarl Rupp     if (!windownumber) title = vdraw->title;
103a297a907SKarl Rupp     else {
1045c6c1daeSBarry Smith       char tmp_str[128];
1055c6c1daeSBarry Smith       ierr  = PetscSNPrintf(tmp_str, 128, "%s:%d", vdraw->title,windownumber);CHKERRQ(ierr);
1065c6c1daeSBarry Smith       title = tmp_str;
1075c6c1daeSBarry Smith     }
108*ce94432eSBarry Smith     ierr = PetscDrawCreate(PetscObjectComm((PetscObject)viewer),vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);CHKERRQ(ierr);
109afe78b3cSBarry Smith     ierr = PetscDrawSetPause(vdraw->draw[windownumber],vdraw->pause);CHKERRQ(ierr);
1105c6c1daeSBarry Smith     ierr = PetscDrawSetFromOptions(vdraw->draw[windownumber]);CHKERRQ(ierr);
1115c6c1daeSBarry Smith   }
1125c6c1daeSBarry Smith   if (draw) *draw = vdraw->draw[windownumber];
1135c6c1daeSBarry Smith   if (draw) PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,-1);
1145c6c1daeSBarry Smith   PetscFunctionReturn(0);
1155c6c1daeSBarry Smith }
1165c6c1daeSBarry Smith 
1175c6c1daeSBarry Smith #undef __FUNCT__
1185c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawBaseAdd"
1195c6c1daeSBarry Smith /*@C
1205c6c1daeSBarry Smith     PetscViewerDrawBaseAdd - add to the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1215c6c1daeSBarry Smith 
1225c6c1daeSBarry Smith     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)
1235c6c1daeSBarry Smith 
1245c6c1daeSBarry Smith     Input Parameters:
1255c6c1daeSBarry Smith +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
1265c6c1daeSBarry Smith -   windownumber - how much to add to the base
1275c6c1daeSBarry Smith 
1285c6c1daeSBarry Smith     Level: developer
1295c6c1daeSBarry Smith 
1305c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
1315c6c1daeSBarry Smith    Concepts: graphics
1325c6c1daeSBarry Smith 
1335c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseSet()
1345c6c1daeSBarry Smith @*/
1355c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseAdd(PetscViewer viewer,PetscInt windownumber)
1365c6c1daeSBarry Smith {
1375c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
1385c6c1daeSBarry Smith   PetscErrorCode   ierr;
1395c6c1daeSBarry Smith   PetscBool        isdraw;
1405c6c1daeSBarry Smith 
1415c6c1daeSBarry Smith   PetscFunctionBegin;
1425c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1435c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1445c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
1455c6c1daeSBarry Smith   if (windownumber + vdraw->draw_base < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber+vdraw->draw_base);
1465c6c1daeSBarry Smith   vdraw->draw_base += windownumber;
1475c6c1daeSBarry Smith   PetscFunctionReturn(0);
1485c6c1daeSBarry Smith }
1495c6c1daeSBarry Smith 
1505c6c1daeSBarry Smith #undef __FUNCT__
1515c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawBaseSet"
1525c6c1daeSBarry Smith /*@C
1535c6c1daeSBarry Smith     PetscViewerDrawBaseSet - sets the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1545c6c1daeSBarry Smith 
1555c6c1daeSBarry Smith     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)
1565c6c1daeSBarry Smith 
1575c6c1daeSBarry Smith     Input Parameters:
1585c6c1daeSBarry Smith +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
1595c6c1daeSBarry Smith -   windownumber - value to set the base
1605c6c1daeSBarry Smith 
1615c6c1daeSBarry Smith     Level: developer
1625c6c1daeSBarry Smith 
1635c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
1645c6c1daeSBarry Smith    Concepts: graphics
1655c6c1daeSBarry Smith 
1665c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd()
1675c6c1daeSBarry Smith @*/
1685c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt windownumber)
1695c6c1daeSBarry Smith {
1705c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
1715c6c1daeSBarry Smith   PetscErrorCode   ierr;
1725c6c1daeSBarry Smith   PetscBool        isdraw;
1735c6c1daeSBarry Smith 
1745c6c1daeSBarry Smith   PetscFunctionBegin;
1755c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1765c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1775c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
1785c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber);
1795c6c1daeSBarry Smith   vdraw->draw_base = windownumber;
1805c6c1daeSBarry Smith   PetscFunctionReturn(0);
1815c6c1daeSBarry Smith }
1825c6c1daeSBarry Smith 
1835c6c1daeSBarry Smith #undef __FUNCT__
1845c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetDrawLG"
1855c6c1daeSBarry Smith /*@C
1865c6c1daeSBarry Smith     PetscViewerDrawGetDrawLG - Returns PetscDrawLG object from PetscViewer object.
1875c6c1daeSBarry Smith     This PetscDrawLG object may then be used to perform graphics using
1885c6c1daeSBarry Smith     PetscDrawLGXXX() commands.
1895c6c1daeSBarry Smith 
1905c6c1daeSBarry Smith     Not Collective (but PetscDrawLG object will be parallel if PetscViewer is)
1915c6c1daeSBarry Smith 
1925c6c1daeSBarry Smith     Input Parameter:
1935c6c1daeSBarry Smith +   PetscViewer - the PetscViewer (created with PetscViewerDrawOpen())
1945c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
1955c6c1daeSBarry Smith 
1965c6c1daeSBarry Smith     Ouput Parameter:
1975c6c1daeSBarry Smith .   draw - the draw line graph object
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith     Level: intermediate
2005c6c1daeSBarry Smith 
2015c6c1daeSBarry Smith   Concepts: line graph^accessing context
2025c6c1daeSBarry Smith 
2035c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
2045c6c1daeSBarry Smith @*/
2055c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawLG(PetscViewer viewer,PetscInt windownumber,PetscDrawLG *drawlg)
2065c6c1daeSBarry Smith {
2075c6c1daeSBarry Smith   PetscErrorCode   ierr;
2085c6c1daeSBarry Smith   PetscBool        isdraw;
2095c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
2105c6c1daeSBarry Smith 
2115c6c1daeSBarry Smith   PetscFunctionBegin;
2125c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2135c6c1daeSBarry Smith   PetscValidPointer(drawlg,3);
2145c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
2155c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
2165c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
2175c6c1daeSBarry Smith 
2185c6c1daeSBarry Smith   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
2190298fd71SBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr);
2205c6c1daeSBarry Smith   }
2215c6c1daeSBarry Smith   if (!vdraw->drawlg[windownumber+vdraw->draw_base]) {
2225c6c1daeSBarry Smith     ierr = PetscDrawLGCreate(vdraw->draw[windownumber+vdraw->draw_base],1,&vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2235c6c1daeSBarry Smith     ierr = PetscLogObjectParent(viewer,vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2245c6c1daeSBarry Smith   }
2255c6c1daeSBarry Smith   *drawlg = vdraw->drawlg[windownumber+vdraw->draw_base];
2265c6c1daeSBarry Smith   PetscFunctionReturn(0);
2275c6c1daeSBarry Smith }
2285c6c1daeSBarry Smith 
2295c6c1daeSBarry Smith #undef __FUNCT__
2305c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetDrawAxis"
2315c6c1daeSBarry Smith /*@C
2325c6c1daeSBarry Smith     PetscViewerDrawGetDrawAxis - Returns PetscDrawAxis object from PetscViewer object.
2335c6c1daeSBarry Smith     This PetscDrawAxis object may then be used to perform graphics using
2345c6c1daeSBarry Smith     PetscDrawAxisXXX() commands.
2355c6c1daeSBarry Smith 
2365c6c1daeSBarry Smith     Not Collective (but PetscDrawAxis object will be parallel if PetscViewer is)
2375c6c1daeSBarry Smith 
2385c6c1daeSBarry Smith     Input Parameter:
2395c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen()
2405c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
2415c6c1daeSBarry Smith 
2425c6c1daeSBarry Smith     Ouput Parameter:
2435c6c1daeSBarry Smith .   drawaxis - the draw axis object
2445c6c1daeSBarry Smith 
2455c6c1daeSBarry Smith     Level: advanced
2465c6c1daeSBarry Smith 
2475c6c1daeSBarry Smith   Concepts: line graph^accessing context
2485c6c1daeSBarry Smith 
2495c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetLG(), PetscViewerDrawOpen()
2505c6c1daeSBarry Smith @*/
2515c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawAxis(PetscViewer viewer,PetscInt windownumber,PetscDrawAxis *drawaxis)
2525c6c1daeSBarry Smith {
2535c6c1daeSBarry Smith   PetscErrorCode   ierr;
2545c6c1daeSBarry Smith   PetscBool        isdraw;
2555c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;;
2565c6c1daeSBarry Smith 
2575c6c1daeSBarry Smith   PetscFunctionBegin;
2585c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2595c6c1daeSBarry Smith   PetscValidPointer(drawaxis,3);
2605c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
2615c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
2625c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
2635c6c1daeSBarry Smith 
2645c6c1daeSBarry Smith   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
2650298fd71SBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr);
2665c6c1daeSBarry Smith   }
2675c6c1daeSBarry Smith   if (!vdraw->drawaxis[windownumber+vdraw->draw_base]) {
2685c6c1daeSBarry Smith     ierr = PetscDrawAxisCreate(vdraw->draw[windownumber+vdraw->draw_base],&vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2695c6c1daeSBarry Smith     ierr = PetscLogObjectParent(viewer,vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2705c6c1daeSBarry Smith   }
2715c6c1daeSBarry Smith   *drawaxis = vdraw->drawaxis[windownumber+vdraw->draw_base];
2725c6c1daeSBarry Smith   PetscFunctionReturn(0);
2735c6c1daeSBarry Smith }
2745c6c1daeSBarry Smith 
2755c6c1daeSBarry Smith #undef __FUNCT__
2765c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawResize"
2775c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawResize(PetscViewer v,int w,int h)
2785c6c1daeSBarry Smith {
2795c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
2805c6c1daeSBarry Smith 
2815c6c1daeSBarry Smith   PetscFunctionBegin;
2825c6c1daeSBarry Smith   vdraw->h = h;
2835c6c1daeSBarry Smith   vdraw->w = w;
2845c6c1daeSBarry Smith   PetscFunctionReturn(0);
2855c6c1daeSBarry Smith }
2865c6c1daeSBarry Smith 
2875c6c1daeSBarry Smith #undef __FUNCT__
2885c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawSetInfo"
2895c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetInfo(PetscViewer v,const char display[],const char title[],int x,int y,int w,int h)
2905c6c1daeSBarry Smith {
2915c6c1daeSBarry Smith   PetscErrorCode   ierr;
2925c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
2935c6c1daeSBarry Smith 
2945c6c1daeSBarry Smith   PetscFunctionBegin;
2955c6c1daeSBarry Smith   vdraw->h = h;
2965c6c1daeSBarry Smith   vdraw->w = w;
2975c6c1daeSBarry Smith   ierr     = PetscStrallocpy(display,&vdraw->display);CHKERRQ(ierr);
2985c6c1daeSBarry Smith   ierr     = PetscStrallocpy(title,&vdraw->title);CHKERRQ(ierr);
2995c6c1daeSBarry Smith   PetscFunctionReturn(0);
3005c6c1daeSBarry Smith }
3015c6c1daeSBarry Smith 
3025c6c1daeSBarry Smith #undef __FUNCT__
3035c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawOpen"
3045c6c1daeSBarry Smith /*@C
3055c6c1daeSBarry Smith    PetscViewerDrawOpen - Opens a window for use as a PetscViewer. If you want to
3065c6c1daeSBarry Smith    do graphics in this window, you must call PetscViewerDrawGetDraw() and
3075c6c1daeSBarry Smith    perform the graphics on the PetscDraw object.
3085c6c1daeSBarry Smith 
3095c6c1daeSBarry Smith    Collective on MPI_Comm
3105c6c1daeSBarry Smith 
3115c6c1daeSBarry Smith    Input Parameters:
3125c6c1daeSBarry Smith +  comm - communicator that will share window
3135c6c1daeSBarry Smith .  display - the X display on which to open, or null for the local machine
3145c6c1daeSBarry Smith .  title - the title to put in the title bar, or null for no title
3155c6c1daeSBarry Smith .  x, y - the screen coordinates of the upper left corner of window, or use PETSC_DECIDE
3165c6c1daeSBarry Smith -  w, h - window width and height in pixels, or may use PETSC_DECIDE or PETSC_DRAW_FULL_SIZE, PETSC_DRAW_HALF_SIZE,
3175c6c1daeSBarry Smith           PETSC_DRAW_THIRD_SIZE, PETSC_DRAW_QUARTER_SIZE
3185c6c1daeSBarry Smith 
3195c6c1daeSBarry Smith    Output Parameters:
3205c6c1daeSBarry Smith . viewer - the PetscViewer
3215c6c1daeSBarry Smith 
3225c6c1daeSBarry Smith    Format Options:
3235c6c1daeSBarry Smith +  PETSC_VIEWER_DRAW_BASIC - displays with basic format
3245c6c1daeSBarry Smith -  PETSC_VIEWER_DRAW_LG    - displays using a line graph
3255c6c1daeSBarry Smith 
3265c6c1daeSBarry Smith    Options Database Keys:
3275c6c1daeSBarry Smith    PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual page for
3285c6c1daeSBarry Smith    PetscDrawCreate() for runtime options, including
3295c6c1daeSBarry Smith +  -draw_type x or null
3305c6c1daeSBarry Smith .  -nox - Disables all x-windows output
3315c6c1daeSBarry Smith .  -display <name> - Specifies name of machine for the X display
3325c6c1daeSBarry Smith .  -geometry <x,y,w,h> - allows setting the window location and size
3335c6c1daeSBarry Smith -  -draw_pause <pause> - Sets time (in seconds) that the
3345c6c1daeSBarry Smith      program pauses after PetscDrawPause() has been called
3355c6c1daeSBarry Smith      (0 is default, -1 implies until user input).
3365c6c1daeSBarry Smith 
3375c6c1daeSBarry Smith    Level: beginner
3385c6c1daeSBarry Smith 
3395c6c1daeSBarry Smith    Note for Fortran Programmers:
3405c6c1daeSBarry Smith    Whenever indicating null character data in a Fortran code,
3410298fd71SBarry Smith    NULL_CHARACTER must be employed; using NULL is not
3420298fd71SBarry Smith    correct for character data!  Thus, NULL_CHARACTER can be
3435c6c1daeSBarry Smith    used for the display and title input parameters.
3445c6c1daeSBarry Smith 
3455c6c1daeSBarry Smith   Concepts: graphics^opening PetscViewer
3465c6c1daeSBarry Smith   Concepts: drawing^opening PetscViewer
3475c6c1daeSBarry Smith 
3485c6c1daeSBarry Smith 
3495c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
3505c6c1daeSBarry Smith           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
3515c6c1daeSBarry Smith @*/
3525c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
3535c6c1daeSBarry Smith {
3545c6c1daeSBarry Smith   PetscErrorCode ierr;
3555c6c1daeSBarry Smith 
3565c6c1daeSBarry Smith   PetscFunctionBegin;
3575c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
3585c6c1daeSBarry Smith   ierr = PetscViewerSetType(*viewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
3595c6c1daeSBarry Smith   ierr = PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);CHKERRQ(ierr);
3605c6c1daeSBarry Smith   PetscFunctionReturn(0);
3615c6c1daeSBarry Smith }
3625c6c1daeSBarry Smith 
3635c6c1daeSBarry Smith #undef __FUNCT__
3645c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetSingleton_Draw"
3655c6c1daeSBarry Smith PetscErrorCode PetscViewerGetSingleton_Draw(PetscViewer viewer,PetscViewer *sviewer)
3665c6c1daeSBarry Smith {
3675c6c1daeSBarry Smith   PetscErrorCode   ierr;
3685c6c1daeSBarry Smith   PetscMPIInt      rank;
3695c6c1daeSBarry Smith   PetscInt         i;
3705c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*vsdraw;
3715c6c1daeSBarry Smith 
3725c6c1daeSBarry Smith   PetscFunctionBegin;
3735c6c1daeSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get singleton without first restoring previous");
3745c6c1daeSBarry Smith 
3755c6c1daeSBarry Smith   /* only processor zero can use the PetscViewer draw singleton */
376*ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
3775c6c1daeSBarry Smith   if (!rank) {
3785c6c1daeSBarry Smith     ierr   = PetscViewerCreate(PETSC_COMM_SELF,sviewer);CHKERRQ(ierr);
3795c6c1daeSBarry Smith     ierr   = PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
3805c6c1daeSBarry Smith     vsdraw = (PetscViewer_Draw*)(*sviewer)->data;
3815c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
3825c6c1daeSBarry Smith       if (vdraw->draw[i]) {
3835c6c1daeSBarry Smith         ierr = PetscDrawGetSingleton(vdraw->draw[i],&vsdraw->draw[i]);CHKERRQ(ierr);
3845c6c1daeSBarry Smith       }
3855c6c1daeSBarry Smith     }
3865c6c1daeSBarry Smith   }
3875c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_TRUE;
3885c6c1daeSBarry Smith   PetscFunctionReturn(0);
3895c6c1daeSBarry Smith }
3905c6c1daeSBarry Smith 
3915c6c1daeSBarry Smith #undef __FUNCT__
3925c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRestoreSingleton_Draw"
3935c6c1daeSBarry Smith PetscErrorCode PetscViewerRestoreSingleton_Draw(PetscViewer viewer,PetscViewer *sviewer)
3945c6c1daeSBarry Smith {
3955c6c1daeSBarry Smith   PetscErrorCode   ierr;
3965c6c1daeSBarry Smith   PetscMPIInt      rank;
3975c6c1daeSBarry Smith   PetscInt         i;
3985c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*vsdraw;
3995c6c1daeSBarry Smith 
4005c6c1daeSBarry Smith   PetscFunctionBegin;
4015c6c1daeSBarry Smith   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
402*ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
4035c6c1daeSBarry Smith   if (!rank) {
4045c6c1daeSBarry Smith     vsdraw = (PetscViewer_Draw*)(*sviewer)->data;
4055c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
4065c6c1daeSBarry Smith       if (vdraw->draw[i] && vsdraw->draw[i]) {
4075c6c1daeSBarry Smith         ierr = PetscDrawRestoreSingleton(vdraw->draw[i],&vsdraw->draw[i]);CHKERRQ(ierr);
4085c6c1daeSBarry Smith       }
4095c6c1daeSBarry Smith     }
4105c6c1daeSBarry Smith     ierr = PetscFree3(vsdraw->draw,vsdraw->drawlg,vsdraw->drawaxis);CHKERRQ(ierr);
4115c6c1daeSBarry Smith     ierr = PetscFree((*sviewer)->data);CHKERRQ(ierr);
4125c6c1daeSBarry Smith     ierr = PetscHeaderDestroy(sviewer);CHKERRQ(ierr);
4135c6c1daeSBarry Smith   }
4145c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
4155c6c1daeSBarry Smith   PetscFunctionReturn(0);
4165c6c1daeSBarry Smith }
4175c6c1daeSBarry Smith 
418e9457bf7SBarry Smith #undef __FUNCT__
419e9457bf7SBarry Smith #define __FUNCT__ "PetscViewerSetFromOptions_Draw"
420e9457bf7SBarry Smith PetscErrorCode PetscViewerSetFromOptions_Draw(PetscViewer v)
421e9457bf7SBarry Smith {
422e9457bf7SBarry Smith   PetscErrorCode ierr;
423e9457bf7SBarry Smith   PetscReal      bounds[16];
424e9457bf7SBarry Smith   PetscInt       nbounds = 16;
425e9457bf7SBarry Smith   PetscBool      flg;
426e9457bf7SBarry Smith 
427e9457bf7SBarry Smith   PetscFunctionBegin;
428e9457bf7SBarry Smith   ierr = PetscOptionsHead("Draw PetscViewer Options");CHKERRQ(ierr);
429e9457bf7SBarry Smith   ierr = PetscOptionsRealArray("-draw_bounds","Bounds to put on plots axis","PetscViewerDrawSetBounds",bounds,&nbounds,&flg);CHKERRQ(ierr);
430e9457bf7SBarry Smith   if (flg) {
431e9457bf7SBarry Smith     ierr = PetscViewerDrawSetBounds(v,nbounds/2,bounds);CHKERRQ(ierr);
432e9457bf7SBarry Smith   }
433e9457bf7SBarry Smith 
434e9457bf7SBarry Smith   ierr = PetscOptionsTail();CHKERRQ(ierr);
435e9457bf7SBarry Smith   PetscFunctionReturn(0);
436e9457bf7SBarry Smith }
437e9457bf7SBarry Smith 
4385c6c1daeSBarry Smith EXTERN_C_BEGIN
4395c6c1daeSBarry Smith #undef __FUNCT__
4405c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate_Draw"
4415c6c1daeSBarry Smith PetscErrorCode  PetscViewerCreate_Draw(PetscViewer viewer)
4425c6c1daeSBarry Smith {
4435c6c1daeSBarry Smith   PetscInt         i;
4445c6c1daeSBarry Smith   PetscErrorCode   ierr;
4455c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
4465c6c1daeSBarry Smith 
4475c6c1daeSBarry Smith   PetscFunctionBegin;
4485c6c1daeSBarry Smith   ierr         = PetscNewLog(viewer,PetscViewer_Draw,&vdraw);CHKERRQ(ierr);
4495c6c1daeSBarry Smith   viewer->data = (void*)vdraw;
4505c6c1daeSBarry Smith 
4515c6c1daeSBarry Smith   viewer->ops->flush            = PetscViewerFlush_Draw;
4525c6c1daeSBarry Smith   viewer->ops->destroy          = PetscViewerDestroy_Draw;
453e9457bf7SBarry Smith   viewer->ops->setfromoptions   = PetscViewerSetFromOptions_Draw;
4545c6c1daeSBarry Smith   viewer->ops->getsingleton     = PetscViewerGetSingleton_Draw;
4555c6c1daeSBarry Smith   viewer->ops->restoresingleton = PetscViewerRestoreSingleton_Draw;
4565c6c1daeSBarry Smith   viewer->format                = PETSC_VIEWER_NOFORMAT;
4575c6c1daeSBarry Smith 
4585c6c1daeSBarry Smith   /* these are created on the fly if requested */
4595c6c1daeSBarry Smith   vdraw->draw_max  = 5;
4605c6c1daeSBarry Smith   vdraw->draw_base = 0;
461ccad63c3SBarry Smith   vdraw->w         = PETSC_DECIDE;
462ccad63c3SBarry Smith   vdraw->h         = PETSC_DECIDE;
463a297a907SKarl Rupp 
4645c6c1daeSBarry Smith   ierr = PetscMalloc3(vdraw->draw_max,PetscDraw,&vdraw->draw,vdraw->draw_max,PetscDrawLG,&vdraw->drawlg,vdraw->draw_max,PetscDrawAxis,&vdraw->drawaxis);CHKERRQ(ierr);
4655c6c1daeSBarry Smith   ierr = PetscMemzero(vdraw->draw,vdraw->draw_max*sizeof(PetscDraw));CHKERRQ(ierr);
4665c6c1daeSBarry Smith   ierr = PetscMemzero(vdraw->drawlg,vdraw->draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr);
4675c6c1daeSBarry Smith   ierr = PetscMemzero(vdraw->drawaxis,vdraw->draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr);
4685c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
4695c6c1daeSBarry Smith     vdraw->draw[i]     = 0;
4705c6c1daeSBarry Smith     vdraw->drawlg[i]   = 0;
4715c6c1daeSBarry Smith     vdraw->drawaxis[i] = 0;
4725c6c1daeSBarry Smith   }
4735c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
4745c6c1daeSBarry Smith   PetscFunctionReturn(0);
4755c6c1daeSBarry Smith }
4765c6c1daeSBarry Smith EXTERN_C_END
4775c6c1daeSBarry Smith 
4785c6c1daeSBarry Smith #undef __FUNCT__
4795c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawClear"
4805c6c1daeSBarry Smith /*@
4815c6c1daeSBarry Smith     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.
4825c6c1daeSBarry Smith 
4835c6c1daeSBarry Smith     Not Collective
4845c6c1daeSBarry Smith 
4855c6c1daeSBarry Smith     Input Parameter:
4865c6c1daeSBarry Smith .  viewer - the PetscViewer
4875c6c1daeSBarry Smith 
4885c6c1daeSBarry Smith     Level: intermediate
4895c6c1daeSBarry Smith 
4905c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
4915c6c1daeSBarry Smith 
4925c6c1daeSBarry Smith @*/
4935c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
4945c6c1daeSBarry Smith {
4955c6c1daeSBarry Smith   PetscErrorCode   ierr;
4965c6c1daeSBarry Smith   PetscInt         i;
4975c6c1daeSBarry Smith   PetscBool        isdraw;
4985c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
4995c6c1daeSBarry Smith 
5005c6c1daeSBarry Smith   PetscFunctionBegin;
5015c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
5025c6c1daeSBarry Smith   if (isdraw) {
5035c6c1daeSBarry Smith     vdraw = (PetscViewer_Draw*)viewer->data;
5045c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
5055c6c1daeSBarry Smith       if (vdraw->draw[i]) {ierr = PetscDrawClear(vdraw->draw[i]);CHKERRQ(ierr);}
5065c6c1daeSBarry Smith     }
5075c6c1daeSBarry Smith   }
5085c6c1daeSBarry Smith   PetscFunctionReturn(0);
5095c6c1daeSBarry Smith }
5105c6c1daeSBarry Smith 
5115c6c1daeSBarry Smith #undef __FUNCT__
5125c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetPause"
5135c6c1daeSBarry Smith /*@
5145c6c1daeSBarry Smith     PetscViewerDrawGetPause - Gets a pause for the first present draw
5155c6c1daeSBarry Smith 
5165c6c1daeSBarry Smith     Not Collective
5175c6c1daeSBarry Smith 
5185c6c1daeSBarry Smith     Input Parameter:
5195c6c1daeSBarry Smith .  viewer - the PetscViewer
5205c6c1daeSBarry Smith 
5215c6c1daeSBarry Smith     Output Parameter:
5225c6c1daeSBarry Smith .  pause - the pause value
5235c6c1daeSBarry Smith 
5245c6c1daeSBarry Smith     Level: intermediate
5255c6c1daeSBarry Smith 
5265c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5275c6c1daeSBarry Smith 
5285c6c1daeSBarry Smith @*/
5295c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
5305c6c1daeSBarry Smith {
5315c6c1daeSBarry Smith   PetscErrorCode   ierr;
5325c6c1daeSBarry Smith   PetscInt         i;
5335c6c1daeSBarry Smith   PetscBool        isdraw;
5345c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
5355c6c1daeSBarry Smith   PetscDraw        draw;
5365c6c1daeSBarry Smith 
5375c6c1daeSBarry Smith   PetscFunctionBegin;
5385c6c1daeSBarry Smith   ierr   = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
5395c6c1daeSBarry Smith   *pause = 0.0;
5405c6c1daeSBarry Smith   if (isdraw) {
5415c6c1daeSBarry Smith     vdraw = (PetscViewer_Draw*)viewer->data;
5425c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
5435c6c1daeSBarry Smith       if (vdraw->draw[i]) {
5445c6c1daeSBarry Smith         ierr = PetscDrawGetPause(vdraw->draw[i],pause);CHKERRQ(ierr);
5455c6c1daeSBarry Smith         PetscFunctionReturn(0);
5465c6c1daeSBarry Smith       }
5475c6c1daeSBarry Smith     }
5485c6c1daeSBarry Smith     /* none exist yet so create one and get its pause */
5495c6c1daeSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
5505c6c1daeSBarry Smith     ierr = PetscDrawGetPause(vdraw->draw[0],pause);CHKERRQ(ierr);
5515c6c1daeSBarry Smith   }
5525c6c1daeSBarry Smith   PetscFunctionReturn(0);
5535c6c1daeSBarry Smith }
5545c6c1daeSBarry Smith 
5555c6c1daeSBarry Smith #undef __FUNCT__
5565c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawSetPause"
5575c6c1daeSBarry Smith /*@
5585c6c1daeSBarry Smith     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer
5595c6c1daeSBarry Smith 
5605c6c1daeSBarry Smith     Not Collective
5615c6c1daeSBarry Smith 
5625c6c1daeSBarry Smith     Input Parameters:
5635c6c1daeSBarry Smith +  viewer - the PetscViewer
5645c6c1daeSBarry Smith -  pause - the pause value
5655c6c1daeSBarry Smith 
5665c6c1daeSBarry Smith     Level: intermediate
5675c6c1daeSBarry Smith 
5685c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5695c6c1daeSBarry Smith 
5705c6c1daeSBarry Smith @*/
5715c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
5725c6c1daeSBarry Smith {
5735c6c1daeSBarry Smith   PetscErrorCode   ierr;
5745c6c1daeSBarry Smith   PetscInt         i;
5755c6c1daeSBarry Smith   PetscBool        isdraw;
5765c6c1daeSBarry Smith 
5775c6c1daeSBarry Smith   PetscFunctionBegin;
5785c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
5795c6c1daeSBarry Smith   if (isdraw) {
580afe78b3cSBarry Smith     PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
581afe78b3cSBarry Smith 
582afe78b3cSBarry Smith     vdraw->pause = pause;
5835c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
5845c6c1daeSBarry Smith       if (vdraw->draw[i]) {ierr = PetscDrawSetPause(vdraw->draw[i],pause);CHKERRQ(ierr);}
5855c6c1daeSBarry Smith     }
5865c6c1daeSBarry Smith   }
5875c6c1daeSBarry Smith   PetscFunctionReturn(0);
5885c6c1daeSBarry Smith }
5895c6c1daeSBarry Smith 
5905c6c1daeSBarry Smith 
5915c6c1daeSBarry Smith #undef __FUNCT__
5925c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawSetHold"
5935c6c1daeSBarry Smith /*@
5945c6c1daeSBarry Smith     PetscViewerDrawSetHold - Holds previous image when drawing new image
5955c6c1daeSBarry Smith 
5965c6c1daeSBarry Smith     Not Collective
5975c6c1daeSBarry Smith 
5985c6c1daeSBarry Smith     Input Parameters:
5995c6c1daeSBarry Smith +  viewer - the PetscViewer
6005c6c1daeSBarry Smith -  hold - indicates to hold or not
6015c6c1daeSBarry Smith 
6025c6c1daeSBarry Smith     Level: intermediate
6035c6c1daeSBarry Smith 
6045c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6055c6c1daeSBarry Smith 
6065c6c1daeSBarry Smith @*/
6075c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
6085c6c1daeSBarry Smith {
6095c6c1daeSBarry Smith   PetscErrorCode   ierr;
6105c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
6115c6c1daeSBarry Smith   PetscBool        isdraw;
6125c6c1daeSBarry Smith 
6135c6c1daeSBarry Smith   PetscFunctionBegin;
6145c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
6155c6c1daeSBarry Smith   if (isdraw) {
6165c6c1daeSBarry Smith     vdraw       = (PetscViewer_Draw*)viewer->data;
6175c6c1daeSBarry Smith     vdraw->hold = hold;
6185c6c1daeSBarry Smith   }
6195c6c1daeSBarry Smith   PetscFunctionReturn(0);
6205c6c1daeSBarry Smith }
6215c6c1daeSBarry Smith 
6225c6c1daeSBarry Smith #undef __FUNCT__
6235c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetHold"
6245c6c1daeSBarry Smith /*@
6255c6c1daeSBarry Smith     PetscViewerDrawGetHold - Holds previous image when drawing new image
6265c6c1daeSBarry Smith 
6275c6c1daeSBarry Smith     Not Collective
6285c6c1daeSBarry Smith 
6295c6c1daeSBarry Smith     Input Parameter:
6305c6c1daeSBarry Smith .  viewer - the PetscViewer
6315c6c1daeSBarry Smith 
6325c6c1daeSBarry Smith     Output Parameter:
6335c6c1daeSBarry Smith .  hold - indicates to hold or not
6345c6c1daeSBarry Smith 
6355c6c1daeSBarry Smith     Level: intermediate
6365c6c1daeSBarry Smith 
6375c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6385c6c1daeSBarry Smith 
6395c6c1daeSBarry Smith @*/
6405c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
6415c6c1daeSBarry Smith {
6425c6c1daeSBarry Smith   PetscErrorCode   ierr;
6435c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
6445c6c1daeSBarry Smith   PetscBool        isdraw;
6455c6c1daeSBarry Smith 
6465c6c1daeSBarry Smith   PetscFunctionBegin;
6475c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
6485c6c1daeSBarry Smith   if (isdraw) {
6495c6c1daeSBarry Smith     vdraw = (PetscViewer_Draw*)viewer->data;
6505c6c1daeSBarry Smith     *hold = vdraw->hold;
6515c6c1daeSBarry Smith   }
6525c6c1daeSBarry Smith   PetscFunctionReturn(0);
6535c6c1daeSBarry Smith }
6545c6c1daeSBarry Smith 
6555c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
6565c6c1daeSBarry Smith /*
6575c6c1daeSBarry Smith     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
6585c6c1daeSBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
6595c6c1daeSBarry Smith */
6605c6c1daeSBarry Smith static PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;
6615c6c1daeSBarry Smith 
6625c6c1daeSBarry Smith #undef __FUNCT__
6635c6c1daeSBarry Smith #define __FUNCT__ "PETSC_VIEWER_DRAW_"
6645c6c1daeSBarry Smith /*@C
6655c6c1daeSBarry Smith     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors
6665c6c1daeSBarry Smith                      in a communicator.
6675c6c1daeSBarry Smith 
6685c6c1daeSBarry Smith      Collective on MPI_Comm
6695c6c1daeSBarry Smith 
6705c6c1daeSBarry Smith      Input Parameter:
6715c6c1daeSBarry Smith .    comm - the MPI communicator to share the window PetscViewer
6725c6c1daeSBarry Smith 
6735c6c1daeSBarry Smith      Level: intermediate
6745c6c1daeSBarry Smith 
6755c6c1daeSBarry Smith      Notes:
6765c6c1daeSBarry Smith      Unlike almost all other PETSc routines, PETSC_VIEWER_DRAW_ does not return
6775c6c1daeSBarry Smith      an error code.  The window is usually used in the form
6785c6c1daeSBarry Smith $       XXXView(XXX object,PETSC_VIEWER_DRAW_(comm));
6795c6c1daeSBarry Smith 
6805c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(),
6815c6c1daeSBarry Smith @*/
6825c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
6835c6c1daeSBarry Smith {
6845c6c1daeSBarry Smith   PetscErrorCode ierr;
6855c6c1daeSBarry Smith   PetscMPIInt    flag;
6865c6c1daeSBarry Smith   PetscViewer    viewer;
6875c6c1daeSBarry Smith   MPI_Comm       ncomm;
6885c6c1daeSBarry Smith 
6895c6c1daeSBarry Smith   PetscFunctionBegin;
6900298fd71SBarry Smith   ierr = PetscCommDuplicate(comm,&ncomm,NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
6915c6c1daeSBarry Smith   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
6925c6c1daeSBarry Smith     ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,MPI_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,0);
6935c6c1daeSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
6945c6c1daeSBarry Smith   }
6955c6c1daeSBarry Smith   ierr = MPI_Attr_get(ncomm,Petsc_Viewer_Draw_keyval,(void**)&viewer,&flag);
6965c6c1daeSBarry Smith   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
6975c6c1daeSBarry Smith   if (!flag) { /* PetscViewer not yet created */
6985c6c1daeSBarry Smith     ierr = PetscViewerDrawOpen(ncomm,0,0,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
6995c6c1daeSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7005c6c1daeSBarry Smith     ierr = PetscObjectRegisterDestroy((PetscObject)viewer);
7015c6c1daeSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7025c6c1daeSBarry Smith     ierr = MPI_Attr_put(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
7035c6c1daeSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7045c6c1daeSBarry Smith   }
7055c6c1daeSBarry Smith   ierr = PetscCommDestroy(&ncomm);
7065c6c1daeSBarry Smith   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7075c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
7085c6c1daeSBarry Smith }
7095c6c1daeSBarry Smith 
7105c6c1daeSBarry Smith #undef __FUNCT__
7115c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawSetBounds"
7125c6c1daeSBarry Smith /*@
7135c6c1daeSBarry Smith     PetscViewerDrawSetBounds - sets the upper and lower bounds to be used in plotting
7145c6c1daeSBarry Smith 
7155c6c1daeSBarry Smith     Collective on PetscViewer
7165c6c1daeSBarry Smith 
7175c6c1daeSBarry Smith     Input Parameters:
7185c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
7195c6c1daeSBarry Smith .   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
7205c6c1daeSBarry Smith -   bounds - the actual bounds, the size of this is 2*nbounds, the values are stored in the order min F_0, max F_0, min F_1, max F_1, .....
7215c6c1daeSBarry Smith 
722e9457bf7SBarry Smith 
723e9457bf7SBarry Smith     Options Database:
724e9457bf7SBarry Smith .   -draw_bounds  minF0,maxF0,minF1,maxF1
725e9457bf7SBarry Smith 
7265c6c1daeSBarry Smith     Level: intermediate
7275c6c1daeSBarry Smith 
728f3f0eb19SBarry Smith     Notes: this determines the colors used in 2d contour plots generated with VecView() for DMDA in 2d. Any values in the vector below or above the
729f3f0eb19SBarry Smith       bounds are moved to the bound value before plotting. In this way the color index from color to physical value remains the same for all plots generated with
730f3f0eb19SBarry Smith       this viewer. Otherwise the color to physical value meaning changes with each new image if this is not set.
731f3f0eb19SBarry Smith 
7325c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
7335c6c1daeSBarry Smith    Concepts: graphics
7345c6c1daeSBarry Smith 
7355c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
7365c6c1daeSBarry Smith @*/
7375c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
7385c6c1daeSBarry Smith {
7395c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
7405c6c1daeSBarry Smith   PetscErrorCode   ierr;
7415c6c1daeSBarry Smith 
7425c6c1daeSBarry Smith 
7435c6c1daeSBarry Smith   PetscFunctionBegin;
7445c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7455c6c1daeSBarry Smith   vdraw->nbounds = nbounds;
746a297a907SKarl Rupp 
7475c6c1daeSBarry Smith   ierr = PetscMalloc(2*nbounds*sizeof(PetscReal),&vdraw->bounds);CHKERRQ(ierr);
7485c6c1daeSBarry Smith   ierr = PetscMemcpy(vdraw->bounds,bounds,2*nbounds*sizeof(PetscReal));CHKERRQ(ierr);
7495c6c1daeSBarry Smith   PetscFunctionReturn(0);
7505c6c1daeSBarry Smith }
7515c6c1daeSBarry Smith 
7525c6c1daeSBarry Smith #undef __FUNCT__
7535c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDrawGetBounds"
7545c6c1daeSBarry Smith /*@C
7555c6c1daeSBarry Smith     PetscViewerDrawGetBounds - gets the upper and lower bounds to be used in plotting set with PetscViewerDrawSetBounds()
7565c6c1daeSBarry Smith 
7575c6c1daeSBarry Smith     Collective on PetscViewer
7585c6c1daeSBarry Smith 
7595c6c1daeSBarry Smith     Input Parameter:
7605c6c1daeSBarry Smith .   viewer - the PetscViewer (created with PetscViewerDrawOpen())
7615c6c1daeSBarry Smith 
7625c6c1daeSBarry Smith     Output Paramters:
7635c6c1daeSBarry Smith +   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
7645c6c1daeSBarry Smith -   bounds - the actual bounds, the size of this is 2*nbounds, the values are stored in the order min F_0, max F_0, min F_1, max F_1, .....
7655c6c1daeSBarry Smith 
7665c6c1daeSBarry Smith     Level: intermediate
7675c6c1daeSBarry Smith 
7685c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
7695c6c1daeSBarry Smith    Concepts: graphics
7705c6c1daeSBarry Smith 
771f3f0eb19SBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawSetBounds()
7725c6c1daeSBarry Smith @*/
7735c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
7745c6c1daeSBarry Smith {
7755c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
7765c6c1daeSBarry Smith 
7775c6c1daeSBarry Smith   PetscFunctionBegin;
7785c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7795c6c1daeSBarry Smith   *nbounds = vdraw->nbounds;
7805c6c1daeSBarry Smith   *bounds  = vdraw->bounds;
7815c6c1daeSBarry Smith   PetscFunctionReturn(0);
7825c6c1daeSBarry Smith }
783