Example #1
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests TETRAHEDRON_NCC_RULE_NUM, TETRAHEDRON_NCC_DEGREE, TETRAHEDRON_NCC_ORDER_NUM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int rule;

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  TETRAHEDRON_NCC_RULE_NUM returns the number of rules;");
        Console.WriteLine("  TETRAHEDRON_NCC_DEGREE returns the degree of a rule;");
        Console.WriteLine("  TETRAHEDRON_NCC_ORDER_NUM returns the order of a rule.");

        int rule_num = NewtonCotesClosed.tetrahedron_ncc_rule_num();

        Console.WriteLine("");
        Console.WriteLine("  Number of available rules = " + rule_num + "");
        Console.WriteLine("");
        Console.WriteLine("      Rule    Degree     Order");
        Console.WriteLine("");

        for (rule = 1; rule <= rule_num; rule++)
        {
            int order_num = NewtonCotesClosed.tetrahedron_ncc_order_num(rule);
            int degree    = NewtonCotesClosed.tetrahedron_ncc_degree(rule);
            Console.WriteLine("  " + rule.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + degree.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + order_num.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");
        }
    }
Example #2
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests TETRAHEDRON_NCC_RULE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int dim_num = 3;
        int       rule;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  TETRAHEDRON_NCC_RULE returns the points and weights");
        Console.WriteLine("  of an NCC rule for the tetrahedron.");
        Console.WriteLine("");
        Console.WriteLine("  In this test, we simply check that the weights");
        Console.WriteLine("  sum to 1.");

        int rule_num = NewtonCotesClosed.tetrahedron_ncc_rule_num();

        Console.WriteLine("");
        Console.WriteLine("  Number of available rules = " + rule_num + "");

        Console.WriteLine("");
        Console.WriteLine("      Rule      Sum of weights");
        Console.WriteLine("");

        for (rule = 1; rule <= rule_num; rule++)
        {
            int order_num = NewtonCotesClosed.tetrahedron_ncc_order_num(rule);

            double[] xyztab = new double[dim_num * order_num];
            double[] wtab   = new double[order_num];

            NewtonCotesClosed.tetrahedron_ncc_rule(rule, order_num, ref xyztab, ref wtab);

            double wtab_sum = 0.0;
            int    order;
            for (order = 0; order < order_num; order++)
            {
                wtab_sum += wtab[order];
            }

            Console.WriteLine("  " + rule.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + wtab_sum.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Example #3
0
    private static void test04()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST04 tests TETRAHEDRON_NCC_RULE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       a;
        const int dim_num = 3;

        Console.WriteLine("");
        Console.WriteLine("TEST04");
        Console.WriteLine("  TETRAHEDRON_NCC_RULE returns the points and weights of");
        Console.WriteLine("  an NCC rule for the unit tetrahedron.");
        Console.WriteLine("");
        Console.WriteLine("  This routine uses those rules to estimate the");
        Console.WriteLine("  integral of monomomials in the unit tetrahedron.");

        int rule_num = NewtonCotesClosed.tetrahedron_ncc_rule_num();

        const double volume = 1.0 / 6.0;

        for (a = 0; a <= 6; a++)
        {
            int b;
            for (b = 0; b <= 6 - a; b++)
            {
                int c;
                for (c = 0; c <= 6 - a - b; c++)
                {
                    //
                    //  Multiplying X**A * Y**B * Z**C by COEF will give us an integrand
                    //  whose integral is exactly 1.  This makes the error calculations easy.
                    //
                    double coef = 1.0;

                    //      for ( i = 1; i <= a; i++ )
                    //      {
                    //        coef = coef * i / i;
                    //      }
                    int i;
                    for (i = a + 1; i <= a + b; i++)
                    {
                        coef = coef * i / (i - a);
                    }

                    for (i = a + b + 1; i <= a + b + c; i++)
                    {
                        coef = coef * i / (i - a - b);
                    }

                    for (i = a + b + c + 1; i <= a + b + c + 3; i++)
                    {
                        coef *= i;
                    }

                    Console.WriteLine("");
                    Console.WriteLine("  Integrate " + coef
                                      + " * X^" + a
                                      + " * Y^" + b
                                      + " * Z^" + c + "");
                    Console.WriteLine("");
                    Console.WriteLine("      Rule       QUAD           ERROR");
                    Console.WriteLine("");

                    int rule;
                    for (rule = 1; rule <= rule_num; rule++)
                    {
                        int order_num = NewtonCotesClosed.tetrahedron_ncc_order_num(rule);

                        double[] xyztab = new double[dim_num * order_num];
                        double[] wtab   = new double[order_num];

                        NewtonCotesClosed.tetrahedron_ncc_rule(rule, order_num, ref xyztab, ref wtab);

                        double quad = 0.0;

                        int order;
                        for (order = 0; order < order_num; order++)
                        {
                            double x = xyztab[0 + order * dim_num];
                            double y = xyztab[1 + order * dim_num];
                            double z = xyztab[2 + order * dim_num];
                            //
                            //  Some tedious calculations to avoid 0**0 complaints.
                            //
                            double value = coef;

                            if (a != 0)
                            {
                                value *= Math.Pow(x, a);
                            }

                            if (b != 0)
                            {
                                value *= Math.Pow(y, b);
                            }

                            if (c != 0)
                            {
                                value *= Math.Pow(z, c);
                            }

                            quad += wtab[order] * value;
                        }

                        quad = volume * quad;

                        double exact = 1.0;
                        double err   = Math.Abs(exact - quad);

                        Console.WriteLine("  " + rule.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                          + "  " + quad.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                                          + "  " + err.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
                    }
                }
            }
        }
    }
Example #4
0
    private static void test03()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests TETRAHEDRON_NCC_RULE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 January 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int rule;

        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  TETRAHEDRON_NCC_RULE returns the points and weights");
        Console.WriteLine("  of an NCC rule for the tetrahedron.");
        Console.WriteLine("");
        Console.WriteLine("  In this test, we simply check that, for each");
        Console.WriteLine("  quadrature point, the barycentric coordinates");
        Console.WriteLine("  add up to 1.");

        int rule_num = NewtonCotesClosed.tetrahedron_ncc_rule_num();

        Console.WriteLine("");
        Console.WriteLine("      Rule    Suborder    Sum of coordinates");
        Console.WriteLine("");

        for (rule = 1; rule <= rule_num; rule++)
        {
            int suborder_num = NewtonCotesClosed.tetrahedron_ncc_suborder_num(rule);

            double[] suborder_xyz = new double[4 * suborder_num];
            double[] suborder_w   = new double[suborder_num];

            NewtonCotesClosed.tetrahedron_ncc_subrule(rule, suborder_num, ref suborder_xyz, ref suborder_w);

            Console.WriteLine("");
            Console.WriteLine("  " + rule.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + suborder_num.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");

            int suborder;
            for (suborder = 0; suborder < suborder_num; suborder++)
            {
                double xyz_sum = suborder_xyz[0 + suborder * 4]
                                 + suborder_xyz[1 + suborder * 4]
                                 + suborder_xyz[2 + suborder * 4]
                                 + suborder_xyz[3 + suborder * 4];
                Console.WriteLine("                    "
                                  + "  " + xyz_sum.ToString("0.################").PadLeft(25) + "");
            }
        }
    }