CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
Classes | Namespaces | Enumerations | Functions
HYPAcousticImpedance.cpp File Reference

Solve the constant coefficient linear sound wave problem. More...

#include <OneD_HYP_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::Acoustic_1d
 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  { p , u }
 

Functions

double CppNoddy::Example::K (4.0)
 bulk modulus More...
 
double CppNoddy::Example::rho_big (4.0)
 higher density More...
 
double CppNoddy::Example::rho_small (1.0)
 lower density More...
 
double CppNoddy::Example::rho (const double &x)
 Density function for the medium. More...
 
void CppNoddy::Example::Q_init (const double &x, DenseVector< double > &q)
 Set the initial state of the system. More...
 
int main ()
 

Detailed Description

Solve the constant coefficient linear sound wave problem.

\[ p_t + K u_x = 0 \]

\[ \rho u_t + p_x = 0 \]

for a right-propagating square pressure pulse in a medium with constant bulk modulus $K=4$ and density $\rho = 1$ if $\vert x \vert < 1$ and $\rho = 4$ elsewhere. The (first) reflected wave's velocity amplitude is

\[ - \left ( \frac{\frac{K_1}{K_2}-\frac{c_1}{c_2}}{\frac{K_1}{K_2}+\frac{c_1}{c_2}} \right ) \]

where $ K_{1,2} $ and $c_{1,2}$ are the bulk modulus and wave speed before and after the density interface, with $c_i = \sqrt{ K_i \rho_i } $.

Definition in file HYPAcousticImpedance.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator

Definition at line 17 of file HYPAcousticImpedance.cpp.

17{ p, u };

Function Documentation

◆ main()

int main ( )

Definition at line 91 of file HYPAcousticImpedance.cpp.

92{
93 cout << "\n";
94 cout << "=== Hyperbolic: 1D acoustic wave, impedance problem =\n";
95 cout << "\n";
96
97 // define the domain/mesh
98 const double left = -7.0;
99 const double right = 7.0;
100 const unsigned N = 800;
101 DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N );
102
103 // time
104 double t = 0.0;
105 double t_end = 5.0;
106
107 // hyperbolic problem
108 Example::Acoustic_1d conservative_problem;
109 OneD_TVDLF_Mesh Acoustic_mesh( faces_x, &conservative_problem, Example::Q_init );
110 Acoustic_mesh.set_limiter( 1 );
111
112 // mesh & test info
113 double I1 = Acoustic_mesh.integrate()[0];
114 int loop_counter( 4 );
115 int file_counter( 1 );
116
117 std::string dirname("./DATA");
118 mkdir( dirname.c_str(), S_IRWXU );
119 std::string filename_stub;
120 filename_stub = "./DATA/HYP_acoustic_imp";
121 TrackerFile my_file( 5 );
122 OneD_Node_Mesh<double> soln = Acoustic_mesh.get_soln();
123 my_file.push_ptr( &soln, "mesh" );
124
125 do
126 {
127 t += Acoustic_mesh.update( 0.499, t_end - t );
128
129 if ( loop_counter % 2 == 0 )
130 {
131 my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" );
132 soln = Acoustic_mesh.get_soln();
133 my_file.update();
134 file_counter += 1;
135 }
136 ++loop_counter;
137
138 }
139 while ( ( t < t_end ) && ( loop_counter < 1500 ) );
140
141 soln = Acoustic_mesh.get_soln();
142 double I2 = Acoustic_mesh.integrate()[0];
143 // the first reflected and first transmitted pulses can be determined explicitly.
144 // they have amplitude ratios of 1/3 and 8/9ths of the input amplitude for the pressure.
145 soln = Acoustic_mesh.get_soln();
146 double E1 = std::abs( soln.get_interpolated_vars( -5.0 )[0] - 1. / 3. );
147 double E2 = std::abs( soln.get_interpolated_vars( 4.0 )[0] - 8. / 9. );
148 if ( ( E1 > 1.e-4 ) || ( E2 > 1.e-4 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) || ( loop_counter >= 1500 ) )
149 {
150 cout << "\033[1;31;48m * FAILED \033[0m\n";
151 return 1;
152 }
153 else
154 {
155 cout << "\033[1;32;48m * PASSED \033[0m\n";
156 return 0;
157 }
158
159} // end of main()
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
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.
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

References CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::get_interpolated_vars(), CppNoddy::OneD_TVDLF_Mesh::get_soln(), CppNoddy::OneD_TVDLF_Mesh::integrate(), CppNoddy::TrackerFile::push_ptr(), CppNoddy::TrackerFile::set_filename(), CppNoddy::OneD_TVDLF_Mesh::set_limiter(), CppNoddy::Utility::stringify(), CppNoddy::Utility::uniform_node_vector(), CppNoddy::TrackerFile::update(), and CppNoddy::OneD_TVDLF_Mesh::update().

© 2012

R.E. Hewitt