CppNoddy  0.92
Loading...
Searching...
No Matches
EVPSparse_slepcd.cpp
Go to the documentation of this file.
1/// \file EVPSparse_slepcd.cpp
2/// \ingroup Tests
3/// \ingroup EVP
4/// Solves a 2x2 generalised eigenvalue problem
5/// \f[ A_{2x2} \,{\underline x}_i = \lambda_i\, B_{2x2}\, {\underline x}_i \f]
6/// for the 2 eigenvalues \f$ \lambda_i \f$, \f$i=1,2.\f$.
7/// As a test case we use the SLEPc library.
8/// In this case \f$ A_{2x2} \f$ and \f$ B_{2x2} = I \f$ are such that
9/// the eigenvalues are \f$ 5,\, -1 \f$. The computation
10/// requests eigenvalues that satisfy \f$ \vert\lambda\vert < 10\f$.
11
13#include <SlepcSession.h>
14
15using namespace CppNoddy;
16using namespace std;
17
18int main(int argc, char* argv[])
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}
int main()
Definition: ArcCircle.cpp:39
Specification of the sparse linear eigensystem class.
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
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt