private static void sgmga_write_test(int dim_num, double[] level_weight, int level_max, int[] rule, int[] growth, int[] np, double[] p, Func <int, int, double[], double[], double[]>[] gw_compute_points, Func <int, int, double[], double[], double[]>[] gw_compute_weights, double tol, string file_name) //***************************************************************************80 // // Purpose: // // SGMGA_WRITE_TEST tests SGMGA_WRITE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 07 June 2010 // // Author: // // John Burkardt // // Parameters: // // Input, integer DIM_NUM, the spatial dimension. // // Input, double LEVEL_WEIGHT[DIM_NUM], the weights for each dimension. // // Input, integer LEVEL_MAX, the level that defines the grid. // // Input, int RULE[DIM_NUM], the rule in each dimension. // 1, "CC", Clenshaw Curtis, Closed Fully Nested. // 2, "F2", Fejer Type 2, Open Fully Nested. // 3, "GP", Gauss Patterson, Open Fully Nested. // 4, "GL", Gauss Legendre, Open Weakly Nested. // 5, "GH", Gauss Hermite, Open Weakly Nested. // 6, "GGH", Generalized Gauss Hermite, Open Weakly Nested. // 7, "LG", Gauss Laguerre, Open Non Nested. // 8, "GLG", Generalized Gauss Laguerre, Open Non Nested. // 9, "GJ", Gauss Jacobi, Open Non Nested. // 10, "HGK", Hermite Genz-Keister, Open Fully Nested. // 11, "UO", User supplied Open, presumably Non Nested. // 12, "UC", User supplied Closed, presumably Non Nested. // // Input, int GROWTH[DIM_NUM], the desired growth in each dimension. // 0, "DF", default growth associated with this quadrature rule; // 1, "SL", slow linear, L+1; // 2 "SO", slow linear odd, O=1+2((L+1)/2) // 3, "ML", moderate linear, 2L+1; // 4, "SE", slow exponential; // 5, "ME", moderate exponential; // 6, "FE", full exponential. // // Input, int NP[RULE_NUM], the number of parameters used by each rule. // // Input, double P[sum(NP[*])], the parameters needed by each rule. // // Input, void ( *GW_COMPUTE_POINTS[] ) ( int order, int np, double p[], double x[] ), // an array of pointers to functions which return the 1D quadrature points // associated with each spatial dimension for which a Golub Welsch rule // is used. // // Input, void ( *GW_COMPUTE_WEIGHTS[] ) ( int order, int np, double p[], double w[] ), // an array of pointers to functions which return the 1D quadrature weights // associated with each spatial dimension for which a Golub Welsch rule // is used. // // Input, double TOL, a tolerance for point equality. // // Input, string FILE_NAME, the main name of the output files. // { Console.WriteLine(""); Console.WriteLine("SGMGA_WRITE_TEST"); Console.WriteLine(" SGMGA_WRITE writes a sparse grid rule to files."); // // Compute necessary data. // int point_total_num = SGMGAniso.sgmga_size_total(dim_num, level_weight, level_max, rule, growth); int point_num = SGMGAniso.sgmga_size(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, tol, growth); int[] sparse_unique_index = new int[point_total_num]; SGMGAniso.sgmga_unique_index(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, tol, point_num, point_total_num, growth, ref sparse_unique_index); int[] sparse_order = new int[dim_num * point_num]; int[] sparse_index = new int[dim_num * point_num]; SGMGAniso.sgmga_index(dim_num, level_weight, level_max, rule, point_num, point_total_num, sparse_unique_index, growth, ref sparse_order, ref sparse_index); // // Compute points and weights. // double[] sparse_point = new double [dim_num * point_num]; SGMGAniso.sgmga_point(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, point_num, sparse_order, sparse_index, growth, ref sparse_point); double[] sparse_weight = new double[point_num]; SGMGAniso.sgmga_weight(dim_num, level_weight, level_max, rule, np, p, gw_compute_weights, point_num, point_total_num, sparse_unique_index, growth, sparse_weight); // // Write points and weights to files. // SGMGAniso.sgmga_write(dim_num, level_weight, rule, np, p, point_num, sparse_weight, sparse_point, file_name); }
private static void sgmga_point_test(int dim_num, double[] importance, double[] level_weight, int level_max_min, int level_max_max, int[] rule, int[] growth, int[] np, double[] p, Func <int, int, double[], double[], double[]>[] gw_compute_points, double tol) //***************************************************************************80 // // Purpose: // // SGMGA_POINT_TEST tests SGMGA_POINT. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 June 2010 // // Author: // // John Burkardt // // Parameters: // // Input, int DIM_NUM, the spatial dimension. // // Input, double IMPORTANCE[DIM_NUM], the importamce for each dimension. // // Input, double LEVEL_WEIGHT[DIM_NUM], the weights for each dimension. // // Input, int LEVEL_MAX_MIN, LEVEL_MAX_MAX, the minimum and // maximum values of LEVEL_MAX. // // Input, int RULE[DIM_NUM], the rule in each dimension. // 1, "CC", Clenshaw Curtis, Closed Fully Nested. // 2, "F2", Fejer Type 2, Open Fully Nested. // 3, "GP", Gauss Patterson, Open Fully Nested. // 4, "GL", Gauss Legendre, Open Weakly Nested. // 5, "GH", Gauss Hermite, Open Weakly Nested. // 6, "GGH", Generalized Gauss Hermite, Open Weakly Nested. // 7, "LG", Gauss Laguerre, Open Non Nested. // 8, "GLG", Generalized Gauss Laguerre, Open Non Nested. // 9, "GJ", Gauss Jacobi, Open Non Nested. // 10, "HGK", Hermite Genz-Keister, Open Fully Nested. // 11, "UO", User supplied Open, presumably Non Nested. // 12, "UC", User supplied Closed, presumably Non Nested. // // Input, int GROWTH[DIM_NUM], the desired growth in each dimension. // 0, "DF", default growth associated with this quadrature rule; // 1, "SL", slow linear, L+1; // 2 "SO", slow linear odd, O=1+2((L+1)/2) // 3, "ML", moderate linear, 2L+1; // 4, "SE", slow exponential; // 5, "ME", moderate exponential; // 6, "FE", full exponential. // // Input, int NP[RULE_NUM], the number of parameters used by each rule. // // Input, double P[sum(NP[*])], the parameters needed by each rule. // // Input, void ( *GW_COMPUTE_POINTS[] ) ( int order, int np, double p[], double x[] ), // an array of pointers to functions which return the 1D quadrature points // associated with each spatial dimension for which a Golub Welsch rule // is used. // // Input, double TOL, a tolerance for point equality. // { int dim; int level_max; Console.WriteLine(""); Console.WriteLine("SGMGA_POINT_TEST"); Console.WriteLine(" SGMGA_POINT returns an array of the points"); Console.WriteLine(" forming a multidimensional sparse grid with mixed factors."); Console.WriteLine(""); Console.WriteLine(" Each sparse grid is of spatial dimension DIM_NUM,"); Console.WriteLine(" and is made up of product grids of levels up to LEVEL_MAX."); Console.WriteLine(""); string cout = " IMPORTANCE: "; for (dim = 0; dim < dim_num; dim++) { cout += " " + importance[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); cout = " LEVEL_WEIGHT:"; for (dim = 0; dim < dim_num; dim++) { cout += " " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); Console.WriteLine(""); Console.WriteLine(" Dimension Rule Growth rate Parameters"); Console.WriteLine(""); int p_index = 0; for (dim = 0; dim < dim_num; dim++) { int i; double alpha; switch (rule[dim]) { case 1: case 2: case 3: case 4: case 5: Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + ""); break; case 6: alpha = p[p_index]; p_index += 1; Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); break; case 7: Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + ""); break; case 8: alpha = p[p_index]; p_index += 1; Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); break; case 9: alpha = p[p_index]; p_index += 1; double beta = p[p_index]; p_index += 1; Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + beta.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); break; case 10: Console.WriteLine(" " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8) + ""); break; case 11: { cout = " " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8); for (i = 0; i < np[dim]; i++) { alpha = p[p_index]; p_index += 1; cout += " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); break; } case 12: { cout = " " + dim.ToString().PadLeft(8) + " " + rule[dim].ToString().PadLeft(8) + " " + growth[dim].ToString().PadLeft(8); for (i = 0; i < np[dim]; i++) { alpha = p[p_index]; p_index += 1; cout += " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14); } Console.WriteLine(cout); break; } default: Console.WriteLine(""); Console.WriteLine("SGMGA_POINT_TEST - Fatal error!"); Console.WriteLine(" Unexpected value of RULE = " + rule[dim] + ""); return; } } for (level_max = level_max_min; level_max <= level_max_max; level_max++) { int point_total_num = SGMGAniso.sgmga_size_total(dim_num, level_weight, level_max, rule, growth); int point_num = SGMGAniso.sgmga_size(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, tol, growth); int[] sparse_unique_index = new int[point_total_num]; SGMGAniso.sgmga_unique_index(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, tol, point_num, point_total_num, growth, ref sparse_unique_index); int[] sparse_order = new int[dim_num * point_num]; int[] sparse_index = new int[dim_num * point_num]; SGMGAniso.sgmga_index(dim_num, level_weight, level_max, rule, point_num, point_total_num, sparse_unique_index, growth, ref sparse_order, ref sparse_index); double[] sparse_point = new double [dim_num * point_num]; SGMGAniso.sgmga_point(dim_num, level_weight, level_max, rule, np, p, gw_compute_points, point_num, sparse_order, sparse_index, growth, ref sparse_point); Console.WriteLine(""); Console.WriteLine(" For LEVEL_MAX = " + level_max + ""); Console.WriteLine(""); int point; for (point = 0; point < point_num; point++) { cout = " " + point.ToString().PadLeft(4) + " "; for (dim = 0; dim < dim_num; dim++) { cout += " " + sparse_point[dim + point * dim_num].ToString(CultureInfo.InvariantCulture).PadLeft(10); } Console.WriteLine(cout); } } }