CppNoddy  0.92
Loading...
Searching...
No Matches
Functions
1DNodeMeshAiry_lapack.cpp File Reference

Solves the Airy equation. More...

#include <Utility.h>
#include <OneD_Node_Mesh.h>
#include <BandedLinearSystem.h>

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Solves the Airy equation.

\[ f''(x) - xf(x) = 0 \]

on the negative real axis over the range [-10,0] then pushes the data into a OneD_GenMesh object and integrates the result. The integral is checked against the table in Abramowitz & Stegun:

\[ \int_{-10}^0 \mbox{Ai}(s) \, \mbox{d}s \approx 0.7656984 \]

The finite-difference solution of the Airy equation and the trapezoidal scheme used in the integration are both second order.

Definition in file 1DNodeMeshAiry_lapack.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 22 of file 1DNodeMeshAiry_lapack.cpp.

23{
24
25 cout << "\n";
26 cout << "=== OneD_Node_Mesh & BandedMatrix: Airy function ====\n";
27 cout << "\n";
28
29 size_t n = 8001; // number of points
30 double l = -10.0; // domain size
31 double d = abs( l ) / ( n - 1 ); // Mesh step
32 // a uniform mesh to store the result in
34
35 BandedMatrix<double> a( n, 3, 0.0 ); // Tridiagonal banded matrix
36 DenseVector<double> b( n, 0.0 ); // RHS vector
37
38 a( 0, 0 ) = 1.0; // BC is that f(-10) = Ai(-10)
39 b[ 0 ] = 0.04024123849; // value from Abramowitz & Stegun
40 for ( size_t i = 1; i < n - 1; ++i )
41 {
42 // set up the f''(x) operator
43 a( i, i-1 ) = 1.0/(d*d);
44 a( i, i ) = -2.0/(d*d);
45 a( i, i+1 ) = 1.0/(d*d);
46 // add the -xf(x) term
47 a( i, i ) -= soln.coord( i );
48 }
49 a( n - 1, n - 1 ) = 1.0; // BC is that f(0) = Ai(0)
50 b[ n - 1 ] = 0.3550280539; // value from Abramowitz & Stegun
51
52 // solve the FD equations
53 BandedLinearSystem<double> system( &a, &b, "lapack" );
54
55 try
56 {
57 system.solve();
58 }
59 catch (const std::runtime_error &error )
60 {
61 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
62 return 1;
63 }
64
65 // put the result into the solution mesh
66 soln.set_vars_from_vector( b );
67
68 // check the integral against Abramowitz & Stegun data
69 const double tol = 1.e-5;
70 if ( abs( soln.integral2() - 0.7656984 ) > tol )
71 {
72 cout << "\033[1;31;48m * FAILED \033[0m\n";
73 cout.precision( 10 );
74 cout << n << " " << soln.integral2() - 0.7656984 << "\n";
75 return 1;
76 }
77 else
78 {
79 cout << "\033[1;32;48m * PASSED \033[0m\n";
80 return 0;
81 }
82
83}
A linear system class for vector right-hand sides.
A matrix class that constructs a BANDED matrix.
Definition: BandedMatrix.h:16
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A one dimensional mesh utility object.
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

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::coord(), CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::integral2(), CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::set_vars_from_vector(), CppNoddy::BandedLinearSystem< _Type >::solve(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt