CppNoddy  0.92
Loading...
Searching...
No Matches
BVPKarmanArclength.cpp
Go to the documentation of this file.
1/// \file BVPKarmanArclength.cpp
2/// \ingroup Tests
3/// \ingroup BVP
4/// Arc-length continuation of 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) + s^2 \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 s \f$.
11/// The class constructs and solves the
12/// global matrix problem using 2nd-order finite differences and
13/// employs arc-length continuation to obtain the first three solution
14/// branches in the neighbourhood of \f$ s=0 \f$. The validation of the
15/// results is based upon the approximate location of the second limit
16/// point.
17
18#include <BVP_bundle.h>
19
20#include "../Utils_Fill.h"
21
22// enumerate the 5 variables of the ODE system
23enum {U, Ud, V, W, Wd};
24
25namespace CppNoddy
26{
27 namespace Example
28 {
29 /// relative rotation rate
30 double s;
31
32 /// Define the Karman equations
33 class Karman_equations : public Equation_1matrix<double>
34 {
35 public:
36
37 /// The Karman system is a 5th order real system of ODEs
39
40 /// Define the Karman system
42 {
43 // The 5th order system for ( U, U', V, W, W' )
44 f[ U ] = z[ Ud ];
45 f[ Ud ] = z[ U ] * z[ U ] + z[ V ] * z[ Ud ] - z[ W ] * z[ W ] + s * s;
46 f[ V ] = -2 * z[ U ];
47 f[ W ] = z[ Wd ];
48 f[ Wd ] = 2 * z[ U ] * z[ W ] + z[ V ] * z[ Wd ];
49 }
50
52 {
54 }
55
56 };
57
58 /// Define the boundary conditions
59 class Karman_left_BC : public Residual<double>
60 {
61 public:
62 // 3 BCs for 5 unknowns
63 Karman_left_BC() : Residual<double> ( 3, 5 ) {}
64
66 {
67 B[ 0 ] = z[ U ];
68 B[ 1 ] = z[ V ];
69 B[ 2 ] = z[ W ] - 1.0;
70 }
71 };
72
73 class Karman_right_BC : public Residual<double>
74 {
75 public:
76 // 2 BCs for 5 unknowns
77 Karman_right_BC() : Residual<double> ( 2, 5 ) {}
78
80 {
81 B[ 0 ] = z[ U ];
82 B[ 1 ] = z[ W ] - s;
83 }
84 };
85
86 } // end Example namespace
87} // end CppNoddy namespace
88
89using namespace CppNoddy;
90using namespace std;
91
92int main()
93{
94 cout << "\n";
95 cout << "=== BVP: Arc-length continuation of the Karman eqns =\n";
96 cout << "\n";
97
101
102 // Boundary layer is from 0 to 20
103 double left = 0.0;
104 //need a large domain for the higher branch modes
105 double right = 150.0;
106 Example::s = 1.0;
107 // number of nodal points
108 unsigned N = 2001;
109 // use a non-uniform mesh
110 DenseVector<double> nodes = Utility::power_node_vector( left, right, N, 1.2 );
111
112 ODE_BVP<double> ode( &problem, nodes, &BC_left, &BC_right );
113
114 // initial state is rigid-body rotation
115 for ( unsigned i = 0; i < N; ++i )
116 {
117 ode.solution()( i, W ) = Example::s;
118 }
119
120 // output to check the adapted mesh
121 std::string dirname("./DATA");
122 mkdir( dirname.c_str(), S_IRWXU );
123 TrackerFile my_file( "./DATA/BVP_Karman_arc.dat", 8 );
124 my_file.push_ptr( &Example::s, "s" );
125 my_file.push_ptr( &ode.solution()( N - 1, V ), "V_inf" );
126
127 // initialise the arc-length routine
128 double ds( -0.02 );
129 ode.init_arc( &Example::s, ds, 0.01 );
130 ode.rescale_theta() = true;
131 ode.desired_arc_proportion() = 0.25;
132 my_file.update();
133
134 double last_approx_lp( 0.0 );
135 // take 101 arc-length steps
136 for ( int i = 0; i < 101; ++i )
137 {
138 try
139 {
140 ds = ode.arclength_solve( ds );
141 cout << Example::s << " " << ode.solution()( N-1, V ) << "\n";
142 }
143 catch (const ExceptionBifurcation &error )
144 {
145 cout << " Bifurcation detected near p = " << Example::s << "\n";
146 last_approx_lp = Example::s;
147 break;
148 }
149 my_file.update();
150 }
151 if ( std::abs( last_approx_lp + 0.1605 ) > 1.e-3 )
152 {
153 cout << "\033[1;31;48m * FAILED \033[0m\n";
154 cout << " Difference = " << abs( last_approx_lp + 0.1605 ) << "\n";
155 return 1;
156 }
157 else
158 {
159 cout << "\033[1;32;48m * PASSED \033[0m\n";
160 return 0;
161 }
162}
@ 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.
bool & rescale_theta()
Handle to the RESCALE_THETA flag.
double & desired_arc_proportion()
Handle to the desired proportion of the parameter to be used in the arc length solver.
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
double arclength_solve(const double &step)
Arc-length solve the system.
Definition: ODE_BVP.cpp:164
OneD_Node_Mesh< _Type, _Xtype > & solution()
Definition: ODE_BVP.h:187
void init_arc(_Type *p, const double &length, const double &max_length)
Initialise the class ready for arc length continuation.
Definition: ODE_BVP.h:179
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 s
relative rotation rate
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