Example #1
0
    private static void triangle_unit_quad_test(int degree_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE_UNIT_QUAD_TEST tests the rules for the unit triangle.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    18 April 2008
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int DEGREE_MAX, the maximum total degree of the
    //    monomials to check.
    //
    {
        const int DIM_NUM = 2;

        int[] expon = new int[DIM_NUM];
        int   h     = 0;
        int   t     = 0;

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE_UNIT_QUAD_TEST");
        Console.WriteLine("  For the unit triangle,");
        Console.WriteLine("  we approximate monomial integrals with:");
        Console.WriteLine("  TRIANGLE_UNIT_O01,");
        Console.WriteLine("  TRIANGLE_UNIT_O03,");
        Console.WriteLine("  TRIANGLE_UNIT_O03b,");
        Console.WriteLine("  TRIANGLE_UNIT_O06,");
        Console.WriteLine("  TRIANGLE_UNIT_O06b,");
        Console.WriteLine("  TRIANGLE_UNIT_O07,");
        Console.WriteLine("  TRIANGLE_UNIT_O12,");

        bool more = false;

        SubCompData data = new();

        for (;;)
        {
            SubComp.subcomp_next(ref data, degree_max, DIM_NUM, ref expon, ref more, ref h, ref t);

            Console.WriteLine("");
            string cout = "  Monomial exponents: ";
            int    dim;
            for (dim = 0; dim < DIM_NUM; dim++)
            {
                cout += "  " + expon[dim].ToString(CultureInfo.InvariantCulture).PadLeft(2);
            }

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

            int      order = 1;
            double[] w     = new double[order];
            double[] xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o01(ref w, ref xy);
            double[] v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            double   quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 3;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o03(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 3;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o03b(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 6;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o06(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 6;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o06b(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 7;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o07(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 12;
            w     = new double[order];
            xy    = new double[DIM_NUM * order];
            QuadratureRule.triangle_unit_o12(ref w, ref xy);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xy);
            quad = QuadratureRule.triangle_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            Console.WriteLine("");
            quad = QuadratureRule.triangle_unit_monomial(expon);
            Console.WriteLine("  " + " Exact"
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            if (!more)
            {
                break;
            }
        }
    }
Example #2
0
    public static void square_quad_test(int degree_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SQUARE_QUAD_TEST tests the rules for a square in 2D.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    06 September 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int DEGREE_MAX, the maximum total degree of the
    //    monomials to check.
    //
    {
        double[] a     = { -1.0, -1.0 };
        double[] b     = { +1.0, +1.0 };
        int[]    expon = new int[2];
        int      h     = 0;

        int[]       order_1d = new int[2];
        int         t        = 0;
        SubCompData data     = new();

        Console.WriteLine("");
        Console.WriteLine("SQUARE_QUAD_TEST");
        Console.WriteLine("  For a square in 2D,");
        Console.WriteLine("  we approximate monomial integrals with:");
        Console.WriteLine("  SQUARE_RULE, which returns M by N point rules..");

        bool more = false;

        for (;;)
        {
            SubComp.subcomp_next(ref data, degree_max, 2, ref expon, ref more, ref h, ref t);

            Console.WriteLine("");
            string cout = "  Monomial exponents: ";
            int    i;
            for (i = 0; i < 2; i++)
            {
                cout += "  " + expon[i].ToString(CultureInfo.InvariantCulture).PadLeft(2);
            }

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

            int      k;
            int      order;
            double[] xy;
            double[] v;
            double   quad;
            double[] w;
            for (k = 1; k <= 5; k++)
            {
                for (i = 0; i < 2; i++)
                {
                    order_1d[i] = k;
                }

                order = order_1d[0] * order_1d[1];
                w     = new double[order];
                xy    = new double[2 * order];
                square_rule(a, b, order_1d, ref w, ref xy);
                v    = Monomial.monomial_value(2, order, expon, xy);
                quad = typeMethods.r8vec_dot_product(order, w, v);
                Console.WriteLine("  " + order_1d[0].ToString(CultureInfo.InvariantCulture).PadLeft(6)
                                  + "  " + order_1d[1].ToString(CultureInfo.InvariantCulture).PadLeft(6)
                                  + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
            }

            //
            //  Try a rule of mixed orders.
            //
            order_1d[0] = 3;
            order_1d[1] = 5;
            order       = order_1d[0] * order_1d[1];
            w           = new double[order];
            xy          = new double[2 * order];
            square_rule(a, b, order_1d, ref w, ref xy);
            v    = Monomial.monomial_value(2, order, expon, xy);
            quad = typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order_1d[0].ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + order_1d[1].ToString(CultureInfo.InvariantCulture).PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            Console.WriteLine("");
            quad = square_monomial(a, b, expon);
            Console.WriteLine("  " + " Exact"
                              + "  " + "      "
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            if (!more)
            {
                break;
            }
        }
    }
Example #3
0
    private static void pyramid_unit_quad_test(int degree_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PYRAMID__UNIT_QUAD_TEST tests the rules for the unit pyramid.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 April 2008
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int DEGREE_MAX, the maximum total degree of the
    //    monomials to check.
    //
    {
        const int DIM_NUM = 3;

        int[] expon = new int[DIM_NUM];
        int   h     = 0;
        int   t     = 0;

        Console.WriteLine("");
        Console.WriteLine("PYRAMID__UNIT_QUAD_TEST");
        Console.WriteLine("  For the unit pyramid,");
        Console.WriteLine("  we approximate monomial integrals with:");
        Console.WriteLine("  PYRAMID__UNIT_O01,");
        Console.WriteLine("  PYRAMID__UNIT_O05,");
        Console.WriteLine("  PYRAMID__UNIT_O06,");
        Console.WriteLine("  PYRAMID__UNIT_O08,");
        Console.WriteLine("  PYRAMID__UNIT_O08b,");
        Console.WriteLine("  PYRAMID__UNIT_O09,");
        Console.WriteLine("  PYRAMID__UNIT_O13,");
        Console.WriteLine("  PYRAMID__UNIT_O18,");
        Console.WriteLine("  PYRAMID__UNIT_O27,");
        Console.WriteLine("  PYRAMID__UNIT_O48,");

        bool more = false;

        SubCompData data = new();

        for (;;)
        {
            SubComp.subcomp_next(ref data, degree_max, DIM_NUM, ref expon, ref more, ref h, ref t);

            if (expon[0] % 2 == 1 || expon[1] % 2 == 1)
            {
                continue;
            }

            Console.WriteLine("");
            string cout = "  Monomial exponents: ";
            int    dim;
            for (dim = 0; dim < DIM_NUM; dim++)
            {
                cout += "  " + expon[dim].ToString().PadLeft(2);
            }

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

            int      order = 1;
            double[] w     = new double[order];
            double[] xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o01(ref w, ref xyz);
            double[] v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            double   quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 5;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o05(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 6;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o06(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 8;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o08(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 8;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o08b(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 9;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o09(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 13;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o13(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 18;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o18(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 27;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o27(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            order = 48;
            w     = new double[order];
            xyz   = new double[DIM_NUM * order];
            FelippaRule.pyramid_unit_o48(ref w, ref xyz);
            v    = Monomial.monomial_value(DIM_NUM, order, expon, xyz);
            quad = FelippaRule.pyramid_unit_volume() * typeMethods.r8vec_dot_product(order, w, v);
            Console.WriteLine("  " + order.ToString().PadLeft(6)
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            Console.WriteLine("");
            quad = FelippaRule.pyramid_unit_monomial(expon);
            Console.WriteLine("  " + " Exact"
                              + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            if (!more)
            {
                break;
            }
        }
    }
Example #4
0
    private static void test02(int degree_max)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests the rules for the unit wedge.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    20 August 2014
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int DEGREE_MAX, the maximum total degree of the
    //    monomials to check.
    //
    {
        const int dim_num = 3;

        int[] expon = new int[3];
        int   h     = 0;

        int[] line_order_array =
        {
            1, 2, 2, 3, 2, 3, 4
        }

        ;
        int       t        = 0;
        const int test_num = 7;

        int[] triangle_order_array =
        {
            1, 3, -3, 6, -6, 7, 12
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  For the unit wedge,");
        Console.WriteLine("  we approximate monomial integrals with WEDG_UNIT_RULE.");

        bool more = false;

        SubCompData data = new();

        for (;;)
        {
            SubComp.subcomp_next(ref data, degree_max, dim_num, ref expon, ref more, ref h, ref t);

            if (expon[2] % 2 == 1)
            {
                if (!more)
                {
                    break;
                }

                continue;
            }

            Console.WriteLine("");
            Console.WriteLine("  Monomial exponents:   "
                              + expon[0].ToString(CultureInfo.InvariantCulture).PadLeft(2) + "  "
                              + expon[1].ToString(CultureInfo.InvariantCulture).PadLeft(2) + "  "
                              + expon[2].ToString(CultureInfo.InvariantCulture).PadLeft(2) + "");
            Console.WriteLine("");

            int    test;
            double quad;
            for (test = 0; test < test_num; test++)
            {
                int line_order     = line_order_array[test];
                int triangle_order = triangle_order_array[test];

                int order = line_order * Math.Abs(triangle_order);

                double[] w   = new double[order];
                double[] xyz = new double[dim_num * order];
                QuadratureRule.wedge_rule(line_order, triangle_order, ref w, ref xyz);
                double[] v = Monomial.monomial_value(dim_num, order, expon, xyz);
                quad = QuadratureRule.wedge_volume() * typeMethods.r8vec_dot_product(order, w, v);
                Console.WriteLine(triangle_order.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                                  + line_order.ToString(CultureInfo.InvariantCulture).PadLeft(6) + "  "
                                  + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
            }

            Console.WriteLine("");
            quad = QuadratureRule.wedge_integral(expon);
            Console.WriteLine("   Exact        "
                              + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

            if (!more)
            {
                break;
            }
        }
    }
Example #5
0
    public static void subcompnz_next_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SUBCOMPNZ_NEXT_TEST tests SUBCOMPNZ_NEXT.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 December 2005
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int n = 6;
        const int k = 3;

        int[]      a     = new int[k];
        bool       more  = false;
        int        h     = 0;
        int        t     = 0;
        int        n2    = 0;
        bool       more2 = false;
        CompNZData data  = new();

        Console.WriteLine("");
        Console.WriteLine("SUBCOMPNZ_NEXT_TEST");
        Console.WriteLine("  SUBCOMPNZ_NEXT generates subcompositions using nonzero parts.");
        Console.WriteLine("");
        Console.WriteLine("  Seek all subcompositions of N = " + n + "");
        Console.WriteLine("  using K = " + k + " nonzero parts.");
        Console.WriteLine("");
        Console.WriteLine("     #   Sum");
        Console.WriteLine("");

        int rank = 0;

        for (;;)
        {
            SubComp.subcompnz_next(ref data, n, k, ref a, ref more, ref h, ref t, ref n2, ref more2);

            int total = 0;
            int i;
            for (i = 0; i < k; i++)
            {
                total += a[i];
            }

            rank += 1;
            string cout = "  " + rank.ToString().PadLeft(4)
                          + "  " + total.ToString().PadLeft(4)
                          + "  ";

            for (i = 0; i < k; i++)
            {
                cout += a[i].ToString().PadLeft(4);
            }

            Console.WriteLine(cout);

            if (!more)
            {
                break;
            }
        }
    }