void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 tests NACA4_SYMMETRIC. Licensing: This code is distributed under the GNU LGPL license. Modified: 22 May 2014 Author: John Burkardt */ { double c; char command_filename[] = "symmetric_commands.txt"; FILE *command_unit; char data_filename[] = "symmetric_data.txt"; int i; int n = 51; double ratio; double t; double *x; double x_max; double x_min; double *xy; double *y; double y_max; double y_min; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " NACA4_SYMMETRIC evaluates y(x) for a NACA\n" ); printf ( " symmetric airfoil defined by a 4-digit code.\n" ); c = 10.0; t = 0.15; x = r8vec_linspace_new ( n, 0.0, c ); y = naca4_symmetric ( t, c, n, x ); /* Reorganize data into a single object. */ xy = ( double * ) malloc ( 2 * 2 * n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { xy[0+i*2] = x[i]; xy[1+i*2] = -y[i]; } for ( i = 0; i < n; i++ ) { xy[0+(n+i)*2] = x[n-1-i]; xy[1+(n+i)*2] = y[n-1-i]; } /* Determine size ratio. */ x_min = r8vec_min ( n, x ); x_max = r8vec_max ( n, x ); y_max = r8vec_max ( n, y ); y_min = - y_max; ratio = ( y_max - y_min ) / ( x_max - x_min ); /* Save data to a file. */ r8mat_write ( data_filename, 2, 2 * n, xy ); printf ( " Data saved in file '%s'\n", data_filename ); /* Create the command file. */ command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "set size ratio %g\n", ratio ); fprintf ( command_unit, "set timestamp\n" ); fprintf ( command_unit, "unset key\n" ); fprintf ( command_unit, "set output 'symmetric.png'\n" ); fprintf ( command_unit, "set xlabel '<---X--->'\n" ); fprintf ( command_unit, "set ylabel '<---Y--->'\n" ); fprintf ( command_unit, "set title 'NACA Symmetric Airfoil'\n" ); fprintf ( command_unit, "plot '%s' using 1:2 with lines lw 3\n", data_filename ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Created command file '%s'\n", command_filename ); free ( x ); free ( y ); return; }
void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 samples the solution at the initial time. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 January 2015 Author: John Burkardt */ { double a; double d; int n; double *p; const double r8_pi = 3.141592653589793; int seed; double t; double *u; double *v; double *w; double *x; double xyz_hi; double xyz_lo; double *y; double *z; a = r8_pi / 4.0; d = r8_pi / 2.0; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Estimate the range of velocity and pressure\n" ); printf ( " at the initial time T = 0, in a region that is the\n" ); printf ( " cube centered at (0,0,0) with 'radius' 1.0.\n" ); printf ( " Parameter A = %g\n", a ); printf ( " Parameter D = %g\n", d ); n = 1000; p = ( double * ) malloc ( n * sizeof ( double ) ); u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); w = ( double * ) malloc ( n * sizeof ( double ) ); xyz_lo = -1.0; xyz_hi = +1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); y = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); z = r8vec_uniform_ab_new ( n, xyz_lo, xyz_hi, &seed ); t = 0.0; uvwp_ethier ( a, d, n, x, y, z, t, u, v, w, p ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); printf ( " W: %14.6g %14.6g\n", r8vec_min ( n, w ), r8vec_max ( n, w ) ); printf ( " P: %14.6g %14.6g\n", r8vec_min ( n, p ), r8vec_max ( n, p ) ); free ( p ); free ( u ); free ( v ); free ( w ); free ( x ); free ( y ); free ( z ); return; }
int ellipsoid_grid_count ( int n, double r[3], double c[3] ) /******************************************************************************/ /* ELLIPSOID_GRID_COUNT counts the grid points inside an ellipsoid. Discussion: The ellipsoid is specified as ( ( X - C1 ) / R1 )^2 + ( ( Y - C2 ) / R2 )^2 + ( ( Z - C3 ) / R3 )^2 = 1 The user supplies a number N. There will be N+1 grid points along the shortest axis. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 November 2011 Author: John Burkardt Parameters: Input, int N, the number of subintervals. Input, double R[3], the half axis lengths. Input, double C[3], the center of the ellipsoid. Output, int ELLIPSOID_GRID_COUNT, the number of grid points. */ { double h; int i; int j; int k; int m; int ng; int ni; int nj; int nk; int np; double rmin; double x; double y; double z; ng = 0; rmin = r8vec_min ( 3, r ); if ( r[0] == rmin ) { h = 2.0 * r[0] / ( double ) ( 2 * n + 1 ); ni = n; nj = i4_ceiling ( r[1] / r[0] ) * ( double ) ( n ); nk = i4_ceiling ( r[2] / r[0] ) * ( double ) ( n ); } else if ( r[1] == rmin ) { h = 2.0 * r[1] / ( double ) ( 2 * n + 1 ); nj = n; ni = i4_ceiling ( r[0] / r[1] ) * ( double ) ( n ); nk = i4_ceiling ( r[2] / r[1] ) * ( double ) ( n ); } else { h = 2.0 * r[2] / ( double ) ( 2 * n + 1 ); nk = n; ni = i4_ceiling ( r[0] / r[2] ) * ( double ) ( n ); nj = i4_ceiling ( r[1] / r[2] ) * ( double ) ( n ); } for ( k = 0; k <= nk; k++ ) { z = c[2] + ( double ) ( k ) * h; for ( j = 0; j <= nj; j++ ) { y = c[1] + ( double ) ( j ) * h; for ( i = 0; i <= ni; i++ ) { x = c[0] + ( double ) ( i ) * h; // // If we have left the ellipsoid, the I loop is completed. // if ( 1.0 < pow ( ( x - c[0] ) / r[0], 2 ) + pow ( ( y - c[1] ) / r[1], 2 ) + pow ( ( z - c[2] ) / r[2], 2 ) ) { break; } // // At least one point is generated, but more possible by symmetry. // np = 1; if ( 0 < i ) { np = 2 * np; } if ( 0 < j ) { np = 2 * np; } if ( 0 < k ) { np = 2 * np; } ng = ng + np; } } } return ng; }
void test02 ( ) /******************************************************************************/ /* Purpose: TEST02 tests NACA4_CAMBERED. Licensing: This code is distributed under the GNU LGPL license. Modified: 21 May 2014 Author: John Burkardt */ { double c; char command_filename[] = "cambered_commands.txt"; FILE *command_unit; char data_filename[] = "cambered_data.txt"; int i; double m; int n = 51; double p; double ratio; double t; double x_max; double x_min; double *xc; double *xl; double *xu; double *xy; double y_max; double y_min; double *yl; double *yu; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " NACA4_CAMBERED evaluates (xu,yu) and (xl,yl) for a NACA\n" ); printf ( " cambered airfoil defined by a 4-digit code.\n" ); m = 0.02; p = 0.4; t = 0.12; c = 10.0; xc = r8vec_linspace_new ( n, 0.0, c ); xu = ( double * ) malloc ( n * sizeof ( double ) ); xl = ( double * ) malloc ( n * sizeof ( double ) ); yu = ( double * ) malloc ( n * sizeof ( double ) ); yl = ( double * ) malloc ( n * sizeof ( double ) ); naca4_cambered ( m, p, t, c, n, xc, xu, yu, xl, yl ); /* Reorganize data into a single object. */ xy = ( double * ) malloc ( 2 * 2 * n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { xy[0+i*2] = xl[i]; xy[1+i*2] = yl[i]; } for ( i = 0; i < n; i++ ) { xy[0+(n+i)*2] = xu[n-1-i]; xy[1+(n+i)*2] = yu[n-1-i]; } /* Determine size ratio. */ x_min = r8_min ( r8vec_min ( n, xl ), r8vec_min ( n, xu ) ); x_max = r8_max ( r8vec_max ( n, xl ), r8vec_max ( n, xu ) ); y_min = r8_min ( r8vec_min ( n, yl ), r8vec_min ( n, yu ) ); y_max = r8_max ( r8vec_max ( n, yl ), r8vec_max ( n, yu ) ); ratio = ( y_max - y_min ) / ( x_max - x_min ); /* Save data to a file. */ r8mat_write ( data_filename, 2, 2 * n, xy ); printf ( " Data saved in file '%s'\n", data_filename ); /* Create the command file. */ command_unit = fopen ( command_filename, "wt" ); fprintf ( command_unit, "set term png\n" ); fprintf ( command_unit, "set grid\n" ); fprintf ( command_unit, "set style data lines\n" ); fprintf ( command_unit, "set size ratio %g\n", ratio ); fprintf ( command_unit, "set timestamp\n" ); fprintf ( command_unit, "unset key\n" ); fprintf ( command_unit, "set output 'cambered.png'\n" ); fprintf ( command_unit, "set xlabel '<---X--->'\n" ); fprintf ( command_unit, "set ylabel '<---Y--->'\n" ); fprintf ( command_unit, "set title 'NACA Cambered Airfoil'\n" ); fprintf ( command_unit, "plot '%s' using 1:2 with lines lw 3\n", data_filename ); fprintf ( command_unit, "quit\n" ); fclose ( command_unit ); printf ( " Created command file '%s'\n", command_filename ); free ( xc ); free ( xl ); free ( xu ); free ( xy ); free ( yl ); free ( yu ); return; }
double *ellipsoid_grid ( int n, double r[3], double c[3], int ng ) /******************************************************************************/ /* Purpose: ELLIPSOID_GRID generates the grid points inside an ellipsoid. Discussion: The ellipsoid is specified as ( ( X - C1 ) / R1 )^2 + ( ( Y - C2 ) / R2 )^2 + ( ( Z - C3 ) / R3 )^2 = 1 The user supplies a number N. There will be N+1 grid points along the shortest axis. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 November 2011 Author: John Burkardt Parameters: Input, int N, the number of subintervals. Input, double R[3], the half axis lengths. Input, double C[3], the center of the ellipsoid. Input, int NG, the number of grid points. Output, double XYZ[3*NG], the grid point coordinates. */ { double h; int ii; int i; int j; int k; int m; int ng2; int ni; int nj; int nk; int np; double p[3*8]; double rmin; double x; double *xyz; double y; double z; ng2 = 0; xyz = ( double * ) malloc ( 3 * ng * sizeof ( double ) ); rmin = r8vec_min ( 3, r ); if ( r[0] == rmin ) { h = 2.0 * r[0] / ( double ) ( 2 * n + 1 ); ni = n; nj = i4_ceiling ( r[1] / r[0] ) * ( double ) ( n ); nk = i4_ceiling ( r[2] / r[0] ) * ( double ) ( n ); } else if ( r[1] == rmin ) { h = 2.0 * r[1] / ( double ) ( 2 * n + 1 ); nj = n; ni = i4_ceiling ( r[0] / r[1] ) * ( double ) ( n ); nk = i4_ceiling ( r[2] / r[1] ) * ( double ) ( n ); } else { h = 2.0 * r[2] / ( double ) ( 2 * n + 1 ); nk = n; ni = i4_ceiling ( r[0] / r[2] ) * ( double ) ( n ); nj = i4_ceiling ( r[1] / r[2] ) * ( double ) ( n ); } for ( k = 0; k <= nk; k++ ) { z = c[2] + ( double ) ( k ) * h; for ( j = 0; j <= nj; j++ ) { y = c[1] + ( double ) ( j ) * h; for ( i = 0; i <= ni; i++ ) { x = c[0] + ( double ) ( i ) * h; /* If we have left the ellipsoid, the I loop is completed. */ if ( 1.0 < pow ( ( x - c[0] ) / r[0], 2 ) + pow ( ( y - c[1] ) / r[1], 2 ) + pow ( ( z - c[2] ) / r[2], 2 ) ) { break; } /* At least one point is generated, but more possible by symmetry. */ np = 0; p[0+np*3] = x; p[1+np*3] = y; p[2+np*3] = z; np = 1; if ( 0 < i ) { for ( m = 0; m < np; m++ ) { p[0+(np+m)*3] = 2.0 * c[0] - p[0+m*3]; p[1+(np+m)*3] = p[1+m*3]; p[2+(np+m)*3] = p[2+m*3]; } np = 2 * np; } if ( 0 < j ) { for ( m = 0; m < np; m++ ) { p[0+(np+m)*3] = p[0+m*3]; p[1+(np+m)*3] = 2.0 * c[1] - p[1+m*3]; p[2+(np+m)*3] = p[2+m*3]; } np = 2 * np; } if ( 0 < k ) { for ( m = 0; m < np; m++ ) { p[0+(np+m)*3] = p[0+m*3]; p[1+(np+m)*3] = p[1+m*3]; p[2+(np+m)*3] = 2.0 * c[2] - p[2+m*3]; } np = 2 * np; } for ( m = 0; m < np; m++ ) { for ( ii = 0; ii < 3; ii++ ) { xyz[ii+(ng2+m)*3] = p[ii+m*3]; } } ng2 = ng2 + np; } } } return xyz; }
void test02 ( void ) /******************************************************************************/ /* Purpose: TEST02 evaluates the objective function at each starting point. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 February 2012 Author: John Burkardt */ { double *a; double *b; double *f; double *fs; int i; int know; int m; int n = 100000; int problem; int problem_num; int seed; char title[100]; double *x; double *xs; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " For each problem, evaluate the function at many points.\n" ); printf ( " Number of sample points = %d\n", n ); /* Get the number of problems. */ problem_num = p00_problem_num ( ); for ( problem = 1; problem <= problem_num; problem++ ) { printf ( "\n" ); printf ( " Problem %d\n", problem ); p00_title ( problem, title ); printf ( " %s\n", title ); m = p00_m ( problem ); printf ( " M = %d\n", m ); a = ( double * ) malloc ( m * sizeof ( double ) ); b = ( double * ) malloc ( m * sizeof ( double ) ); p00_ab ( problem, m, a, b ); printf ( "\n" ); printf ( " I A(i) B(i)\n" ); printf ( "\n" ); for ( i = 0; i < m; i++ ) { printf ( " %4d %10g %10g\n", i, a[i], b[i] ); } seed = 123456789; x = r8col_uniform_new ( m, n, a, b, &seed ); f = p00_f ( problem, m, n, x ); printf ( "\n" ); printf ( " Max(F) = %g\n", r8vec_max ( n, f ) ); printf ( " Min(F) = %g\n", r8vec_min ( n, f ) ); know = 0; xs = p00_sol ( problem, m, &know ); if ( know != 0 ) { fs = p00_f ( problem, m, 1, xs ); printf ( " F(X*) = %g\n", fs[0] ); free ( fs ); free ( xs ); } else { printf ( " X* is not given.\n" ); } free ( a ); free ( b ); free ( f ); free ( x ); } return; }
void uvp_stokes1_test ( ) /******************************************************************************/ /* Purpose: UVP_STOKES1_TEST samples the solution #1. Licensing: This code is distributed under the GNU LGPL license. Modified: 24 January 2015 Author: John Burkardt */ { int n = 1000; double *p; int seed; double *u; double *v; double *x; double xy_hi; double xy_lo; double *y; printf ( "\n" ); printf ( "UVP_STOKES1_TEST\n" ); printf ( " Exact Stokes solution #1:\n" ); printf ( " Estimate the range of velocity and pressure\n" ); printf ( " using a region that is the unit square.\n" ); xy_lo = 0.0; xy_hi = 1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); y = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); p = ( double * ) malloc ( n * sizeof ( double ) ); uvp_stokes1 ( n, x, y, u, v, p ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); printf ( " P: %14.6g %14.6g\n", r8vec_min ( n, p ), r8vec_max ( n, p ) ); free ( p ); free ( u ); free ( v ); free ( x ); free ( y ); return; }
void test02 ( void ) /******************************************************************************/ /* Purpose: TEST02 samples each function using each grid. Licensing: This code is distributed under the GNU LGPL license. Modified: 30 January 2012 Author: John Burkardt */ { double *f; double f_ave; double f_max; double f_min; int f_num; int fi; char ft[100]; int g_num; int gi; int gn; char gt[100]; double *gx; double *gy; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " Sample each function over each grid.\n" ); g_num = g00_num ( ); f_num = f00_num ( ); for ( fi = 1; fi <= f_num; fi++ ) { f00_title ( fi, ft ); printf ( "\n" ); printf ( " %2d %s\n", fi, ft ); printf ( " Grid Title " ); printf ( "Min(F) Ave(F) Max(F)\n" ); printf ( "\n" ); for ( gi = 1; gi <= g_num; gi++ ) { g00_title ( gi, gt ); gn = g00_size ( gi ); gx = ( double * ) malloc ( gn * sizeof ( double ) ); gy = ( double * ) malloc ( gn * sizeof ( double ) ); g00_xy ( gi, gn, gx, gy ); f = ( double * ) malloc ( gn * sizeof ( double ) ); f00_f0 ( fi, gn, gx, gy, f ); f_max = r8vec_max ( gn, f ); f_min = r8vec_min ( gn, f ); f_ave = r8vec_sum ( gn, f ); f_ave = f_ave / ( double ) ( gn ); printf ( " %4d %25s %14g %14g %14g\n", gi, gt, f_min, f_ave, f_max ); free ( f ); free ( gx ); free ( gy ); } } return; }
void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 generates a field and estimates its range. Licensing: This code is distributed under the GNU LGPL license. Modified: 19 January 2015 Author: John Burkardt */ { int n; double c; int seed; double *u; double *v; double *x; double xy_hi; double xy_lo; double *y; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Sample a spiral velocity field and estimate\n" ); printf ( " the range of the solution values.\n" ); n = 1000; xy_lo = +0.0; xy_hi = +1.0; seed = 123456789; x = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); y = r8vec_uniform_ab_new ( n, xy_lo, xy_hi, &seed ); c = 1.0; u = ( double * ) malloc ( n * sizeof ( double ) ); v = ( double * ) malloc ( n * sizeof ( double ) ); uv_spiral ( n, x, y, c, u, v ); printf ( "\n" ); printf ( " Minimum Maximum\n" ); printf ( "\n" ); printf ( " U: %14.6g %14.6g\n", r8vec_min ( n, u ), r8vec_max ( n, u ) ); printf ( " V: %14.6g %14.6g\n", r8vec_min ( n, v ), r8vec_max ( n, v ) ); free ( u ); free ( v ); free ( x ); free ( y ); return; }