CppNoddy  0.92
Loading...
Searching...
No Matches
Functions
EVPSparse_slepcd.cpp File Reference

Solves a 2x2 generalised eigenvalue problem. More...

#include <SparseLinearEigenSystem.h>
#include <SlepcSession.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Solves a 2x2 generalised eigenvalue problem.

\[ A_{2x2} \,{\underline x}_i = \lambda_i\, B_{2x2}\, {\underline x}_i \]

for the 2 eigenvalues $ \lambda_i $, $i=1,2.$. As a test case we use the SLEPc library. In this case $ A_{2x2} $ and $ B_{2x2} = I $ are such that the eigenvalues are $ 5,\, -1 $. The computation requests eigenvalues that satisfy $ \vert\lambda\vert < 10$.

Definition in file EVPSparse_slepcd.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 18 of file EVPSparse_slepcd.cpp.

19{
20
21 SlepcSession::getInstance(argc,argv);
22
23 cout << "\n";
24 cout << "=== EVP: real eigenvalue problem ====\n";
25 cout << "\n";
26
27 SparseMatrix<double> a( 2, 2 );
28 SparseMatrix<double> b( 2, 2 );
29 a( 0, 0 ) = 1;
30 a( 0, 1 ) = 2;
31 a( 1, 0 ) = 4;
32 a( 1, 1 ) = 3;
33
34 b( 0, 0 ) = 1;
35 b( 1, 1 ) = 1;
36
37 // a vector for the eigenvalues
39 // eigenvalues are: 5,-1
40
41 SparseLinearEigenSystem<double> system( &a, &b );
42 try
43 {
44 system.eigensolve();
45 }
46 catch (const std::runtime_error &error )
47 {
48 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
49 return 1;
50 }
51
52 //// tag any eigenvalues within a distance of 2 of the point 4
53 system.set_shift( 4 );
54 system.tag_eigenvalues_disc( +1, 2 );
55 // get those tagged eigenvalues
56 lambdas = system.get_tagged_eigenvalues();
57 const double tol = 1.e-13;
58 //lambdas.dump();
59
60 if ( std::abs( lambdas[ 0 ] - 5.0 ) < tol )
61 {
62 cout << "\033[1;32;48m * PASSED \033[0m\n";
63 return 0;
64 }
65
66 cout << "\033[1;31;48m * FAILED \033[0m\n";
67 cout.precision( 12 );
68 cout << " Final error = " << std::abs( lambdas[ 0 ] - 5.0 ) << "\n";
69 lambdas.dump();
70 return 1;
71}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
void dump() const
Dump to std::cout.
Definition: DenseVector.cpp:64
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
Definition: SparseMatrix.h:31

References CppNoddy::DenseVector< _Type >::dump().

© 2012

R.E. Hewitt