# include # include # include # include # include "traveling_wave_exact.h" int main ( ); void traveling_wave_residual_test ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: traveling_wave_exact_test() tests traveling_wave_exact(). Licensing: This code is distributed under the MIT license. Modified: 11 April 2025 Author: John Burkardt */ { double a; double k; double phi; double t0; double tstop; double w; double xmax; double xmin; timestamp ( ); printf ( "\n" ); printf ( "traveling_wave_exact_test():\n" ); printf ( " C version\n" ); printf ( " Test traveling_wave_exact(),\n" ); printf ( " 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 ); printf ( "\n" ); printf ( " parameters:\n" ); printf ( " a = %g\n", a ); printf ( " k = %g\n", k ); printf ( " w = %g\n", w ); printf ( " phi = %g\n", phi ); printf ( " xmin = %g\n", xmin ); printf ( " xmax = %g\n", xmax ); printf ( " t0 = %g\n", t0 ); printf ( " tstop = %g\n", tstop ); traveling_wave_residual_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "traveling_wave_exact_test():\n" ); printf ( " Normal end of execution.\n" ); timestamp ( ); return 0; } /******************************************************************************/ void traveling_wave_residual_test ( ) /******************************************************************************/ /* Purpose: traveling_wave_residual_test() tests traveling_wave_residual(). Licensing: This code is distributed under the MIT license. Modified: 11 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; printf ( "\n" ); printf ( "traveling_wave_residual_test():\n" ); printf ( " 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 ); printf ( "\n" ); printf ( " X T U(X,T) Resid(X,T)\n" ); printf ( "\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 ); printf ( " %8.4f %8.4f %10.4g %14.6g\n", x[i], t[j], u, r ); } printf ( "\n" ); } free ( t ); free ( x ); return; } /******************************************************************************/ double *r8vec_linspace_new ( int n, double a, double b ) /******************************************************************************/ /* 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, B, the first and last entries. Output: double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. */ { int i; double *x; x = ( double * ) malloc ( n * sizeof ( double ) ); if ( n == 1 ) { x[0] = ( a + b ) / 2.0; } else { for ( i = 0; i < n; i++ ) { x[i] = ( ( double ) ( n - 1 - i ) * a + ( double ) ( i ) * b ) / ( double ) ( n - 1 ); } } return x; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }