CppNoddy  0.92
Loading...
Searching...
No Matches
HYP2DNonlinearAdvectionXY.cpp
Go to the documentation of this file.
1/// \file HYP2DNonlinearAdvectionXY.cpp
2/// \ingroup Tests
3/// \ingroup HYP_2D
4/// Solving the 2D `nonlinear advection equation'
5/// \f[ Q_t + \left ( \frac{Q^2}{\sqrt{2}} \right )_x + \left ( \frac{Q^2}{\sqrt{2}} \right )_y = 0 \quad \mbox{where} \quad Q=Q(x,y,t) \f]
6/// using a TVD Lax-Friedrichs scheme for \f$ (x,y)\in[-1,1]\times[-1,1]\f$. The initial condition is a sine distribution.
7
8#include <TwoD_HYP_bundle.h>
9
10namespace CppNoddy
11{
12 namespace Example
13 {
14
15 /// Define the system
16 class NlinAdv : public TwoD_Hyperbolic_System
17 {
18
19 public:
20
21 /// One dimemsional inviscid Burgers problem
23 {}
24
25 /// Define the vector flux
27 {
28 f[ 0 ] = sqrt( 2. ) * q[ 0 ] * q[ 0 ] / 2;
29 }
30
32 {
33 f[ 0 ] = sqrt( 2. ) * q[ 0 ] * q[ 0 ] / 2;
34 }
35
36 /// Bound the wave speed
38 {
39 // maximum wave speed
40 c[ 0 ] = c[ 1 ] = std::abs( q[ 0 ] );
41 }
42
43 ///// edge conditions
44 std::vector<bool> edge_values( const int& face_index, const DenseVector<double>& x, DenseVector<double>& q ) const
45 {
46 std::vector<bool> inflow( q.size(), true );
47 q[ 0 ] = 0;
48 return inflow;
49 }
50
51 };
52
53 /// Set the initial state of the system
54 void Q_init( const double &x, const double &y, DenseVector<double> &q )
55 {
56 q[ 0 ] = std::sin( M_PI * ( y + x ) ) * std::sin( M_PI * x ) * std::sin( M_PI * y );
57 }
58 } //end Example namespace
59
60} //end CppNoddy namespace
61
62
63using namespace CppNoddy;
64using namespace std;
65
66int main()
67{
68 cout << "\n";
69 cout << "=== Hyperbolic: 2D nonlinear advection at an angle ==\n";
70 cout << "\n";
71
72 std::string dirname("./DATA");
73 mkdir( dirname.c_str(), S_IRWXU );
74 std::string filename_stub( "./DATA/HYP_2D_nlin_adv_xy" );
75
76 // define the domain/mesh
77 const double west = -1.0;
78 const double east = 1.0;
79 const double south = -1.0;
80 const double north = 1.0;
81 const unsigned N = 151;
82 DenseVector<double> faces_x = Utility::uniform_node_vector( west, east, N );
83 DenseVector<double> faces_y = Utility::uniform_node_vector( south, north, N );
84
85 Example::NlinAdv conservative_problem;
86 TwoD_TVDLF_Mesh NlinAdv_mesh( faces_x, faces_y, &conservative_problem, Example::Q_init );
87 NlinAdv_mesh.set_limiter( 0 );
88
89 double asym( 0.0 );
90 unsigned loop_counter( 0 );
91 DenseVector<double> x1( 2, 0.0 );
92 x1[ 0 ] = 0.75;
93 x1[ 1 ] = 0.75;
94 DenseVector<double> x2( 2, 0.0 );
95 x2[ 0 ] = -0.75;
96 x2[ 1 ] = -0.75;
97 do
98 {
99 NlinAdv_mesh.update( 0.49 );
100 NlinAdv_mesh.dump_gnu( filename_stub + Utility::stringify( loop_counter ) + "_gnu.dat" );
101
102 asym = std::max( asym, std::abs( NlinAdv_mesh.get_point_values( x1 )[0] + NlinAdv_mesh.get_point_values( x2 )[0] ) );
103 ++loop_counter;
104 }
105 while ( ( NlinAdv_mesh.get_time() < 0.4 ) && ( loop_counter < 1000 ) );
106
107 // problem should be antisymmetric about x = 1/2
108 if ( ( asym > 1.e-9 ) || ( loop_counter >= 1000 ) )
109 {
110 cout << "\033[1;31;48m * FAILED \033[0m\n";
111 cout << "asymmetry = " << asym << "\n";
112 cout << "loop counter = " << loop_counter << "\n";
113 return 1;
114 }
115 else
116 {
117 cout << "\033[1;32;48m * PASSED \033[0m\n";
118 return 0;
119 }
120
121} // 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
Define the vector flux.
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.
void dump_gnu(std::string filename)
Dump the data to a given filename in a gnuplot format.
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.
std::string stringify(const int &val)
Return an integer value as a string - useful for file naming.
Definition: Utility.cpp:193
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