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

Two dimensional shallow water equations over topography. More...

#include <TwoD_HYP_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::Shallow_2d_source
 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
 

Enumerations

enum  { h , hu , hv }
 

Functions

double CppNoddy::Example::g (9.81)
 gravitational acceleration More...
 
double CppNoddy::Example::A (0.2)
 hump amplitude More...
 
double CppNoddy::Example::z (const double &x, const double &y)
 Topography shape. More...
 
void CppNoddy::Example::Q_init (const double &x, const double &y, DenseVector< double > &q)
 Set the initial state of the system. More...
 
int main ()
 

Detailed Description

Two dimensional shallow water equations over topography.

In this case, although the computation is 2D the topography is independent of the transverse coordinate and the result is checked against the 1D code.

Definition in file HYP2DShallowSource.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
hu 
hv 

Definition at line 11 of file HYP2DShallowSource.cpp.

11{ h, hu, hv };

Function Documentation

◆ main()

int main ( )

Definition at line 135 of file HYP2DShallowSource.cpp.

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}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
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

References CppNoddy::TwoD_TVDLF_Mesh::dump_gnu(), E, CppNoddy::TwoD_TVDLF_Mesh::get_point_values(), CppNoddy::TwoD_TVDLF_Mesh::get_time(), CppNoddy::Utility::power_node_vector(), CppNoddy::TwoD_TVDLF_Mesh::set_limiter(), CppNoddy::Utility::stringify(), and CppNoddy::TwoD_TVDLF_Mesh::update().

© 2012

R.E. Hewitt