CppNoddy  0.92
Loading...
Searching...
No Matches
Namespaces | Functions
EVPHarmonicComplexSparse_slepcz.cpp File Reference
#include <Utility.h>
#include <EVP_bundle.h>
#include <SparseLinearEigenSystem.h>
#include <SlepcSession.h>

Go to the source code of this file.

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Functions

const D_complex CppNoddy::Example::eye (0., 1.0)
 
const double CppNoddy::Example::delta (0.5)
 
D_complex CppNoddy::Example::z (double x)
 
D_complex CppNoddy::Example::zx (double x)
 
D_complex CppNoddy::Example::zxx (double x)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 49 of file EVPHarmonicComplexSparse_slepcz.cpp.

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";
62 bool failed = false;
63 size_t N = 4;
64 // a vector for the eigenvalues
66 DenseMatrix<D_complex> eigenvectors;
67
68 Timer timer;
69 for ( int i = 2; i < 11; ++i )
70 {
71 N = ( size_t ) ( std::pow( 2., i ) );
72 const double delta = 1. / ( N - 1 );
73 const double delta2 = delta * delta;
74 // matrix problem
77 // boundary conditions at f(0) = 0
78 a( 0, 0 ) = 1.0;
79 a( 0, 1 ) = 0.0;
80 for ( unsigned j = 1; j < N-1; ++j ) {
81 // Finite difference representation of f''(x)
82 double x = j*delta;
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 // not a generalised problem - but we'll apply that routine anyway
88 b( j, j ) = -1.0;
89 }
90 // boundary conditions at f(1) = 0
91 a( N - 1, N - 1 ) = 1.0;
92 a( N - 1, N - 2 ) = 0.0;
93 // a vector for the eigenvectors - although we won't use them
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" ); //default
98
99 timer.start();
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";
115 timer.stop();
116 }
117
118 // real parameterisation of complex path
119 DenseVector<double> xNodes( Utility::uniform_node_vector( 0.0, 1.0, N ) );
120 // complex path
121 DenseVector<D_complex> zNodes( N, D_complex(0.0,0.0) );
122 // mesh of complex data along a complex path
123 OneD_Node_Mesh<D_complex, D_complex> mesh( zNodes, 1 );
124 int index(0); // first and only eigenvalue returned
125 for ( unsigned j = 0; j < N; ++j ) {
126 // store the nodes in the complex plane
127 mesh.coord(j) = Example::z(xNodes[j]);
128 mesh(j,0) = eigenvectors(index,j+0); //f_j
129 }
130 // write the complex solution on the complex path
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 )
134 failed = true;
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.
Definition: DenseMatrix.h:25
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A one dimensional mesh utility object.
A matrix class that constructs a SPARSE matrix as a row major std::vector of SparseVectors.
Definition: SparseMatrix.h:31
A simple CPU-clock-tick timer for timing metods.
Definition: Timer.h:19
double get_time() const
Return the time.
Definition: Timer.cpp:34
void start()
Start the timer & reset stored time to zero.
Definition: Timer.cpp:12
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
Definition: Timer.cpp:17
const double delta(0.5)
DenseVector< double > real(const DenseVector< D_complex > &X)
Return a double DENSE vector containing the real part of a complex DENSE vector.
Definition: Utility.cpp:177
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...
Definition: Utility.cpp:113
std::complex< double > D_complex
A complex double precision number using std::complex.
Definition: Types.h:98

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::coord(), CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::dump_gnu(), CppNoddy::Timer::get_time(), CppNoddy::Timer::start(), CppNoddy::Timer::stop(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt