xref: /petsc/src/dm/tests/ex13.c (revision 732aec7a18f2199fb53bb9a2f3aef439a834ce31)
1 static char help[] = "Tests loading DM vector from file.\n\n";
2 
3 /*
4     ex14.c writes out the DMDA and vector read by this program.
5 */
6 
7 #include <petscdmda.h>
8 
main(int argc,char ** argv)9 int main(int argc, char **argv)
10 {
11   PetscInt    M = PETSC_DECIDE, N = PETSC_DECIDE;
12   DM          da;
13   Vec         global;
14   PetscViewer bviewer;
15 
16   PetscFunctionBeginUser;
17   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
18   PetscCall(PetscOptionsGetInt(NULL, NULL, "-M", &M, NULL));
19   PetscCall(PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL));
20 
21   PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD, "daoutput", FILE_MODE_READ, &bviewer));
22   PetscCall(DMCreate(PETSC_COMM_WORLD, &da));
23 
24   PetscCall(DMLoad(da, bviewer));
25   PetscCall(DMCreateGlobalVector(da, &global));
26   PetscCall(VecLoad(global, bviewer));
27   PetscCall(PetscViewerDestroy(&bviewer));
28 
29   PetscCall(VecView(global, PETSC_VIEWER_DRAW_WORLD));
30 
31   /* Free memory */
32   PetscCall(VecDestroy(&global));
33   PetscCall(DMDestroy(&da));
34   PetscCall(PetscFinalize());
35   return 0;
36 }
37