# include # include # include # include # include # include using namespace std; # include "flame_exact.hpp" int main ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // 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; string command_filename; ofstream command_unit; string data_filename; ofstream data_unit; string 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 ( ); cout << "\n"; cout << "flame_exact_test():\n"; cout << " C++ version\n"; cout << " 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 ); cout << "\n"; cout << " parameters:\n"; cout << " t0 = " << t0 << "\n"; cout << " tstop = " << tstop << "\n"; // // Compute (t,y) pairs for n times, and r values of y0. // t = r8vec_linspace_new ( n, t0, tstop ); y = new double[n*r]; for ( j = 0; j < r; j++ ) { y0 = y0_vec[j]; cout << " y0 = " << y0 << "\n"; flame_parameters ( NULL, &y0, NULL, NULL, NULL, NULL ); flame_exact ( n, t, y + n*j ); } // // Create the data file. // data_filename = header + "_data.txt"; data_unit.open ( data_filename.c_str ( ) ); for ( i = 0; i < n; i++ ) { data_unit << t[i]; for ( j = 0; j < r; j++ ) { data_unit << " " << y[i+j*n]; } data_unit << "\n"; } data_unit.close ( ); cout << "\n"; cout << " Data stored in '" << data_filename << "'\n"; // // Create the command file. // command_filename = header + "_commands.txt"; command_unit.open ( command_filename.c_str ( ) ); command_unit << "# " << command_filename << "\n"; command_unit << "#\n"; command_unit << "# Usage:\n"; command_unit << "# gnuplot < " << command_filename << "\n"; command_unit << "#\n"; command_unit << "set term png\n"; command_unit << "set output '" << header << ".png'\n"; command_unit << "set xlabel '<-- t -->'\n"; command_unit << "set ylabel '<-- y(t) -->'\n"; command_unit << "set title 'flame_exact:'\n"; command_unit << "set grid\n"; command_unit << "set style data lines\n"; command_unit << "plot '" << data_filename << "' using 1:2 with lines lw 3,\\\n"; command_unit << " '" << data_filename << "' using 1:3 with lines lw 3,\\\n"; command_unit << " '" << data_filename << "' using 1:4 with lines lw 3,\\\n"; command_unit << " '" << data_filename << "' using 1:5 with lines lw 3\n"; command_unit << "quit\n"; command_unit.close ( ); cout << " Plot commands stored in '" << command_filename << "'\n"; // // Free memory. // delete [] t; delete [] y; // // Terminate. // cout << "\n"; cout << "flame_exact_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 double *r8vec_linspace_new ( int n, double a_first, double a_last ) //****************************************************************************80 // // 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 // // Parameters: // // Input, int N, the number of entries in the vector. // // Input, double A_FIRST, A_LAST, the first and last entries. // // Output, double R8VEC_LINSPACE_NEW[N], a vector of linearly spaced data. // { double *a; int i; a = new double[n]; if ( n == 1 ) { a[0] = ( a_first + a_last ) / 2.0; } else { for ( i = 0; i < n; i++ ) { a[i] = ( ( double ) ( n - 1 - i ) * a_first + ( double ) ( i ) * a_last ) / ( double ) ( n - 1 ); } } return a; } //****************************************************************************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 }