CppNoddy  0.92
Loading...
Searching...
No Matches
EVPShootBiharmonic.cpp
Go to the documentation of this file.
1/// \file EVPShootBiharmonic.cpp
2/// \ingroup Tests
3/// \ingroup EVP
4/// Solving a one-dimensional "Bi-harmonic" eigenvalue problem (EVP)
5/// \f[ \left ( \frac{\mbox{d}^2}{\mbox{d}x^2} - \lambda \right )^2 f(x) = 0\,, \quad \mbox{where} \quad f(0)=f(1)=f'(0)=f'(1)=0\,,\f]
6/// via Runge-Kutta and (vector) Newton iteration. The problem is
7/// nonlinear since \f$\lambda\f$ is unknown.
8///
9/// Locally solving for eigenvalues using IVP methods is generally speaking
10/// not a great way of doing things; this is just a Example rather than
11/// any recommendation! See the other EVP examples for better methods.
12
13
14#include <IVP_bundle.h>
15
16namespace CppNoddy
17{
18 namespace Example
19 {
20 /// Define the biharmonic eigenvalue equation by
21 /// inheriting Equation base class.
22 class Biharmonic_equation : public Equation<D_complex>
23 {
24 public:
25 /// The biharmonic is a 4th order complex problem
27
28 /// We implement the equation as 4 first-order ODEs.
30 {
31 f[ 0 ] = z[ 1 ];
32 f[ 1 ] = z[ 2 ];
33 f[ 2 ] = z[ 3 ];
34 f[ 3 ] = - z[ 2 ] * 2.0 * lambda - z[ 0 ] * pow( lambda, 2 );
35 }
36
37 /// The eigenvalue
39
40 };
41
42 /// Define a residual function using the boundary
43 /// conditions for the biharmonic_equation.
44 class Biharmonic_residual : public Residual<D_complex>
45 {
46 public:
48
50 {
51 // instantiate the 1D bi-harmonic eqn
52 eqn = new Biharmonic_equation;
53 // set up the ODE domain, step etc
54 ode = new ODE_IVP<D_complex>( eqn, 0.0, 1.0, 1000 );
55 }
56
58 {
59 delete ode;
60 delete eqn;
61 }
62
63 /// implement a residual function.
65 {
66 DenseVector<D_complex> u( 4, 0.0 ); // 4th order problem
67 u[ 0 ] = 0.0; // f = 0
68 u[ 1 ] = 0.0; // f' = 0
69 u[ 2 ] = 1.0; // f'' = 1
70 u[ 3 ] = unknown[ 0 ]; // f''' = unknown[0]
71 eqn -> lambda = unknown[ 1 ]; // parameter = unknown[1]
72 // shoot using R-K fixed step size algorithm
73 u = ode -> shoot4( u );
74 // return the BC residuals
75 BC[ 0 ] = u[ 0 ];
76 BC[ 1 ] = u[ 1 ]; // trying to make f = f' = 0 at other boundary
77 }
78 private:
80 };
81 } //end Example namespace
82} //end CppNoddy namespace
83
84
85using namespace CppNoddy;
86using namespace std;
87
88int main()
89{
90
91 cout << "\n";
92 cout << "=== EVP: Biharmonic equation via shooting ==========\n";
93 cout << "\n";
94
96 // instantiate a complex Vector Newton class for the Biharmonic
97 Newton<D_complex> Biharm( &problem );
98
99 const D_complex A( -3.0, 7.0 ); // A guess of f'''(0)
100 const D_complex B( 2.21, 1.25 ); // A guess of the eigenvalue
101 // rig up an initial guess
102 DenseVector<D_complex> unknowns( 2, 0.0 ); // Two complex quantities to to find
103 unknowns[ 0 ] = A;
104 unknowns[ 1 ] = B * B;
105
106 try
107 {
108 Biharm.iterate( unknowns );
109 }
110 catch (const std::runtime_error &error )
111 {
112 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
113 return 1;
114 }
115
116 D_complex eigenvalue( std::sqrt( unknowns[ 1 ] ) );
117
118 std::string dirname("./DATA");
119 mkdir( dirname.c_str(), S_IRWXU );
120 // output for the data
121 TrackerFile my_file( "./DATA/Biharmonic.dat" );
122 my_file.push_ptr( &eigenvalue, "eigenvalue" );
123 my_file.push_ptr( &problem.ode -> get_mesh(), "biharmonic" );
124 my_file.header();
125 my_file.update();
126
127 const double tol = 1.e-8; // A pass/fail tolerance
128 if ( abs( sin( eigenvalue ) + eigenvalue ) < tol )
129 {
130 cout << "\033[1;32;48m * PASSED \033[0m\n";
131 return 0;
132 }
133
134 cout << "\033[1;31;48m * FAILED \033[0m\n";
135 cout << " Diff = " << abs( sin( eigenvalue ) + eigenvalue ) << "\n";
136 return 1;
137
138}
@ f
Definition: BVPBerman.cpp:15
@ lambda
int main()
A shorter bundled include file for initial-value problems.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
An equation object base class used in the BVP/IVP classes.
Definition: Equation.h:22
Define the biharmonic eigenvalue equation by inheriting Equation base class.
Biharmonic_equation()
The biharmonic is a 4th order complex problem.
void residual_fn(const DenseVector< D_complex > &z, DenseVector< D_complex > &f) const
We implement the equation as 4 first-order ODEs.
Define a residual function using the boundary conditions for the biharmonic_equation.
void residual_fn(const DenseVector< D_complex > &unknown, DenseVector< D_complex > &BC) const
implement a residual function.
A vector NEWTON iteration class.
Definition: Newton.h:25
void iterate(DenseVector< _Type > &x)
The Newton iteration method.
Definition: Newton.cpp:35
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_IVP.h:20
A base class to be inherited by objects that define residuals.
Definition: Residual.h:15
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
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