CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
Classes | Namespaces | Enumerations | Functions
EVPHarmonicLocal.cpp File Reference

Solves the harmonic equation. More...

#include <BVP_bundle.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::Harmonic_equation< _Type, _Xtype >
 Define the harmonic equation by inheriting the Equation base class. More...
 
class  CppNoddy::Example::Harmonic_left_BC< _Type >
 
class  CppNoddy::Example::Harmonic_right_BC< _Type >
 

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 , lambda }
 

Functions

int main ()
 

Detailed Description

Solves the harmonic equation.

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

as a LOCAL eigenvalue problem for $ \lambda $ over the unit domain with homogeneous boundary conditions for $ f(x) $ but using the nonlinear BVP solver to refine a guess at an eigenvalue. For example, we would have run an (expensive) global eigenvalue search (EVP_Harmonic) then refined the eigenvalue of interest in the way shown in this example.

Note: This approach (as it stands) is not as efficient as it could be since we include N extra degrees of freedom (where N is the number of mesh points) into the problem for only one eigenvalue. This retains the banded structure, but it would perhaps be better to solve using a sparse structure, or an appropriate multi-step algorithm for the for the banded matrix.

Definition in file EVPHarmonicLocal.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
fd 
lambda 

Definition at line 25 of file EVPHarmonicLocal.cpp.

25{ f, fd, lambda };
@ lambda

Function Documentation

◆ main()

int main ( )

Definition at line 88 of file EVPHarmonicLocal.cpp.

89{
90 cout << "\n";
91 cout << "=== EVP: Local refinement of an eigenvalue =========\n";
92 cout << "\n";
93
94 cout << " Number of points : |local eigenvalue - pi^2| \n";
95
96 // set up the problem
97 Example::Harmonic_equation problem;
98 // set up BCs
99 Example::Harmonic_left_BC BC_left;
100 Example::Harmonic_right_BC BC_right;
101 // set up the domain from 0 to 1
102 double left = 0.0;
103 double right = 1.0;
104 // set our guess for the eigenvalue -- this would come
105 // from the global method in a less trivial problem.
106 D_complex eigenvalue_guess = 9.0;
107 bool failed( true );
108 // loop through some meshes with increasing numbers of points
109 for ( unsigned i = 6; i <= 10; ++i )
110 {
111 unsigned N( 0 );
112 N = unsigned( std::pow( 2.0, double( i ) ) );
113 // mesh
114 DenseVector<double> nodes( Utility::uniform_node_vector( left, right, N ) );
115 // construct the ODE_BVP object
116 ODE_BVP<D_complex> ode( &problem, nodes, &BC_left, &BC_right );
117 // makes no sense to monitor the determinant here
118 ode.set_monitor_det( false );
119 // run through the mesh & set an initial guess
120 for ( unsigned i = 0; i < N; ++i )
121 {
122 double x = ode.solution().coord( i );
123 ode.solution()( i, f ) = x * ( 1 - x );
124 ode.solution()( i, fd ) = 1.0 - 2 * x;
125 ode.solution()( i, lambda ) = eigenvalue_guess;
126 }
127 // solve for the eigenvalue/eigenfunction
128 ode.solve2();
129 // an error measure
130 double abs_error( std::abs( ode.solution()( 1, lambda ) - M_PI * M_PI ) );
131 // output for fun
132 cout << " " << N << " : " << abs_error << "\n";
133 if ( abs_error < 1.e-4 )
134 failed = false;
135 }
136
137 if ( failed )
138 {
139 cout << "\033[1;31;48m * FAILED \033[0m\n";
140 return 1;
141 }
142
143 cout << "\033[1;32;48m * PASSED \033[0m\n";
144 return 0;
145}
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_BVP.h:37
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 f, fd, lambda, CppNoddy::ODE_BVP< _Type, _Xtype >::set_monitor_det(), CppNoddy::ODE_BVP< _Type, _Xtype >::solution(), CppNoddy::ODE_BVP< _Type, _Xtype >::solve2(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt