/*@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); }
void PETSC_STDCALL petscdrawgetpopup_(PetscDraw draw,PetscDraw *popup, int *__ierr ){ *__ierr = PetscDrawGetPopup( (PetscDraw)PetscToPointer((draw) ),popup); }