22{
23 PetscSession::getInstance(argc,argv);
24
25
26
27 cout << "\n";
28 cout << "=== Matrix: Example linear sparse solver ===========\n";
29 cout << "\n";
30
32
33 const double tol = 1.e-10;
34
35
36
37 cout << "=== Matrix: complex ==============================\n";
38
45 B[ 0 ] = 5.;
46 B[ 1 ] = 11.;
47
49
50 try
51 {
52
53 cout << "Prefact\n";
54 small_system.factorise();
55 cout << "Postfact\n";
56 small_system.solve_using_factorisation();
57 cout << "Postsolve\n";
58 }
59 catch ( const std::runtime_error &error )
60 {
61 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
62 return 1;
63 }
65 answer[ 0 ] = 1.0;
66 answer[ 1 ] = 2.0;
67 B.sub( answer );
68 if ( B.inf_norm() > tol )
69 {
70 std::cout << "\033[1;31;48m Simple 2x2 complex sparse system was not solved correctly\033[0m\n";
71 std::cout << " residual vector's inf_norm = " << B.inf_norm() << "\n";
73 }
74 else
75 {
76 std::cout << " Simple 2x2 complex sparse solve works.\n";
77 }
78
79
80 B[ 0 ] = 10.;
81 B[ 1 ] = 22.;
82 try
83 {
84 small_system.solve_using_factorisation();
85 }
86 catch ( const std::runtime_error &error )
87 {
88 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
89 return 1;
90 }
91 answer[ 0 ] = 2.0;
92 answer[ 1 ] = 4.0;
93 B.sub( answer );
94 if ( B.inf_norm() > tol )
95 {
96 std::cout << "\033[1;31;48m Simple 2x2 complex sparse system was not solved correctly\033[0m\n";
97 std::cout << " residual vector's inf_norm = " << B.inf_norm() << "\n";
99 }
100 else
101 {
102 std::cout << " Simple 2x2 complex sparse solve_using_factorisation works.\n";
103 }
104
105
106 small_system.cleanup();
107
108
109 if ( failed )
110 {
111 cout << "\033[1;31;48m * FAILED \033[0m\n";
112 return 1;
113 }
114 else
115 {
116 cout << "\033[1;32;48m * PASSED \033[0m\n";
117 return 0;
118 }
119
120}
An DenseVector class – a dense vector object.
A linear system class for vector right-hand sides.
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
double A(1.0)
initial hump amplitude