1 2 static char help[] = "Plots the various potentials used in the examples.\n"; 3 4 #include <petscdmda.h> 5 #include <petscts.h> 6 #include <petscdraw.h> 7 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; 17 18 PetscFunctionBegin; 19 CHKERRQ(PetscInitialize(&argc,&argv,0,help)); 20 CHKERRQ(PetscViewerDrawResize(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD),1200,800)); 21 CHKERRQ(PetscViewerDrawGetDrawLG(PETSC_VIEWER_DRAW_(PETSC_COMM_WORLD),0,&lg)); 22 CHKERRQ(PetscDrawLGGetDraw(lg,&draw)); 23 CHKERRQ(PetscDrawCheckResizedWindow(draw)); 24 CHKERRQ(PetscDrawViewPortsCreateRect(draw,1,2,&ports)); 25 CHKERRQ(PetscDrawLGGetAxis(lg,&axis)); 26 CHKERRQ(PetscDrawLGReset(lg)); 27 28 /* 29 Plot the energies 30 */ 31 CHKERRQ(PetscDrawLGSetDimension(lg,3)); 32 CHKERRQ(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 CHKERRQ(PetscDrawLGAddPoint(lg,xx,yy)); 40 x += hx; 41 } 42 CHKERRQ(PetscDrawGetPause(draw,&pause)); 43 CHKERRQ(PetscDrawSetPause(draw,0.0)); 44 CHKERRQ(PetscDrawAxisSetLabels(axis,"Energy","","")); 45 CHKERRQ(PetscDrawLGSetLegend(lg,legend)); 46 CHKERRQ(PetscDrawLGDraw(lg)); 47 48 /* 49 Plot the forces 50 */ 51 CHKERRQ(PetscDrawViewPortsSet(ports,0)); 52 CHKERRQ(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 CHKERRQ(PetscDrawLGAddPoint(lg,xx,yy)); 60 x += hx; 61 } 62 CHKERRQ(PetscDrawAxisSetLabels(axis,"Derivative","","")); 63 CHKERRQ(PetscDrawLGSetLegend(lg,NULL)); 64 CHKERRQ(PetscDrawLGDraw(lg)); 65 66 CHKERRQ(PetscDrawSetPause(draw,pause)); 67 CHKERRQ(PetscDrawPause(draw)); 68 CHKERRQ(PetscDrawViewPortsDestroy(ports)); 69 CHKERRQ(PetscFinalize()); 70 return 0; 71 } 72 73 /*TEST 74 75 test: 76 requires: x 77 78 TEST*/ 79