CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
Classes | Namespaces | Functions
HYP2DNonlinearAdvectionY.cpp File Reference

Solving the 1D ‘nonlinear advection equation’. More...

#include <TwoD_HYP_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::NlinAdv
 Define the system. More...
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Functions

void CppNoddy::Example::Q_init (const double &x, const double &y, DenseVector< double > &q)
 Set the initial state of the system. More...
 
int main ()
 

Detailed Description

Solving the 1D ‘nonlinear advection equation’.

\[ Q_t + \left ( \frac{Q^2}{2} \right )_y = 0 \quad \mbox{where} \quad Q=Q(x,y,t) \]

using a TVD Lax-Friedrichs scheme for $ (x,y)\in[-1,1]\times[-1,1]$. The initial condition is a sine distribution.

Definition in file HYP2DNonlinearAdvectionY.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 77 of file HYP2DNonlinearAdvectionY.cpp.

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()
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
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

References CppNoddy::TwoD_TVDLF_Mesh::get_point_values(), CppNoddy::TwoD_TVDLF_Mesh::get_time(), CppNoddy::TwoD_TVDLF_Mesh::set_limiter(), CppNoddy::Utility::uniform_node_vector(), and CppNoddy::TwoD_TVDLF_Mesh::update().

© 2012

R.E. Hewitt