CppNoddy  0.92
Loading...
Searching...
No Matches
HYP2DNonlinearAdvectionY.cpp
Go to the documentation of this file.
1/// \file HYP2DNonlinearAdvectionY.cpp
2/// \ingroup Tests
3/// \ingroup HYP_2D
4/// Solving the 1D `nonlinear advection equation'
5/// \f[ Q_t + \left ( \frac{Q^2}{2} \right )_y = 0 \quad \mbox{where} \quad Q=Q(x,y,t) \f]
6/// using a TVD Lax-Friedrichs scheme
7/// for \f$ (x,y)\in[-1,1]\times[-1,1]\f$. The initial condition is a sine distribution.
8
9#include <TwoD_HYP_bundle.h>
10
11namespace CppNoddy
12{
13 namespace Example
14 {
15
16 /// Define the system
17 class NlinAdv : public TwoD_Hyperbolic_System
18 {
19
20 public:
21
22 /// One dimemsional inviscid Burgers problem
24 {}
25
27 {
28 f[ 0 ] = 0;
29 }
30
32 {
33 f[ 0 ] = q[ 0 ] * q[ 0 ] / 2;
34 }
35
36
37 /// Bound the wave speed
39 {
40 // maximum wave speed
41 c[ 0 ] = c[ 1 ] = std::abs( q[ 0 ] );
42 }
43
44 ///// edge conditions
45 std::vector<bool> edge_values( const int& face_index, const DenseVector<double>& x, DenseVector<double>& q ) const
46 {
47 std::vector<bool> inflow( q.size(), false );
48 // x doesn't matter since the conditions are fixed
49 if ( face_index == 1 )
50 {
51 q[ 0 ] = 0.0;
52 inflow[ 0 ] = true;
53 }
54 if ( face_index == 3 )
55 {
56 q[ 0 ] = 0.0;
57 inflow[ 0 ] = true;
58 }
59 return inflow;
60 }
61
62 };
63
64 /// Set the initial state of the system
65 void Q_init( const double &x, const double &y, DenseVector<double> &q )
66 {
67 q[ 0 ] = std::sin( 2 * M_PI * y );
68 }
69 } //end Example namespace
70
71} //end CppNoddy namespace
72
73
74using namespace CppNoddy;
75using namespace std;
76
77int main()
78{
79
80 cout << "\n";
81 cout << "=== Hyperbolic: 2D nonlinear advection in y =========\n";
82 cout << "\n";
83
84 // define the domain/mesh
85 const double west = 1.0;
86 const double east = 0.0;
87 const double south = 0.0;
88 const double north = 1.0;
89 const unsigned N = 51;
90 DenseVector<double> faces_x = Utility::uniform_node_vector( east, west, N );
91 DenseVector<double> faces_y = Utility::uniform_node_vector( south, north, N );
92
93 Example::NlinAdv conservative_problem;
94 TwoD_TVDLF_Mesh NlinAdv_mesh( faces_x, faces_y, &conservative_problem, Example::Q_init );
95 NlinAdv_mesh.set_limiter( 0 );
96
97 double asym( 0.0 );
98 unsigned loop_counter( 0 );
99 DenseVector<double> x1( 2, 0.0 );
100 x1[ 0 ] = 0.5;
101 x1[ 1 ] = 0.75;
102 DenseVector<double> x2( 2, 0.0 );
103 x2[ 0 ] = 0.5;
104 x2[ 1 ] = 0.25;
105 do
106 {
107 NlinAdv_mesh.update( 0.49 );
108 asym = std::max( asym, std::abs( NlinAdv_mesh.get_point_values( x1 )[0] + NlinAdv_mesh.get_point_values( x2 )[0] ) );
109 ++loop_counter;
110 }
111 while ( ( NlinAdv_mesh.get_time() < 0.4 ) && ( loop_counter < 1000 ) );
112
113 // problem should be antisymmetric about y = 1/2
114 if ( ( asym > 1.e-9 ) || ( loop_counter >= 1000 ) )
115 {
116 cout << "\033[1;31;48m * FAILED \033[0m\n";
117 cout << "asymmetry = " << asym << "\n";
118 cout << "loop counter = " << loop_counter << "\n";
119 return 1;
120 }
121 else
122 {
123 cout << "\033[1;32;48m * PASSED \033[0m\n";
124 return 0;
125 }
126
127} // end of main()
@ f
Definition: BVPBerman.cpp:15
A shorter bundled include file for hyperbolic problems.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
std::size_t size() const
A pass-thru definition to get the size of the vector.
Definition: DenseVector.h:330
void flux_fn_y(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function for the y-derivative.
NlinAdv()
One dimemsional inviscid Burgers problem.
std::vector< bool > edge_values(const int &face_index, const DenseVector< double > &x, DenseVector< double > &q) const
Define the edge boundary conditions.
void flux_fn_x(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function for the x-derivative.
void max_charac_speed(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &c) const
Bound the wave speed.
A class to represent a two-dimensional hyperbolic system of equations.
DenseVector< double > get_point_values(const DenseVector< double > &x)
Get the vector of unknowns at a point in the 2D mesh.
const double & get_time() const
Get a const reference to the time value for the current mesh.
double update(const double &CFL, const double &max_dt=std::numeric_limits< long double >::max())
Update the mesh object.
void set_limiter(const unsigned &id)
Set the limiter type to be applied in the slope values.
void Q_init(const double &x, DenseVector< double > &q)
Set the initial state of the system.
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...

© 2012

R.E. Hewitt