xref: /petsc/src/mat/tests/ex227.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
1 static char help[] = "Test MatNullSpaceTest() with options prefixes.\n\n";
2 
3 #include <petscmat.h>
4 
5 int main(int argc, char **argv) {
6   Mat          mat;
7   MatNullSpace nsp;
8   PetscBool    prefix = PETSC_FALSE, flg;
9   PetscInt     zero   = 0;
10   PetscScalar  value  = 0;
11   PetscFunctionBeginUser;
12   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
13 
14   PetscCall(PetscOptionsGetBool(NULL, NULL, "-with_prefix", &prefix, NULL));
15   PetscCall(MatCreateDense(PETSC_COMM_WORLD, 1, 1, 1, 1, NULL, &mat));
16   PetscCall(MatSetOptionsPrefix(mat, prefix ? "prefix_" : NULL));
17   PetscCall(MatSetUp(mat));
18   PetscCall(MatSetValues(mat, 1, &zero, 1, &zero, &value, INSERT_VALUES));
19   PetscCall(MatAssemblyBegin(mat, MAT_FINAL_ASSEMBLY));
20   PetscCall(MatAssemblyEnd(mat, MAT_FINAL_ASSEMBLY));
21   PetscCall(MatNullSpaceCreate(PETSC_COMM_WORLD, PETSC_TRUE, 0, NULL, &nsp));
22   PetscCall(MatNullSpaceTest(nsp, mat, &flg));
23   PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Null space test failed!");
24   PetscCall(MatNullSpaceDestroy(&nsp));
25   PetscCall(MatDestroy(&mat));
26   PetscCall(PetscFinalize());
27   return 0;
28 }
29 
30 /*TEST
31 
32    test:
33        suffix: no_prefix
34        output_file: output/ex227_no_prefix.out
35        args: -mat_null_space_test_view -mat_view
36 
37    test:
38        suffix: prefix
39        output_file: output/ex227_prefix.out
40        args: -prefix_mat_null_space_test_view -with_prefix -prefix_mat_view
41 
42 TEST*/
43