program main !*****************************************************************************80 ! !! helmholtz_exact_test() tests helmholtz_exact(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 12 June 2025 ! ! Author: ! ! John Burkardt ! implicit none integer m integer n call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'helmholtz_exact_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Test helmholtz_exact().' m = 1 n = 2 call helmholtz_exact_print ( m, n ) m = 2 n = 3 call helmholtz_exact_print ( m, n ) ! ! Terminate. ! write ( *, '(a)' ) '' write ( *, '(a)' ) 'helmholtz_exact_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine helmholtz_exact_print ( m, n ) !*****************************************************************************80 ! !! 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: ! ! 12 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. ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) real ( kind = rk8 ) a real ( kind = rk8 ) alpha real ( kind = rk8 ) beta real ( kind = rk8 ) gamma integer i integer j integer k integer m integer n integer nr integer nt integer nxy real ( kind = rk8 ), allocatable :: r(:) real ( kind = rk8 ), parameter :: r8_pi = 3.141592653589793D+00 real ( kind = rk8 ), allocatable :: t(:) real ( kind = rk8 ), allocatable :: X(:) real ( kind = rk8 ), allocatable :: Y(:) real ( kind = rk8 ), allocatable :: Z(:) a = 1.5D+00 alpha = 4.0D+00 beta = 3.0D+00 gamma = 2.0D+00 nt = 5 allocate ( t(1:nt+1) ) call r8vec_linspace ( nt + 1, 0.0D+00, 2.0D+00 * r8_pi, t ) nr = 5 allocate ( r(1:nr) ) call r8vec_linspace ( nr, 0.0D+00, 1.0D+00, r ) r = sqrt ( r ) * a nxy = ( nr - 1 ) * nt + 1 allocate ( X(1:nxy) ) allocate ( Y(1:nxy) ) allocate ( Z(1:nxy) ) k = 0 do i = 1, nt do j = 1, nr if ( j == 1 .and. 1 < i ) then cycle else k = k + 1 X(k) = r(j) * cos ( t(i) ) Y(k) = r(j) * sin ( t(i) ) end if end do end do call helmholtz_exact ( a, m, n, alpha, beta, gamma, nxy, X, Y, Z ) write ( *, '(a)' ) '' write ( *, '(a)' ) ' Helmholtz exact solution with' write ( *, '(a,i2,a,i2)' ) ' m = ', m, ' n = ', n write ( *, '(a)' ) '' write ( *, '(a)' ) ' k X(k) Y(k) Z(k)' write ( *, '(a)' ) ' ' do k = 1, nxy write ( *, '(2x,i2,2x,f10.4,2x,f10.4,2x,g14.6)' ) k, X(k), Y(k), Z(k) end do deallocate ( r ) deallocate ( t ) deallocate ( X ) deallocate ( Y ) deallocate ( Z ) return end subroutine r8vec_linspace ( n, a, b, x ) !*****************************************************************************80 ! !! r8vec_linspace() 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: ! ! 14 March 2011 ! ! Author: ! ! John Burkardt ! ! Input: ! ! integer N, the number of entries in the vector. ! ! real ( kind = rk8 ) A, B, the first and last entries. ! ! Output: ! ! real ( kind = rk8 ) X(N), a vector of linearly spaced data. ! implicit none integer, parameter :: rk8 = kind ( 1.0D+00 ) integer n real ( kind = rk8 ) a real ( kind = rk8 ) b integer i real ( kind = rk8 ) x(n) if ( n == 1 ) then x(1) = ( a + b ) / 2.0D+00 else do i = 1, n x(i) = ( real ( n - i, kind = rk8 ) * a & + real ( i - 1, kind = rk8 ) * b ) & / real ( n - 1, kind = rk8 ) end do end if return end subroutine timestamp ( ) !*****************************************************************************80 ! !! timestamp() prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 15 August 2021 ! ! Author: ! ! John Burkardt ! implicit none character ( len = 8 ) ampm integer d integer h integer m integer mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer n integer s integer values(8) integer y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2.2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end