/*@C PetscViewerDrawGetDrawLG - Returns PetscDrawLG object from PetscViewer object. This PetscDrawLG object may then be used to perform graphics using PetscDrawLGXXX() commands. Collective on PetscViewer Input Parameter: + PetscViewer - the PetscViewer (created with PetscViewerDrawOpen()) - windownumber - indicates which subwindow (usually 0) Ouput Parameter: . draw - the draw line graph object Level: intermediate Concepts: line graph^accessing context .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen() @*/ PetscErrorCode PetscViewerDrawGetDrawLG(PetscViewer viewer,PetscInt windownumber,PetscDrawLG *drawlg) { PetscErrorCode ierr; PetscBool isdraw; PetscViewer_Draw *vdraw; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); PetscValidLogicalCollectiveInt(viewer,windownumber,2); PetscValidPointer(drawlg,3); ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer"); if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative"); vdraw = (PetscViewer_Draw*)viewer->data; if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) { ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr); } if (!vdraw->drawlg[windownumber+vdraw->draw_base]) { ierr = PetscDrawLGCreate(vdraw->draw[windownumber+vdraw->draw_base],1,&vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr); } *drawlg = vdraw->drawlg[windownumber+vdraw->draw_base]; PetscFunctionReturn(0); }
int main(int argc,char **argv) { PetscDraw draw; PetscDrawLG lg; PetscDrawAxis axis; PetscInt n = 15,i,x = 0,y = 0,width = 400,height = 300,nports = 1; PetscBool useports,flg; const char *xlabel,*ylabel,*toplabel,*legend; PetscReal xd,yd; PetscDrawViewPorts *ports = NULL; PetscErrorCode ierr; toplabel = "Top Label"; xlabel = "X-axis Label"; ylabel = "Y-axis Label"; legend = "Legend"; ierr = PetscInitialize(&argc,&argv,NULL,help);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-x",&x,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-y",&y,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-width",&width,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-height",&height,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-nports",&nports,&useports);CHKERRQ(ierr); ierr = PetscOptionsHasName(NULL,NULL,"-nolegend",&flg);CHKERRQ(ierr); if (flg) legend = NULL; ierr = PetscOptionsHasName(NULL,NULL,"-notoplabel",&flg);CHKERRQ(ierr); if (flg) toplabel = NULL; ierr = PetscOptionsHasName(NULL,NULL,"-noxlabel",&flg);CHKERRQ(ierr); if (flg) xlabel = NULL; ierr = PetscOptionsHasName(NULL,NULL,"-noylabel",&flg);CHKERRQ(ierr); if (flg) ylabel = NULL; ierr = PetscOptionsHasName(NULL,NULL,"-nolabels",&flg);CHKERRQ(ierr); if (flg) {toplabel = NULL; xlabel = NULL; ylabel = NULL;} ierr = PetscDrawCreate(PETSC_COMM_WORLD,0,"Title",x,y,width,height,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); if (useports) { ierr = PetscDrawViewPortsCreate(draw,nports,&ports);CHKERRQ(ierr); ierr = PetscDrawViewPortsSet(ports,0);CHKERRQ(ierr); } ierr = PetscDrawLGCreate(draw,1,&lg);CHKERRQ(ierr); ierr = PetscDrawLGSetUseMarkers(lg,PETSC_TRUE);CHKERRQ(ierr); ierr = PetscDrawLGGetAxis(lg,&axis);CHKERRQ(ierr); ierr = PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);CHKERRQ(ierr); ierr = PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);CHKERRQ(ierr); ierr = PetscDrawLGSetLegend(lg,&legend);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(lg);CHKERRQ(ierr); for (i=0; i<=n; i++) { xd = (PetscReal)(i - 5); yd = xd*xd; ierr = PetscDrawLGAddPoint(lg,&xd,&yd);CHKERRQ(ierr); } ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr); ierr = PetscDrawLGSave(lg);CHKERRQ(ierr); ierr = PetscDrawViewPortsDestroy(ports);CHKERRQ(ierr); ierr = PetscDrawLGDestroy(&lg);CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
/*@C KSPMonitorLGResidualNormCreate - Creates a line graph context for use with KSP to monitor convergence of preconditioned residual norms. Collective on KSP Input Parameters: + comm - communicator context . host - the X display to open, or null for the local machine . label - the title to put in the title bar . x, y - the screen coordinates of the upper left coordinate of the window - m, n - the screen width and height in pixels Output Parameter: . lgctx - the drawing context Options Database Key: . -ksp_monitor_lg_residualnorm - Sets line graph monitor Notes: Use PetscDrawLGDestroy() to destroy this line graph. Level: intermediate .keywords: KSP, monitor, line graph, residual, create .seealso: KSPMonitorSet(), KSPMonitorLGTrueResidualCreate() @*/ PetscErrorCode KSPMonitorLGResidualNormCreate(MPI_Comm comm,const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *lgctx) { PetscDraw draw; PetscErrorCode ierr; PetscDrawAxis axis; PetscDrawLG lg; PetscFunctionBegin; ierr = PetscDrawCreate(comm,host,label,x,y,m,n,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawLGCreate(draw,1,&lg);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(lg);CHKERRQ(ierr); ierr = PetscDrawLGGetAxis(lg,&axis);CHKERRQ(ierr); ierr = PetscDrawAxisSetLabels(axis,"Convergence","Iteration","Residual Norm");CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); *lgctx = lg; PetscFunctionReturn(0); }
/*@C KSPMonitorLGResidualNormCreate - Creates a line graph context for use with KSP to monitor convergence of preconditioned residual norms. Collective on KSP Input Parameters: + host - the X display to open, or null for the local machine . label - the title to put in the title bar . x, y - the screen coordinates of the upper left coordinate of the window - m, n - the screen width and height in pixels Output Parameter: . draw - the drawing context Options Database Key: . -ksp_monitor_lg_residualnorm - Sets line graph monitor Notes: Use KSPMonitorLGResidualNormDestroy() to destroy this line graph; do not use PetscDrawLGDestroy(). Level: intermediate .keywords: KSP, monitor, line graph, residual, create .seealso: KSPMonitorLGResidualNormDestroy(), KSPMonitorSet(), KSPMonitorLGTrueResidualCreate() @*/ PetscErrorCode KSPMonitorLGResidualNormCreate(const char host[],const char label[],int x,int y,int m,int n,PetscObject **objs) { PetscDraw win; PetscErrorCode ierr; PetscDrawAxis axis; PetscDrawLG draw; PetscFunctionBegin; ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&win);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(win);CHKERRQ(ierr); ierr = PetscDrawLGCreate(win,1,&draw);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawLGGetAxis(draw,&axis);CHKERRQ(ierr); ierr = PetscDrawAxisSetLabels(axis,"Convergence","Iteration","Residual Norm");CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)win);CHKERRQ(ierr); ierr = PetscMalloc1(2,objs);CHKERRQ(ierr); (*objs)[0] = (PetscObject)draw; (*objs)[1] = (PetscObject)win; PetscFunctionReturn(0); }
/*@C KSPMonitorSNESLGResidualNormCreate - Creates a line graph context for use with KSP to monitor convergence of preconditioned residual norms. Collective on KSP Input Parameters: + comm - communicator context . host - the X display to open, or null for the local machine . label - the title to put in the title bar . x, y - the screen coordinates of the upper left coordinate of the window - m, n - the screen width and height in pixels Output Parameter: . draw - the drawing context Options Database Key: . -ksp_monitor_lg_residualnorm - Sets line graph monitor Notes: Use KSPMonitorSNESLGResidualNormDestroy() to destroy this line graph; do not use PetscDrawLGDestroy(). Level: intermediate .keywords: KSP, monitor, line graph, residual, create .seealso: KSPMonitorSNESLGResidualNormDestroy(), KSPMonitorSet(), KSPMonitorSNESLGTrueResidualCreate() @*/ PetscErrorCode KSPMonitorSNESLGResidualNormCreate(MPI_Comm comm,const char host[],const char label[],int x,int y,int m,int n,PetscObject **objs) { PetscDraw draw; PetscErrorCode ierr; PetscDrawAxis axis; PetscDrawLG lg; const char *names[] = {"Linear residual","Nonlinear residual"}; PetscFunctionBegin; ierr = PetscDrawCreate(comm,host,label,x,y,m,n,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawLGCreate(draw,2,&lg);CHKERRQ(ierr); ierr = PetscDrawLGSetLegend(lg,names);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(lg);CHKERRQ(ierr); ierr = PetscDrawLGGetAxis(lg,&axis);CHKERRQ(ierr); ierr = PetscDrawAxisSetLabels(axis,"Convergence of Residual Norm","Iteration","Residual Norm");CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); ierr = PetscMalloc1(2,objs);CHKERRQ(ierr); (*objs)[1] = (PetscObject)lg; PetscFunctionReturn(0); }
/*@C KSPMonitorSNESLGResidualNormCreate - Creates a line graph context for use with KSP to monitor convergence of preconditioned residual norms. Collective on KSP Input Parameters: + host - the X display to open, or null for the local machine . label - the title to put in the title bar . x, y - the screen coordinates of the upper left coordinate of the window - m, n - the screen width and height in pixels Output Parameter: . draw - the drawing context Options Database Key: . -ksp_monitor_lg_residualnorm - Sets line graph monitor Notes: Use KSPMonitorSNESLGResidualNormDestroy() to destroy this line graph; do not use PetscDrawLGDestroy(). Level: intermediate .keywords: KSP, monitor, line graph, residual, create .seealso: KSPMonitorSNESLGResidualNormDestroy(), KSPMonitorSet(), KSPMonitorSNESLGTrueResidualCreate() @*/ PetscErrorCode KSPMonitorSNESLGResidualNormCreate(const char host[],const char label[],int x,int y,int m,int n,PetscObject **objs) { PetscDraw draw; PetscErrorCode ierr; PetscDrawAxis axis; PetscDrawLG drawlg; const char *names[] = {"Linear residual","Nonlinear residual"}; PetscFunctionBegin; ierr = PetscDrawCreate(PETSC_COMM_SELF,host,label,x,y,m,n,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawLGCreate(draw,2,&drawlg);CHKERRQ(ierr); ierr = PetscDrawLGSetFromOptions(drawlg);CHKERRQ(ierr); ierr = PetscDrawLGGetAxis(drawlg,&axis);CHKERRQ(ierr); ierr = PetscDrawAxisSetLabels(axis,"Convergence of Residual Norm","Iteration","Residual Norm");CHKERRQ(ierr); ierr = PetscDrawLGSetLegend(drawlg,names);CHKERRQ(ierr); ierr = PetscLogObjectParent((PetscObject)drawlg,(PetscObject)draw);CHKERRQ(ierr); ierr = PetscMalloc1(3,objs);CHKERRQ(ierr); (*objs)[1] = (PetscObject)drawlg; (*objs)[2] = (PetscObject)draw; PetscFunctionReturn(0); }