CppNoddy  0.92
Loading...
Searching...
No Matches
BVPBlasius.cpp
Go to the documentation of this file.
1/// \file BVPBlasius.cpp
2/// \ingroup Tests
3/// \ingroup BVP
4/// Solving the Blasius equation
5/// \f[ f'''(y) + f(y) f''(y) = 0\,, \f]
6/// with \f$ f(0)=f'(0)=0 \f$ and \f$ f'(\infty) = 1 \f$
7/// in the domain \f$ y \in [0,\infty ] \f$
8/// by applying the ODE_BVP class.
9/// The class constructs and solves the
10/// global matrix problem using 2nd-order finite differences
11/// over a finite domain of specified size.
12
13#include <BVP_bundle.h>
14
15#include "../Utils_Fill.h"
16
17// enumerate the 3 variables
18enum { f, fd, fdd };
19
20namespace CppNoddy
21{
22 namespace Example
23 {
24 /// Define the Blasius equation by inheriting Equation base class
25 class Blasius_equation : public Equation_1matrix<double>
26 {
27 public:
28
29 /// The Blasius eqn is a 3rd order real ODE
31
32 /// Define the Blasius eqn
34 {
35 g[ f ] = z[ fd ];
36 g[ fd ] = z[ fdd ];
37 g[ fdd ] = -z[ f ] * z[ fdd ];
38 }
39
41 {
43 }
44 };
45
46 class Blasius_left_BC : public Residual<double>
47 {
48 public:
49 // 2 residuals and 3 unknowns
50 Blasius_left_BC() : Residual<double> ( 2, 3 ) {}
51
53 {
54 B[ 0 ] = z[ f ];
55 B[ 1 ] = z[ fd ];
56 }
57 };
58
59 class Blasius_right_BC : public Residual<double>
60 {
61 public:
62 // 1 residual and 3 unknowns
63 Blasius_right_BC() : Residual<double> ( 1, 3 ) {}
64
66 {
67 B[ 0 ] = z[ fd ] - 1.0;
68 }
69 };
70
71 } // end Example namespace
72} // end CppNoddy namespace
73
74using namespace CppNoddy;
75using namespace std;
76
77int main()
78{
79 cout << "\n";
80 cout << "=== BVP: finite-difference solution of Blasius ======\n";
81 cout << "\n";
82
83 cout << " Number of points : approx. error \n";
84
85 // equation
87 // boundary conditions
90
91 double left = 0.0; // from x=0
92 double right = 20.0; // to x=20
93 bool failed = false;
94
95 const double tol = 1.e-5; // pass/fail tolerance
96 // let's repeat the computation for a sequence of N's
97 // to check on convergence
98 for ( int N = 32; N <= 2048; N *= 2 )
99 {
100 // mesh
101 DenseVector<double> nodes( Utility::power_node_vector( left, right, N, 1.2 ) );
102 // pass it to the ode
103 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
104 for ( int i = 0; i < N; ++i )
105 {
106 double y = ode.solution().coord( i );
107 ode.solution()( i, f ) = y * ( 1.0 - exp( -y ) );
108 ode.solution()( i, fd ) = ( 1.0 - exp( -y ) ) + y * exp( -y );
109 ode.solution()( i, fdd ) = 2.0 * exp( -y ) - y * exp( -y );
110 }
111
112 try
113 {
114 ode.solve2();
115 }
116 catch ( const std::runtime_error &error )
117 {
118 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
119 return 1;
120 }
121
122 const double c = 1.65519036023e0;
123 const double answer = 1. / pow( c, 1.5 );
124 if ( abs( ode.solution()( 0, fdd ) - answer ) > tol )
125 {
126 failed = true;
127 }
128 else
129 {
130 failed = false;
131 }
132
133 // compare to the known stress value
134 std::cout << " N=" << N << " error=" << abs( ode.solution()( 0, fdd ) - answer ) << " IVP answer=" << answer << "\n";
135
136 std::string dirname("./DATA");
137 mkdir( dirname.c_str(), S_IRWXU );
138 ode.solution().dump_gnu("./DATA/blasius.data");
139
140 }
141
142 if ( failed )
143 {
144 cout << "\033[1;31;48m * FAILED \033[0m\n";
145 return 1;
146 }
147 else
148 {
149 cout << "\033[1;32;48m * PASSED \033[0m\n";
150 return 0;
151 }
152}
@ fd
Definition: BVPBerman.cpp:15
@ fdd
Definition: BVPBerman.cpp:15
@ f
Definition: BVPBerman.cpp:15
@ fd
Definition: BVPBlasius.cpp:18
@ fdd
Definition: BVPBlasius.cpp:18
@ f
Definition: BVPBlasius.cpp:18
int main()
Definition: BVPBlasius.cpp:77
A shorter bundled include file for ODE_BVP and PDE_IBVP codes.
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
An equation object base class used in the IBVP classes (and others).
Define the Blasius equation by inheriting Equation base class.
Blasius_equation()
The Blasius eqn is a 3rd order real ODE.
Definition: BVPBlasius.cpp:30
void matrix0(const DenseVector< double > &x, DenseMatrix< double > &m) const
Define the matrix in terms of the current state vector.
Definition: BVPBlasius.cpp:40
void residual_fn(const DenseVector< double > &z, DenseVector< double > &g) const
Define the Blasius eqn.
Definition: BVPBlasius.cpp:33
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPBlasius.cpp:52
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPBlasius.cpp:65
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_BVP.h:37
OneD_Node_Mesh< _Type, _Xtype > & solution()
Definition: ODE_BVP.h:187
void solve2()
Formulate and solve the ODE using Newton iteration and a second-order finite difference scheme.
Definition: ODE_BVP.cpp:83
A base class to be inherited by objects that define residuals.
Definition: Residual.h:15
double g(1.0)
gravitational acceleration
DenseVector< double > power_node_vector(const double &lower, const double &upper, const std::size_t &N, const double &power)
Return a DENSE vector with the nodal points of a non-uniform mesh distributed between the upper/lower...
Definition: Utility.cpp:123
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
void fill_identity(CppNoddy::Sequential_Matrix_base< _Type > &A)
Fill diagonal with unit values.
Definition: Utils_Fill.h:22

© 2012

R.E. Hewitt