# include # include # include # include # include "flame_exact.h" int main ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: flame_exact_test() tests flame_exact(). Licensing: This code is distributed under the MIT license. Modified: 29 April 2024 Author: John Burkardt */ { int r = 4; int n = 101; char command_filename[255]; FILE *command_unit; char data_filename[255]; FILE *data_unit; char *header = "flame_exact"; int i; int j; double *t; double t0; double tstop; double *y; double y0; static double y0_vec[4] = { 0.005, 0.01, 0.02, 0.05 }; timestamp ( ); printf ( "\n" ); printf ( "flame_exact_test():\n" ); printf ( " C version\n" ); printf ( " flame_exact() evaluates the exact solution of the flame ODE.\n" ); /* Get parameters. */ flame_parameters ( NULL, NULL, NULL, &t0, &y0, &tstop ); /* Extend time interval. */ tstop = 300.0; flame_parameters ( NULL, NULL, &tstop, NULL, NULL, NULL ); printf ( "\n" ); printf ( " parameters:\n" ); printf ( " t0 = %g\n", t0 ); printf ( " tstop = %g\n", tstop ); /* Compute (t,y) pairs for n times, and r values of y0. */ t = r8vec_linspace_new ( n, t0, tstop ); y = ( double * ) malloc ( n * r * sizeof ( double ) ); for ( j = 0; j < r; j++ ) { y0 = y0_vec[j]; printf ( " y0 = %g\n", y0 ); flame_parameters ( NULL, &y0, NULL, NULL, NULL, NULL ); flame_exact ( n, t, y + n*j ); } /* Create the data file. */ strcpy ( data_filename, header ); strcat ( data_filename, "_data.txt" ); data_unit = fopen ( data_filename, "wt" ); for ( i = 0; i < n; i++ ) { fprintf ( data_unit, "%g", t[i] ); for ( j = 0; j < r; j++ ) { fprintf ( data_unit, " %g", y[i+j*n] ); } fprintf ( data_unit, "\n" ); } fclose ( data_unit ); printf ( "\n" ); printf ( " Data stored in '%s'\n", data_filename ); /* Create the command file. */ strcpy ( command_filename, header ); strcat ( command_filename, "_commands.txt" ); command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "# %s\n", command_filename ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "# Usage:\n" ); fprintf ( command_unit, "# gnuplot < %s\n", command_filename ); fprintf ( command_unit, "#\n" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set output '%s.png'\n", header ); fprintf ( command_unit, "set xlabel '<-- t -->'\n" ); fprintf ( command_unit, "set ylabel '<-- y(t) -->'\n" ); fprintf ( command_unit, "set title 'flame_exact:'\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "plot '%s' using 1:2 with lines lw 3,\\\n", data_filename ); fprintf ( command_unit, " '%s' using 1:3 with lines lw 3,\\\n", data_filename ); fprintf ( command_unit, " '%s' using 1:4 with lines lw 3,\\\n", data_filename ); fprintf ( command_unit, " '%s' using 1:5 with lines lw 3\n", data_filename ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Plot commands stored in '%s'\n", command_filename ); /* Free memory. */ free ( t ); free ( y ); /* Terminate. */ printf ( "\n" ); printf ( "flame_exact_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ double *r8vec_linspace_new ( int n, double a, double b ) /******************************************************************************/ /* Purpose: r8vec_linspace_new() creates a vector of linearly spaced values. Discussion: An R8VEC is a vector of R8's. 4 points evenly spaced between 0 and 12 will yield 0, 4, 8, 12. In other words, the interval is divided into N-1 even subintervals, and the endpoints of intervals are used as the points. Licensing: This code is distributed under the MIT license. Modified: 29 March 2011 Author: John Burkardt Input: int N, the number of entries in the vector. double A, B, the first and last entries. Output: double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. */ { int i; double *x; x = ( double * ) malloc ( n * sizeof ( double ) ); if ( n == 1 ) { x[0] = ( a + b ) / 2.0; } else { for ( i = 0; i < n; i++ ) { x[i] = ( ( double ) ( n - 1 - i ) * a + ( double ) ( i ) * b ) / ( double ) ( n - 1 ); } } return x; } /******************************************************************************/ 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 }