# include # include # include # include # include "poisson_2d_exact.h" int main ( ); double r8vec_norm_rms ( int n, double x[] ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* 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) ); printf ( "\n" ); printf ( "poisson_2d_exact_test():\n" ); printf ( " C version\n" ); printf ( " Test poisson_2d_exact().\n" ); f = ( double * ) malloc ( n * sizeof ( double ) ); r = ( double * ) malloc ( n * sizeof ( double ) ); u = ( double * ) malloc ( n * sizeof ( double ) ); ux = ( double * ) malloc ( n * sizeof ( double ) ); uy = ( double * ) malloc ( n * sizeof ( double ) ); uxx = ( double * ) malloc ( n * sizeof ( double ) ); uxy = ( double * ) malloc ( n * sizeof ( double ) ); uyy = ( double * ) malloc ( n * sizeof ( double ) ); x = ( double * ) malloc ( n * sizeof ( double ) ); y = ( double * ) malloc ( n * sizeof ( double ) ); 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]; } printf ( " RMS norm of residuals = %g\n", r8vec_norm_rms ( n, r ) ); free ( f ); free ( r ); free ( u ); free ( ux ); free ( uy ); free ( uxx ); free ( uxy ); free ( uyy ); free ( x ); free ( y ); /* Terminate. */ printf ( "\n" ); printf ( "poisson_2d_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. D iscussion: 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 }