CppNoddy  0.92
Loading...
Searching...
No Matches
BVPKarman.cpp
Go to the documentation of this file.
1/// \file BVP_Karman.cpp
2/// \ingroup Examples
3/// \ingroup BVP
4/// Solving the Karman rotating-disk equations for the
5/// flow above an infinite rotating disk:
6/// \f[ U''(y) = U^2(y) + V(y)U'(y) - W^2(y) \f]
7/// \f[ W''(y) = 2U(y)W(y) + V(y)W'(y) \f]
8/// \f[ 2U(y) + V'(y) = 0 \f]
9/// with boundary conditions \f$ U(0)=V(0)=0 \f$, \f$ W(0)=1 \f$
10/// and \f$ U(\infty ) \to 0 \f$, \f$ W(\infty ) \to 0 \f$.
11/// The class constructs and solves the
12/// global matrix problem using 2nd-order finite differences.
13
14
15#include <BVP_bundle.h>
16
17#include "../Utils_Fill.h"
18
19// enumerate the 5 variables of the ODE system
20enum {U, Ud, V, W, Wd};
21
22namespace CppNoddy
23{
24 namespace Example
25 {
26 /// Define the Karman equations
27 class Karman_equations : public Equation_1matrix<double>
28 {
29 public:
30
31 /// The Karman system is a 5th order real system of ODEs
33
34 /// Define the Karman system
36 {
37 // The 5th order system for ( U, U', V, W, W' )
38 f[ U ] = z[ Ud ];
39 f[ Ud ] = z[ U ] * z[ U ] + z[ V ] * z[ Ud ] - z[ W ] * z[ W ];
40 f[ V ] = -2 * z[ U ];
41 f[ W ] = z[ Wd ];
42 f[ Wd ] = 2 * z[ U ] * z[ W ] + z[ V ] * z[ Wd ];
43 }
44
46 {
48 }
49
50 };
51
52 /// Define the boundary conditions
53 class Karman_left_BC : public Residual<double>
54 {
55 public:
56 // 3 BCs for 5 unknowns
57 Karman_left_BC() : Residual<double> ( 3, 5 ) {}
58
60 {
61 B[ 0 ] = z[ U ];
62 B[ 1 ] = z[ V ];
63 B[ 2 ] = z[ W ] - 1.0;
64 }
65 };
66
67 class Karman_right_BC : public Residual<double>
68 {
69 public:
70 // 2 BCs for 5 unknowns
71 Karman_right_BC() : Residual<double> ( 2, 5 ) {}
72
74 {
75 B[ 0 ] = z[ U ];
76 B[ 1 ] = z[ W ];
77 }
78 };
79
80 } // end Example namespace
81} // end CppNoddy namespace
82
83using namespace CppNoddy;
84using namespace std;
85
86int main()
87{
88 cout << "\n";
89 cout << "=== BVP: finite-difference soln of Karman eqns ======\n";
90 cout << "\n";
91
95
96 // Boundary layer is from 0 to 20
97 double left = 0.0;
98 double right = 20.0;
99 // number of nodal points
100 int N = 801;
101
102 DenseVector<double> nodes = Utility::uniform_node_vector( left, right, N );
103 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
104
105 // (re)set the solution to the initial guess
106 for ( int i = 0; i < N; ++i )
107 {
108 double y = ode.solution().coord( i );
109 ode.solution()( i, U ) = 0.0;
110 ode.solution()( i, Ud ) = 0.0;
111 ode.solution()( i, V ) = 0.0;
112 ode.solution()( i, W ) = exp( -y );
113 ode.solution()( i, Wd ) = -exp( -y );
114 }
115
116 try
117 {
118 ode.solve2();
119 }
120 catch (const std::runtime_error &error )
121 {
122 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
123 return 1;
124 }
125
126 // check the BL transpiration vs the known solution
127 double tol( 1.e-4 );
128 if ( abs( ode.solution()( N - 1, V ) + 0.88447 ) > tol )
129 {
130 cout << "\033[1;31;48m * FAILED \033[0m\n";
131 cout << " Difference = " << abs( ode.solution()( N - 1, V ) + 0.88447 ) << "\n";
132 return 1;
133 }
134 else
135 {
136 cout << "\033[1;32;48m * PASSED \033[0m\n";
137 return 0;
138 }
139
140}
@ f
Definition: BVPBerman.cpp:15
@ V
Definition: BVPKarman.cpp:20
@ Wd
Definition: BVPKarman.cpp:20
@ W
Definition: BVPKarman.cpp:20
@ U
Definition: BVPKarman.cpp:20
@ Ud
Definition: BVPKarman.cpp:20
int main()
Definition: BVPKarman.cpp:86
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 Karman equations.
Definition: BVPKarman.cpp:28
Karman_equations()
The Karman system is a 5th order real system of ODEs.
Definition: BVPKarman.cpp:32
void matrix0(const DenseVector< double > &x, DenseMatrix< double > &m) const
Define the matrix in terms of the current state vector.
Definition: BVPKarman.cpp:45
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
Define the Karman system.
Definition: BVPKarman.cpp:35
Define the boundary conditions.
Definition: BVPKarman.cpp:54
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPKarman.cpp:59
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
Definition: BVPKarman.cpp:73
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
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