# include # include # include # include # include using namespace std; # include "traveling_wave_exact.hpp" int main ( ); void traveling_wave_residual_test ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // traveling_wave_exact_test() tests traveling_wave_exact(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 12 April 2025 // // Author: // // John Burkardt // { double a; double k; double phi; double t0; double tstop; double w; double xmax; double xmin; timestamp ( ); cout << "\n"; cout << "traveling_wave_exact_test():\n"; cout << " C++ version\n"; cout << " Test traveling_wave_exact(),\n"; cout << " an exact traveling wave solution of the wave equation.\n"; // // Report the current parameter values. // traveling_wave_parameters ( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &a, &k, &w, &phi, &xmin, &xmax, &t0, &tstop ); cout << "\n"; cout << " parameters:\n"; cout << " a = " << a << "\n"; cout << " k = " << k << "\n"; cout << " w = " << w << "\n"; cout << " phi = " << phi << "\n"; cout << " xmin = " << xmin << "\n"; cout << " xmax = " << xmax << "\n"; cout << " t0 = " << t0 << "\n"; cout << " tstop = " << tstop << "\n"; traveling_wave_residual_test ( ); // // Terminate. // cout << "\n"; cout << "traveling_wave_exact_test():\n"; cout << " Normal end of execution.\n"; timestamp ( ); return 0; } //****************************************************************************80 void traveling_wave_residual_test ( ) //****************************************************************************80 // // Purpose: // // traveling_wave_residual_test() tests traveling_wave_residual(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 12 April 2025 // // Author: // // John Burkardt // { double a; int i; int j; int m; int n; double k; double phi; double r; double *t; double t0; double tstop; double u; double ut; double utt; double ux; double uxx; double w; double *x; double xmax; double xmin; cout << "\n"; cout << "traveling_wave_residual_test():\n"; cout << " Evaluate solution and residual at selected points (X,T)\n"; traveling_wave_parameters ( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &a, &k, &w, &phi, &xmin, &xmax, &t0, &tstop ); n = 11; x = r8vec_linspace_new ( n, xmin, xmax ); m = 5; t = r8vec_linspace_new ( m, t0, tstop ); cout << "\n"; cout << " X T U(X,T) Resid(X,T)\n"; cout << "\n"; for ( j = 0; j < m; j++ ) { for ( i = 0; i < n; i++ ) { traveling_wave_exact ( x[i], t[j], u, ut, utt, ux, uxx ); traveling_wave_residual ( x[i], t[j], r ); cout << " " << setw(8) << x[i] << " " << setw(8) << t[j] << " " << setw(10) << u << " " << setw(14) << r << "\n"; } cout << "\n"; } delete [] t; delete [] x; return; } //****************************************************************************80 double *r8vec_linspace_new ( int n, double a_first, double a_last ) //****************************************************************************80 // // Purpose: // // r8vec_linspace_new() creates a vector of linearly spaced values. // // Discussion: // // An R8VEC is a vector of R8's. // // 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. // // In other words, the interval is divided into N-1 even subintervals, // and the endpoints of intervals are used as the points. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 29 March 2011 // // Author: // // John Burkardt // // Input: // // int N, the number of entries in the vector. // // double A_FIRST, A_LAST, the first and last entries. // // Output: // // double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. // { double *a; int i; a = new double[n]; if ( n == 1 ) { a[0] = ( a_first + a_last ) / 2.0; } else { for ( i = 0; i < n; i++ ) { a[i] = ( ( double ) ( n - 1 - i ) * a_first + ( double ) ( i ) * a_last ) / ( double ) ( n - 1 ); } } return a; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }