26{
27 cout << "\n";
28 cout << "=== EVP: Harmonic equation solved using LAPACK =====\n";
29 cout << "=== with a manually assembled matrix problem.\n";
30 cout << "\n";
31
32 cout.precision( 12 );
33 cout << " Number of nodal points : Leading eigenvalue error : Total CPU time taken (ms) \n";
35 size_t N = 4;
36
39 for ( int i = 2; i < 11; ++i )
40 {
41 N = ( size_t ) ( std::pow( 2., i ) );
42 const double delta = 1. / ( N - 1 );
44
46
47
51
52 a( 0, 0 ) = 1.0;
53 a( 0, 1 ) = 0.0;
54 a( N - 1, N - 1 ) = 1.0;
55 a( N - 1, N - 2 ) = 0.0;
56
57
60 b.scale( -1.0 );
61 b( 0, 0 ) = 0.0;
62 b( N - 1, N - 1 ) = 0.0;
63
65
67 system.set_calc_eigenvectors( true );
68
70 try
71 {
72 system.eigensolve();
73 }
74 catch (const std::runtime_error &error )
75 {
76 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
77 return 1;
78 }
79 system.tag_eigenvalues_disc( + 1, 10. );
80 lambdas = system.get_tagged_eigenvalues();
81 eigenvectors = system.get_tagged_eigenvectors();
82 cout << " " << N << " : " << lambdas[ 0 ].real() - M_PI * M_PI
83 <<
" : " << timer.
get_time() <<
"\n";
85 }
86
87 const double tol = 1.e-4;
88 if ( abs( lambdas[ 0 ].
real() - M_PI * M_PI ) > tol )
90
91 if ( failed )
92 {
93 cout << "\033[1;31;48m * FAILED \033[0m\n";
94 cout <<
" Final error = " << abs( lambdas[ 0 ].
real() - M_PI * M_PI ) <<
"\n";
95 return 1;
96 }
97
98 cout << "\033[1;32;48m * PASSED \033[0m\n";
99 return 0;
100}
A linear Nth-order generalised eigensystem class.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
A simple CPU-clock-tick timer for timing metods.
double get_time() const
Return the time.
void start()
Start the timer & reset stored time to zero.
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
DenseVector< double > real(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the real part of a complex DENSE vector.
void fill_identity(CppNoddy::Sequential_Matrix_base< _Type > &A)
Fill diagonal with unit values.
void fill_band(CppNoddy::Sequential_Matrix_base< _Type > &A, const int &offset, const _Type &value)
Fill a diagonal band of a matrix.