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