Actual source code: drawv.c

petsc-3.8.4 2018-03-24
Report Typos and Errors

  2:  #include <../src/sys/classes/viewer/impls/draw/vdraw.h>
  3:  #include <petscviewer.h>

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

 12:   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Destroying PetscViewer without first restoring singleton");
 13:   for (i=0; i<vdraw->draw_max; i++) {
 14:     PetscDrawAxisDestroy(&vdraw->drawaxis[i]);
 15:     PetscDrawLGDestroy(&vdraw->drawlg[i]);
 16:     PetscDrawDestroy(&vdraw->draw[i]);
 17:   }
 18:   PetscFree(vdraw->display);
 19:   PetscFree(vdraw->title);
 20:   PetscFree3(vdraw->draw,vdraw->drawlg,vdraw->drawaxis);
 21:   PetscFree(vdraw->bounds);
 22:   PetscFree(vdraw->drawtype);
 23:   PetscFree(v->data);
 24:   return(0);
 25: }

 27: static PetscErrorCode PetscViewerFlush_Draw(PetscViewer v)
 28: {
 29:   PetscErrorCode   ierr;
 30:   PetscInt         i;
 31:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;

 34:   for (i=0; i<vdraw->draw_max; i++) {
 35:     if (vdraw->draw[i]) {PetscDrawFlush(vdraw->draw[i]);}
 36:   }
 37:   return(0);
 38: }

 40: /*@C
 41:     PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object.
 42:     This PetscDraw object may then be used to perform graphics using
 43:     PetscDrawXXX() commands.

 45:     Collective on PetscViewer

 47:     Input Parameters:
 48: +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
 49: -   windownumber - indicates which subwindow (usually 0)

 51:     Ouput Parameter:
 52: .   draw - the draw object

 54:     Level: intermediate

 56:    Concepts: drawing^accessing PetscDraw context from PetscViewer
 57:    Concepts: graphics

 59: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
 60: @*/
 61: PetscErrorCode  PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt windownumber,PetscDraw *draw)
 62: {
 63:   PetscViewer_Draw *vdraw;
 64:   PetscErrorCode   ierr;
 65:   PetscBool        isdraw;

 71:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
 72:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
 73:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
 74:   vdraw = (PetscViewer_Draw*)viewer->data;

 76:   windownumber += vdraw->draw_base;
 77:   if (windownumber >= vdraw->draw_max) {
 78:     /* allocate twice as many slots as needed */
 79:     PetscInt      draw_max  = vdraw->draw_max;
 80:     PetscDraw     *tdraw    = vdraw->draw;
 81:     PetscDrawLG   *drawlg   = vdraw->drawlg;
 82:     PetscDrawAxis *drawaxis = vdraw->drawaxis;

 84:     vdraw->draw_max = 2*windownumber;

 86:     PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);

 88:     PetscMemcpy(vdraw->draw,tdraw,draw_max*sizeof(PetscDraw));
 89:     PetscMemcpy(vdraw->drawlg,drawlg,draw_max*sizeof(PetscDrawLG));
 90:     PetscMemcpy(vdraw->drawaxis,drawaxis,draw_max*sizeof(PetscDrawAxis));

 92:     PetscFree3(tdraw,drawlg,drawaxis);
 93:   }

 95:   if (!vdraw->draw[windownumber]) {
 96:     char *title = vdraw->title, tmp_str[128];
 97:     if (windownumber) {
 98:       PetscSNPrintf(tmp_str,sizeof(tmp_str),"%s:%d",vdraw->title?vdraw->title:"",windownumber);
 99:       title = tmp_str;
100:     }
101:     PetscDrawCreate(PetscObjectComm((PetscObject)viewer),vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);
102:     PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->draw[windownumber]);
103:     if (vdraw->drawtype) {
104:       PetscDrawSetType(vdraw->draw[windownumber],vdraw->drawtype);
105:     }
106:     PetscDrawSetPause(vdraw->draw[windownumber],vdraw->pause);
107:     PetscDrawSetOptionsPrefix(vdraw->draw[windownumber],((PetscObject)viewer)->prefix);
108:     PetscDrawSetFromOptions(vdraw->draw[windownumber]);
109:   }
110:   if (draw) *draw = vdraw->draw[windownumber];
112:   return(0);
113: }

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

118:     Logically Collective on PetscViewer

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

124:     Level: developer

126:    Concepts: drawing^accessing PetscDraw context from PetscViewer
127:    Concepts: graphics

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

140:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
141:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
142:   vdraw = (PetscViewer_Draw*)viewer->data;

144:   if (windownumber + vdraw->draw_base < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber+vdraw->draw_base);
145:   vdraw->draw_base += windownumber;
146:   return(0);
147: }

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

152:     Logically Collective on PetscViewer

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

158:     Level: developer

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

163: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd()
164: @*/
165: PetscErrorCode  PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt windownumber)
166: {
167:   PetscViewer_Draw *vdraw;
168:   PetscErrorCode   ierr;
169:   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:   vdraw = (PetscViewer_Draw*)viewer->data;

178:   if (windownumber < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber);
179:   vdraw->draw_base = windownumber;
180:   return(0);
181: }

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:     Collective on PetscViewer

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;

213:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
214:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
215:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
216:   vdraw = (PetscViewer_Draw*)viewer->data;

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

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

235:     Collective on PetscViewer

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

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

244:     Level: advanced

246:   Concepts: line graph^accessing context

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

260:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
261:   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
262:   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
263:   vdraw = (PetscViewer_Draw*)viewer->data;

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

276: PetscErrorCode  PetscViewerDrawResize(PetscViewer v,int w,int h)
277: {
278:   PetscErrorCode   ierr;
279:   PetscViewer_Draw *vdraw;
280:   PetscBool        isdraw;

284:   PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);
285:   if (!isdraw) return(0);
286:   vdraw = (PetscViewer_Draw*)v->data;

288:   if (w >= 1) vdraw->w = w;
289:   if (h >= 1) vdraw->h = h;
290:   return(0);
291: }

293: PetscErrorCode  PetscViewerDrawSetInfo(PetscViewer v,const char display[],const char title[],int x,int y,int w,int h)
294: {
295:   PetscErrorCode   ierr;
296:   PetscViewer_Draw *vdraw;
297:   PetscBool        isdraw;

301:   PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);
302:   if (!isdraw) return(0);
303:   vdraw = (PetscViewer_Draw*)v->data;

305:   PetscStrallocpy(display,&vdraw->display);
306:   PetscStrallocpy(title,&vdraw->title);
307:   if (w >= 1) vdraw->w = w;
308:   if (h >= 1) vdraw->h = h;
309:   return(0);
310: }

312: PetscErrorCode  PetscViewerDrawSetDrawType(PetscViewer v,PetscDrawType drawtype)
313: {
314:   PetscErrorCode   ierr;
315:   PetscViewer_Draw *vdraw;
316:   PetscBool        isdraw;

320:   PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);
321:   if (!isdraw) return(0);
322:   vdraw = (PetscViewer_Draw*)v->data;

324:   PetscFree(vdraw->drawtype);
325:   PetscStrallocpy(drawtype,(char**)&vdraw->drawtype);
326:   return(0);
327: }

329: /*@C
330:    PetscViewerDrawOpen - Opens a window for use as a PetscViewer. If you want to
331:    do graphics in this window, you must call PetscViewerDrawGetDraw() and
332:    perform the graphics on the PetscDraw object.

334:    Collective on MPI_Comm

336:    Input Parameters:
337: +  comm - communicator that will share window
338: .  display - the X display on which to open, or null for the local machine
339: .  title - the title to put in the title bar, or null for no title
340: .  x, y - the screen coordinates of the upper left corner of window, or use PETSC_DECIDE
341: -  w, h - window width and height in pixels, or may use PETSC_DECIDE or PETSC_DRAW_FULL_SIZE, PETSC_DRAW_HALF_SIZE,
342:           PETSC_DRAW_THIRD_SIZE, PETSC_DRAW_QUARTER_SIZE

344:    Output Parameters:
345: . viewer - the PetscViewer

347:    Format Options:
348: +  PETSC_VIEWER_DRAW_BASIC - displays with basic format
349: -  PETSC_VIEWER_DRAW_LG    - displays using a line graph

351:    Options Database Keys:
352:    PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual page for
353:    PetscDrawCreate() for runtime options, including
354: +  -draw_type x or null
355: .  -nox - Disables all x-windows output
356: .  -display <name> - Specifies name of machine for the X display
357: .  -geometry <x,y,w,h> - allows setting the window location and size
358: -  -draw_pause <pause> - Sets time (in seconds) that the
359:      program pauses after PetscDrawPause() has been called
360:      (0 is default, -1 implies until user input).

362:    Level: beginner

364:    Note for Fortran Programmers:
365:    Whenever indicating null character data in a Fortran code,
366:    NULL_CHARACTER must be employed; using NULL is not
367:    correct for character data!  Thus, NULL_CHARACTER can be
368:    used for the display and title input parameters.

370:   Concepts: graphics^opening PetscViewer
371:   Concepts: drawing^opening PetscViewer


374: .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
375:           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
376: @*/
377: PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
378: {

382:   PetscViewerCreate(comm,viewer);
383:   PetscViewerSetType(*viewer,PETSCVIEWERDRAW);
384:   PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);
385:   return(0);
386: }

388: PetscErrorCode PetscViewerGetSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
389: {
390:   PetscErrorCode   ierr;
391:   PetscMPIInt      rank;
392:   PetscInt         i;
393:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;

396:   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get SubViewer without first restoring previous");
397:   /* only processor zero can use the PetscViewer draw singleton */
398:   if (*sviewer) *sviewer = NULL;
399:   MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);
400:   if (!rank) {
401:     PetscViewerCreate(PETSC_COMM_SELF,sviewer);
402:     PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);
403:     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
404:     (*sviewer)->format = viewer->format;
405:     for (i=0; i<vdraw->draw_max; i++) { /* XXX this is wrong if svdraw->draw_max (initially 5) < vdraw->draw_max */
406:       if (vdraw->draw[i]) {PetscDrawGetSingleton(vdraw->draw[i],&svdraw->draw[i]);}
407:     }
408:   }
409:   vdraw->singleton_made = PETSC_TRUE;
410:   return(0);
411: }

413: PetscErrorCode PetscViewerRestoreSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
414: {
415:   PetscErrorCode   ierr;
416:   PetscMPIInt      rank;
417:   PetscInt         i;
418:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;

421:   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
422:   MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);
423:   if (!rank) {
424:     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
425:     for (i=0; i<vdraw->draw_max; i++) {
426:       if (vdraw->draw[i] && svdraw->draw[i]) {
427:         PetscDrawRestoreSingleton(vdraw->draw[i],&svdraw->draw[i]);
428:       }
429:     }
430:     PetscFree3(svdraw->draw,svdraw->drawlg,svdraw->drawaxis);
431:     PetscFree((*sviewer)->data);
432:     PetscHeaderDestroy(sviewer);
433:   }
434:   vdraw->singleton_made = PETSC_FALSE;
435:   return(0);
436: }

438: PetscErrorCode PetscViewerSetFromOptions_Draw(PetscOptionItems *PetscOptionsObject,PetscViewer v)
439: {
441:   PetscReal      bounds[16];
442:   PetscInt       nbounds = 16;
443:   PetscBool      flg;

446:   PetscOptionsHead(PetscOptionsObject,"Draw PetscViewer Options");
447:   PetscOptionsRealArray("-draw_bounds","Bounds to put on plots axis","PetscViewerDrawSetBounds",bounds,&nbounds,&flg);
448:   if (flg) {
449:     PetscViewerDrawSetBounds(v,nbounds/2,bounds);
450:   }
451:   PetscOptionsTail();
452:   return(0);
453: }

455: PetscErrorCode PetscViewerView_Draw(PetscViewer viewer,PetscViewer v)
456: {
457:   PetscErrorCode   ierr;
458:   PetscDraw        draw;
459:   PetscInt         i;
460:   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;

463:   /*  If the PetscViewer has just been created then no vdraw->draw yet
464:       exists so this will not actually call the viewer on any draws. */
465:   for (i=0; i<vdraw->draw_base; i++) {
466:     if (vdraw->draw[i]) {
467:       PetscViewerDrawGetDraw(viewer,i,&draw);
468:       PetscDrawView(draw,v);
469:     }
470:   }
471:   return(0);
472: }

474: /*MC
475:    PETSCVIEWERDRAW - A viewer that generates graphics, either to the screen or a file


478: .seealso:  PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PETSC_VIEWER_DRAW_(),PETSC_VIEWER_DRAW_SELF, PETSC_VIEWER_DRAW_WORLD,
479:            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY, 
480:            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
481:            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()

483:   Level: beginner

485: M*/
486: PETSC_EXTERN PetscErrorCode PetscViewerCreate_Draw(PetscViewer viewer)
487: {
488:   PetscErrorCode   ierr;
489:   PetscViewer_Draw *vdraw;

492:   PetscNewLog(viewer,&vdraw);
493:   viewer->data = (void*)vdraw;

495:   viewer->ops->flush            = PetscViewerFlush_Draw;
496:   viewer->ops->view             = PetscViewerView_Draw;
497:   viewer->ops->destroy          = PetscViewerDestroy_Draw;
498:   viewer->ops->setfromoptions   = PetscViewerSetFromOptions_Draw;
499:   viewer->ops->getsubviewer     = PetscViewerGetSubViewer_Draw;
500:   viewer->ops->restoresubviewer = PetscViewerRestoreSubViewer_Draw;

502:   /* these are created on the fly if requested */
503:   vdraw->draw_max  = 5;
504:   vdraw->draw_base = 0;
505:   vdraw->w         = PETSC_DECIDE;
506:   vdraw->h         = PETSC_DECIDE;

508:   PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);
509:   vdraw->singleton_made = PETSC_FALSE;
510:   return(0);
511: }

513: /*@
514:     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.

516:     Not Collective

518:     Input Parameter:
519: .  viewer - the PetscViewer

521:     Level: intermediate

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

525: @*/
526: PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
527: {
528:   PetscErrorCode   ierr;
529:   PetscViewer_Draw *vdraw;
530:   PetscBool        isdraw;
531:   PetscInt         i;

535:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
536:   if (!isdraw) return(0);
537:   vdraw = (PetscViewer_Draw*)viewer->data;

539:   for (i=0; i<vdraw->draw_max; i++) {
540:     if (vdraw->draw[i]) {PetscDrawClear(vdraw->draw[i]);}
541:   }
542:   return(0);
543: }

545: /*@
546:     PetscViewerDrawGetPause - Gets a pause for the first present draw

548:     Not Collective

550:     Input Parameter:
551: .  viewer - the PetscViewer

553:     Output Parameter:
554: .  pause - the pause value

556:     Level: intermediate

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

560: @*/
561: PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
562: {
563:   PetscErrorCode   ierr;
564:   PetscViewer_Draw *vdraw;
565:   PetscBool        isdraw;
566:   PetscInt         i;
567:   PetscDraw        draw;

571:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
572:   if (!isdraw) {*pause = 0.0; return(0);}
573:   vdraw = (PetscViewer_Draw*)viewer->data;

575:   for (i=0; i<vdraw->draw_max; i++) {
576:     if (vdraw->draw[i]) {
577:       PetscDrawGetPause(vdraw->draw[i],pause);
578:       return(0);
579:     }
580:   }
581:   /* none exist yet so create one and get its pause */
582:   PetscViewerDrawGetDraw(viewer,0,&draw);
583:   PetscDrawGetPause(draw,pause);
584:   return(0);
585: }

587: /*@
588:     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer

590:     Not Collective

592:     Input Parameters:
593: +  viewer - the PetscViewer
594: -  pause - the pause value

596:     Level: intermediate

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

600: @*/
601: PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
602: {
603:   PetscErrorCode   ierr;
604:   PetscViewer_Draw *vdraw;
605:   PetscBool        isdraw;
606:   PetscInt         i;

610:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
611:   if (!isdraw) return(0);
612:   vdraw = (PetscViewer_Draw*)viewer->data;

614:   vdraw->pause = pause;
615:   for (i=0; i<vdraw->draw_max; i++) {
616:     if (vdraw->draw[i]) {PetscDrawSetPause(vdraw->draw[i],pause);}
617:   }
618:   return(0);
619: }


622: /*@
623:     PetscViewerDrawSetHold - Holds previous image when drawing new image

625:     Not Collective

627:     Input Parameters:
628: +  viewer - the PetscViewer
629: -  hold - indicates to hold or not

631:     Level: intermediate

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

635: @*/
636: PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
637: {
638:   PetscErrorCode   ierr;
639:   PetscViewer_Draw *vdraw;
640:   PetscBool        isdraw;

644:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
645:   if (!isdraw) return(0);
646:   vdraw = (PetscViewer_Draw*)viewer->data;

648:   vdraw->hold = hold;
649:   return(0);
650: }

652: /*@
653:     PetscViewerDrawGetHold - Checks if holds previous image when drawing new image

655:     Not Collective

657:     Input Parameter:
658: .  viewer - the PetscViewer

660:     Output Parameter:
661: .  hold - indicates to hold or not

663:     Level: intermediate

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

667: @*/
668: PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
669: {
670:   PetscErrorCode   ierr;
671:   PetscViewer_Draw *vdraw;
672:   PetscBool        isdraw;

676:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
677:   if (!isdraw) {*hold = PETSC_FALSE; return(0);}
678:   vdraw = (PetscViewer_Draw*)viewer->data;

680:   *hold = vdraw->hold;
681:   return(0);
682: }

684: /* ---------------------------------------------------------------------*/
685: /*
686:     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
687:   is attached to a communicator, in this case the attribute is a PetscViewer.
688: */
689: PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;

691: /*@C
692:     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors
693:                      in a communicator.

695:      Collective on MPI_Comm

697:      Input Parameter:
698: .    comm - the MPI communicator to share the window PetscViewer

700:      Level: intermediate

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

707: .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(),
708: @*/
709: PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
710: {
712:   PetscMPIInt    flag;
713:   PetscViewer    viewer;
714:   MPI_Comm       ncomm;

717:   PetscCommDuplicate(comm,&ncomm,NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
718:   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
719:     MPI_Keyval_create(MPI_NULL_COPY_FN,MPI_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,0);
720:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
721:   }
722:   MPI_Attr_get(ncomm,Petsc_Viewer_Draw_keyval,(void**)&viewer,&flag);
723:   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
724:   if (!flag) { /* PetscViewer not yet created */
725:     PetscViewerDrawOpen(ncomm,0,0,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
726:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
727:     PetscObjectRegisterDestroy((PetscObject)viewer);
728:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
729:     MPI_Attr_put(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
730:     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
731:   }
732:   PetscCommDestroy(&ncomm);
733:   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");return(0);}
734:   PetscFunctionReturn(viewer);
735: }

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

740:     Collective on PetscViewer

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


748:     Options Database:
749: .   -draw_bounds  minF0,maxF0,minF1,maxF1

751:     Level: intermediate

753:     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
754:       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
755:       this viewer. Otherwise the color to physical value meaning changes with each new image if this is not set.

757:    Concepts: drawing^accessing PetscDraw context from PetscViewer
758:    Concepts: graphics

760: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
761: @*/
762: PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
763: {
764:   PetscViewer_Draw *vdraw;
765:   PetscBool        isdraw;
766:   PetscErrorCode   ierr;


771:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
772:   if (!isdraw) return(0);
773:   vdraw = (PetscViewer_Draw*)viewer->data;

775:   vdraw->nbounds = nbounds;
776:   PetscFree(vdraw->bounds);
777:   PetscMalloc1(2*nbounds,&vdraw->bounds);
778:   PetscMemcpy(vdraw->bounds,bounds,2*nbounds*sizeof(PetscReal));
779:   return(0);
780: }

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

785:     Collective on PetscViewer

787:     Input Parameter:
788: .   viewer - the PetscViewer (created with PetscViewerDrawOpen())

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

794:     Level: intermediate

796:    Concepts: drawing^accessing PetscDraw context from PetscViewer
797:    Concepts: graphics

799: .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawSetBounds()
800: @*/
801: PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
802: {
803:   PetscViewer_Draw *vdraw;
804:   PetscBool        isdraw;
805:   PetscErrorCode   ierr;

809:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);
810:   if (!isdraw) {if (nbounds) *nbounds = 0; if (bounds) *bounds = NULL; return(0);}
811:   vdraw = (PetscViewer_Draw*)viewer->data;

813:   if (nbounds) *nbounds = vdraw->nbounds;
814:   if (bounds)  *bounds  = vdraw->bounds;
815:   return(0);
816: }