xref: /petsc/src/sys/classes/draw/tests/ex4.c (revision 609caa7c8c030312b00807b4f015fd827bb80932)
1 static char help[] = "Demonstrates use of PetscDrawZoom()\n";
2 
3 #if defined(PETSC_APPLE_FRAMEWORK)
4 
5   #include <PETSc/petscsys.h>
6   #include <PETSc/petscdraw.h>
7 #else
8   #include <petscsys.h>
9   #include <petscdraw.h>
10 #endif
11 
zoomfunction(PetscDraw draw,void * dummy)12 PetscErrorCode zoomfunction(PetscDraw draw, void *dummy)
13 {
14   MPI_Comm    comm;
15   PetscMPIInt size, rank;
16 
17   PetscFunctionBeginUser;
18   PetscCall(PetscObjectGetComm((PetscObject)draw, &comm));
19   PetscCallMPI(MPI_Comm_size(comm, &size));
20   PetscCallMPI(MPI_Comm_rank(comm, &rank));
21   for (int i = rank; i < 256; i += size) {
22     PetscReal y = ((PetscReal)i) / (256 - 1);
23     PetscCall(PetscDrawLine(draw, 0.0, y, 1.0, y, i));
24   }
25   PetscFunctionReturn(PETSC_SUCCESS);
26 }
27 
main(int argc,char ** argv)28 int main(int argc, char **argv)
29 {
30   int       x = 0, y = 0, width = 256, height = 256;
31   PetscDraw draw;
32 
33   PetscFunctionBeginUser;
34   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
35   PetscCall(PetscDrawCreate(PETSC_COMM_WORLD, NULL, "Title", x, y, width, height, &draw));
36   PetscCall(PetscDrawSetFromOptions(draw));
37   PetscCall(PetscDrawZoom(draw, zoomfunction, NULL));
38   PetscCall(PetscDrawDestroy(&draw));
39   PetscCall(PetscFinalize());
40   return 0;
41 }
42 
43 /*TEST
44 
45    build:
46      requires: x
47 
48    test:
49      output_file: output/empty.out
50 
51    test:
52      suffix: db
53      args: -draw_double_buffer 0
54      output_file: output/empty.out
55 
56    test:
57      suffix: df
58      args: -draw_fast
59      output_file: output/empty.out
60 
61    test:
62      suffix: dv
63      args: -draw_virtual
64      output_file: output/empty.out
65 
66 TEST*/
67