47{
48 cout << "\n";
49 cout << "=== EVP: Harmonic equation solved using LAPACK =====\n";
50 cout << "=== with a manually assembled matrix problem.\n";
51 cout << "=== The problem is solved along a path in the complex\n";
52 cout << "=== plane, deformed away from the real axis.\n";
53 cout << "\n";
54
55 cout.precision( 12 );
56 cout << " Number of nodal points : Leading eigenvalue error : Total CPU time taken (ms) \n";
58 size_t N = 4;
59
62
64 for ( int i = 2; i < 11; ++i )
65 {
66 N = ( size_t ) ( std::pow( 2., i ) );
67 const double delta = 1. / ( N - 1 );
69
72
73 a( 0, 0 ) = 1.0;
74 a( 0, 1 ) = 0.0;
75 for ( unsigned j = 1; j < N-1; ++j ) {
76
78 a( j, j-1 ) = (1.0/pow(Example::zx(x),2.0))/delta2 + (Example::zxx(x)/pow(Example::zx(x),3.0))/(2*delta);
79 a( j, j) = -(2.0/pow(Example::zx(x),2.0))/delta2;
80 a( j, j+1 ) = (1.0/pow(Example::zx(x),2.0))/delta2 - (Example::zxx(x)/pow(Example::zx(x),3.0))/(2*delta);
81
82
83 b( j, j ) = -1.0;
84 }
85
86 a( N - 1, N - 1 ) = 1.0;
87 a( N - 1, N - 2 ) = 0.0;
88
90 system.set_calc_eigenvectors( true );
91
93 try
94 {
95 system.eigensolve();
96 } catch (const std::runtime_error &error ) {
97 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
98 return 1;
99 }
100
101 system.tag_eigenvalues_disc( + 1, 10. );
102 lambdas = system.get_tagged_eigenvalues();
103
104 eigenvectors = system.get_tagged_eigenvectors();
105
106 cout << " " << N << " : " << lambdas[ 0 ].real() - M_PI * M_PI << " +i " << lambdas[0].imag()
107 <<
" : " << timer.
get_time() <<
"\n";
109 }
110
111
113
115
117 int index(0);
118 for ( unsigned j = 0; j < N; ++j ) {
119
120 mesh.coord(j) = Example::z(xNodes[j]);
121 mesh(j,0) = eigenvectors(index,j+0);
122 }
123
124 mesh.dump_gnu("/DATA/complexMesh.dat");
125 const double tol = 1.e-4;
126 if ( abs( lambdas[ 0 ].
real() - M_PI * M_PI ) > tol )
128
129 if ( failed )
130 {
131 cout << "\033[1;31;48m * FAILED \033[0m\n";
132 cout <<
" Final error = " << abs( lambdas[ 0 ].
real() - M_PI * M_PI ) <<
"\n";
133 return 1;
134 }
135
136 cout << "\033[1;32;48m * PASSED \033[0m\n";
137 return 0;
138}
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 one dimensional mesh utility 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.
DenseVector< double > uniform_node_vector(const double &lower, const double &upper, const std::size_t &N)
Return a DENSE vector with the nodal points of a uniform mesh distributed between the upper/lower bou...
std::complex< double > D_complex
A complex double precision number using std::complex.