# include # include # include # include # include # include # include using namespace std; # include "doughnut_exact.hpp" int main ( ); double *r8vec_linspace_new ( int n, double a, double b ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // doughnut_exact_test() tests doughnut_exact(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 13 October 2025 // // Author: // // John Burkardt // { string command_filename; ofstream command; string data_filename; ofstream data; int i; double m; double n; int nt; double *t; double t0; double tstop; double *y; double y0[3]; timestamp ( ); cout << "\n"; cout << "doughnut_exact_test():\n"; cout << " C++ version\n"; cout << " Test doughnut_exact(), which evaluates exact solutions\n"; cout << " of the doughnut ODE.\n"; doughnut_parameters ( NULL, NULL, NULL, NULL, NULL, &m, &n, &t0, y0, &tstop ); cout << "\n"; cout << " Parameter values:\n"; cout << " m = " << m << "\n"; cout << " n = " << n << "\n"; cout << " t0 = " << t0 << "\n"; cout << " y0 = " << y0[0] << ", " << y0[1] << ", " << y0[2] << "\n"; cout << " tstop = " << tstop << "\n"; nt = 1001; t = r8vec_linspace_new ( nt, t0, tstop ); y = doughnut_exact ( nt, t ); // // Plot. // data_filename = "doughnut_exact_data.txt"; data.open ( data_filename.c_str ( ) ); for ( i = 0; i < nt; i++ ) { data << " " << t[i] << " " << y[0+i*3] << " " << y[1+i*3] << " " << y[2+i*3] << "\n"; } data.close ( ); cout << " Created data file '" << data_filename << "'.\n"; // // Create the command file. // command_filename = "doughnut_exact_commands.txt"; command.open ( command_filename.c_str ( ) ); command << "# " << command_filename << "\n"; command << "#\n"; command << "# Usage:\n"; command << "# gnuplot < " << command_filename << "\n"; command << "#\n"; command << "set term png\n"; command << "set output 'doughnut_exact.png'\n"; command << "set xlabel '<--- X(T) --->'\n"; command << "set ylabel '<--- Y(T) --->'\n"; command << "set zlabel '<--- Z(T) --->'\n"; command << "set title '(X(T),Y(T),Z(T)) trajectory'\n"; command << "set grid\n"; command << "set style data lines\n"; command << "splot '" << data_filename << "' using 2:3:4 lw 2 linecolor rgb 'blue'\n"; command << "quit\n"; command.close ( ); cout << " Created command file '" << command_filename << "'\n"; // // Free memory. // delete [] t; delete [] y; // // Terminate. // cout << "\n"; cout << "doughnut_exact_test():\n"; cout << " Normal end of execution.\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 // // Input: // // int N, the number of entries in the vector. // // 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 }