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:   PetscErrorCode            ierr;
 12:   PetscInt                  Mx = 100,i;
 13:   PetscReal                 x,hx = .1/Mx,pause,xx[3],yy[3];
 14:   PetscDraw                 draw;
 15:   const char *const         legend[] = {"(1 - u^2)^2","1 - u^2","-(1 - u)log(1 - u)"};
 16:   PetscDrawAxis             axis;
 17:   PetscDrawViewPorts        *ports;

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

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

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

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

 74: /*TEST

 76:    test:
 77:      requires: x

 79: TEST*/