22{
23 PetscSession::getInstance(argc,argv);
24
25 cout << "\n";
26 cout << "=== Matrix: Example linear (double) sparse solver ===\n";
27 cout << "\n";
28
30
31 const double tol = 1.e-10;
32
33
34
35 cout << "=== Matrix: double ===============================\n";
36
43 B[ 0 ] = 5.;
44 B[ 1 ] = 11.;
45
47
48 try
49 {
50 small_system.factorise();
51 small_system.solve_using_factorisation();
52 }
53 catch (const std::runtime_error &error )
54 {
55 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
56 return 1;
57 }
59 answer[ 0 ] = 1.0;
60 answer[ 1 ] = 2.0;
61 B.sub( answer );
62 if ( B.inf_norm() > tol )
63 {
64 std::cout << "\033[1;31;48m Simple 2x2 double sparse system was not solved correctly\033[0m\n";
65 std::cout << " residual vector's inf_norm = " << B.inf_norm() << "\n";
67 }
68 else
69 {
70 std::cout << " Simple 2x2 double sparse solve works.\n";
71 }
72
73
74 B[ 0 ] = 10.;
75 B[ 1 ] = 22.;
76 try
77 {
78 small_system.solve_using_factorisation();
79 }
80 catch (const std::runtime_error &error )
81 {
82 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
83 assert( false );
84 }
85
86 answer[ 0 ] = 2.0;
87 answer[ 1 ] = 4.0;
88 B.sub( answer );
89 if ( B.inf_norm() > tol )
90 {
91 std::cout << "\033[1;31;48m Simple 2x2 double sparse system was not solved correctly\033[0m\n";
92 std::cout << " residual vector's inf_norm = " << B.inf_norm() << "\n";
94 }
95 else
96 {
97 std::cout << " Simple 2x2 double sparse solve_using_factorisation works.\n";
98 }
99
100
101
102
103
104 if ( failed )
105 {
106 cout << "\033[1;31;48m * FAILED \033[0m\n";
107 return 1;
108 }
109 else
110 {
111 cout << "\033[1;32;48m * PASSED \033[0m\n";
112 return 0;
113 }
114
115}
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