15c6c1daeSBarry Smith /* 25c6c1daeSBarry Smith Contains the data structure for drawing scatter plots 35c6c1daeSBarry Smith graphs in a window with an axis. This is intended for scatter 45c6c1daeSBarry Smith plots that change dynamically. 55c6c1daeSBarry Smith */ 65c6c1daeSBarry Smith 79804daf3SBarry Smith #include <petscdraw.h> /*I "petscdraw.h" I*/ 8999739cfSJacob Faibussowitsch #include <petsc/private/drawimpl.h> /*I "petscsys.h" I*/ 95c6c1daeSBarry Smith 105c6c1daeSBarry Smith PetscClassId PETSC_DRAWSP_CLASSID = 0; 115c6c1daeSBarry Smith 125c6c1daeSBarry Smith /*@C 135c6c1daeSBarry Smith PetscDrawSPCreate - Creates a scatter plot data structure. 145c6c1daeSBarry Smith 15*811af0c4SBarry Smith Collective on draw 165c6c1daeSBarry Smith 175c6c1daeSBarry Smith Input Parameters: 185c6c1daeSBarry Smith + win - the window where the graph will be made. 195c6c1daeSBarry Smith - dim - the number of sets of points which will be drawn 205c6c1daeSBarry Smith 215c6c1daeSBarry Smith Output Parameters: 225c6c1daeSBarry Smith . drawsp - the scatter plot context 235c6c1daeSBarry Smith 245c6c1daeSBarry Smith Level: intermediate 255c6c1daeSBarry Smith 2695452b02SPatrick Sanan Notes: 27*811af0c4SBarry Smith Add points to the plot with `PetscDrawSPAddPoint()` or `PetscDrawSPAddPoints()`; the new points are not displayed until `PetscDrawSPDraw()` is called. 280afdd333SBarry Smith 29*811af0c4SBarry Smith `PetscDrawSPReset()` removes all the points that have been added 300afdd333SBarry Smith 31*811af0c4SBarry Smith `PetscDrawSPSetDimension()` determines how many point curves are being plotted. 32*811af0c4SBarry Smith 33*811af0c4SBarry Smith The MPI communicator that owns the `PetscDraw` owns this `PetscDrawSP`, and each process can add points. All MPI ranks in the communicator must call `PetscDrawSPDraw()` to display the updated graph. 347e25d57eSBarry Smith 35db781477SPatrick Sanan .seealso: `PetscDrawLGCreate()`, `PetscDrawLG`, `PetscDrawBarCreate()`, `PetscDrawBar`, `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawSPDestroy()`, `PetscDraw`, `PetscDrawSP`, `PetscDrawSPSetDimension()`, `PetscDrawSPReset()`, 36c2e3fba1SPatrick Sanan `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()`, `PetscDrawSPDraw()`, `PetscDrawSPSave()`, `PetscDrawSPSetLimits()`, `PetscDrawSPGetAxis()`, `PetscDrawAxis`, `PetscDrawSPGetDraw()` 375c6c1daeSBarry Smith @*/ 389371c9d4SSatish Balay PetscErrorCode PetscDrawSPCreate(PetscDraw draw, int dim, PetscDrawSP *drawsp) { 395c6c1daeSBarry Smith PetscDrawSP sp; 405c6c1daeSBarry Smith 415c6c1daeSBarry Smith PetscFunctionBegin; 425c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 435c6c1daeSBarry Smith PetscValidPointer(drawsp, 3); 44e118a51fSLisandro Dalcin 459566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(sp, PETSC_DRAWSP_CLASSID, "DrawSP", "Scatter Plot", "Draw", PetscObjectComm((PetscObject)draw), PetscDrawSPDestroy, NULL)); 469566063dSJacob Faibussowitsch PetscCall(PetscLogObjectParent((PetscObject)draw, (PetscObject)sp)); 479566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)draw)); 485c6c1daeSBarry Smith sp->win = draw; 49e118a51fSLisandro Dalcin sp->view = NULL; 50e118a51fSLisandro Dalcin sp->destroy = NULL; 51e118a51fSLisandro Dalcin sp->nopts = 0; 52f98b2f00SMatthew G. Knepley sp->dim = -1; 535c6c1daeSBarry Smith sp->xmin = 1.e20; 545c6c1daeSBarry Smith sp->ymin = 1.e20; 55f98b2f00SMatthew G. Knepley sp->zmin = 1.e20; 565c6c1daeSBarry Smith sp->xmax = -1.e20; 575c6c1daeSBarry Smith sp->ymax = -1.e20; 58f98b2f00SMatthew G. Knepley sp->zmax = -1.e20; 598c87cf4dSdanfinn sp->colorized = PETSC_FALSE; 605c6c1daeSBarry Smith sp->loc = 0; 61a297a907SKarl Rupp 62f98b2f00SMatthew G. Knepley PetscCall(PetscDrawSPSetDimension(sp, dim)); 639566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisCreate(draw, &sp->axis)); 649566063dSJacob Faibussowitsch PetscCall(PetscLogObjectParent((PetscObject)sp, (PetscObject)sp->axis)); 65a297a907SKarl Rupp 665c6c1daeSBarry Smith *drawsp = sp; 675c6c1daeSBarry Smith PetscFunctionReturn(0); 685c6c1daeSBarry Smith } 695c6c1daeSBarry Smith 705c6c1daeSBarry Smith /*@ 71*811af0c4SBarry Smith PetscDrawSPSetDimension - Change the number of points that are added at each `PetscDrawSPAddPoint()` 725c6c1daeSBarry Smith 73f98b2f00SMatthew G. Knepley Not collective 745c6c1daeSBarry Smith 75d8d19677SJose E. Roman Input Parameters: 76*811af0c4SBarry Smith + sp - the scatter plot context. 77*811af0c4SBarry Smith - dim - the number of point curves on this process 785c6c1daeSBarry Smith 795c6c1daeSBarry Smith Level: intermediate 805c6c1daeSBarry Smith 81db781477SPatrick Sanan .seealso: `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()` 825c6c1daeSBarry Smith @*/ 839371c9d4SSatish Balay PetscErrorCode PetscDrawSPSetDimension(PetscDrawSP sp, int dim) { 845c6c1daeSBarry Smith PetscFunctionBegin; 855c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 865c6c1daeSBarry Smith if (sp->dim == dim) PetscFunctionReturn(0); 875c6c1daeSBarry Smith sp->dim = dim; 88f98b2f00SMatthew G. Knepley PetscCall(PetscFree3(sp->x, sp->y, sp->z)); 89f98b2f00SMatthew G. Knepley PetscCall(PetscMalloc3(dim * PETSC_DRAW_SP_CHUNK_SIZE, &sp->x, dim * PETSC_DRAW_SP_CHUNK_SIZE, &sp->y, dim * PETSC_DRAW_SP_CHUNK_SIZE, &sp->z)); 90f98b2f00SMatthew G. Knepley PetscCall(PetscLogObjectMemory((PetscObject)sp, 3 * dim * PETSC_DRAW_SP_CHUNK_SIZE * sizeof(PetscReal))); 91999739cfSJacob Faibussowitsch sp->len = dim * PETSC_DRAW_SP_CHUNK_SIZE; 925c6c1daeSBarry Smith PetscFunctionReturn(0); 935c6c1daeSBarry Smith } 945c6c1daeSBarry Smith 955c6c1daeSBarry Smith /*@ 96*811af0c4SBarry Smith PetscDrawSPGetDimension - Get the number of sets of points that are to be drawn at each `PetscDrawSPAddPoint()` 97f98b2f00SMatthew G. Knepley 98f98b2f00SMatthew G. Knepley Not collective 99f98b2f00SMatthew G. Knepley 100f98b2f00SMatthew G. Knepley Input Parameters: 101*811af0c4SBarry Smith . sp - the scatter plot context. 102f98b2f00SMatthew G. Knepley 103f98b2f00SMatthew G. Knepley Output Parameter: 104*811af0c4SBarry Smith . dim - the number of point curves on this process 105f98b2f00SMatthew G. Knepley 106f98b2f00SMatthew G. Knepley Level: intermediate 107f98b2f00SMatthew G. Knepley 108db781477SPatrick Sanan .seealso: `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()` 109f98b2f00SMatthew G. Knepley @*/ 1109371c9d4SSatish Balay PetscErrorCode PetscDrawSPGetDimension(PetscDrawSP sp, int *dim) { 111f98b2f00SMatthew G. Knepley PetscFunctionBegin; 112f98b2f00SMatthew G. Knepley PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 113f98b2f00SMatthew G. Knepley PetscValidPointer(dim, 2); 114f98b2f00SMatthew G. Knepley *dim = sp->dim; 115f98b2f00SMatthew G. Knepley PetscFunctionReturn(0); 116f98b2f00SMatthew G. Knepley } 117f98b2f00SMatthew G. Knepley 118f98b2f00SMatthew G. Knepley /*@ 119*811af0c4SBarry Smith PetscDrawSPReset - Clears scatter plot to allow for reuse with new data. 1205c6c1daeSBarry Smith 121f98b2f00SMatthew G. Knepley Not collective 1225c6c1daeSBarry Smith 1235c6c1daeSBarry Smith Input Parameter: 124*811af0c4SBarry Smith . sp - the scatter plot context. 1255c6c1daeSBarry Smith 1265c6c1daeSBarry Smith Level: intermediate 1275c6c1daeSBarry Smith 128db781477SPatrick Sanan .seealso: `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()`, `PetscDrawSPDraw()` 1295c6c1daeSBarry Smith @*/ 1309371c9d4SSatish Balay PetscErrorCode PetscDrawSPReset(PetscDrawSP sp) { 1315c6c1daeSBarry Smith PetscFunctionBegin; 1325c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 1335c6c1daeSBarry Smith sp->xmin = 1.e20; 1345c6c1daeSBarry Smith sp->ymin = 1.e20; 1358c87cf4dSdanfinn sp->zmin = 1.e20; 1365c6c1daeSBarry Smith sp->xmax = -1.e20; 1375c6c1daeSBarry Smith sp->ymax = -1.e20; 1388c87cf4dSdanfinn sp->zmax = -1.e20; 1395c6c1daeSBarry Smith sp->loc = 0; 1405c6c1daeSBarry Smith sp->nopts = 0; 1415c6c1daeSBarry Smith PetscFunctionReturn(0); 1425c6c1daeSBarry Smith } 1435c6c1daeSBarry Smith 144f98b2f00SMatthew G. Knepley /*@ 1455c6c1daeSBarry Smith PetscDrawSPDestroy - Frees all space taken up by scatter plot data structure. 1465c6c1daeSBarry Smith 147*811af0c4SBarry Smith Collective on sp 1485c6c1daeSBarry Smith 1495c6c1daeSBarry Smith Input Parameter: 150*811af0c4SBarry Smith . sp - the scatter plot context 1515c6c1daeSBarry Smith 1525c6c1daeSBarry Smith Level: intermediate 1535c6c1daeSBarry Smith 154db781477SPatrick Sanan .seealso: `PetscDrawSPCreate()`, `PetscDrawSP`, `PetscDrawSPReset()` 1555c6c1daeSBarry Smith @*/ 1569371c9d4SSatish Balay PetscErrorCode PetscDrawSPDestroy(PetscDrawSP *sp) { 1575c6c1daeSBarry Smith PetscFunctionBegin; 1585c6c1daeSBarry Smith if (!*sp) PetscFunctionReturn(0); 159e118a51fSLisandro Dalcin PetscValidHeaderSpecific(*sp, PETSC_DRAWSP_CLASSID, 1); 1609371c9d4SSatish Balay if (--((PetscObject)(*sp))->refct > 0) { 1619371c9d4SSatish Balay *sp = NULL; 1629371c9d4SSatish Balay PetscFunctionReturn(0); 1639371c9d4SSatish Balay } 1645c6c1daeSBarry Smith 1659566063dSJacob Faibussowitsch PetscCall(PetscFree3((*sp)->x, (*sp)->y, (*sp)->z)); 1669566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisDestroy(&(*sp)->axis)); 1679566063dSJacob Faibussowitsch PetscCall(PetscDrawDestroy(&(*sp)->win)); 1689566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(sp)); 1695c6c1daeSBarry Smith PetscFunctionReturn(0); 1705c6c1daeSBarry Smith } 1715c6c1daeSBarry Smith 1725c6c1daeSBarry Smith /*@ 173*811af0c4SBarry Smith PetscDrawSPAddPoint - Adds another point to each of the scatter plot point curves. 1745c6c1daeSBarry Smith 175f98b2f00SMatthew G. Knepley Not collective 1765c6c1daeSBarry Smith 1775c6c1daeSBarry Smith Input Parameters: 1785c6c1daeSBarry Smith + sp - the scatter plot data structure 179*811af0c4SBarry Smith - x, y - two arrays of length dim containing the new x and y coordinate values for each of the point curves. Here dim is the number of point curves passed to PetscDrawSPCreate() 1805c6c1daeSBarry Smith 1815c6c1daeSBarry Smith Level: intermediate 1825c6c1daeSBarry Smith 183*811af0c4SBarry Smith Note: 184*811af0c4SBarry Smith The new points will not be displayed until a call to `PetscDrawSPDraw()` is made 1850afdd333SBarry Smith 186db781477SPatrick Sanan .seealso: `PetscDrawSPAddPoints()`, `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPReset()`, `PetscDrawSPDraw()`, `PetscDrawSPAddPointColorized()` 1875c6c1daeSBarry Smith @*/ 1889371c9d4SSatish Balay PetscErrorCode PetscDrawSPAddPoint(PetscDrawSP sp, PetscReal *x, PetscReal *y) { 1895c6c1daeSBarry Smith PetscInt i; 1905c6c1daeSBarry Smith 1915c6c1daeSBarry Smith PetscFunctionBegin; 1925c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 193e118a51fSLisandro Dalcin 1945c6c1daeSBarry Smith if (sp->loc + sp->dim >= sp->len) { /* allocate more space */ 195f98b2f00SMatthew G. Knepley PetscReal *tmpx, *tmpy, *tmpz; 196f98b2f00SMatthew G. Knepley PetscCall(PetscMalloc3(sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpx, sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpy, sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpz)); 197f98b2f00SMatthew G. Knepley PetscCall(PetscLogObjectMemory((PetscObject)sp, 3 * sp->dim * PETSC_DRAW_SP_CHUNK_SIZE * sizeof(PetscReal))); 1989566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpx, sp->x, sp->len)); 1999566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpy, sp->y, sp->len)); 200f98b2f00SMatthew G. Knepley PetscCall(PetscArraycpy(tmpz, sp->z, sp->len)); 201f98b2f00SMatthew G. Knepley PetscCall(PetscFree3(sp->x, sp->y, sp->z)); 2025c6c1daeSBarry Smith sp->x = tmpx; 2035c6c1daeSBarry Smith sp->y = tmpy; 204f98b2f00SMatthew G. Knepley sp->z = tmpz; 205999739cfSJacob Faibussowitsch sp->len += sp->dim * PETSC_DRAW_SP_CHUNK_SIZE; 2065c6c1daeSBarry Smith } 207f98b2f00SMatthew G. Knepley for (i = 0; i < sp->dim; ++i) { 2085c6c1daeSBarry Smith if (x[i] > sp->xmax) sp->xmax = x[i]; 2095c6c1daeSBarry Smith if (x[i] < sp->xmin) sp->xmin = x[i]; 2105c6c1daeSBarry Smith if (y[i] > sp->ymax) sp->ymax = y[i]; 2115c6c1daeSBarry Smith if (y[i] < sp->ymin) sp->ymin = y[i]; 2125c6c1daeSBarry Smith 2135c6c1daeSBarry Smith sp->x[sp->loc] = x[i]; 2145c6c1daeSBarry Smith sp->y[sp->loc++] = y[i]; 2155c6c1daeSBarry Smith } 216f98b2f00SMatthew G. Knepley ++sp->nopts; 2175c6c1daeSBarry Smith PetscFunctionReturn(0); 2185c6c1daeSBarry Smith } 2195c6c1daeSBarry Smith 2205c6c1daeSBarry Smith /*@C 221*811af0c4SBarry Smith PetscDrawSPAddPoints - Adds several points to each of the scatter plot point curves. 2225c6c1daeSBarry Smith 223f98b2f00SMatthew G. Knepley Not collective 2245c6c1daeSBarry Smith 2255c6c1daeSBarry Smith Input Parameters: 226*811af0c4SBarry Smith + sp - the scatter plot context 227f98b2f00SMatthew G. Knepley . xx,yy - points to two arrays of pointers that point to arrays containing the new x and y points for each curve. 228*811af0c4SBarry Smith - n - number of points being added, each represents a subarray of length dim where dim is the value from `PetscDrawSPGetDimension()` 2295c6c1daeSBarry Smith 2305c6c1daeSBarry Smith Level: intermediate 2315c6c1daeSBarry Smith 232*811af0c4SBarry Smith Note: 233*811af0c4SBarry Smith The new points will not be displayed until a call to `PetscDrawSPDraw()` is made 2340afdd333SBarry Smith 235db781477SPatrick Sanan .seealso: `PetscDrawSPAddPoint()`, `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPReset()`, `PetscDrawSPDraw()`, `PetscDrawSPAddPointColorized()` 2365c6c1daeSBarry Smith @*/ 2379371c9d4SSatish Balay PetscErrorCode PetscDrawSPAddPoints(PetscDrawSP sp, int n, PetscReal **xx, PetscReal **yy) { 2385c6c1daeSBarry Smith PetscInt i, j, k; 2395c6c1daeSBarry Smith PetscReal *x, *y; 2405c6c1daeSBarry Smith 2415c6c1daeSBarry Smith PetscFunctionBegin; 2425c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 2435c6c1daeSBarry Smith 2445c6c1daeSBarry Smith if (sp->loc + n * sp->dim >= sp->len) { /* allocate more space */ 245f98b2f00SMatthew G. Knepley PetscReal *tmpx, *tmpy, *tmpz; 246999739cfSJacob Faibussowitsch PetscInt chunk = PETSC_DRAW_SP_CHUNK_SIZE; 2475c6c1daeSBarry Smith if (n > chunk) chunk = n; 248f98b2f00SMatthew G. Knepley PetscCall(PetscMalloc3(sp->len + sp->dim * chunk, &tmpx, sp->len + sp->dim * chunk, &tmpy, sp->len + sp->dim * chunk, &tmpz)); 249f98b2f00SMatthew G. Knepley PetscCall(PetscLogObjectMemory((PetscObject)sp, 3 * sp->dim * PETSC_DRAW_SP_CHUNK_SIZE * sizeof(PetscReal))); 2509566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpx, sp->x, sp->len)); 2519566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpy, sp->y, sp->len)); 252f98b2f00SMatthew G. Knepley PetscCall(PetscArraycpy(tmpz, sp->z, sp->len)); 253f98b2f00SMatthew G. Knepley PetscCall(PetscFree3(sp->x, sp->y, sp->z)); 254a297a907SKarl Rupp 2555c6c1daeSBarry Smith sp->x = tmpx; 2565c6c1daeSBarry Smith sp->y = tmpy; 257f98b2f00SMatthew G. Knepley sp->z = tmpz; 258999739cfSJacob Faibussowitsch sp->len += sp->dim * PETSC_DRAW_SP_CHUNK_SIZE; 2595c6c1daeSBarry Smith } 260f98b2f00SMatthew G. Knepley for (j = 0; j < sp->dim; ++j) { 2619371c9d4SSatish Balay x = xx[j]; 2629371c9d4SSatish Balay y = yy[j]; 2635c6c1daeSBarry Smith k = sp->loc + j; 264f98b2f00SMatthew G. Knepley for (i = 0; i < n; ++i) { 2655c6c1daeSBarry Smith if (x[i] > sp->xmax) sp->xmax = x[i]; 2665c6c1daeSBarry Smith if (x[i] < sp->xmin) sp->xmin = x[i]; 2675c6c1daeSBarry Smith if (y[i] > sp->ymax) sp->ymax = y[i]; 2685c6c1daeSBarry Smith if (y[i] < sp->ymin) sp->ymin = y[i]; 2695c6c1daeSBarry Smith 2705c6c1daeSBarry Smith sp->x[k] = x[i]; 2715c6c1daeSBarry Smith sp->y[k] = y[i]; 2725c6c1daeSBarry Smith k += sp->dim; 2735c6c1daeSBarry Smith } 2745c6c1daeSBarry Smith } 2755c6c1daeSBarry Smith sp->loc += n * sp->dim; 2765c6c1daeSBarry Smith sp->nopts += n; 2775c6c1daeSBarry Smith PetscFunctionReturn(0); 2785c6c1daeSBarry Smith } 2795c6c1daeSBarry Smith 2805c6c1daeSBarry Smith /*@ 2818c87cf4dSdanfinn PetscDrawSPAddPointColorized - Adds another point to each of the scatter plots as well as a numeric value to be used to colorize the scatter point. 2828c87cf4dSdanfinn 283f98b2f00SMatthew G. Knepley Not collective 2848c87cf4dSdanfinn 2858c87cf4dSdanfinn Input Parameters: 2868c87cf4dSdanfinn + sp - the scatter plot data structure 287*811af0c4SBarry Smith . x, y - two arrays of length dim containing the new x and y coordinate values for each of the point curves. Here dim is the number of point curves passed to `PetscDrawSPCreate()` 2888c87cf4dSdanfinn - z - array of length dim containing the numeric values that will be mapped to [0,255] and used for scatter point colors. 2898c87cf4dSdanfinn 2908c87cf4dSdanfinn Level: intermediate 2918c87cf4dSdanfinn 292*811af0c4SBarry Smith Note: 293*811af0c4SBarry Smith The new points will not be displayed until a call to `PetscDrawSPDraw()` is made 2948c87cf4dSdanfinn 295db781477SPatrick Sanan .seealso: `PetscDrawSPAddPoints()`, `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPReset()`, `PetscDrawSPDraw()`, `PetscDrawSPAddPoint()` 2968c87cf4dSdanfinn @*/ 2979371c9d4SSatish Balay PetscErrorCode PetscDrawSPAddPointColorized(PetscDrawSP sp, PetscReal *x, PetscReal *y, PetscReal *z) { 2988c87cf4dSdanfinn PetscInt i; 2998c87cf4dSdanfinn 3008c87cf4dSdanfinn PetscFunctionBegin; 3018c87cf4dSdanfinn PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 3028c87cf4dSdanfinn sp->colorized = PETSC_TRUE; 3038c87cf4dSdanfinn if (sp->loc + sp->dim >= sp->len) { /* allocate more space */ 3048c87cf4dSdanfinn PetscReal *tmpx, *tmpy, *tmpz; 3059566063dSJacob Faibussowitsch PetscCall(PetscMalloc3(sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpx, sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpy, sp->len + sp->dim * PETSC_DRAW_SP_CHUNK_SIZE, &tmpz)); 306f98b2f00SMatthew G. Knepley PetscCall(PetscLogObjectMemory((PetscObject)sp, 3 * sp->dim * PETSC_DRAW_SP_CHUNK_SIZE * sizeof(PetscReal))); 3079566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpx, sp->x, sp->len)); 3089566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpy, sp->y, sp->len)); 3099566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmpz, sp->z, sp->len)); 3109566063dSJacob Faibussowitsch PetscCall(PetscFree3(sp->x, sp->y, sp->z)); 3118c87cf4dSdanfinn sp->x = tmpx; 3128c87cf4dSdanfinn sp->y = tmpy; 3138c87cf4dSdanfinn sp->z = tmpz; 3148c87cf4dSdanfinn sp->len += sp->dim * PETSC_DRAW_SP_CHUNK_SIZE; 3158c87cf4dSdanfinn } 316f98b2f00SMatthew G. Knepley for (i = 0; i < sp->dim; ++i) { 3178c87cf4dSdanfinn if (x[i] > sp->xmax) sp->xmax = x[i]; 3188c87cf4dSdanfinn if (x[i] < sp->xmin) sp->xmin = x[i]; 3198c87cf4dSdanfinn if (y[i] > sp->ymax) sp->ymax = y[i]; 3208c87cf4dSdanfinn if (y[i] < sp->ymin) sp->ymin = y[i]; 3218c87cf4dSdanfinn if (z[i] < sp->zmin) sp->zmin = z[i]; 3228c87cf4dSdanfinn if (z[i] > sp->zmax) sp->zmax = z[i]; 3238c87cf4dSdanfinn // if (z[i] > sp->zmax && z[i] < 5.) sp->zmax = z[i]; 3248c87cf4dSdanfinn 3258c87cf4dSdanfinn sp->x[sp->loc] = x[i]; 3268c87cf4dSdanfinn sp->y[sp->loc] = y[i]; 3278c87cf4dSdanfinn sp->z[sp->loc++] = z[i]; 3288c87cf4dSdanfinn } 329f98b2f00SMatthew G. Knepley ++sp->nopts; 3308c87cf4dSdanfinn PetscFunctionReturn(0); 3318c87cf4dSdanfinn } 3328c87cf4dSdanfinn 3338c87cf4dSdanfinn /*@ 3345c6c1daeSBarry Smith PetscDrawSPDraw - Redraws a scatter plot. 3355c6c1daeSBarry Smith 336*811af0c4SBarry Smith Collective on sp 3375c6c1daeSBarry Smith 338d8d19677SJose E. Roman Input Parameters: 339*811af0c4SBarry Smith + sp - the scatter plot context 3405c6c1daeSBarry Smith - clear - clear the window before drawing the new plot 3415c6c1daeSBarry Smith 3425c6c1daeSBarry Smith Level: intermediate 3435c6c1daeSBarry Smith 344db781477SPatrick Sanan .seealso: `PetscDrawLGDraw()`, `PetscDrawLGSPDraw()`, `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPReset()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()` 3455c6c1daeSBarry Smith @*/ 3469371c9d4SSatish Balay PetscErrorCode PetscDrawSPDraw(PetscDrawSP sp, PetscBool clear) { 347e118a51fSLisandro Dalcin PetscDraw draw; 348f98b2f00SMatthew G. Knepley PetscBool isnull; 349f98b2f00SMatthew G. Knepley PetscMPIInt rank, size; 3505c6c1daeSBarry Smith 3515c6c1daeSBarry Smith PetscFunctionBegin; 3525c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 353f98b2f00SMatthew G. Knepley draw = sp->win; 354f98b2f00SMatthew G. Knepley PetscCall(PetscDrawIsNull(draw, &isnull)); 3558f69470aSLisandro Dalcin if (isnull) PetscFunctionReturn(0); 3569566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)sp), &rank)); 357f98b2f00SMatthew G. Knepley PetscCallMPI(MPI_Comm_size(PetscObjectComm((PetscObject)sp), &size)); 358e118a51fSLisandro Dalcin 3595c6c1daeSBarry Smith if (clear) { 3609566063dSJacob Faibussowitsch PetscCall(PetscDrawCheckResizedWindow(draw)); 3619566063dSJacob Faibussowitsch PetscCall(PetscDrawClear(draw)); 3625c6c1daeSBarry Smith } 363f98b2f00SMatthew G. Knepley { 364f98b2f00SMatthew G. Knepley PetscReal lower[2] = {sp->xmin, sp->ymin}, glower[2]; 365f98b2f00SMatthew G. Knepley PetscReal upper[2] = {sp->xmax, sp->ymax}, gupper[2]; 366f98b2f00SMatthew G. Knepley PetscCall(MPIU_Allreduce(lower, glower, 2, MPIU_REAL, MPIU_MIN, PetscObjectComm((PetscObject)sp))); 367f98b2f00SMatthew G. Knepley PetscCall(MPIU_Allreduce(upper, gupper, 2, MPIU_REAL, MPIU_MAX, PetscObjectComm((PetscObject)sp))); 368f98b2f00SMatthew G. Knepley PetscCall(PetscDrawAxisSetLimits(sp->axis, glower[0], gupper[0], glower[1], gupper[1])); 3699566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisDraw(sp->axis)); 370f98b2f00SMatthew G. Knepley } 3715c6c1daeSBarry Smith 372d0609cedSBarry Smith PetscDrawCollectiveBegin(draw); 373f98b2f00SMatthew G. Knepley { 374f98b2f00SMatthew G. Knepley const int dim = sp->dim, nopts = sp->nopts; 375f98b2f00SMatthew G. Knepley 376f98b2f00SMatthew G. Knepley for (int i = 0; i < dim; ++i) { 377f98b2f00SMatthew G. Knepley for (int p = 0; p < nopts; ++p) { 378f98b2f00SMatthew G. Knepley PetscInt color = sp->colorized ? PetscDrawRealToColor(sp->z[p * dim], sp->zmin, sp->zmax) : (size > 1 ? PetscDrawRealToColor(rank, 0, size - 1) : PETSC_DRAW_RED); 379f98b2f00SMatthew G. Knepley 380f98b2f00SMatthew G. Knepley PetscCall(PetscDrawPoint(draw, sp->x[p * dim + i], sp->y[p * dim + i], color)); 3815c6c1daeSBarry Smith } 3825c6c1daeSBarry Smith } 3838c87cf4dSdanfinn } 384d0609cedSBarry Smith PetscDrawCollectiveEnd(draw); 3855b399a63SLisandro Dalcin 3869566063dSJacob Faibussowitsch PetscCall(PetscDrawFlush(draw)); 3879566063dSJacob Faibussowitsch PetscCall(PetscDrawPause(draw)); 3885c6c1daeSBarry Smith PetscFunctionReturn(0); 3895c6c1daeSBarry Smith } 3905c6c1daeSBarry Smith 39157fd6651SLisandro Dalcin /*@ 39257fd6651SLisandro Dalcin PetscDrawSPSave - Saves a drawn image 39357fd6651SLisandro Dalcin 394*811af0c4SBarry Smith Collective on sp 39557fd6651SLisandro Dalcin 39657fd6651SLisandro Dalcin Input Parameter: 39757fd6651SLisandro Dalcin . sp - the scatter plot context 39857fd6651SLisandro Dalcin 39957fd6651SLisandro Dalcin Level: intermediate 40057fd6651SLisandro Dalcin 401*811af0c4SBarry Smith .seealso: `PetscDrawSPSave()`, `PetscDrawSPCreate()`, `PetscDrawSPGetDraw()`, `PetscDrawSetSave()`, `PetscDrawSave()` 40257fd6651SLisandro Dalcin @*/ 4039371c9d4SSatish Balay PetscErrorCode PetscDrawSPSave(PetscDrawSP sp) { 40457fd6651SLisandro Dalcin PetscFunctionBegin; 40557fd6651SLisandro Dalcin PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 4069566063dSJacob Faibussowitsch PetscCall(PetscDrawSave(sp->win)); 40757fd6651SLisandro Dalcin PetscFunctionReturn(0); 40857fd6651SLisandro Dalcin } 40957fd6651SLisandro Dalcin 4105c6c1daeSBarry Smith /*@ 411f98b2f00SMatthew G. Knepley PetscDrawSPSetLimits - Sets the axis limits for a scatter plot. If more points are added after this call, the limits will be adjusted to include those additional points. 4125c6c1daeSBarry Smith 413f98b2f00SMatthew G. Knepley Not collective 4145c6c1daeSBarry Smith 4155c6c1daeSBarry Smith Input Parameters: 4165c6c1daeSBarry Smith + xsp - the line graph context 4175c6c1daeSBarry Smith - x_min,x_max,y_min,y_max - the limits 4185c6c1daeSBarry Smith 4195c6c1daeSBarry Smith Level: intermediate 4205c6c1daeSBarry Smith 421*811af0c4SBarry Smith .seealso: `PetscDrawSP`, `PetscDrawAxis`, `PetscDrawSPCreate()`, `PetscDrawSPDraw()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()`, `PetscDrawSPGetAxis()` 4225c6c1daeSBarry Smith @*/ 4239371c9d4SSatish Balay PetscErrorCode PetscDrawSPSetLimits(PetscDrawSP sp, PetscReal x_min, PetscReal x_max, PetscReal y_min, PetscReal y_max) { 4245c6c1daeSBarry Smith PetscFunctionBegin; 4255c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 4265c6c1daeSBarry Smith sp->xmin = x_min; 4275c6c1daeSBarry Smith sp->xmax = x_max; 4285c6c1daeSBarry Smith sp->ymin = y_min; 4295c6c1daeSBarry Smith sp->ymax = y_max; 4305c6c1daeSBarry Smith PetscFunctionReturn(0); 4315c6c1daeSBarry Smith } 4325c6c1daeSBarry Smith 433f98b2f00SMatthew G. Knepley /*@ 434*811af0c4SBarry Smith PetscDrawSPGetAxis - Gets the axis context associated with a scatter plot 4355c6c1daeSBarry Smith 436f98b2f00SMatthew G. Knepley Not Collective 4375c6c1daeSBarry Smith 4385c6c1daeSBarry Smith Input Parameter: 439*811af0c4SBarry Smith . sp - the scatter plot context 4405c6c1daeSBarry Smith 4415c6c1daeSBarry Smith Output Parameter: 4425c6c1daeSBarry Smith . axis - the axis context 4435c6c1daeSBarry Smith 444f98b2f00SMatthew G. Knepley Note: 445f98b2f00SMatthew G. Knepley This is useful if one wants to change some axis property, such as labels, color, etc. The axis context should not be destroyed by the application code. 446f98b2f00SMatthew G. Knepley 4475c6c1daeSBarry Smith Level: intermediate 4485c6c1daeSBarry Smith 449db781477SPatrick Sanan .seealso: `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPDraw()`, `PetscDrawSPAddPoint()`, `PetscDrawSPAddPoints()`, `PetscDrawAxis`, `PetscDrawAxisCreate()` 4505c6c1daeSBarry Smith @*/ 4519371c9d4SSatish Balay PetscErrorCode PetscDrawSPGetAxis(PetscDrawSP sp, PetscDrawAxis *axis) { 4525c6c1daeSBarry Smith PetscFunctionBegin; 4535c6c1daeSBarry Smith PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 45445f3bb6eSLisandro Dalcin PetscValidPointer(axis, 2); 4555c6c1daeSBarry Smith *axis = sp->axis; 4565c6c1daeSBarry Smith PetscFunctionReturn(0); 4575c6c1daeSBarry Smith } 4585c6c1daeSBarry Smith 459f98b2f00SMatthew G. Knepley /*@ 460*811af0c4SBarry Smith PetscDrawSPGetDraw - Gets the draw context associated with a scatter plot 4615c6c1daeSBarry Smith 462f98b2f00SMatthew G. Knepley Not Collective 4635c6c1daeSBarry Smith 4645c6c1daeSBarry Smith Input Parameter: 465*811af0c4SBarry Smith . sp - the scatter plot context 4665c6c1daeSBarry Smith 4675c6c1daeSBarry Smith Output Parameter: 4685c6c1daeSBarry Smith . draw - the draw context 4695c6c1daeSBarry Smith 4705c6c1daeSBarry Smith Level: intermediate 4715c6c1daeSBarry Smith 472db781477SPatrick Sanan .seealso: `PetscDrawSP`, `PetscDrawSPCreate()`, `PetscDrawSPDraw()`, `PetscDraw` 4735c6c1daeSBarry Smith @*/ 4749371c9d4SSatish Balay PetscErrorCode PetscDrawSPGetDraw(PetscDrawSP sp, PetscDraw *draw) { 4755c6c1daeSBarry Smith PetscFunctionBegin; 476e118a51fSLisandro Dalcin PetscValidHeaderSpecific(sp, PETSC_DRAWSP_CLASSID, 1); 47745f3bb6eSLisandro Dalcin PetscValidPointer(draw, 2); 478e118a51fSLisandro Dalcin *draw = sp->win; 4795c6c1daeSBarry Smith PetscFunctionReturn(0); 4805c6c1daeSBarry Smith } 481