Actual source code: potentials.c


  2: static char help[] = "Plots the various potentials used in the examples.\n";

  4: #include <petscdmda.h>
  5: #include <petscts.h>
  6: #include <petscdraw.h>

  8: int main(int argc, char **argv)
  9: {
 10:   PetscDrawLG         lg;
 11:   PetscInt            Mx = 100, i;
 12:   PetscReal           x, hx = .1 / Mx, pause, xx[3], yy[3];
 13:   PetscDraw           draw;
 14:   const char *const   legend[] = {"(1 - u^2)^2", "1 - u^2", "-(1 - u)log(1 - u)"};
 15:   PetscDrawAxis       axis;
 16:   PetscDrawViewPorts *ports;

 19:   PetscInitialize(&argc, &argv, 0, help);
 20:   PetscViewerDrawResize(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD), 1200, 800);
 21:   PetscViewerDrawGetDrawLG(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD), 0, &lg);
 22:   PetscDrawLGGetDraw(lg, &draw);
 23:   PetscDrawCheckResizedWindow(draw);
 24:   PetscDrawViewPortsCreateRect(draw, 1, 2, &ports);
 25:   PetscDrawLGGetAxis(lg, &axis);
 26:   PetscDrawLGReset(lg);

 28:   /*
 29:       Plot the  energies
 30:   */
 31:   PetscDrawLGSetDimension(lg, 3);
 32:   PetscDrawViewPortsSet(ports, 1);
 33:   x = .9;
 34:   for (i = 0; i < Mx; i++) {
 35:     xx[0] = xx[1] = xx[2] = x;
 36:     yy[0]                 = (1. - x * x) * (1. - x * x);
 37:     yy[1]                 = (1. - x * x);
 38:     yy[2]                 = -(1. - x) * PetscLogReal(1. - x);
 39:     PetscDrawLGAddPoint(lg, xx, yy);
 40:     x += hx;
 41:   }
 42:   PetscDrawGetPause(draw, &pause);
 43:   PetscDrawSetPause(draw, 0.0);
 44:   PetscDrawAxisSetLabels(axis, "Energy", "", "");
 45:   PetscDrawLGSetLegend(lg, legend);
 46:   PetscDrawLGDraw(lg);

 48:   /*
 49:       Plot the  forces
 50:   */
 51:   PetscDrawViewPortsSet(ports, 0);
 52:   PetscDrawLGReset(lg);
 53:   x = .9;
 54:   for (i = 0; i < Mx; i++) {
 55:     xx[0] = xx[1] = xx[2] = x;
 56:     yy[0]                 = x * x * x - x;
 57:     yy[1]                 = -x;
 58:     yy[2]                 = 1.0 + PetscLogReal(1. - x);
 59:     PetscDrawLGAddPoint(lg, xx, yy);
 60:     x += hx;
 61:   }
 62:   PetscDrawAxisSetLabels(axis, "Derivative", "", "");
 63:   PetscDrawLGSetLegend(lg, NULL);
 64:   PetscDrawLGDraw(lg);

 66:   PetscDrawSetPause(draw, pause);
 67:   PetscDrawPause(draw);
 68:   PetscDrawViewPortsDestroy(ports);
 69:   PetscFinalize();
 70:   return 0;
 71: }

 73: /*TEST

 75:    test:
 76:      requires: x

 78: TEST*/