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;
18: PetscInitialize(&argc,&argv,0,help);
19: PetscViewerDrawResize(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD),1200,800);
20: PetscViewerDrawGetDrawLG(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD),0,&lg);
21: PetscDrawLGGetDraw(lg,&draw);
22: PetscDrawCheckResizedWindow(draw);
23: PetscDrawViewPortsCreateRect(draw,1,2,&ports);
24: PetscDrawLGGetAxis(lg,&axis);
25: PetscDrawLGReset(lg);
27: /*
28: Plot the energies
29: */
30: PetscDrawLGSetDimension(lg,3);
31: PetscDrawViewPortsSet(ports,1);
32: x = .9;
33: for (i=0; i<Mx; i++) {
34: xx[0] = xx[1] = xx[2] = x;
35: yy[0] = (1.-x*x)*(1. - x*x);
36: yy[1] = (1. - x*x);
37: yy[2] = -(1.-x)*PetscLogReal(1.-x);
38: PetscDrawLGAddPoint(lg,xx,yy);
39: x += hx;
40: }
41: PetscDrawGetPause(draw,&pause);
42: PetscDrawSetPause(draw,0.0);
43: PetscDrawAxisSetLabels(axis,"Energy","","");
44: PetscDrawLGSetLegend(lg,legend);
45: PetscDrawLGDraw(lg);
47: /*
48: Plot the forces
49: */
50: PetscDrawViewPortsSet(ports,0);
51: PetscDrawLGReset(lg);
52: x = .9;
53: for (i=0; i<Mx; i++) {
54: xx[0] = xx[1] = xx[2] = x;
55: yy[0] = x*x*x - x;
56: yy[1] = -x;
57: yy[2] = 1.0 + PetscLogReal(1. - x);
58: PetscDrawLGAddPoint(lg,xx,yy);
59: x += hx;
60: }
61: PetscDrawAxisSetLabels(axis,"Derivative","","");
62: PetscDrawLGSetLegend(lg,NULL);
63: PetscDrawLGDraw(lg);
65: PetscDrawSetPause(draw,pause);
66: PetscDrawPause(draw);
67: PetscDrawViewPortsDestroy(ports);
68: PetscFinalize();
69: return 0;
70: }
72: /*TEST
74: test:
75: requires: x
77: TEST*/