int main() { cout << "\n"; cout << "=== Hyperbolic: 1D Euler gasdynamics shocktube =====\n"; cout << "\n"; // define the domain/mesh const double left = 0.0; const double right = 1.0; const unsigned N = 400; DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N ); double t = 0.0; Example::Euler_1d conservative_problem; OneD_TVDLF_Mesh Euler_mesh( faces_x, &conservative_problem, Example::Q_init ); Euler_mesh.set_limiter( 0 ); double I1 = Euler_mesh.integrate()[0]; int loop_counter( 0 ); int file_counter( 0 ); std::string filename_stub; filename_stub = "./DATA/HYP_shocktube_sod"; TrackerFile my_file( 10 ); OneD_Node_Mesh<double> soln = Euler_mesh.get_soln(); my_file.push_ptr( &soln, "mesh" ); do { if ( loop_counter % 10 == 0 ) { my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" ); soln = Euler_mesh.get_soln( ); my_file.update(); file_counter += 1; } t += Euler_mesh.update( 0.499 ); ++loop_counter; } while ( ( t < 0.2 ) && ( loop_counter < 1000 ) ); double I2 = Euler_mesh.integrate()[0]; // These are clawpack results (to 4dp) with N=400 and minmod for the // density of the two density steps ... soln = Euler_mesh.get_soln( ); double E1 = std::abs( soln.get_interpolated_vars( 0.575 )[0] - 0.4264 ); double E2 = std::abs( soln.get_interpolated_vars( 0.75 )[0] - 0.2656 ); // check against the clawpack data, and that the mass is conserved. if ( ( E1 > 1.e-3 ) || ( E2 > 1.e-3 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) || ( loop_counter >= 1000 ) ) { cout << "\033[1;31;48m * FAILED \033[0m\n"; cout << E1 << " " << E2 << " " << std::abs( I1 - I2 ) << " " << loop_counter << "\n"; } else { cout << "\033[1;32;48m * PASSED \033[0m\n"; } } // end of main()
int main() { cout << "\n"; cout << "=== Hyperbolic: Shallow water radial dam break ======\n"; cout << "\n"; // There is a singular source_fn at r=0, so we bodge it here (for now). /// \todo Include a mechanism for avoiding source term computations /// at the singular point by indicating where edge conditions are specified. /// For the time being, we'll bodge it by stopping away from x=0. const double left = 1.e-4; const double right = 2.5; const unsigned N = 2001; DenseVector<double> faces_x = Utility::power_node_vector( left, right, N, 1.0 ); // time double t = 0; double t_end = 0.5; // hyperbolic problem Example::Shallow_1d_rad conservative_problem; OneD_TVDLF_Mesh Shallow_mesh( faces_x, &conservative_problem, Example::Q_init ); Shallow_mesh.set_limiter( 0 ); // output int loop_counter( 0 ); int file_counter( 0 ); std::string dirname("./DATA"); mkdir( dirname.c_str(), S_IRWXU ); std::string filename_stub; filename_stub = "./DATA/HYP_shallow_rad"; TrackerFile my_file( 5 ); OneD_Node_Mesh<double> soln = Shallow_mesh.get_soln(); my_file.push_ptr( &soln, "mesh" ); do { if ( loop_counter % 50 == 0 ) { my_file.set_filename( filename_stub + Utility::stringify( file_counter ) + ".dat" ); soln = Shallow_mesh.get_soln(); my_file.update(); file_counter += 1; } t += Shallow_mesh.update( 0.499, t_end - t ); ++loop_counter; } while ( ( t < t_end ) && ( loop_counter < 3000 ) ); // we test the result against the Clawpack computational result soln = Shallow_mesh.get_soln(); double h_clawpack( 1.13466 ); double h_test( soln.get_interpolated_vars( 0.5 )[ h ] ); if ( abs( h_test - h_clawpack ) > 1.e-3 ) { cout << "\033[1;31;48m * FAILED \033[0m\n"; cout << " deviation from the Clawpack data = " << abs( h_test - h_clawpack ) << "\n"; return 1; } else { cout << "\033[1;32;48m * PASSED \033[0m\n"; return 0; } } // end of main()
int main() { cout << "\n"; cout << "=== Hyperbolic: 1D nonlinear advection equation ====\n"; cout << "\n"; // define the domain/mesh const double left = 0.0; const double right = 1.0; const unsigned N = 141; DenseVector<double> faces_x = Utility::uniform_node_vector( left, right, N ); double t = 0.0; Example::NlinAdv conservative_problem; OneD_TVDLF_Mesh NlinAdv_mesh( faces_x, &conservative_problem, Example::Q_init ); NlinAdv_mesh.set_limiter( 0 ); double I1 = NlinAdv_mesh.integrate()[0]; int loop_counter( 5 ); TrackerFile my_file( "./DATA/HYP_NlinAdv.dat" ); // first column of the output will always be the time my_file.push_ptr( &t, "time" ); OneD_Node_Mesh<double> soln = NlinAdv_mesh.get_soln(); my_file.push_ptr( &soln, "mesh" ); double asym( 0.0 ); do { double dt = NlinAdv_mesh.update( 0.475 ); t += dt; soln = NlinAdv_mesh.get_soln(); if ( loop_counter % 10 == 0 ) { soln = NlinAdv_mesh.get_soln(); my_file.update(); my_file.newline(); } ++loop_counter; asym = std::max( asym, std::abs( soln.get_interpolated_vars( 0.75 )[0] + soln.get_interpolated_vars( 0.25 )[0] ) ); } while ( ( t < 0.4 ) && ( loop_counter < 1000 ) ); double I2 = NlinAdv_mesh.integrate()[0]; soln = NlinAdv_mesh.get_soln(); my_file.update(); my_file.newline(); // problem should be antisymmetric about x = 1/2 if ( ( asym > 1.e-10 ) || ( std::abs( I1 - I2 ) > 1.e-8 ) || ( loop_counter >= 1000 ) ) { cout << "\033[1;31;48m * FAILED \033[0m\n"; cout << "asymmetry = " << asym << "\n"; cout << "integral difference = " << I1 - I2 << "\n"; cout << "loop counter = " << loop_counter << "\n"; } else { cout << "\033[1;32;48m * PASSED \033[0m\n"; } } // end of main()