CppNoddy  0.92
Loading...
Searching...
No Matches
EVPSparse_slepcz.cpp
Go to the documentation of this file.
1/// \file EVPSparse_slepcz.cpp
2/// \ingroup Tests
3/// \ingroup EVP
4/// Solves a 4x4 complex generalised eigenvalue problem
5/// \f[ A_{4x4} \,{\underline x}_i = \lambda_i\, B_{4x4}\, {\underline x}_i \f]
6/// for the 4 eigenvalues \f$ \lambda_i \f$, \f$i=1,2,3,4.\f$.
7/// As a test case we use the SLEPc library.
8/// In this case \f$ A_{4x4} \f$ and \f$ B_{4x4} \f$ are such that
9/// the eigenvalues are \f$ 3-9i,\, 2-5i,\, 3-i,\, 4-5i \f$. The computation
10/// requests eigenvalues that satisfy \f$ \vert\lambda\vert < 4\f$,
11/// which in this case is \f$ 3-i \f$.
12
14#include <SlepcSession.h>
15
16using namespace CppNoddy;
17using namespace std;
18
19
20int main(int argc, char* argv[])
21{
22
23 SlepcSession::getInstance(argc,argv);
24
25 cout << "\n";
26 cout << "=== EVP: complex generalised eigenvalue problem ====\n";
27 cout << "\n";
28
30
31 a( 0, 0 ) = D_complex( -21.10, -22.50 );
32 a( 0, 1 ) = D_complex( 53.50, -50.50 );
33 a( 0, 2 ) = D_complex( -34.50, 127.50 );
34 a( 0, 3 ) = D_complex( 7.50, 0.50 );
35
36 a( 1, 0 ) = D_complex( -0.46, -7.78 );
37 a( 1, 1 ) = D_complex( -3.50, -37.50 );
38 a( 1, 2 ) = D_complex( -15.50, 58.50 );
39 a( 1, 3 ) = D_complex( -10.50, -1.50 );
40
41 a( 2, 0 ) = D_complex( 4.30, -5.50 );
42 a( 2, 1 ) = D_complex( 39.70, -17.10 );
43 a( 2, 2 ) = D_complex( -68.50, 12.50 );
44 a( 2, 3 ) = D_complex( -7.50, -3.50 );
45
46 a( 3, 0 ) = D_complex( 5.50, 4.40 );
47 a( 3, 1 ) = D_complex( 14.40, 43.30 );
48 a( 3, 2 ) = D_complex( -32.50, -46.00 );
49 a( 3, 3 ) = D_complex( -19.00, -32.50 );
50
52
53 b( 0, 0 ) = D_complex( 1.00, -5.00 );
54 b( 0, 1 ) = D_complex( 1.60, 1.20 );
55 b( 0, 2 ) = D_complex( -3.00, 0.00 );
56 b( 0, 3 ) = D_complex( 0.00, -1.00 );
57
58 b( 1, 0 ) = D_complex( 0.80, -0.60 );
59 b( 1, 1 ) = D_complex( 3.00, -5.00 );
60 b( 1, 2 ) = D_complex( -4.00, 3.00 );
61 b( 1, 3 ) = D_complex( -2.40, -3.20 );
62
63 b( 2, 0 ) = D_complex( 1.00, 0.00 );
64 b( 2, 1 ) = D_complex( 2.40, 1.80 );
65 b( 2, 2 ) = D_complex( -4.00, -5.00 );
66 b( 2, 3 ) = D_complex( 0.00, -3.00 );
67
68 b( 3, 0 ) = D_complex( 0.00, 1.00 );
69 b( 3, 1 ) = D_complex( -1.80, 2.40 );
70 b( 3, 2 ) = D_complex( 0.00, -4.00 );
71 b( 3, 3 ) = D_complex( 4.00, -5.00 );
72
73 // a vector for the eigenvalues
75 // eigenvalues are: (3,-9), (2,-5), (3,-1), (4,-5)
76
77 SparseLinearEigenSystem<D_complex> system( &a, &b );
78 try
79 {
80 system.eigensolve();
81 }
82 catch (const std::runtime_error &error )
83 {
84 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
85 return 1;
86 }
87
88 // tag any eigenvalues within a distance of 0.1 of the point 3-i
89 system.set_shift( D_complex( 3.0, -1.0 ) );
90 system.tag_eigenvalues_disc( + 1, 0.1 );
91 // get those tagged eigenvalues
92 lambdas = system.get_tagged_eigenvalues();
93
94 const double tol = 1.e-10;
95 if ( std::abs( lambdas[ 0 ] - D_complex( 3.0, -1.0 ) ) < tol )
96 {
97 cout << "\033[1;32;48m * PASSED \033[0m\n";
98 return 0;
99 }
100
101 cout << "\033[1;31;48m * FAILED \033[0m\n";
102 cout.precision( 12 );
103 cout << " Final error = " << std::abs( lambdas[ 0 ] - D_complex( 3.0, -1.0 ) ) << "\n";
104 lambdas.dump();
105 return 1;
106}
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...
std::complex< double > D_complex
A complex double precision number using std::complex.
Definition: Types.h:98

© 2012

R.E. Hewitt