CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
EVPHarmonicEasy_lapack.cpp File Reference

Solves the harmonic equation. More...

#include <EVP_bundle.h>
#include <Utility.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::harmonic_equation
 Define the harmonic equation by inheriting the Equation base class. More...
 
class  CppNoddy::Example::harmonic_both_BC
 

Namespaces

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

Enumerations

enum  { f , fd }
 

Functions

int main ()
 

Detailed Description

Solves the harmonic equation.

\[ f''(x) + \lambda f(x) = 0 \]

as an eigenvalue problem for $ \lambda $ over the unit domain with homogeneous boundary conditions for $ f(x) $, returning the smallest eigenvalue. This is the 'easy' approach, using the ODE_EVP class which is constructed from an Equation_with_mass object, with Residual objects for the boundary conditions. The solver then only needs a pointer to the eigenvalue variable.

Definition in file EVPHarmonicEasy_lapack.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
fd 

Definition at line 18 of file EVPHarmonicEasy_lapack.cpp.

18{f, fd };

Function Documentation

◆ main()

int main ( )

Definition at line 72 of file EVPHarmonicEasy_lapack.cpp.

73{
74 cout << "\n";
75 cout << "=== EVP: The harmonic equation done the easy way ====\n";
76 cout << "\n";
77
78 // test pass/fail
79 bool failed( true );
80
81
82 Example::harmonic_equation problem;
83 Example::harmonic_both_BC BC_both;
84 // domain is 0 to 1
85 double left = 0.0;
86 double right = 1.0;
87 // number of nodal points
88 int N = 256;
89 // EV is pi^2 so we'll guess = 10 + 0i
90 D_complex guess( 10.0, 0.0 );
91 // pass/fail tolerance
92 const double tol = 1.e-3;
93
94 cout << " Solving the system using LAPACK:\n";
95 // set up the ode eigenproblem
96 ODE_EVP<double> ode_lapack( &problem, Utility::uniform_node_vector( left, right, N ), &BC_both, &BC_both );
97 ode_lapack.p_eigensystem() -> set_calc_eigenvectors( true );
98 ode_lapack.p_eigensystem() -> set_shift( guess );
99 try
100 {
101 // solve the global eigenvalue
102 ode_lapack.eigensolve();
103 }
104 catch (const std::runtime_error &error )
105 {
106 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
107 return 1;
108 }
109 // get the eigenvalues in a disk of radius 1 about the guess
110 ode_lapack.p_eigensystem() -> tag_eigenvalues_disc( + 1, 1. );
111 // get the tagged eigenvalue(s) -- hopefully only 1
112 DenseVector<D_complex> lapack_lambdas = ode_lapack.p_eigensystem() -> get_tagged_eigenvalues();
113 if ( abs( lapack_lambdas[ 0 ].real() - M_PI * M_PI ) < tol )
114 {
115 failed = false;
116 cout << " LAPACK solver works.\n";
117 }
118
119 if ( failed )
120 {
121 cout << "\033[1;31;48m * FAILED \033[0m\n";
122 return 1;
123 }
124
125 cout << "\033[1;32;48m * PASSED \033[0m\n";
126 return 0;
127
128}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_EVP.h:35
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::ODE_EVP< _Type >::eigensolve(), CppNoddy::ODE_EVP< _Type >::p_eigensystem(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt