PetscErrorCode DrawFA(FA fa,Vec v) { PetscErrorCode ierr; PetscScalar *va; ZoomCtx zctx; PetscReal xmint = 10000.0,xmaxt = -10000.0,ymint = 100000.0,ymaxt = -10000.0; PetscReal xmin,xmax,ymin,ymax; PetscInt i,vn,ln,j; PetscFunctionBeginUser; ierr = VecGetArray(v,&va);CHKERRQ(ierr); ierr = VecGetSize(v,&vn);CHKERRQ(ierr); ierr = VecGetSize(fa->l,&ln);CHKERRQ(ierr); for (j=0; j<3; j++) { if (vn == ln) { zctx.xy[j] = va + 2*fa->offl[j]; zctx.m[j] = fa->ml[j]; zctx.n[j] = fa->nl[j]; } else { zctx.xy[j] = va + 2*fa->offg[j]; zctx.m[j] = fa->mg[j]; zctx.n[j] = fa->ng[j]; } for (i=0; i<zctx.m[j]*zctx.n[j]; i++) { if (zctx.xy[j][2*i] > xmax) xmax = zctx.xy[j][2*i]; if (zctx.xy[j][2*i] < xmin) xmin = zctx.xy[j][2*i]; if (zctx.xy[j][2*i+1] > ymax) ymax = zctx.xy[j][2*i+1]; if (zctx.xy[j][2*i+1] < ymin) ymin = zctx.xy[j][2*i+1]; } } ierr = MPI_Allreduce(&xmin,&xmint,1,MPI_DOUBLE,MPI_MIN,PETSC_COMM_WORLD);CHKERRQ(ierr); ierr = MPI_Allreduce(&xmax,&xmaxt,1,MPI_DOUBLE,MPI_MAX,PETSC_COMM_WORLD);CHKERRQ(ierr); ierr = MPI_Allreduce(&ymin,&ymint,1,MPI_DOUBLE,MPI_MIN,PETSC_COMM_WORLD);CHKERRQ(ierr); ierr = MPI_Allreduce(&ymax,&ymaxt,1,MPI_DOUBLE,MPI_MAX,PETSC_COMM_WORLD);CHKERRQ(ierr); xmin = xmint - .2*(xmaxt - xmint); xmax = xmaxt + .2*(xmaxt - xmint); ymin = ymint - .2*(ymaxt - ymint); ymax = ymaxt + .2*(ymaxt - ymint); #if defined(PETSC_HAVE_X) || defined(PETSC_HAVE_OPENGL) { PetscDraw draw; ierr = PetscDrawCreate(PETSC_COMM_WORLD,0,"meshes",PETSC_DECIDE,PETSC_DECIDE,700,700,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);CHKERRQ(ierr); ierr = PetscDrawZoom(draw,DrawPatch,&zctx);CHKERRQ(ierr); ierr = VecRestoreArray(v,&va);CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); } #endif PetscFunctionReturn(0); }
int main(int argc,char **argv) { PetscDraw draw; int x = 0,y = 0,width = 256,height = 256; PetscErrorCode ierr; ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); ierr = PetscDrawCreate(PETSC_COMM_SELF,0,"Title",x,y,width,height,&draw);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr); ierr = PetscDrawZoom(draw,zoomfunction,NULL);CHKERRQ(ierr); ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }
static PetscErrorCode MatFDColoringView_Draw(MatFDColoring fd,PetscViewer viewer) { PetscErrorCode ierr; PetscBool isnull; PetscDraw draw; PetscReal xr,yr,xl,yl,h,w; PetscFunctionBegin; ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = PetscObjectCompose((PetscObject)fd,"Zoomviewer",(PetscObject)viewer);CHKERRQ(ierr); xr = fd->N; yr = fd->M; h = yr/10.0; w = xr/10.0; xr += w; yr += h; xl = -w; yl = -h; ierr = PetscDrawSetCoordinates(draw,xl,yl,xr,yr);CHKERRQ(ierr); ierr = PetscDrawZoom(draw,MatFDColoringView_Draw_Zoom,fd);CHKERRQ(ierr); ierr = PetscObjectCompose((PetscObject)fd,"Zoomviewer",NULL);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscDrawTensorContour - PetscDraws a contour plot for a two-dimensional array that is stored as a PETSc vector. Collective on PetscDraw, but PetscDraw must be sequential Input Parameters: + win - the window to draw in . m,n - the global number of mesh points in the x and y directions . xi,yi - the locations of the global mesh points (optional, use PETSC_NULL to indicate uniform spacing on [0,1]) - V - the values Options Database Keys: + -draw_x_shared_colormap - Indicates use of private colormap - -draw_contour_grid - PetscDraws grid contour Level: intermediate Concepts: contour plot Concepts: drawing^contour plot .seealso: PetscDrawTensorContourPatch() @*/ PetscErrorCode PetscDrawTensorContour(PetscDraw win,int m,int n,const PetscReal xi[],const PetscReal yi[],PetscReal *v) { PetscErrorCode ierr; int N = m*n; PetscBool isnull; PetscDraw popup; MPI_Comm comm; int xin=1,yin=1,i; PetscMPIInt size; PetscReal h; ZoomCtx ctx; PetscFunctionBegin; ierr = PetscDrawIsNull(win,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = PetscObjectGetComm((PetscObject)win,&comm);CHKERRQ(ierr); ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); if (size > 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"May only be used with single processor PetscDraw"); if (N <= 0) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"n %d and m %d must be positive",m,n); /* create scale window */ ierr = PetscDrawGetPopup(win,&popup);CHKERRQ(ierr); ierr = PetscDrawCheckResizedWindow(win);CHKERRQ(ierr); ctx.v = v; ctx.m = m; ctx.n = n; ctx.max = ctx.min = v[0]; for (i=0; i<N; i++) { if (ctx.max < ctx.v[i]) ctx.max = ctx.v[i]; if (ctx.min > ctx.v[i]) ctx.min = ctx.v[i]; } if (ctx.max - ctx.min < 1.e-7) {ctx.min -= 5.e-8; ctx.max += 5.e-8;} /* PetscDraw the scale window */ if (popup) {ierr = PetscDrawScalePopup(popup,ctx.min,ctx.max);CHKERRQ(ierr);} ctx.showgrid = PETSC_FALSE; ierr = PetscOptionsGetBool(PETSC_NULL,"-draw_contour_grid",&ctx.showgrid,PETSC_NULL);CHKERRQ(ierr); /* fill up x and y coordinates */ if (!xi) { xin = 0; ierr = PetscMalloc(ctx.m*sizeof(PetscReal),&ctx.x);CHKERRQ(ierr); h = 1.0/(ctx.m-1); ctx.x[0] = 0.0; for (i=1; i<ctx.m; i++) ctx.x[i] = ctx.x[i-1] + h; } else { ctx.x = (PetscReal*)xi; } if (!yi) { yin = 0; ierr = PetscMalloc(ctx.n*sizeof(PetscReal),&ctx.y);CHKERRQ(ierr); h = 1.0/(ctx.n-1); ctx.y[0] = 0.0; for (i=1; i<ctx.n; i++) ctx.y[i] = ctx.y[i-1] + h; } else { ctx.y = (PetscReal *)yi; } ierr = PetscDrawZoom(win,(PetscErrorCode (*)(PetscDraw,void *))PetscDrawTensorContour_Zoom,&ctx);CHKERRQ(ierr); if (!xin) {ierr = PetscFree(ctx.x);CHKERRQ(ierr);} if (!yin) {ierr = PetscFree(ctx.y);CHKERRQ(ierr);} PetscFunctionReturn(0); }