CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
BVPKarmanAdaptive.cpp File Reference

Adaptively solve the Karman rotating-disk equations for the flow above an infinite rotating disk: More...

#include <BVP_bundle.h>
#include "../Utils_Fill.h"

Go to the source code of this file.

Classes

class  CppNoddy::Example::Karman_equations
 Define the Karman equations. More...
 
class  CppNoddy::Example::Karman_left_BC
 Define the boundary conditions. More...
 
class  CppNoddy::Example::Karman_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  {
  U , Ud , V , W ,
  Wd
}
 

Functions

int main ()
 

Detailed Description

Adaptively solve the Karman rotating-disk equations for the flow above an infinite rotating disk:

\[ U''(y) = U^2(y) + V(y)U'(y) - W^2(y) \]

\[ W''(y) = 2U(y)W(y) + V(y)W'(y)  \]

\[ 2U(y) + V'(y) = 0 \]

with boundary conditions $ U(0)=V(0)=0 $, $ W(0)=1 $ and $ U(\infty ) \to 0 $, $ W(\infty ) \to 0 $. The class constructs and solves the global matrix problem using 2nd-order finite differences.

Definition in file BVPKarmanAdaptive.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
Ud 
Wd 

Definition at line 19 of file BVPKarmanAdaptive.cpp.

19{U, Ud, V, W, Wd};

Function Documentation

◆ main()

int main ( )

Definition at line 84 of file BVPKarmanAdaptive.cpp.

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
91 Example::Karman_equations problem;
92 Example::Karman_left_BC BC_left;
93 Example::Karman_right_BC BC_right;
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}
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 > 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

References CppNoddy::ODE_BVP< _Type, _Xtype >::adapt(), CppNoddy::Utility::power_node_vector(), CppNoddy::TrackerFile::push_ptr(), CppNoddy::ODE_BVP< _Type, _Xtype >::solution(), CppNoddy::ODE_BVP< _Type, _Xtype >::solve2(), U, Ud, CppNoddy::TrackerFile::update(), V, W, and Wd.

© 2012

R.E. Hewitt