22#include "../Utils_Fill.h"
27int main(
int argc,
char* argv[])
29 SlepcSession::getInstance(argc,argv);
32 cout <<
"=== EVP: Harmonic equation solved using SLEPc ======\n";
33 cout <<
"=== with a manually assembled matrix problem.\n";
37 cout <<
" Number of nodal points : Leading eigenvalue error : Total CPU time taken (ms) \n";
43 for (
int i = 2; i < 11; ++i )
45 N = ( size_t ) ( std::pow( 2., i ) );
46 const double delta = 1. / ( N - 1 );
47 const double delta2 = delta * delta;
49 typedef double PETSC_type;
59 a( N - 1, N - 1 ) = 1.0;
60 a( N - 1, N - 2 ) = 0.0;
67 b( N - 1, N - 1 ) = 0.0;
71 SparseLinearEigenSystem<PETSC_type> system( &a, &b );
72 system.set_calc_eigenvectors(
true );
74 system.set_order(
"EPS_TARGET_MAGNITUDE" );
81 catch (
const std::runtime_error &error )
83 cout <<
" \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
86 system.tag_eigenvalues_disc( + 1, 10. );
87 lambdas = system.get_tagged_eigenvalues();
88 eigenvectors = system.get_tagged_eigenvectors();
89 cout <<
" " << N <<
" : " << lambdas[ 0 ].real() - M_PI * M_PI
90 <<
" : " << timer.
get_time() <<
"\n";
95 const double tol = 1.e-4;
96 if ( abs( lambdas[ 0 ].real() - M_PI * M_PI ) > tol )
101 cout <<
"\033[1;31;48m * FAILED \033[0m\n";
102 cout <<
" Final error = " << abs( lambdas[ 0 ].real() - M_PI * M_PI ) <<
"\n";
106 cout <<
"\033[1;32;48m * PASSED \033[0m\n";
Specification of the sparse linear eigensystem class.
A spec for the CppNoddy Timer object.
A spec for a collection of utility functions.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
void scale(const _Type &mult)
Scale the matrix by a scalar.
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.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
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.