CppNoddy  0.92
Loading...
Searching...
No Matches
BVPKarmanAdaptive.cpp
Go to the documentation of this file.
1/// \file BVPKarmanAdaptive.cpp
2/// \ingroup Tests
3/// \ingroup BVP
4/// Adaptively solve 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#include <BVP_bundle.h>
15
16#include "../Utils_Fill.h"
17
18// enumerate the 5 variables of the ODE system
19enum {U, Ud, V, W, Wd};
20
21namespace CppNoddy
22{
23 namespace Example
24 {
25 /// Define the Karman equations
26 class Karman_equations : public Equation_1matrix<double>
27 {
28 public:
29
30 /// The Karman system is a 5th order real system of ODEs
32
33 /// Define the Karman system
35 {
36 // The 5th order system for ( U, U', V, W, W' )
37 f[ U ] = z[ Ud ];
38 f[ Ud ] = z[ U ] * z[ U ] + z[ V ] * z[ Ud ] - z[ W ] * z[ W ];
39 f[ V ] = -2 * z[ U ];
40 f[ W ] = z[ Wd ];
41 f[ Wd ] = 2 * z[ U ] * z[ W ] + z[ V ] * z[ Wd ];
42 }
43
45 {
47 }
48 };
49
50 /// Define the boundary conditions
51 class Karman_left_BC : public Residual<double>
52 {
53 public:
54 // 3 BCs for 5 unknowns
55 Karman_left_BC() : Residual<double> ( 3, 5 ) {}
56
58 {
59 B[ 0 ] = z[ U ];
60 B[ 1 ] = z[ V ];
61 B[ 2 ] = z[ W ] - 1.0;
62 }
63 };
64
65 class Karman_right_BC : public Residual<double>
66 {
67 public:
68 // 2 BCs for 5 unknowns
69 Karman_right_BC() : Residual<double> ( 2, 5 ) {}
70
72 {
73 B[ 0 ] = z[ U ];
74 B[ 1 ] = z[ W ];
75 }
76 };
77
78 } // end Example namespace
79} // end CppNoddy namespace
80
81using namespace CppNoddy;
82using namespace std;
83
84int main()
85{
86 cout << "\n";
87 cout << "=== BVP: finite-difference soln of Karman eqns ======\n";
88 cout << "=== Here we use an adaptive mesh after timing. ===\n";
89 cout << "\n";
90
94
95 // Boundary layer is from 0 to 20
96 double left = 0.0;
97 double right = 40.0;
98 // number of nodal points
99 int N = 21;
100
101 DenseVector<double> nodes = Utility::power_node_vector( left, right, N, 1.5 );
102
103 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
104
105 for ( int i = 0; i < N; ++i )
106 {
107 double y = ode.solution().coord( i );
108 ode.solution()( i, U ) = 0.0;
109 ode.solution()( i, Ud ) = 0.0;
110 ode.solution()( i, V ) = 0.0;
111 ode.solution()( i, W ) = exp( -y );
112 ode.solution()( i, Wd ) = -exp( -y );
113 }
114
115 try
116 {
117 ode.solve2();
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 std::cout << "=== Adapting the mesh.\n";
125
126 // output to check the adapted mesh
127 std::string dirname("./DATA");
128 mkdir( dirname.c_str(), S_IRWXU );
129 TrackerFile my_file( "./DATA/BVP_Karman.dat", 12 );
130 my_file.push_ptr( &ode.solution(), "soln" );
131
132 const double tol( 1.e-4 );
133 int adapt_counter ( 1 );
134 do
135 {
136 // one adapt
137 ode.adapt( 1.e-4 );
138 ++adapt_counter;
139 // solve
140 ode.solve2();
141 // no. of nodes in the adapted mesh
142 N = ode.solution().get_nnodes();
143 cout << " Adapted mesh to " << ode.solution().get_nnodes() << " nodes.\n";
144 cout << " Adapted error = " << abs( ode.solution()( N - 1, V ) + 0.88447 ) << "\n";
145 // adapt until condition is satisfied or max adaptions are done
146 }
147 while ( ( abs( ode.solution()( N - 1, V ) + 0.88447 ) > tol ) && ( adapt_counter < 10 ) );
148 // store solution for plotting
149 my_file.update();
150
151 // check the BL transpiration vs the known solution
152 if ( abs( ode.solution()( N - 1, V ) + 0.88447 ) > tol )
153 {
154 cout << "\033[1;31;48m * FAILED \033[0m\n";
155 cout << " Difference = " << abs( ode.solution()( N - 1, V ) + 0.88447 ) << "\n";
156 return 1;
157 }
158 else
159 {
160 cout << "\033[1;32;48m * PASSED \033[0m\n";
161 return 0;
162 }
163
164}
@ f
Definition: BVPBerman.cpp:15
int main()
@ 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
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.
void matrix0(const DenseVector< double > &x, DenseMatrix< double > &m) const
Define the matrix in terms of the current state vector.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
Define the Karman system.
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.
void residual_fn(const DenseVector< double > &z, DenseVector< double > &B) const
A blank virtual residual function method.
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
std::pair< unsigned, unsigned > adapt(const double &adapt_tol)
Adapt the computational mesh ONCE.
Definition: ODE_BVP.cpp:481
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
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
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