# include # include # include # include # include # include using namespace std; # include "tetrahedron_grid.hpp" //****************************************************************************80 int i4_max ( int i1, int i2 ) //****************************************************************************80 // // Purpose: // // I4_MAX returns the maximum of two I4's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 13 October 1998 // // Author: // // John Burkardt // // Parameters: // // Input, int I1, I2, are two integers to be compared. // // Output, int I4_MAX, the larger of I1 and I2. // { int value; if ( i2 < i1 ) { value = i1; } else { value = i2; } return value; } //****************************************************************************80 int i4_min ( int i1, int i2 ) //****************************************************************************80 // // Purpose: // // I4_MIN returns the minimum of two I4's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 13 October 1998 // // Author: // // John Burkardt // // Parameters: // // Input, int I1, I2, two integers to be compared. // // Output, int I4_MIN, the smaller of I1 and I2. // { int value; if ( i1 < i2 ) { value = i1; } else { value = i2; } return value; } //****************************************************************************80 void r83vec_print_part ( int n, double a[], int max_print, string title ) //****************************************************************************80 // // Purpose: // // R83VEC_PRINT_PART prints "part" of an R83VEC. // // Discussion: // // An R83VEC is an array of triples of R8's. // // The user specifies MAX_PRINT, the maximum number of lines to print. // // If N, the size of the vector, is no more than MAX_PRINT, then // the entire vector is printed, one entry per line. // // Otherwise, if possible, the first MAX_PRINT-2 entries are printed, // followed by a line of periods suggesting an omission, // and the last entry. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 November 2011 // // Author: // // John Burkardt // // Parameters: // // Input, int N, the number of entries of the vector. // // Input, double A[3*N], the vector to be printed. // // Input, int MAX_PRINT, the maximum number of lines // to print. // // Input, string TITLE, a title. // { int i; if ( max_print <= 0 ) { return; } if ( n <= 0 ) { return; } cout << "\n"; cout << title << "\n"; cout << "\n"; if ( n <= max_print ) { for ( i = 0; i < n; i++ ) { cout << " " << setw(8) << i << " " << setw(14) << a[0+i*3] << " " << setw(14) << a[1+i*3] << " " << setw(14) << a[2+i*3] << "\n"; } } else if ( 3 <= max_print ) { for ( i = 0; i < max_print - 2; i++ ) { cout << " " << setw(8) << i << ": " << setw(14) << a[0+i*3] << " " << setw(14) << a[1+i*3] << " " << setw(14) << a[2+i*3] << "\n"; } cout << " ........ .............. .............. ..............\n"; i = n - 1; cout << " " << setw(8) << i << ": " << setw(14) << a[0+i*3] << " " << setw(14) << a[1+i*3] << " " << setw(14) << a[2+i*3] << "\n"; } else { for ( i = 0; i < max_print - 1; i++ ) { cout << " " << setw(8) << i << ": " << setw(14) << a[0+i*3] << " " << setw(14) << a[1+i*3] << " " << setw(14) << a[2+i*3] << "\n"; } i = max_print - 1; cout << " " << setw(8) << i << ": " << setw(14) << a[0+i*3] << " " << setw(14) << a[1+i*3] << " " << setw(14) << a[2+i*3] << " " << "...more entries...\n"; } return; } //****************************************************************************80 void r8mat_print ( int m, int n, double a[], string title ) //****************************************************************************80 // // Purpose: // // R8MAT_PRINT prints an R8MAT, with an optional title. // // Discussion: // // An R8MAT is an array of R8's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 August 2003 // // Author: // // John Burkardt // // Parameters: // // Input, int M, the number of rows in A. // // Input, int N, the number of columns in A. // // Input, double A[M*N], the M by N matrix. // // Input, string TITLE, a title. // { r8mat_print_some ( m, n, a, 1, 1, m, n, title ); return; } //****************************************************************************80 void r8mat_print_some ( int m, int n, double a[], int ilo, int jlo, int ihi, int jhi, string title ) //****************************************************************************80 // // Purpose: // // R8MAT_PRINT_SOME prints some of an R8MAT. // // Discussion: // // An R8MAT is an array of R8's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 April 2004 // // Author: // // John Burkardt // // Parameters: // // Input, int M, the number of rows of the matrix. // M must be positive. // // Input, int N, the number of columns of the matrix. // N must be positive. // // Input, double A[M*N], the matrix. // // Input, int ILO, JLO, IHI, JHI, designate the first row and // column, and the last row and column to be printed. // // Input, string TITLE, a title. { # define INCX 5 int i; int i2hi; int i2lo; int j; int j2hi; int j2lo; cout << "\n"; cout << title << "\n"; // // Print the columns of the matrix, in strips of 5. // for ( j2lo = jlo; j2lo <= jhi; j2lo = j2lo + INCX ) { j2hi = j2lo + INCX - 1; j2hi = i4_min ( j2hi, n ); j2hi = i4_min ( j2hi, jhi ); cout << "\n"; // // For each column J in the current range... // // Write the header. // cout << " Col: "; for ( j = j2lo; j <= j2hi; j++ ) { cout << setw(7) << j << " "; } cout << "\n"; cout << " Row\n"; cout << " ---\n"; // // Determine the range of the rows in this strip. // i2lo = i4_max ( ilo, 1 ); i2hi = i4_min ( ihi, m ); for ( i = i2lo; i <= i2hi; i++ ) { // // Print out (up to) 5 entries in row I, that lie in the current strip. // cout << setw(5) << i << " "; for ( j = j2lo; j <= j2hi; j++ ) { cout << setw(12) << a[i-1+(j-1)*m] << " "; } cout << "\n"; } } return; # undef INCX } //****************************************************************************80 void r8mat_write ( string output_filename, int m, int n, double table[] ) //****************************************************************************80 // // Purpose: // // R8MAT_WRITE writes an R8MAT file. // // Discussion: // // An R8MAT is an array of R8's. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 June 2009 // // Author: // // John Burkardt // // Parameters: // // Input, string OUTPUT_FILENAME, the output filename. // // Input, int M, the spatial dimension. // // Input, int N, the number of points. // // Input, double TABLE[M*N], the data. // { int i; int j; ofstream output; // // Open the file. // output.open ( output_filename.c_str ( ) ); if ( !output ) { cerr << "\n"; cerr << "R8MAT_WRITE - Fatal error!\n"; cerr << " Could not open the output file.\n"; exit ( 1 ); } // // Write the data. // for ( j = 0; j < n; j++ ) { for ( i = 0; i < m; i++ ) { output << " " << setw(24) << setprecision(16) << table[i+j*m]; } output << "\n"; } // // Close the file. // output.close ( ); return; } //****************************************************************************80 double *tetrahedron_grid ( int n, double t[], int ng ) //****************************************************************************80 // // Purpose: // // TETRAHEDRON_GRID computes points on a tetrahedral grid. // // Discussion: // // The grid is defined by specifying the coordinates of an enclosing // tetrahedron T, and the number of subintervals each edge of the // tetrahedron should be divided into. // // Choosing N = 10, for instance, breaks each side into 10 subintervals, // and produces a grid of ((10+1)*(10+2)*(10+3))/6 = 286 points. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 November 2011 // // Author: // // John Burkardt // // Parameters: // // Input, int N, the number of subintervals. // // Input, double T[3*4], the vertices of the tetrahedron. // // Input, int NG, the number of grid points. // // Output, double TETRAHEDRON_GIRD[3*NG], the tetrahedron grid points. // { int i; int ii; int j; int k; int l; int p; double *tg; tg = new double[3*ng]; p = 0; for ( i = 0; i <= n; i++ ) { for ( j = 0; j <= n - i; j++ ) { for ( k = 0; k <= n - i - j; k++ ) { l = n - i - j - k; for ( ii = 0; ii < 3; ii++ ) { tg[ii+p*3] = ( ( double ) ( i ) * t[ii+0*3] + ( double ) ( j ) * t[ii+1*3] + ( double ) ( k ) * t[ii+2*3] + ( double ) ( l ) * t[ii+3*3] ) / ( double ) ( n ); } p = p + 1; } } } return tg; } //****************************************************************************80 int tetrahedron_grid_count ( int n ) //****************************************************************************80 // // Purpose: // // TETRAHEDRON_GRID_COUNT counts the grid points inside a tetrahedron. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 November 2011 // // Author: // // John Burkardt // // Parameters: // // Input, int N, the number of subintervals. // // Output, int TETRAHEDRON_GRID_COUNT, the number of grid points. // { int ng; ng = ( ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) / 6; return ng; } //****************************************************************************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 GNU LGPL license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // // Parameters: // // None // { # 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 }