CppNoddy  0.92
Loading...
Searching...
No Matches
HYP2DShallowSource.cpp
Go to the documentation of this file.
1/// \file HYP2DShallowSource.cpp
2/// \ingroup Tests
3/// \ingroup HYP_2D
4/// Two dimensional shallow water equations over topography. In this
5/// case, although the computation is 2D the topography is independent
6/// of the transverse coordinate and the result is checked against the
7/// 1D code.
8
9#include <TwoD_HYP_bundle.h>
10
11enum { h, hu, hv };
12
13namespace CppNoddy
14{
15 namespace Example
16 {
17 /// gravitational acceleration
18 double g( 9.81 );
19 /// hump amplitude
20 double A( 0.2 );
21 /// Topography shape
22 double z( const double &x, const double &y )
23 {
24 // to compare with our 1D formulation, we'll make it independent
25 // of the transverse y-coordinate
26 double rsq( ( x - 10 ) * ( x - 10 ) + 0.0 * y * y );
27 return A * std::exp( - 0.5 * rsq );
28 }
29
30 /// Set the initial state of the system
31 void Q_init( const double &x, const double &y, DenseVector<double> &q )
32 {
33 q[ h ] = 0.33;
34 q[ hu ] = 0.18;
35 q[ hv ] = 0.0;
36 }
37
38 /// Define the system
40 {
41
42 public:
43
44 /// One dimemsional constant coefft acoustic problem
46 {}
47
48 /// Define the vector flux
50 {
51 f[ h ] = q[ hu ];
52 f[ hu ] = q[ hu ] * q[ hu ] / q[ h ] + g * q[ h ] * q[ h ] / 2;
53 f[ hv ] = q[ hu ] * q[ hv ] / q[ h ];
54 }
55
57 {
58 f[ h ] = q[ hv ];
59 f[ hu ] = q[ hu ] * q[ hv ] / q[ h ];
60 f[ hv ] = q[ hv ] * q[ hv ] / q[ h ] + g * q[ h ] * q[ h ] / 2;
61 }
62
63 // we'll use analytic Jacobians
65 {
66 J( 0, hu ) = 1;
67 //
68 J( 1, h ) = - q[ hu ] * q[ hu ] / ( q[ h ] * q[ h ] ) + g * q[ h ];
69 J( 1, hu ) = 2 * q[ hu ] / q[ h ];
70 //
71 J( 2, h ) = - q[ hu ] * q[ hv ] / ( q[ h ] * q[ h ] );
72 J( 2, hu ) = q[ hv ] / q[ h ];
73 J( 2, hv ) = q[ hu ] / q[ h ];
74 }
75
77 {
78 J( 0, hv ) = 1;
79 //
80 J( 1, h ) = - q[ hu ] * q[ hv ] / ( q[ h ] * q[ h ] );
81 J( 1, hu ) = q[ hv ] / q[ h ];
82 J( 1, hv ) = q[ hu ] / q[ h ];
83 //
84 J( 2, h ) = - q[ hv ] * q[ hv ] / ( q[ h ] * q[ h ] ) + g * q[ h ];
85 J( 2, hv ) = 2 * q[ hv ] / q[ h ];
86 }
87
88 /// Bound the wave speed
90 {
91 // wave speed
92 double cc = sqrt( g * q[ h ] );
93 // flow speed
94 double U = q[ hu ] / q[ h ];
95 double V = q[ hv ] / q[ h ];
96 // maximum shock speed
97 c[ 0 ] = std::max( std::abs( U + cc ), std::abs( U - cc ) );
98 c[ 1 ] = std::max( std::abs( V + cc ), std::abs( V - cc ) );
99 }
100
101 /// edge conditions
102 std::vector<bool> edge_values( const int& face_index, const DenseVector<double>& x, DenseVector<double>& q ) const
103 {
104 std::vector<bool> comps( q.size(), false );
105 switch ( face_index )
106 {
107 case 1:
108 q[ h ] = 0.33;
109 comps[ h ] = true;
110 break;
111 case 3:
112 q[ hu ] = 0.18;
113 comps[ hu ] = true;
114 break;
115 }
116 return comps;
117 }
118
120 {
121 const double delta( 1.e-6 );
122 r[ h ] = 0.0;
123 r[ hu ] = - g * q[ h ] * ( z( x[0] + delta, x[1] ) - z( x[0], x[1] ) ) / delta;
124 r[ hv ] = - g * q[ h ] * ( z( x[0], x[1] + delta ) - z( x[0], x[1] ) ) / delta;
125 }
126
127 };
128 } //end Example namespace
129} //end CppNoddy namespace
130
131
132using namespace CppNoddy;
133using namespace std;
134
135int main()
136{
137
138 cout << "\n";
139 cout << "=== Hyperbolic: 2D shallow water over topography ====\n";
140 cout << "\n";
141
142 std::string dirname("./DATA");
143 mkdir( dirname.c_str(), S_IRWXU );
144 std::string filename_stub( "./DATA/HYP_2D_shallow_source" );
145 // define the domain/mesh
146 const double west = 0;
147 const double east = 25;
148 const double south = -3;
149 const double north = 3;
150 const unsigned Nx = 401;
151 const unsigned Ny = 3;
152 DenseVector<double> faces_x = Utility::power_node_vector( west, east, Nx, 1.0 );
153 DenseVector<double> faces_y = Utility::power_node_vector( south, north, Ny, 1.0 );
154
155 Example::Shallow_2d_source conservative_problem;
156 TwoD_TVDLF_Mesh Shallow_2d_mesh( faces_x, faces_y, &conservative_problem, Example::Q_init );
157 Shallow_2d_mesh.set_limiter( 1 );
158
159 int file_counter( 0 );
160 int loop_counter( 0 );
161 const double t_end = 5;
162 do
163 {
164 if ( loop_counter % 10 == 0 )
165 {
166 Shallow_2d_mesh.dump_gnu( filename_stub + Utility::stringify( file_counter ) + ".dat" );
167 file_counter += 1;
168 }
169 Shallow_2d_mesh.update( 0.49, std::abs( Shallow_2d_mesh.get_time() - t_end ) );
170 loop_counter += 1;
171
172 }
173 while ( Shallow_2d_mesh.get_time() < t_end );
174
175 DenseVector<double> x( 2, 0.0 );
176 x[ 0 ] = 10;
177 x[ 1 ] = 0;
178 double h_10( Shallow_2d_mesh.get_point_values( x )[0] );
179 // compare this value to the 1D code's result for this resolution and CFL
180 double E( abs( h_10 - 0.116773 ) );
181 if ( E > 1.e-5 )
182 {
183 cout << "\033[1;31;48m * FAILED \033[0m\n";
184 cout << E << " \n";
185 return 1;
186 }
187 else
188 {
189 cout << "\033[1;32;48m * PASSED \033[0m\n";
190 return 0;
191 }
192}
@ 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
std::size_t size() const
A pass-thru definition to get the size of the vector.
Definition: DenseVector.h:330
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.
std::vector< bool > edge_values(const int &face_index, const DenseVector< double > &x, DenseVector< double > &q) const
edge conditions
void source_fn(const DenseVector< double > &x, const DenseVector< double > &q, DenseVector< double > &r) const
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_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.
Shallow_2d_source()
One dimemsional constant coefft acoustic problem.
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.
const double delta(0.5)
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