# include # include # include # include # include using namespace std; # include "laplace_radial_exact.hpp" int main ( ); double r8vec_norm_rms ( int n, double a[] ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // 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 ( ); cout << "\n"; cout << "laplace_radial_exact_test():\n"; cout << " C++ version\n"; cout << " Test laplace_radial_exact().\n"; srand ( time(0) ); R = new double[n]; U = new double[n]; Ux = new double[n]; Uxx = new double[n]; Uxy = new double[n]; Uxz = new double[n]; Uy = new double[n]; Uyy = new double[n]; Uyz = new double[n]; Uz = new double[n]; Uzz = new double[n]; X = new double[n]; Y = new double[n]; Z = new double[n]; for ( i = 0; i < n; i++ ) { X[i] = drand48 ( ); Y[i] = drand48 ( ); Z[i] = drand48 ( ); } a = 1.0; b = 2.0; // // 2D case. // cout << "\n"; cout << " 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]; } cout << " RMS norm of residuals = " << r8vec_norm_rms ( n, R ) << "\n"; // // 3D case. // cout << "\n"; cout << " 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]; } cout << " RMS norm of residuals = " << r8vec_norm_rms ( n, R ) << "\n"; delete [] R; delete [] U; delete [] Ux; delete [] Uxx; delete [] Uxy; delete [] Uxz; delete [] Uy; delete [] Uyy; delete [] Uyz; delete [] Uz; delete [] Uzz; delete [] X; delete [] Y; delete [] Z; // // Terminate. // cout << "\n"; cout << "laplace_radial_exact_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 double r8vec_norm_rms ( int n, double a[] ) //****************************************************************************80 // // Purpose: // // r8vec_norm_rms() returns the RMS norm of an R8VEC. // // Discussion: // // An R8VEC is a vector of R8's. // // The vector RMS norm is defined as: // // R8VEC_RMS_NORM = 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. // // 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; } //****************************************************************************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 }