CppNoddy  0.92
Loading...
Searching...
No Matches
BVPBerman.cpp
Go to the documentation of this file.
1/// \file BVP_Berman.cpp
2/// \ingroup Examples
3/// \ingroup BVP
4/// Solving the Berman suction-channel solution in the form
5/// \f[ f^(iv)(y) = Re ( f(y)f'''(y) - f'(y)f''(y) ) \f]
6/// subject to \f$ f(\pm 1) = \pm 1 \f$ and \f$ f'(\pm 1) = 0 \f$
7/// by applying the ODE_BVP class.
8
9
10#include <BVP_bundle.h>
11
12#include "../Utils_Fill.h"
13
14// enumerate the variables in the ODE
15enum {f, fd, fdd, fddd };
16
17namespace CppNoddy
18{
19 namespace Example
20 {
21 /// Define the Berman equation by inheriting the Equation base class
22 class Berman_equation : public Equation_1matrix<double>
23 {
24 public:
25
26 /// The Berman equation is a 4th order real ODE
28
29 /// The Berman equation
31 {
32 g[ f ] = z[ fd ];
33 g[ fd ] = z[ fdd ];
34 g[ fdd ] = z[ fddd ];
35 g[ fddd ] = Re * ( z[ f ] * z[ fddd ] - z[ fd ] * z[ fdd ] );
36 }
37
39 {
41 }
42
43 // The Reynolds number
44 double Re;
45 };
46
47 class Berman_left_BC : public Residual<double>
48 {
49 public:
50 // 2 boundary conditions and 4 unknowns
51 Berman_left_BC() : Residual<double> ( 2, 4 ) {}
52
54 {
55 B[ 0 ] = z[ f ] + 1.0;
56 B[ 1 ] = z[ fd ];
57 }
58 };
59
60 class Berman_right_BC : public Residual<double>
61 {
62 public:
63 // 2 boundary conditions and 4 unknowns
64 Berman_right_BC() : Residual<double> ( 2, 4 ) {}
65
67 {
68 B[ 0 ] = z[ f ] - 1.0;
69 B[ 1 ] = z[ fd ];
70 }
71 };
72
73 } // end Example namespace
74} // end CppNoddy namespace
75
76using namespace CppNoddy;
77using namespace std;
78
79int main()
80{
81 cout << "\n";
82 cout << "=== BVP: finite-difference solution of Berman eqn ===\n";
83 cout << "\n";
84
88
89 // set the Reynolds number
90 problem.Re = 1.0;
91 // Reynolds number step
92 double delta_Re = 0.1;
93 // domain is -1 to 1
94 double left = -1.0;
95 double right = 1.0;
96 // number of nodal points
97 int N = 1401;
98 // mesh
99 DenseVector<double> nodes( Utility::uniform_node_vector( left, right, N ) );
100 // Example tolerance
101 const double tol = 1.e-4;
102
103 // pass it to the ode
104 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
105
106 // our initial guess
107 for ( int i = 0; i < N; ++i )
108 {
109 double y = ode.solution().coord( i );
110 // set f(y)
111 ode.solution()( i, f ) = 1.5 * ( y - y * y * y / 3 );
112 // set f'(y)
113 ode.solution()( i, fd ) = 1.5 * ( 1 - y * y );
114 // set f''(y)
115 ode.solution()( i, fdd ) = -3 * y;
116 // set f''(y)
117 ode.solution()( i, fddd ) = -3;
118 }
119
120 // zero-order continuation in Re
121 do
122 {
123 // solve the problem using 2nd order finite-difference
124 try
125 {
126 try
127 {
128 ode.solve2();
129 }
130 catch ( const std::runtime_error& error )
131 {
132 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
133 return 1;
134 }
135 }
136 catch ( const ExceptionBifurcation& bifn )
137 {
138 cout << " Bifurcation detected between Re = " << problem.Re - delta_Re
139 << " and Re = " << problem.Re << "\n";
140 cout << " Continuing further.\n";
141 }
142 problem.Re += delta_Re;
143
144 }
145 while ( problem.Re < 10.0 + tol );
146
147
148 // compare against the Shoot_Berman data at Re = 10
149 // data to be compared is f''(y) at y = -1
150 if ( std::abs( 5.99898 - ode.solution()( 0, fdd ) ) > tol )
151 {
152 cout << "\033[1;31;48m * FAILED \033[0m\n";
153 cout << std::abs( 5.99898 - ode.solution()( 0, fdd ) ) << "\n";
154 return 1;
155 }
156 else
157 {
158 cout << "\033[1;32;48m * PASSED \033[0m\n";
159 return 0;
160 }
161}
@ fd
Definition: BVPBerman.cpp:15
@ fdd
Definition: BVPBerman.cpp:15
@ fddd
Definition: BVPBerman.cpp:15
@ f
Definition: BVPBerman.cpp:15
int main()
Definition: BVPBerman.cpp:79
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 Berman equation by inheriting Equation base class.
Berman_equation()
The Berman equation is a 4th order real ODE.
Definition: BVPBerman.cpp:27
void matrix0(const DenseVector< double > &x, DenseMatrix< double > &m) const
Define the matrix in terms of the current state vector.
Definition: BVPBerman.cpp:38
void residual_fn(const DenseVector< double > &z, DenseVector< double > &g) const
The Berman equation.
Definition: BVPBerman.cpp:30
double Re
The Reynolds number.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPBerman.cpp:53
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPBerman.cpp:66
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 > 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
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