1 static char help[] = "Test -dm_preallocate_only with DMStag\n\n";
2
3 #include <petscdm.h>
4 #include <petscdmstag.h>
5
main(int argc,char ** argv)6 int main(int argc, char **argv)
7 {
8 DM dm;
9 PetscInt dim;
10 Mat A;
11 DMStagStencil row, col;
12 PetscScalar value;
13
14 PetscFunctionBeginUser;
15 PetscCall(PetscInitialize(&argc, &argv, NULL, help));
16 dim = 1;
17 PetscCall(PetscOptionsGetInt(NULL, NULL, "-dim", &dim, NULL));
18
19 switch (dim) {
20 case 1:
21 PetscCall(DMStagCreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, 4, 1, 1, DMSTAG_STENCIL_BOX, 1, NULL, &dm));
22 break;
23 default:
24 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Unsupported dimension %" PetscInt_FMT, dim);
25 }
26 PetscCall(DMSetFromOptions(dm));
27 PetscCall(DMSetUp(dm));
28
29 PetscCall(DMCreateMatrix(dm, &A));
30
31 row.c = 0;
32 row.i = 0;
33 row.loc = DMSTAG_ELEMENT;
34
35 col.c = 0;
36 col.i = 1;
37 col.loc = DMSTAG_ELEMENT;
38
39 value = 1.234;
40
41 PetscCall(DMStagMatSetValuesStencil(dm, A, 1, &row, 1, &col, &value, INSERT_VALUES));
42 PetscCall(MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY));
43 PetscCall(MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY));
44
45 PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD));
46
47 PetscCall(MatDestroy(&A));
48 PetscCall(DMDestroy(&dm));
49 PetscCall(PetscFinalize());
50 return 0;
51 }
52
53 /*TEST
54
55 test:
56 args: -dm_preallocate_only
57
58 TEST*/
59