1 static char help[] = "Tests MatILUFactorSymbolic() on matrix with missing diagonal.\n\n";
2
3 #include <petscmat.h>
4 #include <petscpc.h>
5
main(int argc,char ** args)6 int main(int argc, char **args)
7 {
8 Mat C, A;
9 PetscInt i, j;
10 PetscScalar v;
11 PC pc;
12 Vec xtmp;
13
14 PetscFunctionBeginUser;
15 PetscCall(PetscInitialize(&argc, &args, NULL, help));
16 PetscCall(MatCreate(PETSC_COMM_WORLD, &C));
17 PetscCall(MatSetSizes(C, PETSC_DECIDE, PETSC_DECIDE, 3, 3));
18 PetscCall(MatSetFromOptions(C));
19 PetscCall(MatSetUp(C));
20 PetscCall(VecCreateSeq(PETSC_COMM_WORLD, 3, &xtmp));
21 i = 0;
22 j = 0;
23 v = 4;
24 PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
25 i = 0;
26 j = 2;
27 v = 1;
28 PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
29 i = 1;
30 j = 0;
31 v = 1;
32 PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
33 i = 1;
34 j = 1;
35 v = 4;
36 PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
37 i = 2;
38 j = 1;
39 v = 1;
40 PetscCall(MatSetValues(C, 1, &i, 1, &j, &v, INSERT_VALUES));
41
42 PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY));
43 PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY));
44
45 PetscCall(MatView(C, PETSC_VIEWER_STDOUT_WORLD));
46 PetscCall(PCCreate(PETSC_COMM_WORLD, &pc));
47 PetscCall(PCSetFromOptions(pc));
48 PetscCall(PCSetOperators(pc, C, C));
49 PetscCall(PCSetUp(pc));
50 PetscCall(PCFactorGetMatrix(pc, &A));
51 PetscCall(MatView(A, PETSC_VIEWER_STDOUT_WORLD));
52
53 PetscCall(PCDestroy(&pc));
54 PetscCall(VecDestroy(&xtmp));
55 PetscCall(MatDestroy(&C));
56
57 PetscCall(PetscFinalize());
58 return 0;
59 }
60