CppNoddy  0.92
All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Modules Pages
Classes | Namespaces | Enumerations | Functions
HYPAcousticReflection.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_ref
 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 (2.0)
 bulk modulus More...
 
double CppNoddy::Example::rho (2.0)
 higher density 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 pulse in a medium with constant bulk modulus $K=1$ and density $\rho = 1$ and reflecting boundary conditions at both sides.

Definition in file HYPAcousticReflection.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator

Definition at line 13 of file HYPAcousticReflection.cpp.

13{ p, u };

Function Documentation

◆ main()

int main ( )

Definition at line 83 of file HYPAcousticReflection.cpp.

84{
85 cout << "\n";
86 cout << "=== Hyperbolic: 1D acoustic wave reflection problem =\n";
87 cout << "\n";
88
89 // define the domain/mesh
90 const double left = -3.0;
91 const double right = 3.0;
92 const unsigned N = 800;
93 DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N );
94
95 // time
96 double t = 0;
97 double t_end = 6;
98
99 // hyperbolic problem
100 Example::Acoustic_1d_ref conservative_problem;
101 OneD_TVDLF_Mesh Acoustic_mesh( faces_x, &conservative_problem, Example::Q_init );
102 Acoustic_mesh.set_limiter( 1 );
103
104 // output
105 double I1 = Acoustic_mesh.integrate()[0];
106 int loop_counter( 0 );
107 int file_counter( 1 );
108
109 std::string dirname("./DATA");
110 mkdir( dirname.c_str(), S_IRWXU );
111 std::string filename_stub;
112 filename_stub = "./DATA/HYP_acoustic_ref";
113 TrackerFile my_file( 5 );
114 OneD_Node_Mesh<double> soln = Acoustic_mesh.get_soln();
115 my_file.push_ptr( &soln, "mesh" );
116
117 do
118 {
119 if ( loop_counter % 10 == 0 )
120 {
121 my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" );
122 soln = Acoustic_mesh.get_soln();
123 my_file.update();
124 file_counter += 1;
125 }
126 // take a step
127 t += Acoustic_mesh.update( 0.49, t_end - t );
128 ++loop_counter;
129 }
130 while ( ( t < t_end ) && ( loop_counter < 1100 ) );
131
132 double I2 = Acoustic_mesh.integrate()[0];
133 // compute the pressure difference after the pressure pulse
134 // has returned to its original position
135 soln = Acoustic_mesh.get_soln();
136 my_file.update();
137 double diff = 0.0;
138 for ( std::size_t i = 0; i < soln.get_nnodes(); ++i )
139 {
140 // get the initial condition
141 DenseVector<double> q( 2, 0.0 );
142 Example::Q_init( soln.coord( i ), q );
143 // difference between initial and final state
144 diff = std::max( diff, q[0] - soln( i, 0 ) );
145 }
146 // check the maximum difference in the reflected pulse & the
147 // integral of the pressure over the mesh
148 if ( ( diff > 1.e-2 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) )
149 {
150 cout << "\033[1;31;48m * FAILED \033[0m\n";
151 cout << "difference in the reflected wave = " << diff << "\n";
152 cout << "difference in the integral = " << std::abs( I1 - I2 ) << "\n";
153 return 1;
154 }
155 else
156 {
157 cout << "\033[1;32;48m * PASSED \033[0m\n";
158 return 0;
159 }
160
161} // end of main()
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A one dimensional mesh utility object.
const _Xtype & coord(const std::size_t &node) const
Access a nodal position.
std::size_t get_nnodes() const
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 >::coord(), CppNoddy::OneD_Node_Mesh< _Type, _Xtype >::get_nnodes(), 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