15c6c1daeSBarry Smith /* 25c6c1daeSBarry Smith Contains the data structure for plotting a histogram in a window with an axis. 35c6c1daeSBarry Smith */ 49804daf3SBarry Smith #include <petscdraw.h> /*I "petscdraw.h" I*/ 5af0996ceSBarry Smith #include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/ 634a5a0e3SBarry Smith #include <petscviewer.h> /*I "petscviewer.h" I*/ 75c6c1daeSBarry Smith 85c6c1daeSBarry Smith PetscClassId PETSC_DRAWHG_CLASSID = 0; 95c6c1daeSBarry Smith 105c6c1daeSBarry Smith struct _p_PetscDrawHG { 115c6c1daeSBarry Smith PETSCHEADER(int); 125c6c1daeSBarry Smith PetscErrorCode (*destroy)(PetscDrawSP); 135c6c1daeSBarry Smith PetscErrorCode (*view)(PetscDrawSP, PetscViewer); 145c6c1daeSBarry Smith PetscDraw win; 155c6c1daeSBarry Smith PetscDrawAxis axis; 165c6c1daeSBarry Smith PetscReal xmin, xmax; 175c6c1daeSBarry Smith PetscReal ymin, ymax; 185c6c1daeSBarry Smith int numBins; 195c6c1daeSBarry Smith int maxBins; 205c6c1daeSBarry Smith PetscReal *bins; 215c6c1daeSBarry Smith int numValues; 225c6c1daeSBarry Smith int maxValues; 235c6c1daeSBarry Smith PetscReal *values; 24*cddde00dSMatthew G. Knepley PetscReal *weights; 255c6c1daeSBarry Smith int color; 265c6c1daeSBarry Smith PetscBool calcStats; 275c6c1daeSBarry Smith PetscBool integerBins; 285c6c1daeSBarry Smith }; 295c6c1daeSBarry Smith 305c6c1daeSBarry Smith #define CHUNKSIZE 100 315c6c1daeSBarry Smith 32cc4c1da9SBarry Smith /*@ 335c6c1daeSBarry Smith PetscDrawHGCreate - Creates a histogram data structure. 345c6c1daeSBarry Smith 35c3339decSBarry Smith Collective 365c6c1daeSBarry Smith 375c6c1daeSBarry Smith Input Parameters: 385c6c1daeSBarry Smith + draw - The window where the graph will be made 395c6c1daeSBarry Smith - bins - The number of bins to use 405c6c1daeSBarry Smith 4120f4b53cSBarry Smith Output Parameter: 425c6c1daeSBarry Smith . hist - The histogram context 435c6c1daeSBarry Smith 4420f4b53cSBarry Smith Level: intermediate 4520f4b53cSBarry Smith 4695452b02SPatrick Sanan Notes: 471d27aa22SBarry Smith The difference between a bar chart, `PetscDrawBar`, and a histogram, `PetscDrawHG`, is explained here <https://stattrek.com/statistics/charts/histogram.aspx?Tutorial=AP> 480afdd333SBarry Smith 49811af0c4SBarry Smith The histogram is only displayed when `PetscDrawHGDraw()` is called. 500afdd333SBarry Smith 51811af0c4SBarry Smith The MPI communicator that owns the `PetscDraw` owns this `PetscDrawHG`, but the calls to set options and add data are ignored on all processes except the 521d27aa22SBarry Smith zeroth MPI process in the communicator. All MPI processes in the communicator must call `PetscDrawHGDraw()` to display the updated graph. 537e25d57eSBarry Smith 54db781477SPatrick Sanan .seealso: `PetscDrawHGDestroy()`, `PetscDrawHG`, `PetscDrawBarCreate()`, `PetscDrawBar`, `PetscDrawLGCreate()`, `PetscDrawLG`, `PetscDrawSPCreate()`, `PetscDrawSP`, 55db781477SPatrick Sanan `PetscDrawHGSetNumberBins()`, `PetscDrawHGReset()`, `PetscDrawHGAddValue()`, `PetscDrawHGDraw()`, `PetscDrawHGSave()`, `PetscDrawHGView()`, `PetscDrawHGSetColor()`, 56db781477SPatrick Sanan `PetscDrawHGSetLimits()`, `PetscDrawHGCalcStats()`, `PetscDrawHGIntegerBins()`, `PetscDrawHGGetAxis()`, `PetscDrawAxis`, `PetscDrawHGGetDraw()` 575c6c1daeSBarry Smith @*/ 58d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGCreate(PetscDraw draw, int bins, PetscDrawHG *hist) 59d71ae5a4SJacob Faibussowitsch { 60e118a51fSLisandro Dalcin PetscDrawHG h; 615c6c1daeSBarry Smith 625c6c1daeSBarry Smith PetscFunctionBegin; 635c6c1daeSBarry Smith PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 64e118a51fSLisandro Dalcin PetscValidLogicalCollectiveInt(draw, bins, 2); 654f572ea9SToby Isaac PetscAssertPointer(hist, 3); 66e118a51fSLisandro Dalcin 679566063dSJacob Faibussowitsch PetscCall(PetscHeaderCreate(h, PETSC_DRAWHG_CLASSID, "DrawHG", "Histogram", "Draw", PetscObjectComm((PetscObject)draw), PetscDrawHGDestroy, NULL)); 689566063dSJacob Faibussowitsch PetscCall(PetscObjectReference((PetscObject)draw)); 69e118a51fSLisandro Dalcin h->win = draw; 700298fd71SBarry Smith h->view = NULL; 710298fd71SBarry Smith h->destroy = NULL; 725c6c1daeSBarry Smith h->color = PETSC_DRAW_GREEN; 735c6c1daeSBarry Smith h->xmin = PETSC_MAX_REAL; 745c6c1daeSBarry Smith h->xmax = PETSC_MIN_REAL; 755c6c1daeSBarry Smith h->ymin = 0.; 76*cddde00dSMatthew G. Knepley h->ymax = 1.e-6; 775c6c1daeSBarry Smith h->numBins = bins; 785c6c1daeSBarry Smith h->maxBins = bins; 799566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(h->maxBins, &h->bins)); 805c6c1daeSBarry Smith h->numValues = 0; 815c6c1daeSBarry Smith h->maxValues = CHUNKSIZE; 825c6c1daeSBarry Smith h->calcStats = PETSC_FALSE; 835c6c1daeSBarry Smith h->integerBins = PETSC_FALSE; 84*cddde00dSMatthew G. Knepley PetscCall(PetscMalloc2(h->maxValues, &h->values, h->maxValues, &h->weights)); 859566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisCreate(draw, &h->axis)); 865c6c1daeSBarry Smith *hist = h; 873ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 885c6c1daeSBarry Smith } 895c6c1daeSBarry Smith 905c6c1daeSBarry Smith /*@ 91811af0c4SBarry Smith PetscDrawHGSetNumberBins - Change the number of bins that are to be drawn in the histogram 925c6c1daeSBarry Smith 93c3339decSBarry Smith Logically Collective 945c6c1daeSBarry Smith 95d8d19677SJose E. Roman Input Parameters: 965c6c1daeSBarry Smith + hist - The histogram context. 97e118a51fSLisandro Dalcin - bins - The number of bins. 985c6c1daeSBarry Smith 995c6c1daeSBarry Smith Level: intermediate 1005c6c1daeSBarry Smith 101db781477SPatrick Sanan .seealso: `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawHGDraw()`, `PetscDrawHGIntegerBins()` 1025c6c1daeSBarry Smith @*/ 103d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGSetNumberBins(PetscDrawHG hist, int bins) 104d71ae5a4SJacob Faibussowitsch { 1055c6c1daeSBarry Smith PetscFunctionBegin; 1065c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 107e118a51fSLisandro Dalcin PetscValidLogicalCollectiveInt(hist, bins, 2); 108e118a51fSLisandro Dalcin 1095c6c1daeSBarry Smith if (hist->maxBins < bins) { 1109566063dSJacob Faibussowitsch PetscCall(PetscFree(hist->bins)); 1119566063dSJacob Faibussowitsch PetscCall(PetscMalloc1(bins, &hist->bins)); 1125c6c1daeSBarry Smith hist->maxBins = bins; 1135c6c1daeSBarry Smith } 1145c6c1daeSBarry Smith hist->numBins = bins; 1153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1165c6c1daeSBarry Smith } 1175c6c1daeSBarry Smith 1185c6c1daeSBarry Smith /*@ 1195c6c1daeSBarry Smith PetscDrawHGReset - Clears histogram to allow for reuse with new data. 1205c6c1daeSBarry Smith 121c3339decSBarry Smith Logically Collective 1225c6c1daeSBarry Smith 1235c6c1daeSBarry Smith Input Parameter: 1245c6c1daeSBarry Smith . hist - The histogram context. 1255c6c1daeSBarry Smith 1265c6c1daeSBarry Smith Level: intermediate 1275c6c1daeSBarry Smith 128db781477SPatrick Sanan .seealso: `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawHGDraw()`, `PetscDrawHGAddValue()` 1295c6c1daeSBarry Smith @*/ 130d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGReset(PetscDrawHG hist) 131d71ae5a4SJacob Faibussowitsch { 1325c6c1daeSBarry Smith PetscFunctionBegin; 1335c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 134e118a51fSLisandro Dalcin 1355c6c1daeSBarry Smith hist->xmin = PETSC_MAX_REAL; 1365c6c1daeSBarry Smith hist->xmax = PETSC_MIN_REAL; 1375c6c1daeSBarry Smith hist->ymin = 0.0; 138*cddde00dSMatthew G. Knepley hist->ymax = 1.e-6; 1395c6c1daeSBarry Smith hist->numValues = 0; 1403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1415c6c1daeSBarry Smith } 1425c6c1daeSBarry Smith 1435d83a8b1SBarry Smith /*@ 1445c6c1daeSBarry Smith PetscDrawHGDestroy - Frees all space taken up by histogram data structure. 1455c6c1daeSBarry Smith 146c3339decSBarry Smith Collective 1475c6c1daeSBarry Smith 1485c6c1daeSBarry Smith Input Parameter: 1495c6c1daeSBarry Smith . hist - The histogram context 1505c6c1daeSBarry Smith 1515c6c1daeSBarry Smith Level: intermediate 1525c6c1daeSBarry Smith 153db781477SPatrick Sanan .seealso: `PetscDrawHGCreate()`, `PetscDrawHG` 1545c6c1daeSBarry Smith @*/ 155d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGDestroy(PetscDrawHG *hist) 156d71ae5a4SJacob Faibussowitsch { 1575c6c1daeSBarry Smith PetscFunctionBegin; 1583ba16761SJacob Faibussowitsch if (!*hist) PetscFunctionReturn(PETSC_SUCCESS); 159e118a51fSLisandro Dalcin PetscValidHeaderSpecific(*hist, PETSC_DRAWHG_CLASSID, 1); 160f4f49eeaSPierre Jolivet if (--((PetscObject)*hist)->refct > 0) { 1619371c9d4SSatish Balay *hist = NULL; 1623ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1639371c9d4SSatish Balay } 1645c6c1daeSBarry Smith 1659566063dSJacob Faibussowitsch PetscCall(PetscFree((*hist)->bins)); 166*cddde00dSMatthew G. Knepley PetscCall(PetscFree2((*hist)->values, (*hist)->weights)); 1679566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisDestroy(&(*hist)->axis)); 1689566063dSJacob Faibussowitsch PetscCall(PetscDrawDestroy(&(*hist)->win)); 1699566063dSJacob Faibussowitsch PetscCall(PetscHeaderDestroy(hist)); 1703ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1715c6c1daeSBarry Smith } 1725c6c1daeSBarry Smith 1735c6c1daeSBarry Smith /*@ 1745c6c1daeSBarry Smith PetscDrawHGAddValue - Adds another value to the histogram. 1755c6c1daeSBarry Smith 176c3339decSBarry Smith Logically Collective 1775c6c1daeSBarry Smith 1785c6c1daeSBarry Smith Input Parameters: 1795c6c1daeSBarry Smith + hist - The histogram 1805c6c1daeSBarry Smith - value - The value 1815c6c1daeSBarry Smith 1825c6c1daeSBarry Smith Level: intermediate 1835c6c1daeSBarry Smith 184*cddde00dSMatthew G. Knepley Note: 185*cddde00dSMatthew G. Knepley Calls to this function are used to create a standard histogram with integer bin heights. Use calls to `PetscDrawHGAddWeightedValue()` to create a histogram with non-integer bin heights. 186*cddde00dSMatthew G. Knepley 187*cddde00dSMatthew G. Knepley .seealso: `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawHGDraw()`, `PetscDrawHGReset()`, `PetscDrawHGAddWeightedValue()` 1885c6c1daeSBarry Smith @*/ 189d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGAddValue(PetscDrawHG hist, PetscReal value) 190d71ae5a4SJacob Faibussowitsch { 1915c6c1daeSBarry Smith PetscFunctionBegin; 1925c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 193e118a51fSLisandro Dalcin 1945c6c1daeSBarry Smith /* Allocate more memory if necessary */ 1955c6c1daeSBarry Smith if (hist->numValues >= hist->maxValues) { 196*cddde00dSMatthew G. Knepley PetscReal *tmp, *tmpw; 1975c6c1daeSBarry Smith 198*cddde00dSMatthew G. Knepley PetscCall(PetscMalloc2(hist->maxValues + CHUNKSIZE, &tmp, hist->maxValues + CHUNKSIZE, &tmpw)); 1999566063dSJacob Faibussowitsch PetscCall(PetscArraycpy(tmp, hist->values, hist->maxValues)); 200*cddde00dSMatthew G. Knepley PetscCall(PetscArraycpy(tmpw, hist->weights, hist->maxValues)); 201*cddde00dSMatthew G. Knepley PetscCall(PetscFree2(hist->values, hist->weights)); 202a297a907SKarl Rupp 2035c6c1daeSBarry Smith hist->values = tmp; 204*cddde00dSMatthew G. Knepley hist->weights = tmpw; 2055c6c1daeSBarry Smith hist->maxValues += CHUNKSIZE; 2065c6c1daeSBarry Smith } 2075c6c1daeSBarry Smith /* I disagree with the original Petsc implementation here. There should be no overshoot, but rather the 2085c6c1daeSBarry Smith stated convention of using half-open intervals (always the way to go) */ 209d0c080abSJoseph Pusztay if (!hist->numValues && (hist->xmin == PETSC_MAX_REAL) && (hist->xmax == PETSC_MIN_REAL)) { 2105c6c1daeSBarry Smith hist->xmin = value; 2115c6c1daeSBarry Smith hist->xmax = value; 2125c6c1daeSBarry Smith #if 1 2135c6c1daeSBarry Smith } else { 2145c6c1daeSBarry Smith /* Update limits */ 215a297a907SKarl Rupp if (value > hist->xmax) hist->xmax = value; 216a297a907SKarl Rupp if (value < hist->xmin) hist->xmin = value; 2175c6c1daeSBarry Smith #else 2185c6c1daeSBarry Smith } else if (hist->numValues == 1) { 2195c6c1daeSBarry Smith /* Update limits -- We need to overshoot the largest value somewhat */ 2206497c311SBarry Smith if (value > hist->xmax) hist->xmax = value + 0.001 * (value - hist->xmin) / (PetscReal)hist->numBins; 2215c6c1daeSBarry Smith if (value < hist->xmin) { 2225c6c1daeSBarry Smith hist->xmin = value; 2236497c311SBarry Smith hist->xmax = hist->xmax + 0.001 * (hist->xmax - hist->xmin) / (PetscReal)hist->numBins; 2245c6c1daeSBarry Smith } 2255c6c1daeSBarry Smith } else { 2265c6c1daeSBarry Smith /* Update limits -- We need to overshoot the largest value somewhat */ 2276497c311SBarry Smith if (value > hist->xmax) hist->xmax = value + 0.001 * (hist->xmax - hist->xmin) / (PetscReal)hist->numBins; 228a297a907SKarl Rupp if (value < hist->xmin) hist->xmin = value; 2295c6c1daeSBarry Smith #endif 2305c6c1daeSBarry Smith } 2315c6c1daeSBarry Smith 232*cddde00dSMatthew G. Knepley hist->values[hist->numValues] = value; 233*cddde00dSMatthew G. Knepley hist->weights[hist->numValues] = 1.; 234*cddde00dSMatthew G. Knepley ++hist->numValues; 235*cddde00dSMatthew G. Knepley PetscFunctionReturn(PETSC_SUCCESS); 236*cddde00dSMatthew G. Knepley } 237*cddde00dSMatthew G. Knepley 238*cddde00dSMatthew G. Knepley /*@ 239*cddde00dSMatthew G. Knepley PetscDrawHGAddWeightedValue - Adds another value to the histogram with a weight. 240*cddde00dSMatthew G. Knepley 241*cddde00dSMatthew G. Knepley Logically Collective 242*cddde00dSMatthew G. Knepley 243*cddde00dSMatthew G. Knepley Input Parameters: 244*cddde00dSMatthew G. Knepley + hist - The histogram 245*cddde00dSMatthew G. Knepley . value - The value 246*cddde00dSMatthew G. Knepley - weight - The value weight 247*cddde00dSMatthew G. Knepley 248*cddde00dSMatthew G. Knepley Level: intermediate 249*cddde00dSMatthew G. Knepley 250*cddde00dSMatthew G. Knepley Notes: 251*cddde00dSMatthew G. Knepley Calls to this function are used to create a histogram with non-integer bin heights. Use calls to `PetscDrawHGAddValue()` to create a standard histogram with integer bin heights. 252*cddde00dSMatthew G. Knepley 253*cddde00dSMatthew G. Knepley This allows us to histogram frequency and probability distributions (<https://learnche.org/pid/univariate-review/histograms-and-probability-distributions>). We can use this to look at particle weight distributions in Particle-in-Cell (PIC) methods, for example. 254*cddde00dSMatthew G. Knepley 255*cddde00dSMatthew G. Knepley .seealso: `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawHGDraw()`, `PetscDrawHGReset()`, `PetscDrawHGAddValue()` 256*cddde00dSMatthew G. Knepley @*/ 257*cddde00dSMatthew G. Knepley PetscErrorCode PetscDrawHGAddWeightedValue(PetscDrawHG hist, PetscReal value, PetscReal weight) 258*cddde00dSMatthew G. Knepley { 259*cddde00dSMatthew G. Knepley PetscFunctionBegin; 260*cddde00dSMatthew G. Knepley PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 261*cddde00dSMatthew G. Knepley 262*cddde00dSMatthew G. Knepley /* Allocate more memory if necessary */ 263*cddde00dSMatthew G. Knepley if (hist->numValues >= hist->maxValues) { 264*cddde00dSMatthew G. Knepley PetscReal *tmp, *tmpw; 265*cddde00dSMatthew G. Knepley 266*cddde00dSMatthew G. Knepley PetscCall(PetscMalloc2(hist->maxValues + CHUNKSIZE, &tmp, hist->maxValues + CHUNKSIZE, &tmpw)); 267*cddde00dSMatthew G. Knepley PetscCall(PetscArraycpy(tmp, hist->values, hist->maxValues)); 268*cddde00dSMatthew G. Knepley PetscCall(PetscArraycpy(tmpw, hist->weights, hist->maxValues)); 269*cddde00dSMatthew G. Knepley PetscCall(PetscFree2(hist->values, hist->weights)); 270*cddde00dSMatthew G. Knepley 271*cddde00dSMatthew G. Knepley hist->values = tmp; 272*cddde00dSMatthew G. Knepley hist->weights = tmpw; 273*cddde00dSMatthew G. Knepley hist->maxValues += CHUNKSIZE; 274*cddde00dSMatthew G. Knepley } 275*cddde00dSMatthew G. Knepley /* I disagree with the original Petsc implementation here. There should be no overshoot, but rather the 276*cddde00dSMatthew G. Knepley stated convention of using half-open intervals (always the way to go) */ 277*cddde00dSMatthew G. Knepley if (!hist->numValues && (hist->xmin == PETSC_MAX_REAL) && (hist->xmax == PETSC_MIN_REAL)) { 278*cddde00dSMatthew G. Knepley hist->xmin = value; 279*cddde00dSMatthew G. Knepley hist->xmax = value; 280*cddde00dSMatthew G. Knepley } else { 281*cddde00dSMatthew G. Knepley /* Update limits */ 282*cddde00dSMatthew G. Knepley if (value > hist->xmax) hist->xmax = value; 283*cddde00dSMatthew G. Knepley if (value < hist->xmin) hist->xmin = value; 284*cddde00dSMatthew G. Knepley } 285*cddde00dSMatthew G. Knepley 286*cddde00dSMatthew G. Knepley hist->values[hist->numValues] = value; 287*cddde00dSMatthew G. Knepley hist->weights[hist->numValues] = weight; 288*cddde00dSMatthew G. Knepley ++hist->numValues; 2893ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2905c6c1daeSBarry Smith } 2915c6c1daeSBarry Smith 2925c6c1daeSBarry Smith /*@ 2935c6c1daeSBarry Smith PetscDrawHGDraw - Redraws a histogram. 2945c6c1daeSBarry Smith 295c3339decSBarry Smith Collective 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith Input Parameter: 2985c6c1daeSBarry Smith . hist - The histogram context 2995c6c1daeSBarry Smith 3005c6c1daeSBarry Smith Level: intermediate 3015c6c1daeSBarry Smith 30242747ad1SJacob Faibussowitsch .seealso: `PetscDrawHGCreate()`, `PetscDrawHG`, `PetscDrawHGAddValue()`, `PetscDrawHGReset()` 3035c6c1daeSBarry Smith @*/ 304d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGDraw(PetscDrawHG hist) 305d71ae5a4SJacob Faibussowitsch { 306e118a51fSLisandro Dalcin PetscDraw draw; 307*cddde00dSMatthew G. Knepley PetscBool isnull, usewt = PETSC_FALSE; 308*cddde00dSMatthew G. Knepley PetscReal xmin, xmax, ymin, ymax, *bins, *values, *weights, binSize, binLeft, binRight, maxHeight, mean, var, totwt = 0.; 3095c6c1daeSBarry Smith char title[256]; 3105c6c1daeSBarry Smith char xlabel[256]; 3116497c311SBarry Smith PetscInt numValues, initSize, i, p; 3126497c311SBarry Smith int bcolor, color, numBins, numBinsOld; 313e118a51fSLisandro Dalcin PetscMPIInt rank; 3145c6c1daeSBarry Smith 3155c6c1daeSBarry Smith PetscFunctionBegin; 3165c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 3179566063dSJacob Faibussowitsch PetscCall(PetscDrawIsNull(hist->win, &isnull)); 3183ba16761SJacob Faibussowitsch if (isnull) PetscFunctionReturn(PETSC_SUCCESS); 3199566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_rank(PetscObjectComm((PetscObject)hist), &rank)); 320e118a51fSLisandro Dalcin 3213ba16761SJacob Faibussowitsch if ((hist->xmin >= hist->xmax) || (hist->ymin >= hist->ymax)) PetscFunctionReturn(PETSC_SUCCESS); 3223ba16761SJacob Faibussowitsch if (hist->numValues < 1) PetscFunctionReturn(PETSC_SUCCESS); 3235c6c1daeSBarry Smith 3245c6c1daeSBarry Smith color = hist->color; 32571917b75SLisandro Dalcin if (color == PETSC_DRAW_ROTATE) bcolor = PETSC_DRAW_BLACK + 1; 326a297a907SKarl Rupp else bcolor = color; 327a297a907SKarl Rupp 3285c6c1daeSBarry Smith xmin = hist->xmin; 3295c6c1daeSBarry Smith xmax = hist->xmax; 3305c6c1daeSBarry Smith ymin = hist->ymin; 3315c6c1daeSBarry Smith ymax = hist->ymax; 3325c6c1daeSBarry Smith numValues = hist->numValues; 3335c6c1daeSBarry Smith values = hist->values; 334*cddde00dSMatthew G. Knepley weights = hist->weights; 3355c6c1daeSBarry Smith mean = 0.0; 3365c6c1daeSBarry Smith var = 0.0; 3375c6c1daeSBarry Smith 3385b399a63SLisandro Dalcin draw = hist->win; 3399566063dSJacob Faibussowitsch PetscCall(PetscDrawCheckResizedWindow(draw)); 3409566063dSJacob Faibussowitsch PetscCall(PetscDrawClear(draw)); 341e118a51fSLisandro Dalcin 3425c6c1daeSBarry Smith if (xmin == xmax) { 3435c6c1daeSBarry Smith /* Calculate number of points in each bin */ 3445c6c1daeSBarry Smith bins = hist->bins; 3455c6c1daeSBarry Smith bins[0] = 0.; 3465c6c1daeSBarry Smith for (p = 0; p < numValues; p++) { 347*cddde00dSMatthew G. Knepley if (values[p] == xmin) bins[0] += weights[0]; 348*cddde00dSMatthew G. Knepley mean += values[p] * weights[p]; 349*cddde00dSMatthew G. Knepley var += values[p] * values[p] * weights[p]; 350*cddde00dSMatthew G. Knepley totwt += weights[p]; 351*cddde00dSMatthew G. Knepley if (weights[p] != 1.) usewt = PETSC_TRUE; 3525c6c1daeSBarry Smith } 3535c6c1daeSBarry Smith maxHeight = bins[0]; 3545c6c1daeSBarry Smith if (maxHeight > ymax) ymax = hist->ymax = maxHeight; 3555c6c1daeSBarry Smith xmax = xmin + 1; 3569566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisSetLimits(hist->axis, xmin, xmax, ymin, ymax)); 3575c6c1daeSBarry Smith if (hist->calcStats) { 358*cddde00dSMatthew G. Knepley if (usewt) { 359*cddde00dSMatthew G. Knepley mean /= totwt; 360*cddde00dSMatthew G. Knepley var = (var - totwt * mean * mean) / totwt; 361*cddde00dSMatthew G. Knepley 362*cddde00dSMatthew G. Knepley PetscCall(PetscSNPrintf(xlabel, 256, "Total Weight: %g", (double)totwt)); 363*cddde00dSMatthew G. Knepley } else { 364*cddde00dSMatthew G. Knepley mean /= numValues; 365*cddde00dSMatthew G. Knepley if (numValues > 1) var = (var - numValues * mean * mean) / (PetscReal)(numValues - 1); 366a297a907SKarl Rupp else var = 0.0; 367*cddde00dSMatthew G. Knepley 3689566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(xlabel, 256, "Total: %" PetscInt_FMT, numValues)); 369*cddde00dSMatthew G. Knepley } 370*cddde00dSMatthew G. Knepley PetscCall(PetscSNPrintf(title, 256, "Mean: %g Var: %g", (double)mean, (double)var)); 3719566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisSetLabels(hist->axis, title, xlabel, NULL)); 3725c6c1daeSBarry Smith } 3739566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisDraw(hist->axis)); 374d0609cedSBarry Smith PetscDrawCollectiveBegin(draw); 375dd400576SPatrick Sanan if (rank == 0) { /* Draw bins */ 3765c6c1daeSBarry Smith binLeft = xmin; 3775c6c1daeSBarry Smith binRight = xmax; 3789566063dSJacob Faibussowitsch PetscCall(PetscDrawRectangle(draw, binLeft, ymin, binRight, bins[0], bcolor, bcolor, bcolor, bcolor)); 3799566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binLeft, ymin, binLeft, bins[0], PETSC_DRAW_BLACK)); 3809566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binRight, ymin, binRight, bins[0], PETSC_DRAW_BLACK)); 3819566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binLeft, bins[0], binRight, bins[0], PETSC_DRAW_BLACK)); 382e118a51fSLisandro Dalcin } 383d0609cedSBarry Smith PetscDrawCollectiveEnd(draw); 3845c6c1daeSBarry Smith } else { 3855c6c1daeSBarry Smith numBins = hist->numBins; 3865c6c1daeSBarry Smith numBinsOld = hist->numBins; 3875c6c1daeSBarry Smith if (hist->integerBins && (((int)xmax - xmin) + 1.0e-05 > xmax - xmin)) { 388835f2295SStefano Zampini initSize = ((int)(xmax - xmin)) / numBins; 3895c6c1daeSBarry Smith while (initSize * numBins != (int)xmax - xmin) { 3905c6c1daeSBarry Smith initSize = PetscMax(initSize - 1, 1); 391835f2295SStefano Zampini numBins = ((int)(xmax - xmin)) / initSize; 3929566063dSJacob Faibussowitsch PetscCall(PetscDrawHGSetNumberBins(hist, numBins)); 3935c6c1daeSBarry Smith } 3945c6c1daeSBarry Smith } 3956497c311SBarry Smith binSize = (xmax - xmin) / (PetscReal)numBins; 3965c6c1daeSBarry Smith bins = hist->bins; 3975c6c1daeSBarry Smith 3989566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(bins, numBins)); 399a297a907SKarl Rupp 4005c6c1daeSBarry Smith maxHeight = 0.0; 4015c6c1daeSBarry Smith for (i = 0; i < numBins; i++) { 4025c6c1daeSBarry Smith binLeft = xmin + binSize * i; 4035c6c1daeSBarry Smith binRight = xmin + binSize * (i + 1); 4045c6c1daeSBarry Smith for (p = 0; p < numValues; p++) { 405*cddde00dSMatthew G. Knepley if ((values[p] >= binLeft) && (values[p] < binRight)) bins[i] += weights[p]; 4065c6c1daeSBarry Smith /* Handle last bin separately */ 407*cddde00dSMatthew G. Knepley if ((i == numBins - 1) && (values[p] == binRight)) bins[i] += weights[p]; 4085c6c1daeSBarry Smith if (!i) { 409*cddde00dSMatthew G. Knepley mean += values[p] * weights[p]; 410*cddde00dSMatthew G. Knepley var += values[p] * values[p] * weights[p]; 411*cddde00dSMatthew G. Knepley totwt += weights[p]; 412*cddde00dSMatthew G. Knepley if (weights[p] != 1.) usewt = PETSC_TRUE; 4135c6c1daeSBarry Smith } 4145c6c1daeSBarry Smith } 4155c6c1daeSBarry Smith maxHeight = PetscMax(maxHeight, bins[i]); 4165c6c1daeSBarry Smith } 4175c6c1daeSBarry Smith if (maxHeight > ymax) ymax = hist->ymax = maxHeight; 4185c6c1daeSBarry Smith 4199566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisSetLimits(hist->axis, xmin, xmax, ymin, ymax)); 4205c6c1daeSBarry Smith if (hist->calcStats) { 421*cddde00dSMatthew G. Knepley if (usewt) { 422*cddde00dSMatthew G. Knepley mean /= totwt; 423*cddde00dSMatthew G. Knepley var = (var - totwt * mean * mean) / totwt; 424*cddde00dSMatthew G. Knepley 425*cddde00dSMatthew G. Knepley PetscCall(PetscSNPrintf(xlabel, 256, "Total Weight: %g", (double)totwt)); 426*cddde00dSMatthew G. Knepley } else { 4275c6c1daeSBarry Smith mean /= numValues; 428*cddde00dSMatthew G. Knepley if (numValues > 1) var = (var - numValues * mean * mean) / (PetscReal)(numValues - 1); 429a297a907SKarl Rupp else var = 0.0; 430*cddde00dSMatthew G. Knepley 4319566063dSJacob Faibussowitsch PetscCall(PetscSNPrintf(xlabel, 256, "Total: %" PetscInt_FMT, numValues)); 432*cddde00dSMatthew G. Knepley } 433*cddde00dSMatthew G. Knepley PetscCall(PetscSNPrintf(title, 256, "Mean: %g Var: %g", (double)mean, (double)var)); 4349566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisSetLabels(hist->axis, title, xlabel, NULL)); 4355c6c1daeSBarry Smith } 4369566063dSJacob Faibussowitsch PetscCall(PetscDrawAxisDraw(hist->axis)); 437d0609cedSBarry Smith PetscDrawCollectiveBegin(draw); 438dd400576SPatrick Sanan if (rank == 0) { /* Draw bins */ 4395c6c1daeSBarry Smith for (i = 0; i < numBins; i++) { 4405c6c1daeSBarry Smith binLeft = xmin + binSize * i; 4415c6c1daeSBarry Smith binRight = xmin + binSize * (i + 1); 4429566063dSJacob Faibussowitsch PetscCall(PetscDrawRectangle(draw, binLeft, ymin, binRight, bins[i], bcolor, bcolor, bcolor, bcolor)); 4439566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binLeft, ymin, binLeft, bins[i], PETSC_DRAW_BLACK)); 4449566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binRight, ymin, binRight, bins[i], PETSC_DRAW_BLACK)); 4459566063dSJacob Faibussowitsch PetscCall(PetscDrawLine(draw, binLeft, bins[i], binRight, bins[i], PETSC_DRAW_BLACK)); 446e118a51fSLisandro Dalcin if (color == PETSC_DRAW_ROTATE && bins[i]) bcolor++; 44771917b75SLisandro Dalcin if (bcolor > PETSC_DRAW_BASIC_COLORS - 1) bcolor = PETSC_DRAW_BLACK + 1; 448e118a51fSLisandro Dalcin } 4495c6c1daeSBarry Smith } 450d0609cedSBarry Smith PetscDrawCollectiveEnd(draw); 4519566063dSJacob Faibussowitsch PetscCall(PetscDrawHGSetNumberBins(hist, numBinsOld)); 4525c6c1daeSBarry Smith } 453e118a51fSLisandro Dalcin 4549566063dSJacob Faibussowitsch PetscCall(PetscDrawFlush(draw)); 4559566063dSJacob Faibussowitsch PetscCall(PetscDrawPause(draw)); 4563ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 4575c6c1daeSBarry Smith } 4585c6c1daeSBarry Smith 45957fd6651SLisandro Dalcin /*@ 46057fd6651SLisandro Dalcin PetscDrawHGSave - Saves a drawn image 46157fd6651SLisandro Dalcin 462c3339decSBarry Smith Collective 46357fd6651SLisandro Dalcin 46457fd6651SLisandro Dalcin Input Parameter: 465aec76313SJacob Faibussowitsch . hg - The histogram context 46657fd6651SLisandro Dalcin 46757fd6651SLisandro Dalcin Level: intermediate 46857fd6651SLisandro Dalcin 469aec76313SJacob Faibussowitsch .seealso: `PetscDrawSave()`, `PetscDrawHGCreate()`, `PetscDrawHGGetDraw()`, `PetscDrawSetSave()`, `PetscDrawHGDraw()` 47057fd6651SLisandro Dalcin @*/ 471d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGSave(PetscDrawHG hg) 472d71ae5a4SJacob Faibussowitsch { 47357fd6651SLisandro Dalcin PetscFunctionBegin; 47457fd6651SLisandro Dalcin PetscValidHeaderSpecific(hg, PETSC_DRAWHG_CLASSID, 1); 4759566063dSJacob Faibussowitsch PetscCall(PetscDrawSave(hg->win)); 4763ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 47757fd6651SLisandro Dalcin } 47857fd6651SLisandro Dalcin 4795c6c1daeSBarry Smith /*@ 480811af0c4SBarry Smith PetscDrawHGView - Prints the histogram information to a viewer 4815c6c1daeSBarry Smith 48220f4b53cSBarry Smith Not Collective 4835c6c1daeSBarry Smith 48410450e9eSJacob Faibussowitsch Input Parameters: 48510450e9eSJacob Faibussowitsch + hist - The histogram context 48610450e9eSJacob Faibussowitsch - viewer - The viewer to view it with 4875c6c1daeSBarry Smith 4885c6c1daeSBarry Smith Level: beginner 4895c6c1daeSBarry Smith 490811af0c4SBarry Smith .seealso: `PetscDrawHG`, `PetscViewer`, `PetscDrawHGCreate()`, `PetscDrawHGGetDraw()`, `PetscDrawSetSave()`, `PetscDrawSave()`, `PetscDrawHGDraw()` 4915c6c1daeSBarry Smith @*/ 492d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGView(PetscDrawHG hist, PetscViewer viewer) 493d71ae5a4SJacob Faibussowitsch { 494*cddde00dSMatthew G. Knepley PetscReal xmax, xmin, *bins, *values, *weights, binSize, binLeft, binRight, mean, var, totwt = 0.; 4955c6c1daeSBarry Smith PetscInt numBins, numBinsOld, numValues, initSize, i, p; 496*cddde00dSMatthew G. Knepley PetscBool usewt = PETSC_FALSE; 497835f2295SStefano Zampini int inumBins; 4985c6c1daeSBarry Smith 4995c6c1daeSBarry Smith PetscFunctionBegin; 5005c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 501e118a51fSLisandro Dalcin 5023ba16761SJacob Faibussowitsch if ((hist->xmin > hist->xmax) || (hist->ymin >= hist->ymax)) PetscFunctionReturn(PETSC_SUCCESS); 5033ba16761SJacob Faibussowitsch if (hist->numValues < 1) PetscFunctionReturn(PETSC_SUCCESS); 5045c6c1daeSBarry Smith 50548a46eb9SPierre Jolivet if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)hist), &viewer)); 5069566063dSJacob Faibussowitsch PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)hist, viewer)); 5075c6c1daeSBarry Smith xmax = hist->xmax; 5085c6c1daeSBarry Smith xmin = hist->xmin; 5095c6c1daeSBarry Smith numValues = hist->numValues; 5105c6c1daeSBarry Smith values = hist->values; 511*cddde00dSMatthew G. Knepley weights = hist->weights; 5125c6c1daeSBarry Smith mean = 0.0; 5135c6c1daeSBarry Smith var = 0.0; 5145c6c1daeSBarry Smith if (xmax == xmin) { 5155c6c1daeSBarry Smith /* Calculate number of points in the bin */ 5165c6c1daeSBarry Smith bins = hist->bins; 5175c6c1daeSBarry Smith bins[0] = 0.; 5185c6c1daeSBarry Smith for (p = 0; p < numValues; p++) { 519*cddde00dSMatthew G. Knepley if (values[p] == xmin) bins[0] += weights[0]; 520*cddde00dSMatthew G. Knepley mean += values[p] * weights[p]; 521*cddde00dSMatthew G. Knepley var += values[p] * values[p] * weights[p]; 522*cddde00dSMatthew G. Knepley totwt += weights[p]; 523*cddde00dSMatthew G. Knepley if (weights[p] != 1.) usewt = PETSC_TRUE; 5245c6c1daeSBarry Smith } 5255c6c1daeSBarry Smith /* Draw bins */ 5269566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Bin %2d (%6.2g - %6.2g): %.0g\n", 0, (double)xmin, (double)xmax, (double)bins[0])); 5275c6c1daeSBarry Smith } else { 5285c6c1daeSBarry Smith numBins = hist->numBins; 5295c6c1daeSBarry Smith numBinsOld = hist->numBins; 5305c6c1daeSBarry Smith if (hist->integerBins && (((int)xmax - xmin) + 1.0e-05 > xmax - xmin)) { 5315c6c1daeSBarry Smith initSize = (int)((int)xmax - xmin) / numBins; 5325c6c1daeSBarry Smith while (initSize * numBins != (int)xmax - xmin) { 5335c6c1daeSBarry Smith initSize = PetscMax(initSize - 1, 1); 5345c6c1daeSBarry Smith numBins = (int)((int)xmax - xmin) / initSize; 535835f2295SStefano Zampini PetscCall(PetscCIntCast(numBins, &inumBins)); 536835f2295SStefano Zampini PetscCall(PetscDrawHGSetNumberBins(hist, inumBins)); 5375c6c1daeSBarry Smith } 5385c6c1daeSBarry Smith } 5395c6c1daeSBarry Smith binSize = (xmax - xmin) / numBins; 5405c6c1daeSBarry Smith bins = hist->bins; 5415c6c1daeSBarry Smith 5425c6c1daeSBarry Smith /* Calculate number of points in each bin */ 5439566063dSJacob Faibussowitsch PetscCall(PetscArrayzero(bins, numBins)); 5445c6c1daeSBarry Smith for (i = 0; i < numBins; i++) { 5455c6c1daeSBarry Smith binLeft = xmin + binSize * i; 5465c6c1daeSBarry Smith binRight = xmin + binSize * (i + 1); 5475c6c1daeSBarry Smith for (p = 0; p < numValues; p++) { 548*cddde00dSMatthew G. Knepley if ((values[p] >= binLeft) && (values[p] < binRight)) bins[i] += weights[p]; 5495c6c1daeSBarry Smith /* Handle last bin separately */ 550*cddde00dSMatthew G. Knepley if ((i == numBins - 1) && (values[p] == binRight)) bins[i] += weights[p]; 5515c6c1daeSBarry Smith if (!i) { 552*cddde00dSMatthew G. Knepley mean += values[p] * weights[p]; 553*cddde00dSMatthew G. Knepley var += values[p] * values[p] * weights[p]; 554*cddde00dSMatthew G. Knepley totwt += weights[p]; 555*cddde00dSMatthew G. Knepley if (weights[p] != 1.) usewt = PETSC_TRUE; 5565c6c1daeSBarry Smith } 5575c6c1daeSBarry Smith } 5585c6c1daeSBarry Smith } 5595c6c1daeSBarry Smith /* Draw bins */ 5605c6c1daeSBarry Smith for (i = 0; i < numBins; i++) { 5615c6c1daeSBarry Smith binLeft = xmin + binSize * i; 5625c6c1daeSBarry Smith binRight = xmin + binSize * (i + 1); 563835f2295SStefano Zampini PetscCall(PetscViewerASCIIPrintf(viewer, "Bin %2" PetscInt_FMT " (%6.2g - %6.2g): %.0g\n", i, (double)binLeft, (double)binRight, (double)bins[i])); 5645c6c1daeSBarry Smith } 565835f2295SStefano Zampini PetscCall(PetscCIntCast(numBinsOld, &inumBins)); 566835f2295SStefano Zampini PetscCall(PetscDrawHGSetNumberBins(hist, inumBins)); 5675c6c1daeSBarry Smith } 5685c6c1daeSBarry Smith 5695c6c1daeSBarry Smith if (hist->calcStats) { 570*cddde00dSMatthew G. Knepley if (usewt) { 571*cddde00dSMatthew G. Knepley mean /= totwt; 572*cddde00dSMatthew G. Knepley var = (var - totwt * mean * mean) / totwt; 573*cddde00dSMatthew G. Knepley 574*cddde00dSMatthew G. Knepley PetscCall(PetscViewerASCIIPrintf(viewer, "Total Weight: %g\n", (double)totwt)); 575*cddde00dSMatthew G. Knepley } else { 5765c6c1daeSBarry Smith mean /= numValues; 577*cddde00dSMatthew G. Knepley if (numValues > 1) var = (var - numValues * mean * mean) / (PetscReal)(numValues - 1); 578a297a907SKarl Rupp else var = 0.0; 579*cddde00dSMatthew G. Knepley 5809566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Total: %" PetscInt_FMT "\n", numValues)); 5815c6c1daeSBarry Smith } 582*cddde00dSMatthew G. Knepley PetscCall(PetscViewerASCIIPrintf(viewer, "Mean: %g Var: %g\n", (double)mean, (double)var)); 583*cddde00dSMatthew G. Knepley } 5843ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5855c6c1daeSBarry Smith } 5865c6c1daeSBarry Smith 5875c6c1daeSBarry Smith /*@ 5885c6c1daeSBarry Smith PetscDrawHGSetColor - Sets the color the bars will be drawn with. 5895c6c1daeSBarry Smith 590c3339decSBarry Smith Logically Collective 5915c6c1daeSBarry Smith 5925c6c1daeSBarry Smith Input Parameters: 5935c6c1daeSBarry Smith + hist - The histogram context 5942fe279fdSBarry Smith - color - one of the colors defined in petscdraw.h or `PETSC_DRAW_ROTATE` to make each bar a different color 5955c6c1daeSBarry Smith 5965c6c1daeSBarry Smith Level: intermediate 5975c6c1daeSBarry Smith 598811af0c4SBarry Smith .seealso: `PetscDrawHG`, `PetscDrawHGCreate()`, `PetscDrawHGGetDraw()`, `PetscDrawSetSave()`, `PetscDrawSave()`, `PetscDrawHGDraw()`, `PetscDrawHGGetAxis()` 5995c6c1daeSBarry Smith @*/ 600d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGSetColor(PetscDrawHG hist, int color) 601d71ae5a4SJacob Faibussowitsch { 6025c6c1daeSBarry Smith PetscFunctionBegin; 6035c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 604e118a51fSLisandro Dalcin 6055c6c1daeSBarry Smith hist->color = color; 6063ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 6075c6c1daeSBarry Smith } 6085c6c1daeSBarry Smith 6095c6c1daeSBarry Smith /*@ 6105c6c1daeSBarry Smith PetscDrawHGSetLimits - Sets the axis limits for a histogram. If more 6115c6c1daeSBarry Smith points are added after this call, the limits will be adjusted to 6125c6c1daeSBarry Smith include those additional points. 6135c6c1daeSBarry Smith 614c3339decSBarry Smith Logically Collective 6155c6c1daeSBarry Smith 6165c6c1daeSBarry Smith Input Parameters: 6175c6c1daeSBarry Smith + hist - The histogram context 6182fe279fdSBarry Smith . x_min - the horizontal lower limit 619aaa8cc7dSPierre Jolivet . x_max - the horizontal upper limit 6202fe279fdSBarry Smith . y_min - the vertical lower limit 6212fe279fdSBarry Smith - y_max - the vertical upper limit 6225c6c1daeSBarry Smith 6235c6c1daeSBarry Smith Level: intermediate 6245c6c1daeSBarry Smith 625811af0c4SBarry Smith .seealso: `PetscDrawHG`, `PetscDrawHGCreate()`, `PetscDrawHGGetDraw()`, `PetscDrawSetSave()`, `PetscDrawSave()`, `PetscDrawHGDraw()`, `PetscDrawHGGetAxis()` 6265c6c1daeSBarry Smith @*/ 627d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGSetLimits(PetscDrawHG hist, PetscReal x_min, PetscReal x_max, int y_min, int y_max) 628d71ae5a4SJacob Faibussowitsch { 6295c6c1daeSBarry Smith PetscFunctionBegin; 6305c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 631e118a51fSLisandro Dalcin 6325c6c1daeSBarry Smith hist->xmin = x_min; 6335c6c1daeSBarry Smith hist->xmax = x_max; 6345c6c1daeSBarry Smith hist->ymin = y_min; 6355c6c1daeSBarry Smith hist->ymax = y_max; 6363ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 6375c6c1daeSBarry Smith } 6385c6c1daeSBarry Smith 6395c6c1daeSBarry Smith /*@ 640811af0c4SBarry Smith PetscDrawHGCalcStats - Turns on calculation of descriptive statistics associated with the histogram 6415c6c1daeSBarry Smith 64220f4b53cSBarry Smith Not Collective 6435c6c1daeSBarry Smith 6445c6c1daeSBarry Smith Input Parameters: 6455c6c1daeSBarry Smith + hist - The histogram context 6465c6c1daeSBarry Smith - calc - Flag for calculation 6475c6c1daeSBarry Smith 6485c6c1daeSBarry Smith Level: intermediate 6495c6c1daeSBarry Smith 650811af0c4SBarry Smith .seealso: `PetscDrawHG`, `PetscDrawHGCreate()`, `PetscDrawHGAddValue()`, `PetscDrawHGView()`, `PetscDrawHGDraw()` 6515c6c1daeSBarry Smith @*/ 652d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGCalcStats(PetscDrawHG hist, PetscBool calc) 653d71ae5a4SJacob Faibussowitsch { 6545c6c1daeSBarry Smith PetscFunctionBegin; 6555c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 656e118a51fSLisandro Dalcin 6575c6c1daeSBarry Smith hist->calcStats = calc; 6583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 6595c6c1daeSBarry Smith } 6605c6c1daeSBarry Smith 6615c6c1daeSBarry Smith /*@ 6625c6c1daeSBarry Smith PetscDrawHGIntegerBins - Turns on integer width bins 6635c6c1daeSBarry Smith 66420f4b53cSBarry Smith Not Collective 6655c6c1daeSBarry Smith 6665c6c1daeSBarry Smith Input Parameters: 6675c6c1daeSBarry Smith + hist - The histogram context 6685c6c1daeSBarry Smith - ints - Flag for integer width bins 6695c6c1daeSBarry Smith 6705c6c1daeSBarry Smith Level: intermediate 6715c6c1daeSBarry Smith 672811af0c4SBarry Smith .seealso: `PetscDrawHG`, `PetscDrawHGCreate()`, `PetscDrawHGAddValue()`, `PetscDrawHGView()`, `PetscDrawHGDraw()`, `PetscDrawHGSetColor()` 6735c6c1daeSBarry Smith @*/ 674d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGIntegerBins(PetscDrawHG hist, PetscBool ints) 675d71ae5a4SJacob Faibussowitsch { 6765c6c1daeSBarry Smith PetscFunctionBegin; 6775c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 678e118a51fSLisandro Dalcin 6795c6c1daeSBarry Smith hist->integerBins = ints; 6803ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 6815c6c1daeSBarry Smith } 6825c6c1daeSBarry Smith 6835d83a8b1SBarry Smith /*@ 6845c6c1daeSBarry Smith PetscDrawHGGetAxis - Gets the axis context associated with a histogram. 6855c6c1daeSBarry Smith This is useful if one wants to change some axis property, such as 6865c6c1daeSBarry Smith labels, color, etc. The axis context should not be destroyed by the 6875c6c1daeSBarry Smith application code. 6885c6c1daeSBarry Smith 689811af0c4SBarry Smith Not Collective, axis is parallel if hist is parallel 6905c6c1daeSBarry Smith 6915c6c1daeSBarry Smith Input Parameter: 6925c6c1daeSBarry Smith . hist - The histogram context 6935c6c1daeSBarry Smith 6945c6c1daeSBarry Smith Output Parameter: 6955c6c1daeSBarry Smith . axis - The axis context 6965c6c1daeSBarry Smith 6975c6c1daeSBarry Smith Level: intermediate 6985c6c1daeSBarry Smith 699aec76313SJacob Faibussowitsch .seealso: `PetscDrawHG`, `PetscDrawAxis`, `PetscDrawHGCreate()`, `PetscDrawHGAddValue()`, `PetscDrawHGView()`, `PetscDrawHGDraw()`, `PetscDrawHGSetColor()`, `PetscDrawHGSetLimits()` 7005c6c1daeSBarry Smith @*/ 701d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGGetAxis(PetscDrawHG hist, PetscDrawAxis *axis) 702d71ae5a4SJacob Faibussowitsch { 7035c6c1daeSBarry Smith PetscFunctionBegin; 704e118a51fSLisandro Dalcin PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 7054f572ea9SToby Isaac PetscAssertPointer(axis, 2); 7065c6c1daeSBarry Smith *axis = hist->axis; 7073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7085c6c1daeSBarry Smith } 7095c6c1daeSBarry Smith 7105d83a8b1SBarry Smith /*@ 7115c6c1daeSBarry Smith PetscDrawHGGetDraw - Gets the draw context associated with a histogram. 7125c6c1daeSBarry Smith 713811af0c4SBarry Smith Not Collective, draw is parallel if hist is parallel 7145c6c1daeSBarry Smith 7155c6c1daeSBarry Smith Input Parameter: 7165c6c1daeSBarry Smith . hist - The histogram context 7175c6c1daeSBarry Smith 7185c6c1daeSBarry Smith Output Parameter: 719e118a51fSLisandro Dalcin . draw - The draw context 7205c6c1daeSBarry Smith 7215c6c1daeSBarry Smith Level: intermediate 7225c6c1daeSBarry Smith 723811af0c4SBarry Smith .seealso: `PetscDraw`, `PetscDrawHG`, `PetscDrawHGCreate()`, `PetscDrawHGAddValue()`, `PetscDrawHGView()`, `PetscDrawHGDraw()`, `PetscDrawHGSetColor()`, `PetscDrawAxis`, `PetscDrawHGSetLimits()` 7245c6c1daeSBarry Smith @*/ 725d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscDrawHGGetDraw(PetscDrawHG hist, PetscDraw *draw) 726d71ae5a4SJacob Faibussowitsch { 7275c6c1daeSBarry Smith PetscFunctionBegin; 7285c6c1daeSBarry Smith PetscValidHeaderSpecific(hist, PETSC_DRAWHG_CLASSID, 1); 7294f572ea9SToby Isaac PetscAssertPointer(draw, 2); 730e118a51fSLisandro Dalcin *draw = hist->win; 7313ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7325c6c1daeSBarry Smith } 733