# include # include # include # include # include "tetrahedron01_monte_carlo.h" int main ( ); void test01 ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: tetrahedron01_monte_carlo_test() tests tetrahedron01_monte_carlo(). Licensing: This code is distributed under the MIT license. Modified: 16 January 2014 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "TETRAHEDRON01_MONTE_CARLO_TEST():\n" ); printf ( " C version\n" ); printf ( " Test TETRAHEDRON01_MONTE_CARLO().\n" ); test01 ( ); /* Terminate. */ printf ( "\n" ); printf ( "TETRAHEDRON01_MONTE_CARLO_TEST():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 uses TETRAHEDRON01_SAMPLE with an increasing number of points. Licensing: This code is distributed under the MIT license. Modified: 15 January 2014 Author: John Burkardt */ { int e[3]; int e_test[3*10] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 1, 1, 0, 1, 0, 1, 0, 2, 0, 0, 1, 1, 0, 0, 2 }; int i; int j; int m = 3; int n; double result; int seed; double *value; double *x; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Use TETRAHEDRON01_SAMPLE for a Monte Carlo estimate of an\n" ); printf ( " integral over the interior of the unit tetrahedron in 3D.\n" ); seed = 123456789; printf ( "\n" ); printf ( " N 1 X Y " ); printf ( " Z X^2 XY XZ" ); printf ( " Y^2 YZ Z^2\n" ); printf ( "\n" ); n = 1; while ( n <= 65536 ) { x = tetrahedron01_sample ( n, &seed ); printf ( " %8d", n ); for ( j = 0; j < 10; j++ ) { for ( i = 0; i < m; i++ ) { e[i] = e_test[i+j*m]; } value = monomial_value ( m, n, e, x ); result = tetrahedron01_volume ( ) * r8vec_sum ( n, value ) / ( double ) ( n ); printf ( " %14.6g", result ); free ( value ); } printf ( "\n" ); free ( x ); n = 2 * n; } printf ( "\n" ); printf ( " Exact" ); for ( j = 0; j < 10; j++ ) { for ( i = 0; i < m; i++ ) { e[i] = e_test[i+j*m]; } result = tetrahedron01_monomial_integral ( e ); printf ( " %14.6g", result ); } printf ( "\n" ); return; } /******************************************************************************/ 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 }