Actual source code: drawv.c

petsc-3.3-p7 2013-05-11
  2: #include <../src/sys/viewer/impls/draw/vdraw.h> /*I "petscdraw.h" I*/

  6: PetscErrorCode PetscViewerDestroy_Draw(PetscViewer v)
  7: {
  8:   PetscErrorCode   ierr;
  9:   PetscInt         i;
 10:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;

 13:   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Destroying PetscViewer without first restoring singleton");
 14:   for (i=0; i<vdraw->draw_max; i++) {
 15:     PetscDrawAxisDestroy(&vdraw->drawaxis[i]);
 16:     PetscDrawLGDestroy(&vdraw->drawlg[i]);
 17:     PetscDrawDestroy(&vdraw->draw[i]);
 18:   }

 20:   PetscFree(vdraw->display);
 21:   PetscFree(vdraw->title);
 22:   PetscFree3(vdraw->draw,vdraw->drawlg,vdraw->drawaxis);
 23:   PetscFree(vdraw->bounds);
 24:   PetscFree(vdraw);
 25:   return(0);
 26: }

 30: PetscErrorCode PetscViewerFlush_Draw(PetscViewer v)
 31: {
 32:   PetscErrorCode   ierr;
 33:   PetscInt         i;
 34:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;

 37:   for (i=0; i<vdraw->draw_max; i++) {
 38:     if (vdraw->draw[i]) {PetscDrawSynchronizedFlush(vdraw->draw[i]);}
 39:   }
 40:   return(0);
 41: }

 45: /*@C
 46:     PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object.
 47:     This PetscDraw object may then be used to perform graphics using 
 48:     PetscDrawXXX() commands.

 50:     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)

 52:     Input Parameters:
 53: +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
 54: -   windownumber - indicates which subwindow (usually 0)

 56:     Ouput Parameter:
 57: .   draw - the draw object

 59:     Level: intermediate

 61:    Concepts: drawing^accessing PetscDraw context from PetscViewer
 62:    Concepts: graphics

 64: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
 65: @*/
 66: PetscErrorCode  PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt  windownumber,PetscDraw *draw)
 67: {
 68:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
 69:   PetscErrorCode   ierr;
 70:   PetscBool        isdraw;
 71:   char             *title;

 76:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
 77:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
 78:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
 79:   windownumber += vdraw->draw_base;
 80:   if (windownumber >= vdraw->draw_max) {
 81:      /* allocate twice as many slots as needed */
 82:      PetscInt      draw_max = vdraw->draw_max;
 83:      PetscDraw     *tdraw = vdraw->draw;
 84:      PetscDrawLG   *drawlg = vdraw->drawlg;
 85:      PetscDrawAxis *drawaxis = vdraw->drawaxis;

 87:      vdraw->draw_max = 2*windownumber;
 88:      PetscMalloc3(vdraw->draw_max,PetscDraw,&vdraw->draw,vdraw->draw_max,PetscDrawLG,&vdraw->drawlg,vdraw->draw_max,PetscDrawAxis,&vdraw->drawaxis);
 89:      PetscMemzero(vdraw->draw,vdraw->draw_max*sizeof(PetscDraw));
 90:      PetscMemzero(vdraw->drawlg,vdraw->draw_max*sizeof(PetscDrawLG));
 91:      PetscMemzero(vdraw->drawaxis,vdraw->draw_max*sizeof(PetscDrawAxis));

 93:      PetscMemcpy(vdraw->draw,tdraw,draw_max*sizeof(PetscDraw));
 94:      PetscMemcpy(vdraw->drawlg,drawlg,draw_max*sizeof(PetscDrawLG));
 95:      PetscMemcpy(vdraw->drawaxis,drawaxis,draw_max*sizeof(PetscDrawAxis));

 97:      PetscFree3(tdraw,drawlg,drawaxis);
 98:   }

100:   if (!vdraw->draw[windownumber]) {
101:     if (!windownumber) {
102:       title = vdraw->title;
103:     } else {
104:       char tmp_str[128];
105:       PetscSNPrintf(tmp_str, 128, "%s:%d", vdraw->title,windownumber);
106:       title = tmp_str;
107:     }
108:     PetscDrawCreate(((PetscObject)viewer)->comm,vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);
109:     PetscDrawSetFromOptions(vdraw->draw[windownumber]);
110:   }
111:   if (draw) *draw = vdraw->draw[windownumber];
112:   return(0);
113: }

117: /*@C
118:     PetscViewerDrawBaseAdd - add to the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()

120:     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)

122:     Input Parameters:
123: +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
124: -   windownumber - how much to add to the base

126:     Level: developer

128:    Concepts: drawing^accessing PetscDraw context from PetscViewer
129:    Concepts: graphics

131: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseSet()
132: @*/
133: PetscErrorCode  PetscViewerDrawBaseAdd(PetscViewer viewer,PetscInt  windownumber)
134: {
135:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
136:   PetscErrorCode   ierr;
137:   PetscBool        isdraw;

141:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
142:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
143:   if (windownumber + vdraw->draw_base < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber+vdraw->draw_base);
144:   vdraw->draw_base += windownumber;
145:   return(0);
146: }

150: /*@C
151:     PetscViewerDrawBaseSet - sets the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()

153:     Not collective (but PetscDraw returned will be parallel object if PetscViewer is)

155:     Input Parameters:
156: +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
157: -   windownumber - value to set the base

159:     Level: developer

161:    Concepts: drawing^accessing PetscDraw context from PetscViewer
162:    Concepts: graphics

164: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd()
165: @*/
166: PetscErrorCode  PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt  windownumber)
167: {
168:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
169:   PetscErrorCode   ierr;
170:   PetscBool        isdraw;

174:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
175:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
176:   if (windownumber < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber);
177:   vdraw->draw_base = windownumber;
178:   return(0);
179: }

183: /*@C
184:     PetscViewerDrawGetDrawLG - Returns PetscDrawLG object from PetscViewer object.
185:     This PetscDrawLG object may then be used to perform graphics using 
186:     PetscDrawLGXXX() commands.

188:     Not Collective (but PetscDrawLG object will be parallel if PetscViewer is)

190:     Input Parameter:
191: +   PetscViewer - the PetscViewer (created with PetscViewerDrawOpen())
192: -   windownumber - indicates which subwindow (usually 0)

194:     Ouput Parameter:
195: .   draw - the draw line graph object

197:     Level: intermediate

199:   Concepts: line graph^accessing context

201: .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
202: @*/
203: PetscErrorCode  PetscViewerDrawGetDrawLG(PetscViewer viewer,PetscInt  windownumber,PetscDrawLG *drawlg)
204: {
205:   PetscErrorCode   ierr;
206:   PetscBool        isdraw;
207:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;

212:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
213:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
214:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");

216:   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
217:     PetscViewerDrawGetDraw(viewer,windownumber,PETSC_NULL);
218:   }
219:   if (!vdraw->drawlg[windownumber+vdraw->draw_base]) {
220:     PetscDrawLGCreate(vdraw->draw[windownumber+vdraw->draw_base],1,&vdraw->drawlg[windownumber+vdraw->draw_base]);
221:     PetscLogObjectParent(viewer,vdraw->drawlg[windownumber+vdraw->draw_base]);
222:   }
223:   *drawlg = vdraw->drawlg[windownumber+vdraw->draw_base];
224:   return(0);
225: }

229: /*@C
230:     PetscViewerDrawGetDrawAxis - Returns PetscDrawAxis object from PetscViewer object.
231:     This PetscDrawAxis object may then be used to perform graphics using 
232:     PetscDrawAxisXXX() commands.

234:     Not Collective (but PetscDrawAxis object will be parallel if PetscViewer is)

236:     Input Parameter:
237: +   viewer - the PetscViewer (created with PetscViewerDrawOpen()
238: -   windownumber - indicates which subwindow (usually 0)

240:     Ouput Parameter:
241: .   drawaxis - the draw axis object

243:     Level: advanced

245:   Concepts: line graph^accessing context

247: .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetLG(), PetscViewerDrawOpen()
248: @*/
249: PetscErrorCode  PetscViewerDrawGetDrawAxis(PetscViewer viewer,PetscInt  windownumber,PetscDrawAxis *drawaxis)
250: {
251:   PetscErrorCode   ierr;
252:   PetscBool        isdraw;
253:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;;

258:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
259:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
260:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");

262:   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
263:     PetscViewerDrawGetDraw(viewer,windownumber,PETSC_NULL);
264:   }
265:   if (!vdraw->drawaxis[windownumber+vdraw->draw_base]) {
266:     PetscDrawAxisCreate(vdraw->draw[windownumber+vdraw->draw_base],&vdraw->drawaxis[windownumber+vdraw->draw_base]);
267:     PetscLogObjectParent(viewer,vdraw->drawaxis[windownumber+vdraw->draw_base]);
268:   }
269:   *drawaxis = vdraw->drawaxis[windownumber+vdraw->draw_base];
270:   return(0);
271: }

275: PetscErrorCode  PetscViewerDrawResize(PetscViewer v,int w,int h)
276: {
277:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;

280:   vdraw->h  = h;
281:   vdraw->w  = w;
282:   return(0);
283: }

287: PetscErrorCode  PetscViewerDrawSetInfo(PetscViewer v,const char display[],const char title[],int x,int y,int w,int h)
288: {
289:   PetscErrorCode   ierr;
290:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;

293:   vdraw->h  = h;
294:   vdraw->w  = w;
295:   PetscStrallocpy(display,&vdraw->display);
296:   PetscStrallocpy(title,&vdraw->title);
297:   return(0);
298: }

302: /*@C
303:    PetscViewerDrawOpen - Opens an X window for use as a PetscViewer. If you want to 
304:    do graphics in this window, you must call PetscViewerDrawGetDraw() and
305:    perform the graphics on the PetscDraw object.

307:    Collective on MPI_Comm

309:    Input Parameters:
310: +  comm - communicator that will share window
311: .  display - the X display on which to open, or null for the local machine
312: .  title - the title to put in the title bar, or null for no title
313: .  x, y - the screen coordinates of the upper left corner of window, or use PETSC_DECIDE
314: -  w, h - window width and height in pixels, or may use PETSC_DECIDE or PETSC_DRAW_FULL_SIZE, PETSC_DRAW_HALF_SIZE,
315:           PETSC_DRAW_THIRD_SIZE, PETSC_DRAW_QUARTER_SIZE

317:    Output Parameters:
318: . viewer - the PetscViewer

320:    Format Options:
321: +  PETSC_VIEWER_DRAW_BASIC - displays with basic format
322: -  PETSC_VIEWER_DRAW_LG    - displays using a line graph

324:    Options Database Keys:
325:    PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual page for
326:    PetscDrawCreate() for runtime options, including
327: +  -draw_type x or null
328: .  -nox - Disables all x-windows output
329: .  -display <name> - Specifies name of machine for the X display
330: .  -geometry <x,y,w,h> - allows setting the window location and size
331: -  -draw_pause <pause> - Sets time (in seconds) that the
332:      program pauses after PetscDrawPause() has been called
333:      (0 is default, -1 implies until user input).

335:    Level: beginner

337:    Note for Fortran Programmers:
338:    Whenever indicating null character data in a Fortran code,
339:    PETSC_NULL_CHARACTER must be employed; using PETSC_NULL is not
340:    correct for character data!  Thus, PETSC_NULL_CHARACTER can be
341:    used for the display and title input parameters.

343:   Concepts: graphics^opening PetscViewer
344:   Concepts: drawing^opening PetscViewer


347: .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
348:           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
349: @*/
350: PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
351: {

355:   PetscViewerCreate(comm,viewer);
356:   PetscViewerSetType(*viewer,PETSCVIEWERDRAW);
357:   PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);
358:   return(0);
359: }

363: PetscErrorCode PetscViewerGetSingleton_Draw(PetscViewer viewer,PetscViewer *sviewer)
364: {
365:   PetscErrorCode   ierr;
366:   PetscMPIInt      rank;
367:   PetscInt         i;
368:   PetscViewer_Draw *vdraw = (PetscViewer_Draw *)viewer->data,*vsdraw;

371:   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get singleton without first restoring previous");

373:   /* only processor zero can use the PetscViewer draw singleton */
374:   MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);
375:   if (!rank) {
376:     PetscViewerCreate(PETSC_COMM_SELF,sviewer);
377:     PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);
378:     vsdraw = (PetscViewer_Draw *)(*sviewer)->data;
379:     for (i=0; i<vdraw->draw_max; i++) {
380:       if (vdraw->draw[i]) {
381:         PetscDrawGetSingleton(vdraw->draw[i],&vsdraw->draw[i]);
382:       }
383:     }
384:   }
385:   vdraw->singleton_made = PETSC_TRUE;
386:   return(0);
387: }

391: PetscErrorCode PetscViewerRestoreSingleton_Draw(PetscViewer viewer,PetscViewer *sviewer)
392: {
393:   PetscErrorCode   ierr;
394:   PetscMPIInt      rank;
395:   PetscInt         i;
396:   PetscViewer_Draw *vdraw = (PetscViewer_Draw *)viewer->data,*vsdraw;

399:   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
400:   MPI_Comm_rank(((PetscObject)viewer)->comm,&rank);
401:   if (!rank) {
402:     vsdraw = (PetscViewer_Draw *)(*sviewer)->data;
403:     for (i=0; i<vdraw->draw_max; i++) {
404:       if (vdraw->draw[i] && vsdraw->draw[i]) {
405:          PetscDrawRestoreSingleton(vdraw->draw[i],&vsdraw->draw[i]);
406:       }
407:     }
408:     PetscFree3(vsdraw->draw,vsdraw->drawlg,vsdraw->drawaxis);
409:     PetscFree((*sviewer)->data);
410:     PetscHeaderDestroy(sviewer);
411:   }
412:   vdraw->singleton_made = PETSC_FALSE;
413:   return(0);
414: }

416: EXTERN_C_BEGIN
419: PetscErrorCode  PetscViewerCreate_Draw(PetscViewer viewer)
420: {
421:   PetscInt         i;
422:   PetscErrorCode   ierr;
423:   PetscViewer_Draw *vdraw;

426:   PetscNewLog(viewer,PetscViewer_Draw,&vdraw);
427:   viewer->data = (void*)vdraw;

429:   viewer->ops->flush            = PetscViewerFlush_Draw;
430:   viewer->ops->destroy          = PetscViewerDestroy_Draw;
431:   viewer->ops->getsingleton     = PetscViewerGetSingleton_Draw;
432:   viewer->ops->restoresingleton = PetscViewerRestoreSingleton_Draw;
433:   viewer->format                = PETSC_VIEWER_NOFORMAT;

435:   /* these are created on the fly if requested */
436:   vdraw->draw_max  = 5;
437:   vdraw->draw_base = 0;
438:   PetscMalloc3(vdraw->draw_max,PetscDraw,&vdraw->draw,vdraw->draw_max,PetscDrawLG,&vdraw->drawlg,vdraw->draw_max,PetscDrawAxis,&vdraw->drawaxis);
439:   PetscMemzero(vdraw->draw,vdraw->draw_max*sizeof(PetscDraw));
440:   PetscMemzero(vdraw->drawlg,vdraw->draw_max*sizeof(PetscDrawLG));
441:   PetscMemzero(vdraw->drawaxis,vdraw->draw_max*sizeof(PetscDrawAxis));
442:   for (i=0; i<vdraw->draw_max; i++) {
443:     vdraw->draw[i]     = 0;
444:     vdraw->drawlg[i]   = 0;
445:     vdraw->drawaxis[i] = 0;
446:   }
447:   vdraw->singleton_made = PETSC_FALSE;
448:   return(0);
449: }
450: EXTERN_C_END

454: /*@
455:     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.

457:     Not Collective

459:     Input Parameter:
460: .  viewer - the PetscViewer 

462:     Level: intermediate

464: .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), 

466: @*/
467: PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
468: {
469:   PetscErrorCode   ierr;
470:   PetscInt         i;
471:   PetscBool        isdraw;
472:   PetscViewer_Draw *vdraw;

475:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
476:   if (isdraw) {
477:     vdraw = (PetscViewer_Draw*)viewer->data;
478:     for (i=0; i<vdraw->draw_max; i++) {
479:       if (vdraw->draw[i]) {PetscDrawClear(vdraw->draw[i]);}
480:     }
481:   }
482:   return(0);
483: }

487: /*@
488:     PetscViewerDrawGetPause - Gets a pause for the first present draw

490:     Not Collective

492:     Input Parameter:
493: .  viewer - the PetscViewer 

495:     Output Parameter:
496: .  pause - the pause value

498:     Level: intermediate

500: .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), 

502: @*/
503: PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
504: {
505:   PetscErrorCode   ierr;
506:   PetscInt         i;
507:   PetscBool        isdraw;
508:   PetscViewer_Draw *vdraw;
509:   PetscDraw        draw;

512:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
513:   *pause = 0.0;
514:   if (isdraw) {
515:     vdraw = (PetscViewer_Draw*)viewer->data;
516:     for (i=0; i<vdraw->draw_max; i++) {
517:       if (vdraw->draw[i]) {
518:         PetscDrawGetPause(vdraw->draw[i],pause);
519:         return(0);
520:       }
521:     }
522:     /* none exist yet so create one and get its pause */
523:     PetscViewerDrawGetDraw(viewer,0,&draw);
524:     PetscDrawGetPause(vdraw->draw[0],pause);
525:   }
526:   return(0);
527: }

531: /*@
532:     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer

534:     Not Collective

536:     Input Parameters:
537: +  viewer - the PetscViewer 
538: -  pause - the pause value

540:     Level: intermediate

542: .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), 

544: @*/
545: PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
546: {
547:   PetscErrorCode   ierr;
548:   PetscInt         i;
549:   PetscBool        isdraw;
550:   PetscViewer_Draw *vdraw;

553:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
554:   if (isdraw) {
555:     vdraw = (PetscViewer_Draw*)viewer->data;
556:     for (i=0; i<vdraw->draw_max; i++) {
557:       if (vdraw->draw[i]) {PetscDrawSetPause(vdraw->draw[i],pause);}
558:     }
559:   }
560:   return(0);
561: }


566: /*@
567:     PetscViewerDrawSetHold - Holds previous image when drawing new image

569:     Not Collective

571:     Input Parameters:
572: +  viewer - the PetscViewer 
573: -  hold - indicates to hold or not

575:     Level: intermediate

577: .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), 

579: @*/
580: PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
581: {
582:   PetscErrorCode   ierr;
583:   PetscViewer_Draw *vdraw;
584:   PetscBool        isdraw;

587:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
588:   if (isdraw) {
589:     vdraw = (PetscViewer_Draw*)viewer->data;
590:     vdraw->hold = hold;
591:   }
592:   return(0);
593: }

597: /*@
598:     PetscViewerDrawGetHold - Holds previous image when drawing new image

600:     Not Collective

602:     Input Parameter:
603: .  viewer - the PetscViewer 

605:     Output Parameter:
606: .  hold - indicates to hold or not

608:     Level: intermediate

610: .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), 

612: @*/
613: PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
614: {
615:   PetscErrorCode   ierr;
616:   PetscViewer_Draw *vdraw;
617:   PetscBool        isdraw;

620:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
621:   if (isdraw) {
622:     vdraw = (PetscViewer_Draw*)viewer->data;
623:     *hold = vdraw->hold;
624:   }
625:   return(0);
626: }

628: /* ---------------------------------------------------------------------*/
629: /*
630:     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
631:   is attached to a communicator, in this case the attribute is a PetscViewer.
632: */
633: static PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;

637: /*@C
638:     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors 
639:                      in a communicator.

641:      Collective on MPI_Comm

643:      Input Parameter:
644: .    comm - the MPI communicator to share the window PetscViewer

646:      Level: intermediate

648:      Notes:
649:      Unlike almost all other PETSc routines, PETSC_VIEWER_DRAW_ does not return 
650:      an error code.  The window is usually used in the form
651: $       XXXView(XXX object,PETSC_VIEWER_DRAW_(comm));

653: .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(), 
654: @*/
655: PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
656: {
658:   PetscMPIInt    flag;
659:   PetscViewer    viewer;
660:   MPI_Comm       ncomm;

663:   PetscCommDuplicate(comm,&ncomm,PETSC_NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
664:   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
665:     MPI_Keyval_create(MPI_NULL_COPY_FN,MPI_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,0);
666:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
667:   }
668:   MPI_Attr_get(ncomm,Petsc_Viewer_Draw_keyval,(void **)&viewer,&flag);
669:   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
670:   if (!flag) { /* PetscViewer not yet created */
671:     PetscViewerDrawOpen(ncomm,0,0,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
672:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
673:     PetscObjectRegisterDestroy((PetscObject)viewer);
674:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
675:     MPI_Attr_put(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
676:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
677:   }
678:   PetscCommDestroy(&ncomm);
679:   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
680:   PetscFunctionReturn(viewer);
681: }

685: /*@
686:     PetscViewerDrawSetBounds - sets the upper and lower bounds to be used in plotting

688:     Collective on PetscViewer

690:     Input Parameters:
691: +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
692: .   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
693: -   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, .....

695:     Level: intermediate

697:    Concepts: drawing^accessing PetscDraw context from PetscViewer
698:    Concepts: graphics

700: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
701: @*/
702: PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
703: {
704:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
705:   PetscErrorCode   ierr;


710:   vdraw->nbounds   = nbounds;
711:   PetscMalloc(2*nbounds*sizeof(PetscReal),&vdraw->bounds);
712:   PetscMemcpy(vdraw->bounds,bounds,2*nbounds*sizeof(PetscReal));
713:   return(0);
714: }

718: /*@C
719:     PetscViewerDrawGetBounds - gets the upper and lower bounds to be used in plotting set with PetscViewerDrawSetBounds()

721:     Collective on PetscViewer

723:     Input Parameter:
724: .   viewer - the PetscViewer (created with PetscViewerDrawOpen())

726:     Output Paramters:
727: +   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
728: -   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, .....

730:     Level: intermediate

732:    Concepts: drawing^accessing PetscDraw context from PetscViewer
733:    Concepts: graphics

735: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
736: @*/
737: PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
738: {
739:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;

743:   *nbounds = vdraw->nbounds;
744:   *bounds  = vdraw->bounds;
745:   return(0);
746: }