# include # include # include # include # include using namespace std; # include "helmholtz_exact.hpp" int main ( ); void helmholtz_exact_print ( int m, int n ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // helmholtz_exact_test() tests helmholtz_exact(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 17 June 2025 // // Author: // // John Burkardt // { int m; int n; timestamp ( ); cout << "\n"; cout << "helmholtz_exact_test():\n"; cout << " C version\n"; cout << " Test helmholtz_exact().\n"; m = 1; n = 2; helmholtz_exact_print ( m, n ); m = 2; n = 3; helmholtz_exact_print ( m, n ); // // Terminate. // cout << "\n"; cout << "helmholtz_exact_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void helmholtz_exact_print ( int m, int n ) //****************************************************************************80 // // 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: // // 17 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 = new double[nxy]; Y = new double[nxy]; 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 ); cout << "\n"; cout << " Helmholtz exact solution with\n"; cout << " m = " << m << ", n = " << n << "\n"; cout << "\n"; cout << " k X(k) Y(k) Z(k)\n"; cout << "\n"; for ( k = 0; k < nxy; k++ ) { cout << " " << setw(2) << k << " " << setw(10) << X[k] << " " << setw(10) << Y[k] << " " << setw(10) << Z[k] << "\n"; } delete [] r; delete [] t; delete [] X; delete [] Y; delete [] Z; 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 }