xref: /petsc/src/sys/classes/viewer/impls/draw/drawv.c (revision 1f49e1f73dad464759f4f6edc53861b4418ff9ce)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith #include <../src/sys/classes/viewer/impls/draw/vdraw.h> /*I "petscdraw.h" I*/
3665c2dedSJed Brown #include <petscviewer.h>                                /*I "petscviewer.h" I*/
45c6c1daeSBarry Smith 
5e0877f53SBarry Smith static PetscErrorCode PetscViewerDestroy_Draw(PetscViewer v)
65c6c1daeSBarry Smith {
75c6c1daeSBarry Smith   PetscErrorCode   ierr;
85c6c1daeSBarry Smith   PetscInt         i;
95c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
105c6c1daeSBarry Smith 
115c6c1daeSBarry Smith   PetscFunctionBegin;
125c6c1daeSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Destroying PetscViewer without first restoring singleton");
135c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
145c6c1daeSBarry Smith     ierr = PetscDrawAxisDestroy(&vdraw->drawaxis[i]);CHKERRQ(ierr);
155c6c1daeSBarry Smith     ierr = PetscDrawLGDestroy(&vdraw->drawlg[i]);CHKERRQ(ierr);
165c6c1daeSBarry Smith     ierr = PetscDrawDestroy(&vdraw->draw[i]);CHKERRQ(ierr);
175c6c1daeSBarry Smith   }
185c6c1daeSBarry Smith   ierr = PetscFree(vdraw->display);CHKERRQ(ierr);
195c6c1daeSBarry Smith   ierr = PetscFree(vdraw->title);CHKERRQ(ierr);
205c6c1daeSBarry Smith   ierr = PetscFree3(vdraw->draw,vdraw->drawlg,vdraw->drawaxis);CHKERRQ(ierr);
215c6c1daeSBarry Smith   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
22d1da0b69SBarry Smith   ierr = PetscFree(vdraw->drawtype);CHKERRQ(ierr);
23e5ab1681SLisandro Dalcin   ierr = PetscFree(v->data);CHKERRQ(ierr);
245c6c1daeSBarry Smith   PetscFunctionReturn(0);
255c6c1daeSBarry Smith }
265c6c1daeSBarry Smith 
27e0877f53SBarry Smith static PetscErrorCode PetscViewerFlush_Draw(PetscViewer v)
285c6c1daeSBarry Smith {
295c6c1daeSBarry Smith   PetscErrorCode   ierr;
305c6c1daeSBarry Smith   PetscInt         i;
315c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
325c6c1daeSBarry Smith 
335c6c1daeSBarry Smith   PetscFunctionBegin;
345c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
355b399a63SLisandro Dalcin     if (vdraw->draw[i]) {ierr = PetscDrawFlush(vdraw->draw[i]);CHKERRQ(ierr);}
365c6c1daeSBarry Smith   }
375c6c1daeSBarry Smith   PetscFunctionReturn(0);
385c6c1daeSBarry Smith }
395c6c1daeSBarry Smith 
405c6c1daeSBarry Smith /*@C
415c6c1daeSBarry Smith     PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object.
425c6c1daeSBarry Smith     This PetscDraw object may then be used to perform graphics using
435c6c1daeSBarry Smith     PetscDrawXXX() commands.
445c6c1daeSBarry Smith 
45d94959e9SLisandro Dalcin     Collective on PetscViewer
465c6c1daeSBarry Smith 
475c6c1daeSBarry Smith     Input Parameters:
485c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
495c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
505c6c1daeSBarry Smith 
515c6c1daeSBarry Smith     Ouput Parameter:
525c6c1daeSBarry Smith .   draw - the draw object
535c6c1daeSBarry Smith 
545c6c1daeSBarry Smith     Level: intermediate
555c6c1daeSBarry Smith 
565c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
575c6c1daeSBarry Smith    Concepts: graphics
585c6c1daeSBarry Smith 
595c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
605c6c1daeSBarry Smith @*/
615c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt windownumber,PetscDraw *draw)
625c6c1daeSBarry Smith {
63e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
645c6c1daeSBarry Smith   PetscErrorCode   ierr;
655c6c1daeSBarry Smith   PetscBool        isdraw;
665c6c1daeSBarry Smith 
675c6c1daeSBarry Smith   PetscFunctionBegin;
685c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
69e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
705c6c1daeSBarry Smith   if (draw) PetscValidPointer(draw,3);
715c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
725c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
735c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
74e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
75e5ab1681SLisandro Dalcin 
765c6c1daeSBarry Smith   windownumber += vdraw->draw_base;
775c6c1daeSBarry Smith   if (windownumber >= vdraw->draw_max) {
785c6c1daeSBarry Smith     /* allocate twice as many slots as needed */
795c6c1daeSBarry Smith     PetscInt      draw_max  = vdraw->draw_max;
805c6c1daeSBarry Smith     PetscDraw     *tdraw    = vdraw->draw;
815c6c1daeSBarry Smith     PetscDrawLG   *drawlg   = vdraw->drawlg;
825c6c1daeSBarry Smith     PetscDrawAxis *drawaxis = vdraw->drawaxis;
835c6c1daeSBarry Smith 
845c6c1daeSBarry Smith     vdraw->draw_max = 2*windownumber;
85a297a907SKarl Rupp 
861795a4d1SJed Brown     ierr = PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);CHKERRQ(ierr);
875c6c1daeSBarry Smith 
885c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->draw,tdraw,draw_max*sizeof(PetscDraw));CHKERRQ(ierr);
895c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->drawlg,drawlg,draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr);
905c6c1daeSBarry Smith     ierr = PetscMemcpy(vdraw->drawaxis,drawaxis,draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr);
915c6c1daeSBarry Smith 
925c6c1daeSBarry Smith     ierr = PetscFree3(tdraw,drawlg,drawaxis);CHKERRQ(ierr);
935c6c1daeSBarry Smith   }
945c6c1daeSBarry Smith 
955c6c1daeSBarry Smith   if (!vdraw->draw[windownumber]) {
96e5ab1681SLisandro Dalcin     char *title = vdraw->title, tmp_str[128];
9710f3a0f4SLisandro Dalcin     if (windownumber) {
9810f3a0f4SLisandro Dalcin       ierr = PetscSNPrintf(tmp_str,sizeof(tmp_str),"%s:%d",vdraw->title?vdraw->title:"",windownumber);CHKERRQ(ierr);
995c6c1daeSBarry Smith       title = tmp_str;
1005c6c1daeSBarry Smith     }
101ce94432eSBarry Smith     ierr = PetscDrawCreate(PetscObjectComm((PetscObject)viewer),vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);CHKERRQ(ierr);
102e5ab1681SLisandro Dalcin     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->draw[windownumber]);CHKERRQ(ierr);
103d1da0b69SBarry Smith     if (vdraw->drawtype) {
104d1da0b69SBarry Smith       ierr = PetscDrawSetType(vdraw->draw[windownumber],vdraw->drawtype);CHKERRQ(ierr);
105d1da0b69SBarry Smith     }
106afe78b3cSBarry Smith     ierr = PetscDrawSetPause(vdraw->draw[windownumber],vdraw->pause);CHKERRQ(ierr);
107d94959e9SLisandro Dalcin     ierr = PetscDrawSetOptionsPrefix(vdraw->draw[windownumber],((PetscObject)viewer)->prefix);CHKERRQ(ierr);
1085c6c1daeSBarry Smith     ierr = PetscDrawSetFromOptions(vdraw->draw[windownumber]);CHKERRQ(ierr);
1095c6c1daeSBarry Smith   }
1105c6c1daeSBarry Smith   if (draw) *draw = vdraw->draw[windownumber];
1115c6c1daeSBarry Smith   if (draw) PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,-1);
1125c6c1daeSBarry Smith   PetscFunctionReturn(0);
1135c6c1daeSBarry Smith }
1145c6c1daeSBarry Smith 
1155c6c1daeSBarry Smith /*@C
1165c6c1daeSBarry Smith     PetscViewerDrawBaseAdd - add to the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1175c6c1daeSBarry Smith 
118d94959e9SLisandro Dalcin     Logically Collective on PetscViewer
1195c6c1daeSBarry Smith 
1205c6c1daeSBarry Smith     Input Parameters:
1215c6c1daeSBarry Smith +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
1225c6c1daeSBarry Smith -   windownumber - how much to add to the base
1235c6c1daeSBarry Smith 
1245c6c1daeSBarry Smith     Level: developer
1255c6c1daeSBarry Smith 
1265c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
1275c6c1daeSBarry Smith    Concepts: graphics
1285c6c1daeSBarry Smith 
1295c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseSet()
1305c6c1daeSBarry Smith @*/
1315c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseAdd(PetscViewer viewer,PetscInt windownumber)
1325c6c1daeSBarry Smith {
133e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
1345c6c1daeSBarry Smith   PetscErrorCode   ierr;
1355c6c1daeSBarry Smith   PetscBool        isdraw;
1365c6c1daeSBarry Smith 
1375c6c1daeSBarry Smith   PetscFunctionBegin;
1385c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
139e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
1405c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1415c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
142e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
143e5ab1681SLisandro Dalcin 
1445c6c1daeSBarry 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);
1455c6c1daeSBarry Smith   vdraw->draw_base += windownumber;
1465c6c1daeSBarry Smith   PetscFunctionReturn(0);
1475c6c1daeSBarry Smith }
1485c6c1daeSBarry Smith 
1495c6c1daeSBarry Smith /*@C
1505c6c1daeSBarry Smith     PetscViewerDrawBaseSet - sets the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1515c6c1daeSBarry Smith 
152d94959e9SLisandro Dalcin     Logically Collective on PetscViewer
1535c6c1daeSBarry Smith 
1545c6c1daeSBarry Smith     Input Parameters:
1555c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
1565c6c1daeSBarry Smith -   windownumber - value to set the base
1575c6c1daeSBarry Smith 
1585c6c1daeSBarry Smith     Level: developer
1595c6c1daeSBarry Smith 
1605c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
1615c6c1daeSBarry Smith    Concepts: graphics
1625c6c1daeSBarry Smith 
1635c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd()
1645c6c1daeSBarry Smith @*/
1655c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt windownumber)
1665c6c1daeSBarry Smith {
167e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
1685c6c1daeSBarry Smith   PetscErrorCode   ierr;
1695c6c1daeSBarry Smith   PetscBool        isdraw;
1705c6c1daeSBarry Smith 
1715c6c1daeSBarry Smith   PetscFunctionBegin;
1725c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
173e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
1745c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1755c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
176e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
177e5ab1681SLisandro Dalcin 
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 /*@C
1845c6c1daeSBarry Smith     PetscViewerDrawGetDrawLG - Returns PetscDrawLG object from PetscViewer object.
1855c6c1daeSBarry Smith     This PetscDrawLG object may then be used to perform graphics using
1865c6c1daeSBarry Smith     PetscDrawLGXXX() commands.
1875c6c1daeSBarry Smith 
188d94959e9SLisandro Dalcin     Collective on PetscViewer
1895c6c1daeSBarry Smith 
1905c6c1daeSBarry Smith     Input Parameter:
1915c6c1daeSBarry Smith +   PetscViewer - the PetscViewer (created with PetscViewerDrawOpen())
1925c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
1935c6c1daeSBarry Smith 
1945c6c1daeSBarry Smith     Ouput Parameter:
1955c6c1daeSBarry Smith .   draw - the draw line graph object
1965c6c1daeSBarry Smith 
1975c6c1daeSBarry Smith     Level: intermediate
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith   Concepts: line graph^accessing context
2005c6c1daeSBarry Smith 
2015c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
2025c6c1daeSBarry Smith @*/
2035c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawLG(PetscViewer viewer,PetscInt windownumber,PetscDrawLG *drawlg)
2045c6c1daeSBarry Smith {
2055c6c1daeSBarry Smith   PetscErrorCode   ierr;
2065c6c1daeSBarry Smith   PetscBool        isdraw;
207e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
2085c6c1daeSBarry Smith 
2095c6c1daeSBarry Smith   PetscFunctionBegin;
2105c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
211e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
2125c6c1daeSBarry Smith   PetscValidPointer(drawlg,3);
2135c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
2145c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
2155c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
216e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
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);
2233bb1ff40SBarry Smith     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
224de1a4edeSLisandro Dalcin     ierr = PetscDrawLGSetFromOptions(vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2255c6c1daeSBarry Smith   }
2265c6c1daeSBarry Smith   *drawlg = vdraw->drawlg[windownumber+vdraw->draw_base];
2275c6c1daeSBarry Smith   PetscFunctionReturn(0);
2285c6c1daeSBarry Smith }
2295c6c1daeSBarry Smith 
2305c6c1daeSBarry Smith /*@C
2315c6c1daeSBarry Smith     PetscViewerDrawGetDrawAxis - Returns PetscDrawAxis object from PetscViewer object.
2325c6c1daeSBarry Smith     This PetscDrawAxis object may then be used to perform graphics using
2335c6c1daeSBarry Smith     PetscDrawAxisXXX() commands.
2345c6c1daeSBarry Smith 
235d94959e9SLisandro Dalcin     Collective on PetscViewer
2365c6c1daeSBarry Smith 
2375c6c1daeSBarry Smith     Input Parameter:
2385c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen()
2395c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
2405c6c1daeSBarry Smith 
2415c6c1daeSBarry Smith     Ouput Parameter:
2425c6c1daeSBarry Smith .   drawaxis - the draw axis object
2435c6c1daeSBarry Smith 
2445c6c1daeSBarry Smith     Level: advanced
2455c6c1daeSBarry Smith 
2465c6c1daeSBarry Smith   Concepts: line graph^accessing context
2475c6c1daeSBarry Smith 
2485c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetLG(), PetscViewerDrawOpen()
2495c6c1daeSBarry Smith @*/
2505c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawAxis(PetscViewer viewer,PetscInt windownumber,PetscDrawAxis *drawaxis)
2515c6c1daeSBarry Smith {
2525c6c1daeSBarry Smith   PetscErrorCode   ierr;
2535c6c1daeSBarry Smith   PetscBool        isdraw;
254e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
2555c6c1daeSBarry Smith 
2565c6c1daeSBarry Smith   PetscFunctionBegin;
2575c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
258e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
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");
263e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
2645c6c1daeSBarry Smith 
2655c6c1daeSBarry Smith   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
2660298fd71SBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr);
2675c6c1daeSBarry Smith   }
2685c6c1daeSBarry Smith   if (!vdraw->drawaxis[windownumber+vdraw->draw_base]) {
2695c6c1daeSBarry Smith     ierr = PetscDrawAxisCreate(vdraw->draw[windownumber+vdraw->draw_base],&vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2703bb1ff40SBarry Smith     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2715c6c1daeSBarry Smith   }
2725c6c1daeSBarry Smith   *drawaxis = vdraw->drawaxis[windownumber+vdraw->draw_base];
2735c6c1daeSBarry Smith   PetscFunctionReturn(0);
2745c6c1daeSBarry Smith }
2755c6c1daeSBarry Smith 
2765c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawResize(PetscViewer v,int w,int h)
2775c6c1daeSBarry Smith {
278e5ab1681SLisandro Dalcin   PetscErrorCode   ierr;
279e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
280e5ab1681SLisandro Dalcin   PetscBool        isdraw;
2815c6c1daeSBarry Smith 
2825c6c1daeSBarry Smith   PetscFunctionBegin;
283e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
284e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
285e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
286e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
287e5ab1681SLisandro Dalcin 
288e5ab1681SLisandro Dalcin   if (w >= 1) vdraw->w = w;
289e5ab1681SLisandro Dalcin   if (h >= 1) vdraw->h = h;
2905c6c1daeSBarry Smith   PetscFunctionReturn(0);
2915c6c1daeSBarry Smith }
2925c6c1daeSBarry Smith 
2935c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetInfo(PetscViewer v,const char display[],const char title[],int x,int y,int w,int h)
2945c6c1daeSBarry Smith {
2955c6c1daeSBarry Smith   PetscErrorCode   ierr;
296e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
297e5ab1681SLisandro Dalcin   PetscBool        isdraw;
2985c6c1daeSBarry Smith 
2995c6c1daeSBarry Smith   PetscFunctionBegin;
300e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
301e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
302e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
303e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
304e5ab1681SLisandro Dalcin 
3055c6c1daeSBarry Smith   ierr = PetscStrallocpy(display,&vdraw->display);CHKERRQ(ierr);
3065c6c1daeSBarry Smith   ierr = PetscStrallocpy(title,&vdraw->title);CHKERRQ(ierr);
307e5ab1681SLisandro Dalcin   if (w >= 1) vdraw->w = w;
308e5ab1681SLisandro Dalcin   if (h >= 1) vdraw->h = h;
3095c6c1daeSBarry Smith   PetscFunctionReturn(0);
3105c6c1daeSBarry Smith }
3115c6c1daeSBarry Smith 
312d1da0b69SBarry Smith PetscErrorCode  PetscViewerDrawSetDrawType(PetscViewer v,PetscDrawType drawtype)
313d1da0b69SBarry Smith {
314d1da0b69SBarry Smith   PetscErrorCode   ierr;
315e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
316e5ab1681SLisandro Dalcin   PetscBool        isdraw;
317d1da0b69SBarry Smith 
318d1da0b69SBarry Smith   PetscFunctionBegin;
319e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
320e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
321e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
322e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
323e5ab1681SLisandro Dalcin 
324d1da0b69SBarry Smith   ierr = PetscFree(vdraw->drawtype);CHKERRQ(ierr);
325d1da0b69SBarry Smith   ierr = PetscStrallocpy(drawtype,(char**)&vdraw->drawtype);CHKERRQ(ierr);
326d1da0b69SBarry Smith   PetscFunctionReturn(0);
327d1da0b69SBarry Smith }
328d1da0b69SBarry Smith 
329*1f49e1f7SLisandro Dalcin PetscErrorCode PetscViewerDrawGetDrawType(PetscViewer v,PetscDrawType *drawtype)
330*1f49e1f7SLisandro Dalcin {
331*1f49e1f7SLisandro Dalcin   PetscErrorCode   ierr;
332*1f49e1f7SLisandro Dalcin   PetscViewer_Draw *vdraw;
333*1f49e1f7SLisandro Dalcin   PetscBool        isdraw;
334*1f49e1f7SLisandro Dalcin 
335*1f49e1f7SLisandro Dalcin   PetscFunctionBegin;
336*1f49e1f7SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
337*1f49e1f7SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
338*1f49e1f7SLisandro Dalcin   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
339*1f49e1f7SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
340*1f49e1f7SLisandro Dalcin 
341*1f49e1f7SLisandro Dalcin   *drawtype = vdraw->drawtype;
342*1f49e1f7SLisandro Dalcin   PetscFunctionReturn(0);
343*1f49e1f7SLisandro Dalcin }
344*1f49e1f7SLisandro Dalcin 
3455c6c1daeSBarry Smith /*@C
3465c6c1daeSBarry Smith    PetscViewerDrawOpen - Opens a window for use as a PetscViewer. If you want to
3475c6c1daeSBarry Smith    do graphics in this window, you must call PetscViewerDrawGetDraw() and
3485c6c1daeSBarry Smith    perform the graphics on the PetscDraw object.
3495c6c1daeSBarry Smith 
3505c6c1daeSBarry Smith    Collective on MPI_Comm
3515c6c1daeSBarry Smith 
3525c6c1daeSBarry Smith    Input Parameters:
3535c6c1daeSBarry Smith +  comm - communicator that will share window
3545c6c1daeSBarry Smith .  display - the X display on which to open, or null for the local machine
3555c6c1daeSBarry Smith .  title - the title to put in the title bar, or null for no title
3565c6c1daeSBarry Smith .  x, y - the screen coordinates of the upper left corner of window, or use PETSC_DECIDE
3575c6c1daeSBarry Smith -  w, h - window width and height in pixels, or may use PETSC_DECIDE or PETSC_DRAW_FULL_SIZE, PETSC_DRAW_HALF_SIZE,
3585c6c1daeSBarry Smith           PETSC_DRAW_THIRD_SIZE, PETSC_DRAW_QUARTER_SIZE
3595c6c1daeSBarry Smith 
3605c6c1daeSBarry Smith    Output Parameters:
3615c6c1daeSBarry Smith . viewer - the PetscViewer
3625c6c1daeSBarry Smith 
3635c6c1daeSBarry Smith    Format Options:
3645c6c1daeSBarry Smith +  PETSC_VIEWER_DRAW_BASIC - displays with basic format
3655c6c1daeSBarry Smith -  PETSC_VIEWER_DRAW_LG    - displays using a line graph
3665c6c1daeSBarry Smith 
3675c6c1daeSBarry Smith    Options Database Keys:
3685c6c1daeSBarry Smith    PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual page for
3695c6c1daeSBarry Smith    PetscDrawCreate() for runtime options, including
3705c6c1daeSBarry Smith +  -draw_type x or null
3715c6c1daeSBarry Smith .  -nox - Disables all x-windows output
3725c6c1daeSBarry Smith .  -display <name> - Specifies name of machine for the X display
3735c6c1daeSBarry Smith .  -geometry <x,y,w,h> - allows setting the window location and size
3745c6c1daeSBarry Smith -  -draw_pause <pause> - Sets time (in seconds) that the
3755c6c1daeSBarry Smith      program pauses after PetscDrawPause() has been called
3765c6c1daeSBarry Smith      (0 is default, -1 implies until user input).
3775c6c1daeSBarry Smith 
3785c6c1daeSBarry Smith    Level: beginner
3795c6c1daeSBarry Smith 
3805c6c1daeSBarry Smith    Note for Fortran Programmers:
3815c6c1daeSBarry Smith    Whenever indicating null character data in a Fortran code,
3820298fd71SBarry Smith    NULL_CHARACTER must be employed; using NULL is not
3830298fd71SBarry Smith    correct for character data!  Thus, NULL_CHARACTER can be
3845c6c1daeSBarry Smith    used for the display and title input parameters.
3855c6c1daeSBarry Smith 
3865c6c1daeSBarry Smith   Concepts: graphics^opening PetscViewer
3875c6c1daeSBarry Smith   Concepts: drawing^opening PetscViewer
3885c6c1daeSBarry Smith 
3895c6c1daeSBarry Smith 
3905c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
3915c6c1daeSBarry Smith           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
3925c6c1daeSBarry Smith @*/
3935c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
3945c6c1daeSBarry Smith {
3955c6c1daeSBarry Smith   PetscErrorCode ierr;
3965c6c1daeSBarry Smith 
3975c6c1daeSBarry Smith   PetscFunctionBegin;
3985c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
3995c6c1daeSBarry Smith   ierr = PetscViewerSetType(*viewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
4005c6c1daeSBarry Smith   ierr = PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);CHKERRQ(ierr);
4015c6c1daeSBarry Smith   PetscFunctionReturn(0);
4025c6c1daeSBarry Smith }
4035c6c1daeSBarry Smith 
4043f08860eSBarry Smith PetscErrorCode PetscViewerGetSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4055c6c1daeSBarry Smith {
4065c6c1daeSBarry Smith   PetscErrorCode   ierr;
4075c6c1daeSBarry Smith   PetscMPIInt      rank;
4085c6c1daeSBarry Smith   PetscInt         i;
409c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4105c6c1daeSBarry Smith 
4115c6c1daeSBarry Smith   PetscFunctionBegin;
4123f08860eSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get SubViewer without first restoring previous");
4135c6c1daeSBarry Smith   /* only processor zero can use the PetscViewer draw singleton */
414c6228bbaSLisandro Dalcin   if (*sviewer) *sviewer = NULL;
415ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
4165c6c1daeSBarry Smith   if (!rank) {
4175c6c1daeSBarry Smith     ierr = PetscViewerCreate(PETSC_COMM_SELF,sviewer);CHKERRQ(ierr);
4185c6c1daeSBarry Smith     ierr = PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
419c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
420c6228bbaSLisandro Dalcin     (*sviewer)->format = viewer->format;
421c6228bbaSLisandro Dalcin     for (i=0; i<vdraw->draw_max; i++) { /* XXX this is wrong if svdraw->draw_max (initially 5) < vdraw->draw_max */
422c6228bbaSLisandro Dalcin       if (vdraw->draw[i]) {ierr = PetscDrawGetSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);}
4235c6c1daeSBarry Smith     }
4245c6c1daeSBarry Smith   }
4255c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_TRUE;
4265c6c1daeSBarry Smith   PetscFunctionReturn(0);
4275c6c1daeSBarry Smith }
4285c6c1daeSBarry Smith 
4293f08860eSBarry Smith PetscErrorCode PetscViewerRestoreSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4305c6c1daeSBarry Smith {
4315c6c1daeSBarry Smith   PetscErrorCode   ierr;
4325c6c1daeSBarry Smith   PetscMPIInt      rank;
4335c6c1daeSBarry Smith   PetscInt         i;
434c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4355c6c1daeSBarry Smith 
4365c6c1daeSBarry Smith   PetscFunctionBegin;
4375c6c1daeSBarry Smith   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
438ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
4395c6c1daeSBarry Smith   if (!rank) {
440c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
4415c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
442c6228bbaSLisandro Dalcin       if (vdraw->draw[i] && svdraw->draw[i]) {
443c6228bbaSLisandro Dalcin         ierr = PetscDrawRestoreSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);
4445c6c1daeSBarry Smith       }
4455c6c1daeSBarry Smith     }
446c6228bbaSLisandro Dalcin     ierr = PetscFree3(svdraw->draw,svdraw->drawlg,svdraw->drawaxis);CHKERRQ(ierr);
4475c6c1daeSBarry Smith     ierr = PetscFree((*sviewer)->data);CHKERRQ(ierr);
4485c6c1daeSBarry Smith     ierr = PetscHeaderDestroy(sviewer);CHKERRQ(ierr);
4495c6c1daeSBarry Smith   }
4505c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
4515c6c1daeSBarry Smith   PetscFunctionReturn(0);
4525c6c1daeSBarry Smith }
4535c6c1daeSBarry Smith 
4544416b707SBarry Smith PetscErrorCode PetscViewerSetFromOptions_Draw(PetscOptionItems *PetscOptionsObject,PetscViewer v)
455e9457bf7SBarry Smith {
456e9457bf7SBarry Smith   PetscErrorCode ierr;
457e9457bf7SBarry Smith   PetscReal      bounds[16];
458e9457bf7SBarry Smith   PetscInt       nbounds = 16;
459e9457bf7SBarry Smith   PetscBool      flg;
460e9457bf7SBarry Smith 
461e9457bf7SBarry Smith   PetscFunctionBegin;
462e55864a3SBarry Smith   ierr = PetscOptionsHead(PetscOptionsObject,"Draw PetscViewer Options");CHKERRQ(ierr);
463e9457bf7SBarry Smith   ierr = PetscOptionsRealArray("-draw_bounds","Bounds to put on plots axis","PetscViewerDrawSetBounds",bounds,&nbounds,&flg);CHKERRQ(ierr);
464e9457bf7SBarry Smith   if (flg) {
465e9457bf7SBarry Smith     ierr = PetscViewerDrawSetBounds(v,nbounds/2,bounds);CHKERRQ(ierr);
466e9457bf7SBarry Smith   }
467e9457bf7SBarry Smith   ierr = PetscOptionsTail();CHKERRQ(ierr);
468e9457bf7SBarry Smith   PetscFunctionReturn(0);
469e9457bf7SBarry Smith }
470e9457bf7SBarry Smith 
4710076e027SBarry Smith PetscErrorCode PetscViewerView_Draw(PetscViewer viewer,PetscViewer v)
4720076e027SBarry Smith {
4730076e027SBarry Smith   PetscErrorCode   ierr;
4740076e027SBarry Smith   PetscDraw        draw;
4750076e027SBarry Smith   PetscInt         i;
4760076e027SBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
4770076e027SBarry Smith 
4780076e027SBarry Smith   PetscFunctionBegin;
4790076e027SBarry Smith   /*  If the PetscViewer has just been created then no vdraw->draw yet
4800076e027SBarry Smith       exists so this will not actually call the viewer on any draws. */
4810076e027SBarry Smith   for (i=0; i<vdraw->draw_base; i++) {
4820076e027SBarry Smith     if (vdraw->draw[i]) {
4830076e027SBarry Smith       ierr = PetscViewerDrawGetDraw(viewer,i,&draw);CHKERRQ(ierr);
4840076e027SBarry Smith       ierr = PetscDrawView(draw,v);CHKERRQ(ierr);
4850076e027SBarry Smith     }
4860076e027SBarry Smith   }
4870076e027SBarry Smith   PetscFunctionReturn(0);
4880076e027SBarry Smith }
4890076e027SBarry Smith 
4908556b5ebSBarry Smith /*MC
4918556b5ebSBarry Smith    PETSCVIEWERDRAW - A viewer that generates graphics, either to the screen or a file
4928556b5ebSBarry Smith 
4938556b5ebSBarry Smith 
4948556b5ebSBarry Smith .seealso:  PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PETSC_VIEWER_DRAW_(),PETSC_VIEWER_DRAW_SELF, PETSC_VIEWER_DRAW_WORLD,
4958556b5ebSBarry Smith            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY,
4968556b5ebSBarry Smith            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
4978556b5ebSBarry Smith            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()
4988556b5ebSBarry Smith 
4991b266c99SBarry Smith   Level: beginner
5001b266c99SBarry Smith 
5018556b5ebSBarry Smith M*/
5028cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerCreate_Draw(PetscViewer viewer)
5035c6c1daeSBarry Smith {
5045c6c1daeSBarry Smith   PetscErrorCode   ierr;
5055c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
5065c6c1daeSBarry Smith 
5075c6c1daeSBarry Smith   PetscFunctionBegin;
508b00a9115SJed Brown   ierr = PetscNewLog(viewer,&vdraw);CHKERRQ(ierr);
5095c6c1daeSBarry Smith   viewer->data = (void*)vdraw;
5105c6c1daeSBarry Smith 
5115c6c1daeSBarry Smith   viewer->ops->flush            = PetscViewerFlush_Draw;
5120076e027SBarry Smith   viewer->ops->view             = PetscViewerView_Draw;
5135c6c1daeSBarry Smith   viewer->ops->destroy          = PetscViewerDestroy_Draw;
514e9457bf7SBarry Smith   viewer->ops->setfromoptions   = PetscViewerSetFromOptions_Draw;
515559f443fSBarry Smith   viewer->ops->getsubviewer     = PetscViewerGetSubViewer_Draw;
516559f443fSBarry Smith   viewer->ops->restoresubviewer = PetscViewerRestoreSubViewer_Draw;
5175c6c1daeSBarry Smith 
5185c6c1daeSBarry Smith   /* these are created on the fly if requested */
5195c6c1daeSBarry Smith   vdraw->draw_max  = 5;
5205c6c1daeSBarry Smith   vdraw->draw_base = 0;
521ccad63c3SBarry Smith   vdraw->w         = PETSC_DECIDE;
522ccad63c3SBarry Smith   vdraw->h         = PETSC_DECIDE;
523a297a907SKarl Rupp 
5241795a4d1SJed Brown   ierr = PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);CHKERRQ(ierr);
5255c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
5265c6c1daeSBarry Smith   PetscFunctionReturn(0);
5275c6c1daeSBarry Smith }
5285c6c1daeSBarry Smith 
5295c6c1daeSBarry Smith /*@
5305c6c1daeSBarry Smith     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.
5315c6c1daeSBarry Smith 
5325c6c1daeSBarry Smith     Not Collective
5335c6c1daeSBarry Smith 
5345c6c1daeSBarry Smith     Input Parameter:
5355c6c1daeSBarry Smith .  viewer - the PetscViewer
5365c6c1daeSBarry Smith 
5375c6c1daeSBarry Smith     Level: intermediate
5385c6c1daeSBarry Smith 
5395c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5405c6c1daeSBarry Smith 
5415c6c1daeSBarry Smith @*/
5425c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
5435c6c1daeSBarry Smith {
5445c6c1daeSBarry Smith   PetscErrorCode   ierr;
5455c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
546e5ab1681SLisandro Dalcin   PetscBool        isdraw;
547e5ab1681SLisandro Dalcin   PetscInt         i;
5485c6c1daeSBarry Smith 
5495c6c1daeSBarry Smith   PetscFunctionBegin;
550e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
5515c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
552e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
5535c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
554e5ab1681SLisandro Dalcin 
5555c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
5565c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawClear(vdraw->draw[i]);CHKERRQ(ierr);}
5575c6c1daeSBarry Smith   }
5585c6c1daeSBarry Smith   PetscFunctionReturn(0);
5595c6c1daeSBarry Smith }
5605c6c1daeSBarry Smith 
5615c6c1daeSBarry Smith /*@
5625c6c1daeSBarry Smith     PetscViewerDrawGetPause - Gets a pause for the first present draw
5635c6c1daeSBarry Smith 
5645c6c1daeSBarry Smith     Not Collective
5655c6c1daeSBarry Smith 
5665c6c1daeSBarry Smith     Input Parameter:
5675c6c1daeSBarry Smith .  viewer - the PetscViewer
5685c6c1daeSBarry Smith 
5695c6c1daeSBarry Smith     Output Parameter:
5705c6c1daeSBarry Smith .  pause - the pause value
5715c6c1daeSBarry Smith 
5725c6c1daeSBarry Smith     Level: intermediate
5735c6c1daeSBarry Smith 
5745c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5755c6c1daeSBarry Smith 
5765c6c1daeSBarry Smith @*/
5775c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
5785c6c1daeSBarry Smith {
5795c6c1daeSBarry Smith   PetscErrorCode   ierr;
5805c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
581e5ab1681SLisandro Dalcin   PetscBool        isdraw;
582e5ab1681SLisandro Dalcin   PetscInt         i;
5835c6c1daeSBarry Smith   PetscDraw        draw;
5845c6c1daeSBarry Smith 
5855c6c1daeSBarry Smith   PetscFunctionBegin;
586e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
5875c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
588e5ab1681SLisandro Dalcin   if (!isdraw) {*pause = 0.0; PetscFunctionReturn(0);}
5895c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
590e5ab1681SLisandro Dalcin 
5915c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
5925c6c1daeSBarry Smith     if (vdraw->draw[i]) {
5935c6c1daeSBarry Smith       ierr = PetscDrawGetPause(vdraw->draw[i],pause);CHKERRQ(ierr);
5945c6c1daeSBarry Smith       PetscFunctionReturn(0);
5955c6c1daeSBarry Smith     }
5965c6c1daeSBarry Smith   }
5975c6c1daeSBarry Smith   /* none exist yet so create one and get its pause */
5985c6c1daeSBarry Smith   ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
599e5ab1681SLisandro Dalcin   ierr = PetscDrawGetPause(draw,pause);CHKERRQ(ierr);
6005c6c1daeSBarry Smith   PetscFunctionReturn(0);
6015c6c1daeSBarry Smith }
6025c6c1daeSBarry Smith 
6035c6c1daeSBarry Smith /*@
6045c6c1daeSBarry Smith     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer
6055c6c1daeSBarry Smith 
6065c6c1daeSBarry Smith     Not Collective
6075c6c1daeSBarry Smith 
6085c6c1daeSBarry Smith     Input Parameters:
6095c6c1daeSBarry Smith +  viewer - the PetscViewer
6105c6c1daeSBarry Smith -  pause - the pause value
6115c6c1daeSBarry Smith 
6125c6c1daeSBarry Smith     Level: intermediate
6135c6c1daeSBarry Smith 
6145c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6155c6c1daeSBarry Smith 
6165c6c1daeSBarry Smith @*/
6175c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
6185c6c1daeSBarry Smith {
6195c6c1daeSBarry Smith   PetscErrorCode   ierr;
620e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
6215c6c1daeSBarry Smith   PetscBool        isdraw;
622e5ab1681SLisandro Dalcin   PetscInt         i;
6235c6c1daeSBarry Smith 
6245c6c1daeSBarry Smith   PetscFunctionBegin;
625e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6265c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
627e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
628e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
629afe78b3cSBarry Smith 
630afe78b3cSBarry Smith   vdraw->pause = pause;
6315c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6325c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawSetPause(vdraw->draw[i],pause);CHKERRQ(ierr);}
6335c6c1daeSBarry Smith   }
6345c6c1daeSBarry Smith   PetscFunctionReturn(0);
6355c6c1daeSBarry Smith }
6365c6c1daeSBarry Smith 
6375c6c1daeSBarry Smith 
6385c6c1daeSBarry Smith /*@
6395c6c1daeSBarry Smith     PetscViewerDrawSetHold - Holds previous image when drawing new image
6405c6c1daeSBarry Smith 
6415c6c1daeSBarry Smith     Not Collective
6425c6c1daeSBarry Smith 
6435c6c1daeSBarry Smith     Input Parameters:
6445c6c1daeSBarry Smith +  viewer - the PetscViewer
6455c6c1daeSBarry Smith -  hold - indicates to hold or not
6465c6c1daeSBarry Smith 
6475c6c1daeSBarry Smith     Level: intermediate
6485c6c1daeSBarry Smith 
6495c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6505c6c1daeSBarry Smith 
6515c6c1daeSBarry Smith @*/
6525c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
6535c6c1daeSBarry Smith {
6545c6c1daeSBarry Smith   PetscErrorCode   ierr;
6555c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
6565c6c1daeSBarry Smith   PetscBool        isdraw;
6575c6c1daeSBarry Smith 
6585c6c1daeSBarry Smith   PetscFunctionBegin;
659e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6605c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
661e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
6625c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
663e5ab1681SLisandro Dalcin 
6645c6c1daeSBarry Smith   vdraw->hold = hold;
6655c6c1daeSBarry Smith   PetscFunctionReturn(0);
6665c6c1daeSBarry Smith }
6675c6c1daeSBarry Smith 
6685c6c1daeSBarry Smith /*@
669d97d059aSBarry Smith     PetscViewerDrawGetHold - Checks if holds previous image when drawing new image
6705c6c1daeSBarry Smith 
6715c6c1daeSBarry Smith     Not Collective
6725c6c1daeSBarry Smith 
6735c6c1daeSBarry Smith     Input Parameter:
6745c6c1daeSBarry Smith .  viewer - the PetscViewer
6755c6c1daeSBarry Smith 
6765c6c1daeSBarry Smith     Output Parameter:
6775c6c1daeSBarry Smith .  hold - indicates to hold or not
6785c6c1daeSBarry Smith 
6795c6c1daeSBarry Smith     Level: intermediate
6805c6c1daeSBarry Smith 
6815c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6825c6c1daeSBarry Smith 
6835c6c1daeSBarry Smith @*/
6845c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
6855c6c1daeSBarry Smith {
6865c6c1daeSBarry Smith   PetscErrorCode   ierr;
6875c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
6885c6c1daeSBarry Smith   PetscBool        isdraw;
6895c6c1daeSBarry Smith 
6905c6c1daeSBarry Smith   PetscFunctionBegin;
691e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6925c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
693e5ab1681SLisandro Dalcin   if (!isdraw) {*hold = PETSC_FALSE; PetscFunctionReturn(0);}
6945c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
695e5ab1681SLisandro Dalcin 
6965c6c1daeSBarry Smith   *hold = vdraw->hold;
6975c6c1daeSBarry Smith   PetscFunctionReturn(0);
6985c6c1daeSBarry Smith }
6995c6c1daeSBarry Smith 
7005c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
7015c6c1daeSBarry Smith /*
7025c6c1daeSBarry Smith     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
7035c6c1daeSBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
7045c6c1daeSBarry Smith */
705d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;
7065c6c1daeSBarry Smith 
7075c6c1daeSBarry Smith /*@C
7085c6c1daeSBarry Smith     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors
7095c6c1daeSBarry Smith                      in a communicator.
7105c6c1daeSBarry Smith 
7115c6c1daeSBarry Smith      Collective on MPI_Comm
7125c6c1daeSBarry Smith 
7135c6c1daeSBarry Smith      Input Parameter:
7145c6c1daeSBarry Smith .    comm - the MPI communicator to share the window PetscViewer
7155c6c1daeSBarry Smith 
7165c6c1daeSBarry Smith      Level: intermediate
7175c6c1daeSBarry Smith 
7185c6c1daeSBarry Smith      Notes:
7195c6c1daeSBarry Smith      Unlike almost all other PETSc routines, PETSC_VIEWER_DRAW_ does not return
7205c6c1daeSBarry Smith      an error code.  The window is usually used in the form
7215c6c1daeSBarry Smith $       XXXView(XXX object,PETSC_VIEWER_DRAW_(comm));
7225c6c1daeSBarry Smith 
7235c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(),
7245c6c1daeSBarry Smith @*/
7255c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
7265c6c1daeSBarry Smith {
7275c6c1daeSBarry Smith   PetscErrorCode ierr;
7285c6c1daeSBarry Smith   PetscMPIInt    flag;
7295c6c1daeSBarry Smith   PetscViewer    viewer;
7305c6c1daeSBarry Smith   MPI_Comm       ncomm;
7315c6c1daeSBarry Smith 
7325c6c1daeSBarry Smith   PetscFunctionBegin;
733efca3c55SSatish Balay   ierr = PetscCommDuplicate(comm,&ncomm,NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7345c6c1daeSBarry Smith   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
73512801b39SBarry Smith     ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,0);
736efca3c55SSatish Balay     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7375c6c1daeSBarry Smith   }
73847435625SJed Brown   ierr = MPI_Comm_get_attr(ncomm,Petsc_Viewer_Draw_keyval,(void**)&viewer,&flag);
739efca3c55SSatish Balay   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7405c6c1daeSBarry Smith   if (!flag) { /* PetscViewer not yet created */
7415c6c1daeSBarry Smith     ierr = PetscViewerDrawOpen(ncomm,0,0,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
742efca3c55SSatish Balay     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7435c6c1daeSBarry Smith     ierr = PetscObjectRegisterDestroy((PetscObject)viewer);
744efca3c55SSatish Balay     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
74547435625SJed Brown     ierr = MPI_Comm_set_attr(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
746efca3c55SSatish Balay     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7475c6c1daeSBarry Smith   }
7485c6c1daeSBarry Smith   ierr = PetscCommDestroy(&ncomm);
749efca3c55SSatish Balay   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);}
7505c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
7515c6c1daeSBarry Smith }
7525c6c1daeSBarry Smith 
7535c6c1daeSBarry Smith /*@
7545c6c1daeSBarry Smith     PetscViewerDrawSetBounds - sets the upper and lower bounds to be used in plotting
7555c6c1daeSBarry Smith 
7565c6c1daeSBarry Smith     Collective on PetscViewer
7575c6c1daeSBarry Smith 
7585c6c1daeSBarry Smith     Input Parameters:
7595c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
7605c6c1daeSBarry Smith .   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
7615c6c1daeSBarry 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, .....
7625c6c1daeSBarry Smith 
763e9457bf7SBarry Smith 
764e9457bf7SBarry Smith     Options Database:
765e9457bf7SBarry Smith .   -draw_bounds  minF0,maxF0,minF1,maxF1
766e9457bf7SBarry Smith 
7675c6c1daeSBarry Smith     Level: intermediate
7685c6c1daeSBarry Smith 
769f3f0eb19SBarry 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
770f3f0eb19SBarry 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
771f3f0eb19SBarry Smith       this viewer. Otherwise the color to physical value meaning changes with each new image if this is not set.
772f3f0eb19SBarry Smith 
7735c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
7745c6c1daeSBarry Smith    Concepts: graphics
7755c6c1daeSBarry Smith 
7765c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
7775c6c1daeSBarry Smith @*/
7785c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
7795c6c1daeSBarry Smith {
780e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
781e5ab1681SLisandro Dalcin   PetscBool        isdraw;
7825c6c1daeSBarry Smith   PetscErrorCode   ierr;
7835c6c1daeSBarry Smith 
7845c6c1daeSBarry Smith 
7855c6c1daeSBarry Smith   PetscFunctionBegin;
7865c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
787e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
788e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
789e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
790a297a907SKarl Rupp 
791e5ab1681SLisandro Dalcin   vdraw->nbounds = nbounds;
792e5ab1681SLisandro Dalcin   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
793785e854fSJed Brown   ierr = PetscMalloc1(2*nbounds,&vdraw->bounds);CHKERRQ(ierr);
7945c6c1daeSBarry Smith   ierr = PetscMemcpy(vdraw->bounds,bounds,2*nbounds*sizeof(PetscReal));CHKERRQ(ierr);
7955c6c1daeSBarry Smith   PetscFunctionReturn(0);
7965c6c1daeSBarry Smith }
7975c6c1daeSBarry Smith 
7985c6c1daeSBarry Smith /*@C
7995c6c1daeSBarry Smith     PetscViewerDrawGetBounds - gets the upper and lower bounds to be used in plotting set with PetscViewerDrawSetBounds()
8005c6c1daeSBarry Smith 
8015c6c1daeSBarry Smith     Collective on PetscViewer
8025c6c1daeSBarry Smith 
8035c6c1daeSBarry Smith     Input Parameter:
8045c6c1daeSBarry Smith .   viewer - the PetscViewer (created with PetscViewerDrawOpen())
8055c6c1daeSBarry Smith 
8065c6c1daeSBarry Smith     Output Paramters:
8075c6c1daeSBarry Smith +   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
8085c6c1daeSBarry 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, .....
8095c6c1daeSBarry Smith 
8105c6c1daeSBarry Smith     Level: intermediate
8115c6c1daeSBarry Smith 
8125c6c1daeSBarry Smith    Concepts: drawing^accessing PetscDraw context from PetscViewer
8135c6c1daeSBarry Smith    Concepts: graphics
8145c6c1daeSBarry Smith 
815f3f0eb19SBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawSetBounds()
8165c6c1daeSBarry Smith @*/
8175c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
8185c6c1daeSBarry Smith {
819e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
820e5ab1681SLisandro Dalcin   PetscBool        isdraw;
821e5ab1681SLisandro Dalcin   PetscErrorCode   ierr;
8225c6c1daeSBarry Smith 
8235c6c1daeSBarry Smith   PetscFunctionBegin;
8245c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
825e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
826e5ab1681SLisandro Dalcin   if (!isdraw) {if (nbounds) *nbounds = 0; if (bounds) *bounds = NULL; PetscFunctionReturn(0);}
827e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
828e5ab1681SLisandro Dalcin 
829e5ab1681SLisandro Dalcin   if (nbounds) *nbounds = vdraw->nbounds;
830e5ab1681SLisandro Dalcin   if (bounds)  *bounds  = vdraw->bounds;
8315c6c1daeSBarry Smith   PetscFunctionReturn(0);
8325c6c1daeSBarry Smith }
833