50{
51 SlepcSession::getInstance(argc,argv);
52
53 cout << "\n";
54 cout << "=== EVP: Harmonic equation solved using LAPACK =====\n";
55 cout << "=== with a manually assembled matrix problem.\n";
56 cout << "=== The problem is solved along a path in the complex\n";
57 cout << "=== plane, deformed away from the real axis.\n";
58 cout << "\n";
59
60 cout.precision( 12 );
61 cout << " Number of nodal points : Leading eigenvalue error : Total CPU time taken (ms) \n";
63 size_t N = 4;
64
67
69 for ( int i = 2; i < 11; ++i )
70 {
71 N = ( size_t ) ( std::pow( 2., i ) );
72 const double delta = 1. / ( N - 1 );
74
77
78 a( 0, 0 ) = 1.0;
79 a( 0, 1 ) = 0.0;
80 for ( unsigned j = 1; j < N-1; ++j ) {
81
83 a( j, j-1 ) = (1.0/pow(Example::zx(x),2.0))/delta2 + (Example::zxx(x)/pow(Example::zx(x),3.0))/(2*delta);
84 a( j, j) = -(2.0/pow(Example::zx(x),2.0))/delta2;
85 a( j, j+1 ) = (1.0/pow(Example::zx(x),2.0))/delta2 - (Example::zxx(x)/pow(Example::zx(x),3.0))/(2*delta);
86
87
88 b( j, j ) = -1.0;
89 }
90
91 a( N - 1, N - 1 ) = 1.0;
92 a( N - 1, N - 2 ) = 0.0;
93
94 SparseLinearEigenSystem<D_complex> system( &a, &b );
95 system.set_calc_eigenvectors( true );
96 system.set_nev(4);
97 system.set_order( "EPS_TARGET_MAGNITUDE" );
98
100 try
101 {
102 system.eigensolve();
103 } catch (const std::runtime_error &error ) {
104 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
105 return 1;
106 }
107
108 system.tag_eigenvalues_disc( + 1, 10. );
109 lambdas = system.get_tagged_eigenvalues();
110
111 eigenvectors = system.get_tagged_eigenvectors();
112
113 cout << " " << N << " : " << lambdas[ 0 ].real() - M_PI * M_PI << " +i " << lambdas[0].imag()
114 <<
" : " << timer.
get_time() <<
"\n";
116 }
117
118
120
122
124 int index(0);
125 for ( unsigned j = 0; j < N; ++j ) {
126
127 mesh.coord(j) = Example::z(xNodes[j]);
128 mesh(j,0) = eigenvectors(index,j+0);
129 }
130
131 mesh.dump_gnu("/DATA/complexMesh.dat");
132 const double tol = 1.e-4;
133 if ( abs( lambdas[ 0 ].
real() - M_PI * M_PI ) > tol )
135
136 if ( failed )
137 {
138 cout << "\033[1;31;48m * FAILED \033[0m\n";
139 cout <<
" Final error = " << abs( lambdas[ 0 ].
real() - M_PI * M_PI ) <<
"\n";
140 return 1;
141 }
142
143 cout << "\033[1;32;48m * PASSED \033[0m\n";
144 return 0;
145}
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 matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
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.