CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
BVPBerman.cpp File Reference
#include <BVP_bundle.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::Berman_equation
 Define the Berman equation by inheriting Equation base class. More...
 
class  CppNoddy::Example::Berman_left_BC
 
class  CppNoddy::Example::Berman_right_BC
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Enumerations

enum  { f , fd , fdd , fddd }
 

Functions

int main ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
fd 
fdd 
fddd 

Definition at line 15 of file BVPBerman.cpp.

15{f, fd, fdd, fddd };
@ fd
Definition: BVPBerman.cpp:15
@ fdd
Definition: BVPBerman.cpp:15
@ fddd
Definition: BVPBerman.cpp:15
@ f
Definition: BVPBerman.cpp:15

Function Documentation

◆ main()

int main ( )

Definition at line 79 of file BVPBerman.cpp.

80{
81 cout << "\n";
82 cout << "=== BVP: finite-difference solution of Berman eqn ===\n";
83 cout << "\n";
84
85 Example::Berman_equation problem;
86 Example::Berman_left_BC BC_left;
87 Example::Berman_right_BC BC_right;
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}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_BVP.h:37
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 f, fd, fdd, fddd, CppNoddy::Example::Berman_equation::Re, CppNoddy::ODE_BVP< _Type, _Xtype >::solution(), CppNoddy::ODE_BVP< _Type, _Xtype >::solve2(), and CppNoddy::Utility::uniform_node_vector().

© 2012

R.E. Hewitt