CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
HYPNonlinearAdvection.cpp File Reference

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

#include <OneD_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, 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 )_x = 0 \quad \mbox{where} \quad Q=Q(x,t) \]

using a TVD Lax-Friedrichs scheme for $ x\in[0,1]$. The initial condition is taken to be

\[ Q(x,0) =  \sin( 2\pi x ) \]

The test is simply conservation of $ Q $ in this case.

Definition in file HYPNonlinearAdvection.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 72 of file HYPNonlinearAdvection.cpp.

73{
74 cout << "\n";
75 cout << "=== Hyperbolic: 1D nonlinear advection equation ====\n";
76 cout << "\n";
77
78 // define the domain/mesh
79 const double left = 0.0;
80 const double right = 1.0;
81 const unsigned N = 141;
82 DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N );
83
84 double t = 0.0;
85
86 Example::NlinAdv conservative_problem;
87 OneD_TVDLF_Mesh NlinAdv_mesh( faces_x, &conservative_problem, Example::Q_init );
88 NlinAdv_mesh.set_limiter( 0 );
89
90 double I1 = NlinAdv_mesh.integrate()[0];
91 int loop_counter( 5 );
92
93 std::string dirname("./DATA");
94 mkdir( dirname.c_str(), S_IRWXU );
95 TrackerFile my_file( "./DATA/HYP_NlinAdv.dat" );
96 // first column of the output will always be the time
97 my_file.push_ptr( &t, "time" );
98 OneD_Node_Mesh<double> soln = NlinAdv_mesh.get_soln();
99 my_file.push_ptr( &soln, "mesh" );
100
101 double asym( 0.0 );
102 do
103 {
104 double dt = NlinAdv_mesh.update( 0.475 );
105 t += dt;
106 soln = NlinAdv_mesh.get_soln();
107
108 if ( loop_counter % 10 == 0 )
109 {
110 soln = NlinAdv_mesh.get_soln();
111 my_file.update();
112 my_file.newline();
113 }
114 ++loop_counter;
115 asym = std::max( asym, std::abs( soln.get_interpolated_vars( 0.75 )[0] + soln.get_interpolated_vars( 0.25 )[0] ) );
116 }
117 while ( ( t < 0.4 ) && ( loop_counter < 1000 ) );
118
119 double I2 = NlinAdv_mesh.integrate()[0];
120 soln = NlinAdv_mesh.get_soln();
121 my_file.update();
122 my_file.newline();
123 // problem should be antisymmetric about x = 1/2
124 if ( ( asym > 1.e-10 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) || ( loop_counter >= 1000 ) )
125 {
126 cout << "\033[1;31;48m * FAILED \033[0m\n";
127 cout << "asymmetry = " << asym << "\n";
128 cout << "integral difference = " << I1 - I2 << "\n";
129 cout << "loop counter = " << loop_counter << "\n";
130 return 1;
131 }
132 else
133 {
134 cout << "\033[1;32;48m * PASSED \033[0m\n";
135 return 0;
136 }
137
138} // end of main()
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A one dimensional mesh utility object.
DenseVector< _Type > get_interpolated_vars(const _Xtype &pos) const
Get the variable data at an interpolated position using a first order scheme.
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::OneD_Node_Mesh< _Type, _Xtype >::get_interpolated_vars(), CppNoddy::OneD_TVDLF_Mesh::get_soln(), CppNoddy::OneD_TVDLF_Mesh::integrate(), CppNoddy::TrackerFile::newline(), CppNoddy::TrackerFile::push_ptr(), CppNoddy::OneD_TVDLF_Mesh::set_limiter(), CppNoddy::Utility::uniform_node_vector(), CppNoddy::TrackerFile::update(), and CppNoddy::OneD_TVDLF_Mesh::update().

© 2012

R.E. Hewitt