# include # include # include # include # include "laplace_radial_exact.h" int main ( ); double r8vec_norm_rms ( int n, double a[] ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: laplace_radial_exact_test() tests laplace_radial_exact(). Licensing: This code is distributed under the MIT license. Modified: 04 June 2025 Author: John Burkardt */ { double a; double b; int i; int n = 5; double *R; double *U; double *Ux; double *Uxx; double *Uxy; double *Uxz; double *Uy; double *Uyy; double *Uyz; double *Uz; double *Uzz; double *X; double *Y; double *Z; timestamp ( ); printf ( "\n" ); printf ( "laplace_radial_exact_test():\n" ); printf ( " C version\n" ); printf ( " Test laplace_radial_exact().\n" ); srand ( time(0) ); R = ( double * ) malloc ( n * sizeof ( double ) ); U = ( double * ) malloc ( n * sizeof ( double ) ); Ux = ( double * ) malloc ( n * sizeof ( double ) ); Uxx = ( double * ) malloc ( n * sizeof ( double ) ); Uxy = ( double * ) malloc ( n * sizeof ( double ) ); Uxz = ( double * ) malloc ( n * sizeof ( double ) ); Uy = ( double * ) malloc ( n * sizeof ( double ) ); Uyy = ( double * ) malloc ( n * sizeof ( double ) ); Uyz = ( double * ) malloc ( n * sizeof ( double ) ); Uz = ( double * ) malloc ( n * sizeof ( double ) ); Uzz = ( double * ) malloc ( n * sizeof ( double ) ); X = ( double * ) malloc ( n * sizeof ( double ) ); Y = ( double * ) malloc ( n * sizeof ( double ) ); Z = ( double * ) malloc ( n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { X[i] = drand48 ( ); Y[i] = drand48 ( ); Z[i] = drand48 ( ); } a = 1.0; b = 2.0; /* 2D case. */ printf ( "\n" ); printf ( " Radial solution in 2D:\n" ); laplace_radial_2d_exact ( n, X, Y, a, b, U, Ux, Uy, Uxx, Uxy, Uyy ); for ( i = 0; i < n; i++ ) { R[i] = Uxx[i] + Uyy[i]; } printf ( " RMS norm of residuals = %g\n", r8vec_norm_rms ( n, R ) ); /* 3D case. */ printf ( "\n" ); printf ( " Radial solution in 3D:\n" ); laplace_radial_3d_exact ( n, X, Y, Z, a, b, U, Ux, Uy, Uz, Uxx, Uxy, Uxz, Uyy, Uyz, Uzz ); for ( i = 0; i < n; i++ ) { R[i] = Uxx[i] + Uyy[i] + Uzz[i]; } printf ( " RMS norm of residuals = %g\n", r8vec_norm_rms ( n, R ) ); free ( R ); free ( U ); free ( Ux ); free ( Uxx ); free ( Uxy ); free ( Uxz ); free ( Uy ); free ( Uyy ); free ( Uyz ); free ( Uz ); free ( Uzz ); free ( X ); free ( Y ); free ( Z ); /* Terminate. */ printf ( "\n" ); printf ( "laplace_radial_exact_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ double r8vec_norm_rms ( int n, double a[] ) /******************************************************************************/ /* Purpose: r8vec_norm_rms() returns the RMS norm of an R8VEC. Discussion: The vector RMS norm is defined as: R8VEC_NORM_RMS = sqrt ( sum ( 1 <= I <= N ) A(I)^2 / N ) Licensing: This code is distributed under the MIT license. Modified: 26 October 2011 Author: John Burkardt Input: int N, the number of entries in A. double A[N], the vector whose L2 norm is desired. Output: double R8VEC_NORM_RMS, the RMS norm of A. */ { int i; double v; v = 0.0; if ( 0 < n ) { for ( i = 0; i < n; i++ ) { v = v + a[i] * a[i]; } v = sqrt ( v / ( double ) ( n ) ); } return v; } /******************************************************************************/ 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 }