CppNoddy  0.92
Loading...
Searching...
No Matches
HYPRadialDamBreak.cpp
Go to the documentation of this file.
1/// \file HYPRadialDamBreak.cpp
2/// \ingroup Tests
3/// \ingroup HYP_1D
4/// Solve the shallow water equations in one dimension for an
5/// initial column of fluid
6/// \f[ h_t + (uh)_r = -hu/r \f]
7/// \f[ (uh)_t + (hu^2 + gh^2 /2 )_r = -hu^2/r \f]
8/// The result is compared to the same problem solved using
9/// Clawpack, evaluated at the single point x=0.5.
10
11#include <OneD_HYP_bundle.h>
12
13enum { h, hu };
14
15namespace CppNoddy
16{
17 namespace Example
18 {
19 /// gravitational acceleration
20 double g( 1.0 );
21 /// initial hump amplitude
22 double A( 1.0 );
23
24 /// Define the system
26 {
27
28 public:
29
30 /// One dimemsional constant coefft acoustic problem
32 {}
33
34 /// Define the vector flux
35 void flux_fn( const double &x, const DenseVector<double> &q, DenseVector<double> &f ) const
36 {
37 f[ h ] = q[ hu ];
38 f[ hu ] = q[ hu ] * q[ hu ] / q[ h ] + g * q[ h ] * q[ h ] / 2;
39 }
40
41 /// Bound the shock speed
42 double max_charac_speed( const DenseVector<double> &q ) const
43 {
44 // sound speeds
45 const double c( sqrt( g * q[ h ] ) );
46 // flow speed
47 const double u( q[ hu ] / q[ h ] );
48 // maximum shock speed
49 return std::max( std::abs( u + c ), std::abs( u - c ) );
50 }
51
52 void source_fn( const double& x, const DenseVector<double>& q, const DenseVector<double>& slope, DenseVector<double>& r ) const
53 {
54 r[ h ] = -q[ hu ] / x;
55 r[ hu ] = -q[ hu ] * q[ hu ] / ( q[ h ] * x );
56 }
57
58 };
59
60 /// Set the initial state of the system
61 void Q_init( const double &x, DenseVector<double> &q )
62 {
63 double xi( x - 0.5 );
64 q[ h ] = 1 + 0.5 * ( 1 - std::tanh( 100 * xi ) );
65 q[ hu ] = 0;
66 }
67 } //end Example namespace
68
69} //end CppNoddy namespace
70
71
72using namespace CppNoddy;
73using namespace std;
74
75int main()
76{
77 cout << "\n";
78 cout << "=== Hyperbolic: Shallow water radial dam break ======\n";
79 cout << "\n";
80
81 // There is a singular source_fn at r=0, so we bodge it here (for now).
82 /// \todo Include a mechanism for avoiding source term computations
83 /// at the singular point by indicating where edge conditions are specified.
84 /// For the time being, we'll bodge it by stopping away from x=0.
85 const double left = 1.e-4;
86 const double right = 2.5;
87 const unsigned N = 2001;
88 DenseVector<double> faces_x = Utility::power_node_vector( left, right, N, 1.0 );
89
90 // time
91 double t = 0;
92 double t_end = 0.5;
93
94 // hyperbolic problem
95 Example::Shallow_1d_rad conservative_problem;
96 OneD_TVDLF_Mesh Shallow_mesh( faces_x, &conservative_problem, Example::Q_init );
97 Shallow_mesh.set_limiter( 0 );
98
99 // output
100 int loop_counter( 0 );
101 int file_counter( 0 );
102
103 std::string dirname("./DATA");
104 mkdir( dirname.c_str(), S_IRWXU );
105 std::string filename_stub;
106 filename_stub = "./DATA/HYP_shallow_rad";
107 TrackerFile my_file( 5 );
108 OneD_Node_Mesh<double> soln = Shallow_mesh.get_soln();
109 my_file.push_ptr( &soln, "mesh" );
110
111 do
112 {
113 if ( loop_counter % 50 == 0 )
114 {
115 my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" );
116 soln = Shallow_mesh.get_soln();
117 my_file.update();
118 file_counter += 1;
119 }
120 t += Shallow_mesh.update( 0.499, t_end - t );
121 ++loop_counter;
122 }
123 while ( ( t < t_end ) && ( loop_counter < 3000 ) );
124
125 // we test the result against the Clawpack computational result
126 soln = Shallow_mesh.get_soln();
127 double h_clawpack( 1.13466 );
128 double h_test( soln.get_interpolated_vars( 0.5 )[ h ] );
129 if ( abs( h_test - h_clawpack ) > 1.e-3 )
130 {
131 cout << "\033[1;31;48m * FAILED \033[0m\n";
132 cout << " deviation from the Clawpack data = " << abs( h_test - h_clawpack ) << "\n";
133 return 1;
134 }
135 else
136 {
137 cout << "\033[1;32;48m * PASSED \033[0m\n";
138 return 0;
139 }
140
141} // 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
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.
void source_fn(const double &x, const DenseVector< double > &q, const DenseVector< double > &slope, DenseVector< double > &r) const
Shallow_1d_rad()
One dimemsional constant coefft acoustic problem.
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.
void push_ptr(double *scalar, std::string desc="")
Definition: TrackerFile.cpp:27
void set_filename(std::string filename)
Definition: TrackerFile.cpp:70
void Q_init(const double &x, DenseVector< double > &q)
Set the initial state of the system.
double A(1.0)
initial hump amplitude
double g(1.0)
gravitational acceleration
DenseVector< double > power_node_vector(const double &lower, const double &upper, const std::size_t &N, const double &power)
Return a DENSE vector with the nodal points of a non-uniform mesh distributed between the upper/lower...
Definition: Utility.cpp:123
std::string stringify(const int &val)
Return an integer value as a string - useful for file naming.
Definition: Utility.cpp:193
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt