# include # include # include # include # include using namespace std; # include "poisson_2d_exact.hpp" int main ( ); double r8vec_norm_rms ( int n, double x[] ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // poisson_2d_exact_test() tests poisson_2d_exact(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 06 June 2025 // // Author: // // John Burkardt // { double *f; int i; int n = 5; double *r; double *u; double *ux; double *uy; double *uxx; double *uxy; double *uyy; double *x; double *y; timestamp ( ); srand ( time(0) ); cout << "\n"; cout << "poisson_2d_exact_test():\n"; cout << " C++ version\n"; cout << " Test poisson_2d_exact().\n"; f = new double[n]; r = new double[n]; u = new double[n]; ux = new double[n]; uy = new double[n]; uxx = new double[n]; uxy = new double[n]; uyy = new double[n]; x = new double[n]; y = new double[n]; for ( i = 0; i < n; i++ ) { x[i] = drand48 ( ); y[i] = drand48 ( ); } poisson_2d_exact ( n, x, y, u, ux, uy, uxx, uxy, uyy ); for ( i = 0; i < n; i++ ) { f[i] = 0.0; } for ( i = 0; i < n; i++ ) { r[i] = uxx[i] + uyy[i] + f[i]; } cout << " RMS norm of residuals = " << r8vec_norm_rms ( n, r ) << "\n"; delete [] f; delete [] r; delete [] u; delete [] ux; delete [] uy; delete [] uxx; delete [] uxy; delete [] uyy; delete [] x; delete [] y; // // Terminate. // cout << "\n"; cout << "poisson_2d_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 }