CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
HYPSodsShocktube.cpp
Go to the documentation of this file.
1/// \file HYPSodsShocktube.cpp
2/// \ingroup Tests
3/// \ingroup HYP_1D
4/// Solving the 1D Euler problem for gas dynamics
5/// \f[ \rho_t + \left ( m \right )_x = 0 \f]
6/// \f[ m_t + \left ( \rho u^2 + p \right )_x = 0 \f]
7/// \f[ E_t + \left ( u ( E + p ) \right )_x = 0 \f]
8/// where
9/// \f[ u = m / \rho \f]
10/// \f[ p = ( \gamma - 1 ) ( E - \frac12 \rho u^2 ) \f]
11/// and \f$ \gamma = 1.4 \f$.
12/// The initial conditions correspond to Sod's problem
13/// \f[ (\rho, m, E ) = ( 1, 0, 2.5 ) \f] for \f$ x < \frac12 \f$
14/// \f[ (\rho, m, E ) = ( 0.125, 0, 0.25 ) \f] for \f$ x > \frac12 \f$.
15
16#include <OneD_HYP_bundle.h>
17
18enum { rho, m, E };
19
20namespace CppNoddy
21{
22 namespace Example
23 {
24 /// Adiabatic index -- ratio of specific heats
25 double gamma( 1.4 );
26
27 /// Define the system
29 {
30
31 public:
32
33 /// One dimemsional Euler problem, so 3rd order
35 {}
36
37 /// Define the vector flux
38 void flux_fn( const double &x, const DenseVector<double> &q, DenseVector<double> &f ) const
39 {
40 double u = q[ m ] / q[ rho ];
41 double p = ( gamma - 1. ) * ( q[ E ] - 0.5 * q[ rho ] * u * u );
42 f[ rho ] = q[ m ];
43 f[ m ] = q[ rho ] * u * u + p;
44 f[ E ] = u * ( q[ E ] + p );
45 }
46
47 /// Bound the shock speed
48 double max_charac_speed( const DenseVector<double> &q ) const
49 {
50 // sound speeds
51 double u = q[ m ] / q[ rho ];
52 double p = ( gamma - 1. ) * ( q[ E ] - 0.5 * q[ rho ] * u * u );
53 double c = sqrt( gamma * p / q[ rho ] );
54 // maximum shock speed
55 return std::max( u + c, u - c );
56 }
57
58 };
59
60 /// Set the initial state of the system
61 void Q_init( const double &x, DenseVector<double> &q )
62 {
63 if ( x < 0.5 )
64 {
65 q[ rho ] = 1.0;
66 q[ m ] = 0.0;
67 q[ E ] = 2.5; // => P = 1.0
68 }
69 else
70 {
71 q[ rho ] = 0.125;
72 q[ m ] = 0.0;
73 q[ E ] = 0.25; // => P = 0.1
74 }
75 }
76 } //end Example namespace
77} //end CppNoddy namespace
78
79
80using namespace CppNoddy;
81using namespace std;
82
83int main()
84{
85 cout << "\n";
86 cout << "=== Hyperbolic: 1D Euler gasdynamics shocktube =====\n";
87 cout << "\n";
88
89 // define the domain/mesh
90 const double left = 0.0;
91 const double right = 1.0;
92 const unsigned N = 400;
93 DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N );
94
95 double t = 0.0;
96
97 Example::Euler_1d conservative_problem;
98 OneD_TVDLF_Mesh Euler_mesh( faces_x, &conservative_problem, Example::Q_init );
99 Euler_mesh.set_limiter( 0 );
100
101 double I1 = Euler_mesh.integrate()[0];
102 int loop_counter( 0 );
103 int file_counter( 0 );
104
105 std::string dirname("./DATA");
106 mkdir( dirname.c_str(), S_IRWXU );
107 std::string filename_stub;
108 filename_stub = "./DATA/HYP_shocktube_sod";
109 TrackerFile my_file( 10 );
110 OneD_Node_Mesh<double> soln = Euler_mesh.get_soln();
111 my_file.push_ptr( &soln, "mesh" );
112
113 do
114 {
115 if ( loop_counter % 10 == 0 )
116 {
117 my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" );
118 soln = Euler_mesh.get_soln( );
119 my_file.update();
120 file_counter += 1;
121 }
122 t += Euler_mesh.update( 0.499 );
123 ++loop_counter;
124 }
125 while ( ( t < 0.2 ) && ( loop_counter < 1000 ) );
126
127 double I2 = Euler_mesh.integrate()[0];
128 // These are clawpack results (to 4dp) with N=400 and minmod for the
129 // density of the two density steps ...
130 soln = Euler_mesh.get_soln( );
131 double E1 = std::abs( soln.get_interpolated_vars( 0.575 )[0] - 0.4264 );
132 double E2 = std::abs( soln.get_interpolated_vars( 0.75 )[0] - 0.2656 );
133 // check against the clawpack data, and that the mass is conserved.
134 if ( ( E1 > 1.e-3 ) || ( E2 > 1.e-3 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) || ( loop_counter >= 1000 ) )
135 {
136 cout << "\033[1;31;48m * FAILED \033[0m\n";
137 cout << E1 << " " << E2 << " " << std::abs( I1 - I2 ) << " " << loop_counter << "\n";
138 return 1;
139 }
140 else
141 {
142 cout << "\033[1;32;48m * PASSED \033[0m\n";
143 return 0;
144 }
145
146} // end of main()
@ f
Definition: BVPBerman.cpp:15
int main()
A shorter bundled include file for hyperbolic problems.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
Euler_1d()
One dimemsional Euler problem, so 3rd order.
void flux_fn(const double &x, const DenseVector< double > &q, DenseVector< double > &f) const
Define the vector flux.
double max_charac_speed(const DenseVector< double > &q) const
Bound the shock speed.
A class to represent a one dimensional hyperbolic system of equations.
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.
OneD_Node_Mesh< double > get_soln(std::string location="centre", std::string colour="black")
Get a OneD_Mesh<double> object containing the one dimensional data in the usual format.
double update(const double &CFL, const double &max_dt=std::numeric_limits< long double >::max())
Update all the elements in this mesh to a new time step.
void set_limiter(unsigned id)
Set the limiter type to be applied in the slope values.
DenseVector< double > integrate() const
Integrate the concentration values across the entire mesh.
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
void set_filename(std::string filename)
Definition: TrackerFile.cpp:70
double gamma(1.4)
Adiabatic index – ratio of specific heats.
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