CppNoddy  0.92
Loading...
Searching...
No Matches
IBVPKarman.cpp
Go to the documentation of this file.
1/// \file IBVPKarman.cpp
2/// \ingroup Tests
3/// \ingroup IBVP
4/// Solving the unsteady Karman rotating-disk equations for the
5/// flow above an infinite rotating disk in a rotating fluid:
6/// \f[ -U_t + U_{yy} = U^2 + VU_y - W^2 - W_\infty^2 \f]
7/// \f[ -W_t + W_{yy} = 2U W + V W_y \f]
8/// \f[ 2U + V_y = 0 \f]
9/// with boundary conditions \f$ U(y=0)=V(y=0)=0 \f$, \f$ W(y=0)=\Omega(t) \f$
10/// and \f$ U(y \to \infty ) \to 0 \f$, \f$ W(y \to \infty ) \to 0 \f$. The
11/// initial condition corresponds to rigid rotation of the fluid and boundary at
12/// the frequency \f$ W_{\infty} \f$
13/// The class constructs and solves the IBVP using 2nd order finite-differencing
14/// in both space and time over a non-uniform spatial mesh.
15/// The example shows the case \f$ W_\infty = 0 \f$ and
16/// \f[ \Omega(t) = 1 - (1 - W_\infty) \exp( -10t )\f] and simply
17/// checks for convergence to the correct steady state solution.
18
19#include <IBVP_bundle.h>
20
21enum { U, Ud, V, W, Wd };
22
23namespace CppNoddy
24{
25 namespace Example
26 {
27 // rotation frequency at infinity, appears as a pressure gradient term
28 double W_inf( 0.0 );
29 // rotation of the disk, appears in the BCs
30 double W_disk( 1.0 );
31
32 class Karman_equations : public Equation_2matrix<double>
33 {
34 public:
35
36 /// The problem is 5th order and real
38
39 /// Define the Karman equations
41 {
42 // The 5th order system for ( U, U', V, W, W' )
43 f[ 0 ] = z[ 1 ];
44 f[ 1 ] = z[ 0 ] * z[ 0 ] + z[ 2 ] * z[ 1 ] - z[ 3 ] * z[ 3 ] + W_inf * W_inf;
45 f[ 2 ] = -2 * z[ 0 ];
46 f[ 3 ] = z[ 4 ];
47 f[ 4 ] = 2 * z[ 0 ] * z[ 3 ] + z[ 2 ] * z[ 4 ];
48 }
49
50 /// Define the BVP deriv by providing the matrix
52 {
53 // identity matrix
54 m( 0, 0 ) = 1.0;
55 m( 1, 1 ) = 1.0;
56 m( 2, 2 ) = 1.0;
57 m( 3, 3 ) = 1.0;
58 m( 4, 4 ) = 1.0;
59 }
60
61 /// To speed things up we'll overload this to say the mass matrix is constant
63 {
64 // blank definition leads to a zero result
65 }
66
67 /// Define the unsteady terms by providing the mass matrix
69 {
70 m( 1, 0 ) = -1.0;
71 m( 4, 3 ) = -1.0;
72 }
73
74 /// To speed things up we'll overload this to say the mass matrix is constant
76 {
77 // blank definition leads to a zero result
78 }
79
80 };
81
82 /// Define the boundary conditions
83 class Karman_left_BC : public Residual_with_coords<double>
84 {
85 public:
86 // 3 BCs for 5 unknowns and one independent coordinate (time)
87 Karman_left_BC() : Residual_with_coords<double> ( 3, 5, 1 ) {}
88
90 {
91 // get the time level for unsteady boundary condition
92 const double t = coord( 0 );
93 const double W_bc = Example::W_disk + ( Example::W_inf - Example::W_disk ) * std::exp( - 2 * t * t );
94 b[ 0 ] = z[ U ];
95 b[ 1 ] = z[ V ];
96 b[ 2 ] = z[ W ] - W_bc;
97 }
98 };
99
100 class Karman_right_BC : public Residual_with_coords<double>
101 {
102 public:
103 // 2 BCs for 5 unknowns and one independent coordinate (time)
104 Karman_right_BC() : Residual_with_coords<double> ( 2, 5, 1 ) {}
105
107 {
108 b[ 0 ] = z[ U ];
109 b[ 1 ] = z[ W ] - W_inf;
110 }
111 };
112
113 } // end Example namespace
114} // end CppNoddy namespace
115
116using namespace CppNoddy;
117using namespace std;
118
119int main()
120{
121 cout << "\n";
122 cout << "=== IBVP: The unsteady Karman equations ============\n";
123 cout << "\n";
124
125 // define the system
127 // define the boundary conditions
130
131 // domain definition
132 double left = 0.0;
133 double right = 40.0;
134 // number of (spatial) nodal points
135 unsigned ny = 400;
136 // time step
137 double dt = 0.005;
138 // number of time steps
139 unsigned max_steps = ( unsigned ) ( 30.0 / dt );
140
141 // construct our IBVP with more nodes near the boundary
142 PDE_IBVP<double> karman( &problem, Utility::power_node_vector( left, right, ny, 2.0 ), &BC_left, &BC_right );
143 //
144 for ( unsigned i = 0; i < ny; ++i )
145 {
146 karman.solution()( i, U ) = 0.0;
147 karman.solution()( i, Ud ) = 0.0;
148 karman.solution()( i, V ) = 0.0;
149 karman.solution()( i, W ) = Example::W_inf;
150 karman.solution()( i, Wd ) = 0.0;
151 }
152
153 // set up output details
154 std::string dirname("./DATA");
155 mkdir( dirname.c_str(), S_IRWXU );
156 TrackerFile metric( "./DATA/IBVP_Karman_metric.dat" );
157 metric.push_ptr( &karman.coord(), "time" );
158 metric.push_ptr( &karman.solution()( ny - 1, V ), "Ekman suction" );
159 metric.header();
160 TrackerFile profs( "./DATA/IBVP_Karman_profs.dat" );
161 profs.push_ptr( &karman.coord(), "time" );
162 profs.push_ptr( &karman.solution(), "solution" );
163 profs.header();
164
165 // time step
166 for ( unsigned i = 1; i < max_steps; ++i )
167 {
168 // take a time step
169 try
170 {
171 karman.step2( dt );
172 }
173 catch (const std::runtime_error &error )
174 {
175 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
176 return 1;
177 }
178 metric.update();
179 }
180
181 const double tol( 1.e-4 );
182 // check the BL transpiration vs the known solution
183 if ( abs( karman.solution()( ny - 1, V ) + 0.88447 ) > tol )
184 {
185 cout << "\033[1;31;48m * FAILED \033[0m\n";
186 cout << " Difference = " << abs( karman.solution()( ny - 1, V ) + 0.88447 ) << "\n";
187 return 1;
188 }
189 else
190 {
191 cout << "\033[1;32;48m * PASSED \033[0m\n";
192 return 0;
193 }
194
195}
@ f
Definition: BVPBerman.cpp:15
@ V
Definition: BVPKarman.cpp:20
@ W
Definition: BVPKarman.cpp:20
@ U
Definition: BVPKarman.cpp:20
@ V
Definition: IBVPKarman.cpp:21
@ Wd
Definition: IBVPKarman.cpp:21
@ W
Definition: IBVPKarman.cpp:21
@ U
Definition: IBVPKarman.cpp:21
@ Ud
Definition: IBVPKarman.cpp:21
int main()
Definition: IBVPKarman.cpp:119
A shorter bundled include file for initial boundary value problems.
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 PDE_double_IBVP class.
Define the Karman equations.
Definition: BVPKarman.cpp:28
void matrix0(const DenseVector< double > &z, DenseMatrix< double > &m) const
Define the BVP deriv by providing the matrix.
Definition: IBVPKarman.cpp:51
Karman_equations()
The problem is 5th order and real.
Definition: IBVPKarman.cpp:37
void matrix1(const DenseVector< double > &z, DenseMatrix< double > &m) const
Define the unsteady terms by providing the mass matrix.
Definition: IBVPKarman.cpp:68
void get_jacobian_of_matrix1_mult_vector(const DenseVector< double > &state, const DenseVector< double > &vec, DenseMatrix< double > &h) const
To speed things up we'll overload this to say the mass matrix is constant.
Definition: IBVPKarman.cpp:75
void get_jacobian_of_matrix0_mult_vector(const DenseVector< double > &state, const DenseVector< double > &vec, DenseMatrix< double > &h) const
To speed things up we'll overload this to say the mass matrix is constant.
Definition: IBVPKarman.cpp:62
void residual_fn(const DenseVector< double > &z, DenseVector< double > &f) const
Define the Karman equations.
Definition: IBVPKarman.cpp:40
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: IBVPKarman.cpp:89
void residual_fn(const DenseVector< double > &z, DenseVector< double > &b) const
A blank virtual residual function method.
Definition: IBVPKarman.cpp:106
A templated object for real/complex vector system of unsteady equations.
Definition: PDE_IBVP.h:37
void step2(const double &dt)
A Crank-Nicolson 'time' stepper.
Definition: PDE_IBVP.cpp:72
OneD_Node_Mesh< _Type > & solution()
Definition: PDE_IBVP.h:127
double & coord()
Return a reference to the current value of the 'timelike/parabolic' coordinate.
Definition: PDE_IBVP.h:65
A base class to be inherited by objects that define residuals.
double & coord(const unsigned &i)
General handle access to the coordinates.
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
double W_disk(1.0)
double W_inf(0.0)
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...

© 2012

R.E. Hewitt