# include # include # include # include # include "helmholtz_exact.h" int main ( ); void helmholtz_exact_print ( int m, int n ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: helmholtz_exact_test() tests helmholtz_exact(). Licensing: This code is distributed under the MIT license. Modified: 16 June 2025 Author: John Burkardt */ { int m; int n; timestamp ( ); printf ( "\n" ); printf ( "helmholtz_exact_test():\n" ); printf ( " C version\n" ); printf ( " Test helmholtz_exact().\n" ); m = 1; n = 2; helmholtz_exact_print ( m, n ); m = 2; n = 3; helmholtz_exact_print ( m, n ); /* Terminate. */ printf ( "\n" ); printf ( "helmholtz_exact_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void helmholtz_exact_print ( int m, int n ) /******************************************************************************/ /* Purpose: helmholtz_exact_print() tabulates a solution of the Helmholtz equation. Discussion: The solution is assumed to have a simple form depending on the n-th J Bessel function and its m-th root. Licensing: This code is distributed under the MIT license. Modified: 16 June 2025 Author: John Burkardt Input: integer m: the index of the root of the Bessel function J(n,x). integer n: the index of the Bessel function. */ { double a; double alpha; double beta; double gamma; int i; int j; int k; int nr; int nt; int nxy; double *r; double r8_pi = 3.141592653589793; double *t; double *X; double *Y; double *Z; a = 1.5; alpha = 4.0; beta = 3.0; gamma = 2.0; nt = 5; t = r8vec_linspace_new ( nt + 1, 0.0, 2.0 * r8_pi ); nr = 5; r = r8vec_linspace_new ( nr, 0.0, 1.0 ); for ( i = 0; i < nr; i++ ) { r[i] = sqrt ( r[i] ) * a; } nxy = ( nr - 1 ) * nt + 1; X = ( double * ) malloc ( nxy * sizeof ( double ) ); Y = ( double * ) malloc ( nxy * sizeof ( double ) ); k = 0; for ( i = 0; i < nt; i++ ) { for ( j = 0; j < nr; j++ ) { if ( j == 0 && 0 < i ) { continue; } else { X[k] = r[j] * cos ( t[i] ); Y[k] = r[j] * sin ( t[i] ); k = k + 1; } } } Z = helmholtz_exact ( a, m, n, alpha, beta, gamma, nxy, X, Y ); printf ( "\n" ); printf ( " Helmholtz exact solution with\n" ); printf ( " m = %d, n = %d\n", m, n ); printf ( "\n" ); printf ( " k X(k) Y(k) Z(k)\n" ); printf ( "\n" ); for ( k = 0; k < nxy; k++ ) { printf ( " %2d %10.4f %10.4f %14.6g\n", k, X[k], Y[k], Z[k] ); } free ( r ); free ( t ); free ( X ); free ( Y ); free ( Z ); 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 }