CppNoddy  0.92
Loading...
Searching...
No Matches
HYP2DRadialDamBreak.cpp
Go to the documentation of this file.
1/// \file HYP_2D_radial_dam_break.cpp
2/// \ingroup Tests
3/// \ingroup HYP_2D
4/// A radial dam-break problem for the 2D shallow water equations.
5/// The flow height at a single point is compared with the result
6/// obtained from CLAWPACK.
7
8#include <TwoD_HYP_bundle.h>
9
10enum { h, hu, hv };
11
12namespace CppNoddy
13{
14 namespace Example
15 {
16 /// gravitational acceleration
17 double g( 1.0 );
18 /// initial hump amplitude
19 double A( 1.0 );
20 /// Set the initial state of the system
21 void Q_init( const double &x, const double &y, DenseVector<double> &q )
22 {
23 double r( std::sqrt( x*x + y*y ) - 0.5 );
24 q[ h ] = 1 + 0.5 * ( 1 - std::tanh( 500 * r ) );
25 q[ hu ] = 0;
26 }
27
28 /// Define the system
30 {
31
32 public:
33
34 /// One dimemsional constant coefft acoustic problem
36 {}
37
38 /// Define the vector flux
40 {
41 f[ h ] = q[ hu ];
42 f[ hu ] = q[ hu ] * q[ hu ] / q[ h ] + g * q[ h ] * q[ h ] / 2.;
43 f[ hv ] = q[ hu ] * q[ hv ] / q[ h ];
44 }
45
47 {
48 f[ h ] = q[ hv ];
49 f[ hu ] = q[ hu ] * q[ hv ] / q[ h ];
50 f[ hv ] = q[ hv ] * q[ hv ] / q[ h ] + g * q[ h ] * q[ h ] / 2.;
51 }
52
53 // just for fun, we'll use analytic Jacobians
55 {
56 J( 0, hu ) = 1;
57 J( 1, h ) = - q[ hu ] * q[ hu ] / ( q[ h ] * q[ h ] ) + g * q[ h ];
58 J( 1, hu ) = 2 * q[ hu ] / q[ h ];
59 J( 2, h ) = - q[ hu ] * q[ hv ] / ( q[ h ] * q[ h ] );
60 J( 2, hu ) = q[ hv ] / q[ h ];
61 J( 2, hv ) = q[ hu ] / q[ h ];
62 }
63
65 {
66 J( 0, hv ) = 1;
67 J( 1, h ) = - q[ hu ] * q[ hv ] / ( q[ h ] * q[ h ] );
68 J( 1, hu ) = q[ hv ] / q[ h ];
69 J( 1, hv ) = q[ hu ] / q[ h ];
70 J( 2, h ) = - q[ hv ] * q[ hv ] / ( q[ h ] * q[ h ] ) + g * q[ h ];
71 J( 2, hv ) = 2 * q[ hv ] / q[ h ];
72 }
73
74 /// Bound the wave speed
76 {
77 // wave speed
78 double cc = sqrt( g * q[ h ] );
79 // flow speed
80 double U = q[ hu ] / q[ h ];
81 double V = q[ hv ] / q[ h ];
82 // maximum shock speed
83 c[ 0 ] = std::max( std::abs( U + cc ), std::abs( U - cc ) );
84 c[ 1 ] = std::max( std::abs( V + cc ), std::abs( V - cc ) );
85 }
86
87 };
88
89 } //end Example namespace
90
91} //end CppNoddy namespace
92
93
94using namespace CppNoddy;
95using namespace std;
96
97int main()
98{
99 cout << "\n";
100 cout << "=== Hyperbolic: 2D radial dam-break in Cartesians ===\n";
101 cout << "\n";
102
103 // define the domain/mesh
104 const double west = -1;
105 const double east = 1;
106 const double south = -1;
107 const double north = 1;
108 const unsigned N = 151;
109 DenseVector<double> faces_x = Utility::power_node_vector( west, east, N, 1.0 );
110 DenseVector<double> faces_y = Utility::power_node_vector( south, north, N, 1.0 );
111
112 std::string dirname("./DATA");
113 mkdir( dirname.c_str(), S_IRWXU );
114 std::string filename_stub( "./DATA/HYP_2D_rad_dam" );
115
116 Example::Shallow_2d_rad conservative_problem;
117 TwoD_TVDLF_Mesh Shallow_2d_mesh( faces_x, faces_y, &conservative_problem, Example::Q_init );
118 Shallow_2d_mesh.set_limiter( 0 );
119
120 int file_counter( 1 );
121 const double t_end = 0.5;
122 DenseVector<double> x1( 2, 0.0 );
123 x1[0] = 0.4;
124 x1[1] = 0.1;
125 DenseVector<double> x2( 2, 0.0 );
126 x2[0] = 0.1;
127 x2[1] = 0.4;
128 do
129 {
130 Shallow_2d_mesh.update( 0.49, std::abs( Shallow_2d_mesh.get_time() - t_end ) );
131 Shallow_2d_mesh.dump_gnu( filename_stub + Utility::stringify( file_counter ) + "_gnu.dat" );
132 file_counter += 1;
133 }
134 while ( Shallow_2d_mesh.get_time() < t_end );
135
136 double h_clawpack( 1.13466 );
137 double theta = M_PI / 4;
138 DenseVector<double> x( 2, 0.0 );
139 x[ 0 ] = 0.5 * cos( theta );
140 x[ 1 ] = 0.5 * sin( theta );
141 double h_diag = Shallow_2d_mesh.get_point_values( x )[ h ];
142 if ( abs( h_diag - h_clawpack ) > 1.e-3 )
143 {
144 cout << "\033[1;31;48m * FAILED \033[0m\n";
145 cout << " deviation from the Clawpack data = " << abs( h_diag - h_clawpack ) << "\n";
146 return 1;
147 }
148 else
149 {
150 cout << "\033[1;32;48m * PASSED \033[0m\n";
151 return 0;
152 }
153}
@ f
Definition: BVPBerman.cpp:15
@ V
Definition: BVPKarman.cpp:20
@ U
Definition: BVPKarman.cpp:20
int main()
A shorter bundled include file for hyperbolic problems.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
Shallow_2d_rad()
One dimemsional constant coefft acoustic problem.
void Jac_flux_fn_y(const DenseVector< double > &x, const DenseVector< double > &q, DenseMatrix< double > &J) const
A virtual function function to define the Jacobian of the y-flux function.
void max_charac_speed(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &c) const
Bound the wave speed.
void flux_fn_y(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
A virtual flux function for the y-derivative.
void flux_fn_x(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &f) const
Define the vector flux.
void Jac_flux_fn_x(const DenseVector< double > &x, const DenseVector< double > &q, DenseMatrix< double > &J) const
A virtual function function to define the Jacobian of the x-flux function.
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.
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