private static void sgmga_aniso_normalize_test(int dim_num, double[] level_weight)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_ANISO_NORMALIZE_TEST calls SGMGA_ANISO_NORMALIZE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 November 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;
        int option;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_ANISO_NORMALIZE_TEST");
        Console.WriteLine("  Input weight sum: "
                          + typeMethods.r8vec_sum(dim_num, level_weight) + "");
        string cout = "";

        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
        }

        Console.WriteLine(cout);

        for (option = 0; option <= 2; option++)
        {
            SGMGAniso.sgmga_aniso_normalize(option, dim_num, ref level_weight);

            Console.WriteLine("  For OPTION = " + option
                              + "  Normalized weight sum: "
                              + typeMethods.r8vec_sum(dim_num, level_weight) + "");
            cout = "";
            for (dim = 0; dim < dim_num; dim++)
            {
                cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
            }

            Console.WriteLine(cout);
        }
    }
    private static void sgmga_aniso_balance_test(double alpha_max, int dim_num,
                                                 double[] level_weight)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_ANISO_BALANCE_TEST calls SGMGA_ANISO_BALANCE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    03 February 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_ANISO_BALANCE_TEST");
        Console.WriteLine("  ALPHA_MAX = " + alpha_max + "");
        Console.WriteLine("  Input weight sum: "
                          + typeMethods.r8vec_sum(dim_num, level_weight) + "");
        string cout = "";

        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
        }

        Console.WriteLine(cout);

        double[] level_weight2 = SGMGAniso.sgmga_aniso_balance(alpha_max, dim_num, level_weight);

        Console.WriteLine("  Output weight sum: "
                          + typeMethods.r8vec_sum(dim_num, level_weight2) + "");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight2[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
        }

        Console.WriteLine(cout);
    }
    private static void sgmga_importance_to_aniso_test(int dim_num, double[] importance,
                                                       double[] level_weight)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_IMPORTANCE_TO_ANISO_TEST calls SGMGA_IMPORTANCE_TO_ANISO.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 November 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_IMPORTANCE_TO_ANISO_TEST");
        Console.WriteLine("  Importances:");
        string cout = "";

        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + importance[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
        }

        Console.WriteLine(cout);

        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);

        Console.WriteLine("  Anisotropic coefficients:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(12);
        }

        Console.WriteLine(cout);
    }
Exemple #4
0
    private static void sgmga_unique_index_tests()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_UNIQUE_INDEX_TESTS calls SGMGA_UNIQUE_INDEX_TEST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Local Parameters:
    //
    //    Local, double TOL, a tolerance for point equality.
    //    A value of sqrt ( eps ) is reasonable, and will allow the code to
    //    consolidate points which are equal, or very nearly so.  A value of
    //    -1.0, on the other hand, will force the code to use every point,
    //    regardless of duplication.
    //
    {
        int dim;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_UNIQUE_INDEX_TESTS");
        Console.WriteLine("  Call SGMGA_UNIQUE_INDEX_TEST with various arguments");
        //
        //  Set the point equality tolerance.
        //
        double tol = Math.Sqrt(typeMethods.r8_epsilon());

        Console.WriteLine("");
        Console.WriteLine("  All tests will use a point equality tolerance of " + tol + "");

        int dim_num = 2;

        double[] importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        double[] level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        int level_max_min = 0;
        int level_max_max = 2;

        int[] np = new int[dim_num];
        np[0] = 0;
        np[1] = 0;
        int np_sum = typeMethods.i4vec_sum(dim_num, np);

        double[] p    = new double[np_sum];
        int[]    rule = new int[dim_num];
        rule[0] = 1;
        rule[1] = 1;
        int[] growth = new int[dim_num];
        growth[0] = 6;
        growth[1] = 6;
        Func <int, int, double[], double[], double[]>[] gw_compute_points = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 1;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 6;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np[2]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 1;
        rule[2]              = 1;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 6;
        growth[2]            = 6;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np[2]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 1;
        rule[2]              = 1;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 6;
        growth[2]            = 6;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 3;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 6;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = PattersonQuadrature.patterson_lookup_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 4;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 7;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = Burkardt.Laguerre.QuadratureRule.laguerre_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 1;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        p[0]                 = 1.5;
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 8;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = Burkardt.Laguerre.QuadratureRule.gen_laguerre_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 2;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        p[0]                 = 0.5;
        p[1]                 = 1.5;
        rule                 = new int[dim_num];
        rule[0]              = 2;
        rule[1]              = 9;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = Fejer2.fejer2_compute_points_np;
        gw_compute_points[1] = JacobiQuadrature.jacobi_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 1;
        np[1]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        p[0]                 = 2.0;
        rule                 = new int[dim_num];
        rule[0]              = 6;
        rule[1]              = 10;
        growth               = new int[dim_num];
        growth[0]            = 3;
        growth[1]            = 4;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = HermiteQuadrature.gen_hermite_compute_points_np;
        gw_compute_points[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np[2]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 4;
        rule[2]              = 5;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        growth[2]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        gw_compute_points[2] = HermiteQuadrature.hermite_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);
        //
        //  Repeat, treating  rules #2 and #3 as Golub Welsch rules.
        //
        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 2;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np[2]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 11;
        rule[2]              = 11;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 3;
        growth[2]            = 3;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        gw_compute_points[2] = HermiteQuadrature.hermite_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);
        //
        //  Try a case which includes a dimension of "0 importance".
        //
        dim_num       = 3;
        importance    = new double[dim_num];
        importance[0] = 1.0;
        importance[1] = 0.0;
        importance[2] = 1.0;
        level_weight  = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min        = 0;
        level_max_max        = 3;
        np                   = new int[dim_num];
        np[0]                = 0;
        np[1]                = 0;
        np[2]                = 0;
        np_sum               = typeMethods.i4vec_sum(dim_num, np);
        p                    = new double[np_sum];
        rule                 = new int[dim_num];
        rule[0]              = 1;
        rule[1]              = 1;
        rule[2]              = 1;
        growth               = new int[dim_num];
        growth[0]            = 6;
        growth[1]            = 6;
        growth[2]            = 6;
        gw_compute_points    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[2] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        sgmga_unique_index_test(dim_num, importance, level_weight, level_max_min,
                                level_max_max, rule, growth, np, p, gw_compute_points, tol);
    }
Exemple #5
0
    private static void sgmga_unique_index_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_UNIQUE_INDEX_TEST tests SGMGA_UNIQUE_INDEX.
    //
    //  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 importance 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_UNIQUE_INDEX_TEST");
        Console.WriteLine("  SGMGA_UNIQUE_INDEX returns a mapping between");
        Console.WriteLine("  the nonunique and unique points in a sparse grid.");
        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++)
        {
            double alpha;
            int    i;
            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_UNIQUE_INDEX_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);

            Console.WriteLine("");
            Console.WriteLine(" LEVEL_MAX POINT_NUM POINT_NUM");
            Console.WriteLine("              Unique     Total");

            Console.WriteLine("");
            Console.WriteLine("  " + level_max.ToString().PadLeft(8)
                              + "  " + point_num.ToString().PadLeft(8)
                              + "  " + point_total_num.ToString().PadLeft(8) + "");

            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);

            Console.WriteLine("");
            Console.WriteLine("     POINT    UNIQUE");
            Console.WriteLine("");
            int point;
            for (point = 0; point < point_total_num; point++)
            {
                Console.WriteLine("  " + point.ToString().PadLeft(8)
                                  + "  " + sparse_unique_index[point].ToString().PadLeft(8) + "");
            }
        }
    }
Exemple #6
0
    private static void sgmga_vcn_coef_tests()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_COEF_TESTS calls SGMGA_VCN_COEF_TEST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 November 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_COEF_TESTS");
        Console.WriteLine("  calls SGMGA_VCN_COEF_TEST.");

        int dim_num = 2;

        double[] importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        double[] level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        int level_max_min = 0;
        int level_max_max = 4;

        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min = 0;
        level_max_max = 4;
        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min = 0;
        level_max_max = 4;
        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min = 0;
        level_max_max = 4;
        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);

        dim_num    = 4;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min = 0;
        level_max_max = 3;
        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);
        //
        //  Try a case with a dimension of "0 importance".
        //
        dim_num       = 3;
        importance    = new double[dim_num];
        importance[0] = 1.0;
        importance[1] = 0.0;
        importance[2] = 1.0;
        level_weight  = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max_min = 0;
        level_max_max = 3;
        sgmga_vcn_coef_test(dim_num, importance, level_weight, level_max_min,
                            level_max_max);
    }
Exemple #7
0
    private static void sgmga_vcn_coef_test(int dim_num, double[] importance,
                                            double[] level_weight, int level_max_min, int level_max_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_COEF_TEST tests SGMGA_VCN_COEF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 May 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;
        int level_max;

        SGMGAniso.SGMGAData data = new();
        string cout = "";

        int[] level_1d     = new int[dim_num];
        int[] level_1d_max = new int[dim_num];
        int[] level_1d_min = new int[dim_num];

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_COEF_TEST");
        Console.WriteLine("  For anisotropic problems, a \"combinatorial coefficent\"");
        Console.WriteLine("  must be computed for each component product grid.");
        Console.WriteLine("  SGMGA_VCN_COEF_NAIVE does this in a simple, inefficient way.");
        Console.WriteLine("  SGMGA_VCN_COEF tries to be more efficient.");
        Console.WriteLine("  Here, we simply compare COEF1 and COEF2, the same");
        Console.WriteLine("  coefficient computed by the naive and efficient ways.");
        Console.WriteLine("");
        Console.WriteLine("  IMPORTANCE:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + importance[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  LEVEL_WEIGHT:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);

        for (level_max = level_max_min; level_max <= level_max_max; level_max++)
        {
            int    i         = 0;
            double coef1_sum = 0.0;
            double coef2_sum = 0.0;
            //
            //  Initialization.
            //
            double level_weight_min_pos = typeMethods.r8vec_min_pos(dim_num, level_weight);
            double q_min = level_max * level_weight_min_pos
                           - typeMethods.r8vec_sum(dim_num, level_weight);
            double q_max = level_max * level_weight_min_pos;
            for (dim = 0; dim < dim_num; dim++)
            {
                level_1d_min[dim] = 0;
            }

            for (dim = 0; dim < dim_num; dim++)
            {
                switch (level_weight[dim])
                {
                case > 0.0:
                {
                    level_1d_max[dim] = (int)Math.Floor(q_max / level_weight[dim]) + 1;
                    if (q_max <= (level_1d_max[dim] - 1) * level_weight[dim])
                    {
                        level_1d_max[dim] -= 1;
                    }

                    break;
                }

                default:
                    level_1d_max[dim] = 0;
                    break;
                }
            }

            bool more_grids = false;


            Console.WriteLine("");
            Console.WriteLine("     I               Q       Coef1       Coef2   X");
            cout = "   MIN" + "  " + q_min.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                   + "                        ";
            for (dim = 0; dim < dim_num; dim++)
            {
                cout += "  " + level_1d_min[dim].ToString().PadLeft(2);
            }

            Console.WriteLine(cout);
            //
            //  Seek all vectors LEVEL_1D which satisfy the constraint:
            //
            //    LEVEL_MAX * LEVEL_WEIGHT_MIN_POS - sum ( LEVEL_WEIGHT )
            //      < sum ( 0 <= I < DIM_NUM ) LEVEL_WEIGHT[I] * LEVEL_1D[I]
            //      <= LEVEL_MAX * LEVEL_WEIGHT_MIN_POS.
            //
            for (;;)
            {
                SGMGAniso.sgmga_vcn_ordered_naive(ref data, dim_num, level_weight, level_1d_max,
                                                  level_1d, q_min, q_max, ref more_grids);

                if (!more_grids)
                {
                    break;
                }

                //
                //  Compute the combinatorial coefficient.
                //
                double coef1 = SGMGAniso.sgmga_vcn_coef_naive(dim_num, level_weight, level_1d_max,
                                                              level_1d, q_min, q_max);

                double coef2 = SGMGAniso.sgmga_vcn_coef(dim_num, level_weight, level_1d, q_max);

                i += 1;

                double q = 0.0;
                for (dim = 0; dim < dim_num; dim++)
                {
                    q += level_weight[dim] * level_1d[dim];
                }

                coef1_sum += coef1;
                coef2_sum += coef2;

                cout = "  " + i.ToString().PadLeft(4)
                       + "  " + q.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                       + "  " + coef1.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                       + "  " + coef2.ToString(CultureInfo.InvariantCulture).PadLeft(10);
                for (dim = 0; dim < dim_num; dim++)
                {
                    cout += "  " + level_1d[dim].ToString().PadLeft(2);
                }

                Console.WriteLine(cout);
            }

            cout = "   MAX" + "  " + q_max.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                   + "                        ";
            for (dim = 0; dim < dim_num; dim++)
            {
                cout += "  " + level_1d_max[dim].ToString().PadLeft(2);
            }

            Console.WriteLine(cout);
            Console.WriteLine("   SUM                "
                              + "  " + coef1_sum.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + coef2_sum.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Exemple #8
0
    private static void sgmga_weight_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,
                                          Func <int, int, double[], double[], double[]>[] gw_compute_weights,
                                          double tol)

    //***************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_WEIGHT_TEST checks the sum of the quadrature weights.
    //
    //  Discussion:
    //
    //    If any component rule is of Golub-Welsch type, we cannot compute
    //    the exact weight sum, which we set, instead, to zero.
    //
    //  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 anisotropic importance.
    //
    //    Input, double LEVEL_WEIGHT[DIM_NUM], the anisotropic weights.
    //
    //    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, 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.
    //
    {
        double alpha;
        double beta;
        int    dim;
        int    i;
        int    level_max;
        string cout = "";

        Console.WriteLine("");
        Console.WriteLine("SGMGA_WEIGHT_TEST");
        Console.WriteLine("  Compute the weights of a sparse grid.");
        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("");
        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++)
        {
            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;
                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_WEIGHT_TEST - Fatal error!");
                Console.WriteLine("  Unexpected value of RULE = " + rule[dim] + "");
                return;
            }
        }

        double weight_sum_exact = 1.0;

        p_index = 0;
        for (dim = 0; dim < dim_num; dim++)
        {
            switch (rule[dim])
            {
            case 1:
            case 2:
            case 3:
            case 4:
                weight_sum_exact *= 2.0;
                break;

            case 5:
                weight_sum_exact *= Math.Sqrt(Math.PI);
                break;

            case 6:
                alpha             = p[p_index];
                p_index          += 1;
                weight_sum_exact *= typeMethods.r8_gamma(0.5 * (alpha + 1.0));
                break;

            case 7:
                weight_sum_exact *= 1.0;
                break;

            case 8:
                alpha             = p[p_index];
                p_index          += 1;
                weight_sum_exact *= typeMethods.r8_gamma(alpha + 1.0);
                break;

            case 9:
                alpha    = p[p_index];
                p_index += 1;
                beta     = p[p_index];
                p_index += 1;
                double arg1   = -alpha;
                double arg2   = 1.0;
                double arg3   = beta + 2.0;
                double arg4   = -1.0;
                double value1 = typeMethods.r8_hyper_2f1(arg1, arg2, arg3, arg4);
                arg1 = -beta;
                arg2 = 1.0;
                arg3 = alpha + 2.0;
                arg4 = -1.0;
                double value2 = typeMethods.r8_hyper_2f1(arg1, arg2, arg3, arg4);
                weight_sum_exact *= value1 / (beta + 1.0) + value2 / (alpha + 1.0);
                break;

            case 10:
                weight_sum_exact *= Math.Sqrt(Math.PI);
                break;

            case 11:
            {
                for (i = 0; i < np[dim]; i++)
                {
                    alpha    = p[p_index];
                    p_index += 1;
                }

                weight_sum_exact = 0.0;
                break;
            }

            case 12:
            {
                for (i = 0; i < np[dim]; i++)
                {
                    alpha    = p[p_index];
                    p_index += 1;
                }

                weight_sum_exact = 0.0;
                break;
            }

            default:
                Console.WriteLine("");
                Console.WriteLine("SGMGA_WEIGHT_TEST - Fatal error!");
                Console.WriteLine("  Unexpected value of RULE[" + dim + "] = "
                                  + rule[dim] + ".");
                return;
            }
        }

        switch (weight_sum_exact)
        {
        case 0.0:
            Console.WriteLine("");
            Console.WriteLine("  Because this rule includes Golub-Welsch components,");
            Console.WriteLine("  we do not try to compute the exact weight sum.");
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("  As a simple test, sum these weights.");
            Console.WriteLine("  They should sum to exactly " + weight_sum_exact + "");
            break;
        }

        Console.WriteLine("");
        Console.WriteLine("     Level      Weight sum  Expected sum    Difference");
        Console.WriteLine("");

        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);

            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);

            double weight_sum = typeMethods.r8vec_sum(point_num, sparse_weight);

            double weight_sum_error = typeMethods.r8_abs(weight_sum - weight_sum_exact);

            Console.WriteLine("  " + level_max.ToString().PadLeft(8)
                              + "  " + weight_sum.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + weight_sum_exact.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + weight_sum_error.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
    private static void sgmga_write_tests()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_WRITE_TESTS calls SGMGA_WRITE_TEST.
    //
    //  Discussion:
    //
    //    We can't test Golub-Welsch rules in this routine, because the program
    //    that writes out the files needs to know the integration region for each
    //    component, and we have not specified how that would be done with
    //    Golub Welsch rules.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Local Parameters:
    //
    //    Local, double TOL, a tolerance for point equality.
    //    A value of sqrt ( eps ) is reasonable, and will allow the code to
    //    consolidate points which are equal, or very nearly so.  A value of
    //    -1.0, on the other hand, will force the code to use every point,
    //    regardless of duplication.
    //
    {
        int dim;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_WRITE_TESTS");
        Console.WriteLine("  Call SGMGA_WRITE_TEST with various arguments.");
        //
        //  Set the point equality tolerance.
        //
        double tol = Math.Sqrt(typeMethods.r8_epsilon());

        Console.WriteLine("");
        Console.WriteLine("  All tests will use a point equality tolerance of " + tol + "");

        int dim_num = 2;

        double[] importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        double[] level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        int level_max = 2;

        int[] rule = new int[dim_num];
        rule[0] = 1;
        rule[1] = 1;
        int[] growth = new int[dim_num];
        growth[0] = 6;
        growth[1] = 6;
        int[] np = new int[dim_num];
        np[0] = 0;
        np[1] = 0;
        int np_sum = typeMethods.i4vec_sum(dim_num, np);

        double[] p = new double[np_sum];
        Func <int, int, double[], double[], double[]>[] gw_compute_points = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1] = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        Func <int, int, double[], double[], double[]>[] gw_compute_weights = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        string file_name = "sgmga_d2_l2_ccxcc_iso";

        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d2_l2_ccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        rule[2]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        growth[2]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np[2]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[2]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[2] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d3_l2_ccxccxcc_iso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        rule[2]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        growth[2]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np[2]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[2]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[2] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d3_l2_ccxccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 3;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 3;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = PattersonQuadrature.patterson_lookup_weights_np;
        file_name             = "sgmga_d2_l3_ccxgp_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 4;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 3;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_weights_np;
        file_name             = "sgmga_d2_l2_ccxgl_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 7;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 3;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = Burkardt.Laguerre.QuadratureRule.laguerre_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = Burkardt.Laguerre.QuadratureRule.laguerre_compute_weights_np;
        file_name             = "sgmga_d2_l2_ccxlg_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 8;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 3;
        np                    = new int[dim_num];
        np[0]                 = 1;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        p[0]                  = 1.5;
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = Burkardt.Laguerre.QuadratureRule.gen_laguerre_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = Burkardt.Laguerre.QuadratureRule.gen_laguerre_compute_weights_np;
        file_name             = "sgmga_d2_l2_ccxglg_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 2;
        rule[1]               = 9;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 3;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 2;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        p[0]                  = 0.5;
        p[1]                  = 1.5;
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = Fejer2.fejer2_compute_points_np;
        gw_compute_points[1]  = JacobiQuadrature.jacobi_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = Fejer2.fejer2_compute_weights_np;
        gw_compute_weights[1] = JacobiQuadrature.jacobi_compute_weights_np;
        file_name             = "sgmga_d2_l2_f2xgj_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);

        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 6;
        rule[1]               = 10;
        growth                = new int[dim_num];
        growth[0]             = 3;
        growth[1]             = 4;
        np                    = new int[dim_num];
        np[0]                 = 1;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        p[0]                  = 2.0;
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = HermiteQuadrature.gen_hermite_compute_points_np;
        gw_compute_points[1]  = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = HermiteQuadrature.gen_hermite_compute_weights_np;
        gw_compute_weights[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_weights_np;
        file_name             = "sgmga_d2_l2_gghxhgk_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  LEVEL_MAX = 1
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 1;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d2_l1_ccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  LEVEL_MAX = 2 (already done)
        //
        //  LEVEL_MAX = 3
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 3;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d2_l3_ccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  LEVEL_MAX = 4
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 4;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d2_l4_ccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  LEVEL_MAX = 5
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 5;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 1;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        file_name             = "sgmga_d2_l5_ccxcc_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  Dimension 3
        //
        dim_num    = 3;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = dim + 1;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 2;
        rule                  = new int[dim_num];
        rule[0]               = 1;
        rule[1]               = 4;
        rule[2]               = 5;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 3;
        growth[2]             = 3;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np[2]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = ClenshawCurtis.clenshaw_curtis_compute_points_np;
        gw_compute_points[1]  = Burkardt.Legendre.QuadratureRule.legendre_compute_points_np;
        gw_compute_points[2]  = HermiteQuadrature.hermite_compute_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = ClenshawCurtis.clenshaw_curtis_compute_weights_np;
        gw_compute_weights[1] = Burkardt.Legendre.QuadratureRule.legendre_compute_weights_np;
        gw_compute_weights[2] = HermiteQuadrature.hermite_compute_weights_np;
        file_name             = "sgmga_d3_l2_ccxglxgh_aniso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  Rule 3, LEVEL_MAX = 4
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 4;
        rule                  = new int[dim_num];
        rule[0]               = 3;
        rule[1]               = 3;
        growth                = new int[dim_num];
        growth[0]             = 6;
        growth[1]             = 6;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_points[1]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = PattersonQuadrature.patterson_lookup_weights_np;
        gw_compute_weights[1] = PattersonQuadrature.patterson_lookup_weights_np;
        file_name             = "sgmga_d2_l4_gpxgp_iso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  Rule 3, Slow Exponential Growth, LEVEL_MAX = 4
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 4;
        rule                  = new int[dim_num];
        rule[0]               = 3;
        rule[1]               = 3;
        growth                = new int[dim_num];
        growth[0]             = 4;
        growth[1]             = 4;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_points[1]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = PattersonQuadrature.patterson_lookup_weights_np;
        gw_compute_weights[1] = PattersonQuadrature.patterson_lookup_weights_np;
        file_name             = "sgmga_d2_l4_gpsexgpse_iso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
        //
        //  Rule 3, Moderate Exponential Growth, LEVEL_MAX = 4
        //
        dim_num    = 2;
        importance = new double[dim_num];
        for (dim = 0; dim < dim_num; dim++)
        {
            importance[dim] = 1.0;
        }

        level_weight = new double[dim_num];
        SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
        level_max             = 4;
        rule                  = new int[dim_num];
        rule[0]               = 3;
        rule[1]               = 3;
        growth                = new int[dim_num];
        growth[0]             = 5;
        growth[1]             = 5;
        np                    = new int[dim_num];
        np[0]                 = 0;
        np[1]                 = 0;
        np_sum                = typeMethods.i4vec_sum(dim_num, np);
        p                     = new double[np_sum];
        gw_compute_points     = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_points[0]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_points[1]  = PattersonQuadrature.patterson_lookup_points_np;
        gw_compute_weights    = new Func <int, int, double[], double[], double[]> [dim_num];
        gw_compute_weights[0] = PattersonQuadrature.patterson_lookup_weights_np;
        gw_compute_weights[1] = PattersonQuadrature.patterson_lookup_weights_np;
        file_name             = "sgmga_d2_l4_gpmexgpme_iso";
        sgmga_write_test(dim_num, level_weight, level_max, rule, growth, np,
                         p, gw_compute_points, gw_compute_weights, tol, file_name);
    }
    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_size_tabulate(int rule_1d, int growth_1d, int np_1d, double[] p_1d,
                                            int dim_min, int dim_max, int level_max_min, int level_max_max,
                                            Func <int, int, double[], double[], double[]> gw_compute_points_1d)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_SIZE_TABULATE tests SGMGA_SIZE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int RULE_1D, the 1D rule.
    //     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_1D, 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_1D, the number of parameters in the 1D rule.
    //
    //    Input, double P_1D[NP_1D], the parameters.
    //
    //    Input, int DIM_MIN, the minimum spatial dimension to consider.
    //
    //    Input, int DIM_MAX, the maximum spatial dimension to consider.
    //
    //    Input, int LEVEL_MAX_MIN, the minimum value of LEVEL_MAX to consider.
    //
    //    Input, int LEVEL_MAX_MAX, the maximum value of LEVEL_MAX to consider.
    //
    //    Input, GW_COMPUTE_POINTS_1D ( int order, int np, double p[], double x[] ),
    //    a function which return the 1D quadrature points.
    //
    {
        int dim_num;
        int level_max;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_SIZE_TABULATE");
        Console.WriteLine("  SGMGA_SIZE returns the number of distinct");
        Console.WriteLine("  points in a sparse grid.");
        Console.WriteLine("");
        Console.WriteLine("  We use the same rule in all dimensions, and count the points,");
        Console.WriteLine("  for a range of dimensions and levels.");
        Console.WriteLine("");
        Console.WriteLine("  1D rule index = " + rule_1d + "");
        Console.WriteLine("  1D growth rule = " + growth_1d + "");
        Console.WriteLine("");

        double tol = Math.Sqrt(typeMethods.r8_epsilon());

        string cout = "   DIM: ";

        for (dim_num = dim_min; dim_num <= dim_max; dim_num++)
        {
            cout += "  " + dim_num.ToString().PadLeft(8);
        }

        Console.WriteLine(cout);
        Console.WriteLine("");
        Console.WriteLine("   LEVEL_MAX");
        Console.WriteLine("");

        for (level_max = level_max_min; level_max <= level_max_max; level_max++)
        {
            cout = "    " + level_max.ToString().PadLeft(4);
            for (dim_num = dim_min; dim_num <= dim_max; dim_num++)
            {
                double[] level_weight = new double[dim_num];
                int[]    rule         = new int[dim_num];
                int[]    growth       = new int[dim_num];
                int[]    np           = new int[dim_num];
                int      np_sum       = dim_num * np_1d;
                double[] p            = new double[np_sum];
                Func <int, int, double[], double[], double[]>[] gw_compute_points = new Func <int, int, double[], double[], double[]> [dim_num];

                int dim;
                for (dim = 0; dim < dim_num; dim++)
                {
                    level_weight[dim] = 1.0;
                    rule[dim]         = rule_1d;
                    growth[dim]       = growth_1d;
                    np[dim]           = np_1d;
                    int i;
                    for (i = 0; i < np_1d; i++)
                    {
                        p[i + dim * np_1d] = p_1d[i];
                    }

                    gw_compute_points[dim] = gw_compute_points_1d;
                }

                int point_num = SGMGAniso.sgmga_size(dim_num, level_weight, level_max, rule,
                                                     np, p, gw_compute_points, tol, growth);

                cout += "  " + point_num.ToString().PadLeft(8);
            }

            Console.WriteLine(cout);
        }
    }
Exemple #12
0
    private static void sgmga_vcn_ordered_tests()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_ORDERED_TESTS calls SGMGA_VCN_ORDERED_TEST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 May 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;
        int dim_num;

        int[] dim_num_array =
        {
            2, 2, 2, 2, 2,
            3, 3, 3, 3, 3,
            4, 4
        };
        double[] importance;
        int      level_max;

        int[] level_max_array =
        {
            0, 1, 2, 3, 4,
            0, 1, 2, 3, 4,
            2, 3
        };
        double[]  level_weight;
        double    q_max;
        double    q_min;
        int       test;
        const int test_num = 12;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_ORDERED_TESTS");
        Console.WriteLine("  calls SGMGA_VCN_ORDERED_TEST.");
        //
        //  Isotropic examples.
        //
        for (test = 0; test < test_num; test++)
        {
            dim_num    = dim_num_array[test];
            importance = new double[dim_num];
            for (dim = 0; dim < dim_num; dim++)
            {
                importance[dim] = 1.0;
            }

            level_weight = new double[dim_num];
            SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
            level_max = level_max_array[test];
            q_min     = level_max - typeMethods.r8vec_sum(dim_num, level_weight);
            q_max     = level_max;

            sgmga_vcn_ordered_test(dim_num, importance, level_weight, q_min, q_max);
        }

        //
        //  Anisotropic examples.
        //
        for (test = 0; test < test_num; test++)
        {
            dim_num    = dim_num_array[test];
            importance = new double[dim_num];
            for (dim = 0; dim < dim_num; dim++)
            {
                importance[dim] = dim + 1;
            }

            level_weight = new double[dim_num];
            SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
            level_max = level_max_array[test];
            q_min     = level_max - typeMethods.r8vec_sum(dim_num, level_weight);
            q_max     = level_max;

            sgmga_vcn_ordered_test(dim_num, importance, level_weight, q_min, q_max);
        }
    }
Exemple #13
0
    private static void sgmga_vcn_timing_test(int dim_num, double[] importance,
                                              double[] level_weight, double q_min, double q_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_TIMING_TEST times SGMGA_VCN and SGMGA_VCN_NAIVE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 April 2011
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        SGMGAniso.SGMGAData data = new();
        string cout;

        int[] level_1d     = new int[dim_num];
        int[] level_1d_max = new int[dim_num];
        int[] level_1d_min = new int[dim_num];

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_TIMING_TEST");
        Console.WriteLine("  Consider vectors 0 <= LEVEL_1D(1:N) <= LEVEL_1D_MAX(1:N),");
        Console.WriteLine("  Set Q = sum ( LEVEL_WEIGHT(1:N) * LEVEL_1D(1:N) )");
        Console.WriteLine("  Accept vectors for which Q_MIN < Q <= Q_MAX");
        Console.WriteLine("  No particular order is imposed on the LEVEL_1D values.");
        Console.WriteLine("  SGMGA_VCN_NAIVE uses a naive approach;");
        Console.WriteLine("  SGMGA_VCN tries to be more efficient.");
        Console.WriteLine("  Here, we compare the timings.");

        for (dim = 0; dim < dim_num; dim++)
        {
            switch (level_weight[dim])
            {
            case > 0.0:
            {
                level_1d_max[dim] = (int)Math.Floor(q_max / level_weight[dim]) + 1;
                if (q_max <= (level_1d_max[dim] - 1) * level_weight[dim])
                {
                    level_1d_max[dim] -= 1;
                }

                break;
            }

            default:
                level_1d_max[dim] = 0;
                break;
            }
        }

        for (dim = 0; dim < dim_num; dim++)
        {
            level_1d_min[dim] = 0;
        }

        bool more_grids = false;

        Console.WriteLine("");
        Console.WriteLine("  IMPORTANCE:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + importance[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  LEVEL_WEIGHT:");
        cout = "";
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_weight[dim].ToString(CultureInfo.InvariantCulture).PadLeft(14);
        }

        Console.WriteLine(cout);
        Console.WriteLine("");
        Console.WriteLine("  SGMGA_VCN_NAIVE");
        Console.WriteLine("     I               Q   X");
        cout = "   MIN" + "  " + q_min.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_min[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);

        DateTime t1 = DateTime.Now;

        for (;;)
        {
            SGMGAniso.sgmga_vcn_naive(dim_num, level_weight, level_1d_max, level_1d,
                                      q_min, q_max, ref more_grids);

            if (!more_grids)
            {
                break;
            }
        }

        DateTime t2 = DateTime.Now;

        cout = "   MAX" + "  " + q_max.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_max[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  TIME" + "  "
                          + (t2 - t1).TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

        Console.WriteLine("");
        Console.WriteLine("  SGMGA_VCN");
        Console.WriteLine("     I               Q   X");
        cout = "   MIN" + "  " + q_min.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_min[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);

        t1 = DateTime.Now;
        for (;;)
        {
            SGMGAniso.sgmga_vcn(ref data, dim_num, level_weight, ref level_1d, q_min, q_max,
                                ref more_grids);

            if (!more_grids)
            {
                break;
            }
        }

        t2   = DateTime.Now;
        cout = "   MAX" + "  " + q_max.ToString(CultureInfo.InvariantCulture).PadLeft(14);
        for (dim = 0; dim < dim_num; dim++)
        {
            cout += "  " + level_1d_max[dim].ToString().PadLeft(2);
        }

        Console.WriteLine(cout);
        Console.WriteLine("  TIME" + "  "
                          + (t2 - t1).TotalSeconds.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
    }
Exemple #14
0
    private static void sgmga_vcn_timing_tests()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_VCN_TIMING_TESTS calls SGMGA_VCN_TIMING_TEST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 May 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int dim;

        double[] importance;
        int      level_max;

        double[] level_weight;
        double   q_max;
        double   q_min;
        int      test;

        Console.WriteLine("");
        Console.WriteLine("SGMGA_VCN_TIMING_TESTS");
        Console.WriteLine("  calls SGMGA_VCN_TIMING_TEST.");
        //
        //  Isotropic examples.
        //
        int dim_num = 2;

        for (test = 0; test < 2; test++)
        {
            dim_num   *= 2;
            importance = new double[dim_num];
            for (dim = 0; dim < dim_num; dim++)
            {
                importance[dim] = 1.0;
            }

            level_weight = new double[dim_num];
            SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
            level_max = 2;
            q_min     = level_max - typeMethods.r8vec_sum(dim_num, level_weight);
            q_max     = level_max;

            sgmga_vcn_timing_test(dim_num, importance, level_weight, q_min, q_max);
        }

        //
        //  Anisotropic examples.
        //
        dim_num = 2;

        for (test = 0; test < 2; test++)
        {
            dim_num   *= 2;
            importance = new double[dim_num];
            for (dim = 0; dim < dim_num; dim++)
            {
                importance[dim] = dim + 1;
            }

            level_weight = new double[dim_num];
            SGMGAniso.sgmga_importance_to_aniso(dim_num, importance, ref level_weight);
            level_max = 2;
            q_min     = level_max - typeMethods.r8vec_sum(dim_num, level_weight);
            q_max     = level_max;

            sgmga_vcn_timing_test(dim_num, importance, level_weight, q_min, q_max);
        }
    }
    private static void sgmga_product_weight_test(int dim_num, int[] order_1d,
                                                  int order_nd, int[] rule, int[] np, double[] p,
                                                  Func <int, int, double[], double[], double[]>[] gw_compute_weights)

    //***************************************************************************80
    //
    //  Purpose:
    //
    //    SGMGA_PRODUCT_WEIGHT_TEST: weights of a mixed factor product rule.
    //
    //  Discussion:
    //
    //    This routine computes a sparse grid and compares the sum of the weights
    //    to the expected exact value.
    //
    //    The routine cannot produce a result for rules that include one or more
    //    component rules of type 10, that is, Golub-Welsch rules.
    //
    //  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, int ORDER_1D[DIM_NUM], the order of the 1D rules.
    //
    //    Input, int ORDER_ND, the order of the product rule.
    //
    //    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 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_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.
    //
    {
        double alpha;
        double beta;
        int    dim;
        int    i;
        //
        //  Determine the integral of 1 over the multidimensional weighted region.
        //
        int p_index = 0;

        double weight_sum_exact = 1.0;

        for (dim = 0; dim < dim_num; dim++)
        {
            switch (rule[dim])
            {
            case 1:
            case 2:
            case 3:
            case 4:
                weight_sum_exact *= 2.0;
                break;

            case 5:
                weight_sum_exact *= Math.Sqrt(Math.PI);
                break;

            case 6:
                alpha    = p[p_index];
                p_index += 1;

                weight_sum_exact *= typeMethods.r8_gamma(0.5 * (alpha + 1.0));
                break;

            case 7:
                weight_sum_exact *= 1.0;
                break;

            case 8:
                alpha    = p[p_index];
                p_index += 1;

                weight_sum_exact *= typeMethods.r8_gamma(alpha + 1.0);
                break;

            case 9:
                alpha    = p[p_index];
                p_index += 1;
                beta     = p[p_index];
                p_index += 1;
                double arg1   = -alpha;
                double arg2   = 1.0;
                double arg3   = beta + 2.0;
                double arg4   = -1.0;
                double value1 = typeMethods.r8_hyper_2f1(arg1, arg2, arg3, arg4);
                arg1 = -beta;
                arg2 = 1.0;
                arg3 = alpha + 2.0;
                arg4 = -1.0;
                double value2 = typeMethods.r8_hyper_2f1(arg1, arg2, arg3, arg4);
                weight_sum_exact *= value1 / (beta + 1.0) + value2 / (alpha + 1.0);
                break;

            case 10:
                weight_sum_exact *= Math.Sqrt(Math.PI);
                break;

            case 11:
            {
                for (i = 0; i < np[dim]; i++)
                {
                    alpha    = p[p_index];
                    p_index += 1;
                }

                weight_sum_exact = 0.0;
                break;
            }

            case 12:
            {
                for (i = 0; i < np[dim]; i++)
                {
                    alpha    = p[p_index];
                    p_index += 1;
                }

                weight_sum_exact = 0.0;
                break;
            }

            default:
                Console.WriteLine("");
                Console.WriteLine("SGMGA_PRODUCT_WEIGHT_TEST - Fatal error!");
                Console.WriteLine("  Unexpected value of RULE[" + dim + "] = "
                                  + rule[dim] + ".");
                return;
            }
        }

        Console.WriteLine("");
        Console.WriteLine("SGMGA_PRODUCT_WEIGHT_TEST:");
        Console.WriteLine("  Compute the weights of a mixed factor product grid.");
        if (weight_sum_exact != 0.0)
        {
            Console.WriteLine("");
            Console.WriteLine("  As a simple test, sum these weights.");
            Console.WriteLine("  They should sum to exactly " + weight_sum_exact + "");
        }

        Console.WriteLine("");
        Console.WriteLine("  Spatial dimension DIM_NUM = " + dim_num + "");

        Console.WriteLine("");
        Console.WriteLine(" Dimension      Rule    Growth        Parameters");
        Console.WriteLine("");

        p_index = 0;
        for (dim = 0; dim < dim_num; dim++)
        {
            switch (rule[dim])
            {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                Console.WriteLine("  " + dim.ToString().PadLeft(8)
                                  + "  " + rule[dim].ToString().PadLeft(8)
                                  + "  " + order_1d[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)
                                  + "  " + order_1d[dim].ToString().PadLeft(8)
                                  + "  " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
                break;

            case 7:
                Console.WriteLine("  " + dim.ToString().PadLeft(8)
                                  + "  " + rule[dim].ToString().PadLeft(8)
                                  + "  " + order_1d[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)
                                  + "  " + order_1d[dim].ToString().PadLeft(8)
                                  + "  " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
                break;

            case 9:
                alpha    = p[p_index];
                p_index += 1;
                beta     = p[p_index];
                p_index += 1;
                Console.WriteLine("  " + dim.ToString().PadLeft(8)
                                  + "  " + rule[dim].ToString().PadLeft(8)
                                  + "  " + order_1d[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)
                                  + "  " + order_1d[dim].ToString().PadLeft(8) + "");
                break;

            case 11:
            {
                string cout = "  " + dim.ToString().PadLeft(8)
                              + "  " + rule[dim].ToString().PadLeft(8)
                              + "  " + order_1d[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:
            {
                string cout = "  " + dim.ToString().PadLeft(8)
                              + "  " + rule[dim].ToString().PadLeft(8)
                              + "  " + order_1d[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_PRODUCT_WEIGHT_TEST - Fatal error!");
                Console.WriteLine("  Cannot perform test for rule = " + rule[dim] + "");
                return;
            }
        }

        //
        //  Compute the weights.
        //
        double[] weight = new double[order_nd];

        SGMGAniso.sgmga_product_weight(dim_num, order_1d, order_nd, rule,
                                       np, p, gw_compute_weights, ref weight);
        //
        //  Sum the weights to get the approximation to the integral of 1.
        //
        double weight_sum = typeMethods.r8vec_sum(order_nd, weight);
        //
        //  Compare the exact and estimated integrals.
        //
        double weight_sum_error = typeMethods.r8_abs(weight_sum - weight_sum_exact);

        if (weight_sum_exact != 0.0)
        {
            Console.WriteLine("");
            Console.WriteLine("    Weight sum  Expected sum    Difference");
            Console.WriteLine("");
            Console.WriteLine("  " + weight_sum.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + weight_sum_exact.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + weight_sum_error.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
        else
        {
            Console.WriteLine("");
            Console.WriteLine("    Weight sum");
            Console.WriteLine("");
            Console.WriteLine("  " + weight_sum.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }