CppNoddy  0.92
Loading...
Searching...
No Matches
BermanShooting.cpp
Go to the documentation of this file.
1/// \file BermanShooting.cpp
2/// \ingroup Tests
3/// \ingroup BVP
4/// Solving the fourth-order Berman (porous channel) similarity equation
5/// \f[ f'''(y) = Re \left ( f(y)f''(y) - f'(y)^2 - K \right )\f]
6/// where \f$y\in [-1,1]\f$ and \f$K\f$ is a pressure constant and \f$Re\f$ is the
7/// Reynolds number based on the channel half-height and the wall suction. The boundary
8/// conditions are that \f$f(\pm 1) = \pm 1\f$ and \f$f'(\pm 1 ) = 0\f$.
9/// This BVP is solved via Runge-Kutta and (vector) Newton iteration. This similarity
10/// form is an exact reduction of the Navier-Stokes equations.
11///
12/// Solving a BVP by converting it to an IVP like this is generally not a smart move!
13
14#include <IVP_bundle.h>
15
16#include "../Utils_Fill.h"
17
18namespace CppNoddy
19{
20 namespace Example
21 {
22 /// Define the Berman equation by
23 /// inheriting Equation base class.
24 class Berman_equation : public Equation<double>
25 {
26 public:
27
28 /// Construct the Berman equation as a 4th order real system
29 Berman_equation() : Equation<double> ( 4 ) {}
30
31 /// We implement the equation as 4 first-order ODEs.
33 {
34 f[ 0 ] = z[ 1 ];
35 f[ 1 ] = z[ 2 ];
36 f[ 2 ] = Re * ( - z[ 3 ] - z[ 1 ] * z[ 1 ] + z[ 0 ] * z[ 2 ] );
37 f[ 3 ] = 0.0;
38 }
39
41 {
43 }
44
45 /// The Reynolds number
46 double Re;
47
48 };
49
50 /// Define a residual function using the boundary
51 /// conditions for the Berman equation.
52 class Berman_residual : public Residual<double>
53 {
54 public:
56
57 // There are two residuals to be satisfied
58 Berman_residual() : Residual<double> ( 2 )
59 {
60 // instantiate the Berman equation as our problem
61 eqn = new Berman_equation;
62 // set the Reynolds number
63 eqn -> Re = 1.0;
64 // instantiate an ODE in [-1.,1] with a maximum of
65 // 100 integrator steps, using this problem equation
66 ode = new ODE_IVP<double>( eqn, -1.0, 1.0, 500 );
67
68 }
69
71 {
72 delete ode;
73 delete eqn;
74 }
75
76 /// implement a residual function.
77 void residual_fn( const DenseVector<double>& unknown, DenseVector<double>& BC ) const
78 {
79 DenseVector<double> u( 4, 0.0 ); // 4 variables of Berman problem
80
81 u[ 0 ] = -1.0; // V = 0
82 u[ 1 ] = 0.0; // V' = 0
83 u[ 2 ] = unknown[ 0 ]; // V'' = unknown0
84 u[ 3 ] = unknown[ 1 ]; // A = unknown1
85
86 u = ode -> shoot4( u );
87
88 BC[ 0 ] = u[ 0 ] - 1.;
89 BC[ 1 ] = u[ 1 ];
90 }
91 private:
92 Berman_equation* eqn;
93 };
94 } //end Example namespace
95} //end CppNoddy namespace
96
97using namespace CppNoddy;
98using namespace std;
99
100int main()
101{
102
103 cout << "\n";
104 cout << "=== BVP_Shoot: vector Newton solution of Berman eqn =\n";
105 cout << "\n";
106
108 // instantiate a Vector Newton class for the Biharmonic
109 Newton<double> Berman( &problem );
110
111 DenseVector<double> guess( 2, 0.0 );
112 guess[ 0 ] = -2.0;
113 guess[ 1 ] = 1.0;
114
115 try
116 {
117 Berman.iterate( guess );
118 }
119 catch ( const std::runtime_error &error )
120 {
121 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
122 return 1;
123 }
124
125 // output the data
126 std::string dirname("./DATA");
127 mkdir( dirname.c_str(), S_IRWXU );
128 TrackerFile my_file( "./DATA/Berman.dat" );
129 my_file.push_ptr( &( problem.ode -> get_mesh() ) );
130 my_file.update();
131
132 // check against the known pressure constant K for Re=1.
133 if ( std::abs( guess[ 1 ] - 0.70457 ) > 1.e-5 )
134 {
135 cout << "\033[1;31;48m * FAILED \033[0m\n";
136 cout.precision( 14 );
137 cout << guess[ 0 ] << " " << guess[ 1 ] << "\n";
138 return 1;
139 }
140 else
141 {
142 cout << "\033[1;32;48m * PASSED \033[0m\n";
143 return 0;
144 }
145
146
147}
@ f
Definition: BVPBerman.cpp:15
int main()
A shorter bundled include file for initial-value problems.
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 BVP/IVP classes.
Definition: Equation.h:22
Define the Berman equation by inheriting Equation base class.
void mass(const DenseVector< double > &x, DenseMatrix< double > &m) const
Berman_equation()
Construct the Berman equation as a 4th order real system.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
We implement the equation as 4 first-order ODEs.
double Re
The Reynolds number.
Define a residual function using the boundary conditions for the Berman equation.
void residual_fn(const DenseVector< double > &unknown, DenseVector< double > &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
double Re
Globally define the Reynolds number and wavenumber.
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