Beispiel #1
0
    public static void test03(int degree, int numnodes, double[] vert1, double[] vert2,
                              double[] vert3, string header)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 calls TRIASYMQ_GNUPLOT to generate graphics files.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU GPL license.
    //
    //  Modified:
    //
    //    30 June 2014
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Hong Xiao, Zydrunas Gimbutas,
    //    A numerical algorithm for the construction of efficient quadrature
    //    rules in two and higher dimensions,
    //    Computers and Mathematics with Applications,
    //    Volume 59, 2010, pages 663-676.
    //
    //  Parameters:
    //
    //    Input, int DEGREE, the desired total polynomial degree exactness
    //    of the quadrature rule.  0 <= DEGREE <= 50.
    //
    //    Input, int NUMNODES, the number of nodes to be used by the rule.
    //
    //    Input, double VERT1[2], VERT2[2], VERT3[2], the
    //    vertices of the triangle.
    //
    //    Input, string HEADER, an identifier for the graphics filenames.
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  TRIASYMQ_GNUPLOT creates gnuplot graphics files.");
        Console.WriteLine("  Polynomial exactness degree DEGREE = " + degree + "");

        double[] rnodes  = new double[2 * numnodes];
        double[] weights = new double[numnodes];

        SymmetricQuadrature.triasymq(degree, vert1, vert2, vert3, ref rnodes, ref weights, numnodes);

        Console.WriteLine("  Number of nodes = " + numnodes + "");

        SymmetricQuadrature.triasymq_gnuplot(vert1, vert2, vert3, numnodes, rnodes, header);
    }
Beispiel #2
0
    public static void test05(int degree, int numnodes, double[] vert1, double[] vert2,
                              double[] vert3)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 calls TRIASYMQ for a quadrature rule of given order and region.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU GPL license.
    //
    //  Modified:
    //
    //    28 June 2014
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Hong Xiao, Zydrunas Gimbutas,
    //    A numerical algorithm for the construction of efficient quadrature
    //    rules in two and higher dimensions,
    //    Computers and Mathematics with Applications,
    //    Volume 59, 2010, pages 663-676.
    //
    //  Parameters:
    //
    //    Input, int DEGREE, the desired total polynomial degree
    //    exactness of the quadrature rule.  0 <= DEGREE <= 50.
    //
    //    Input, int NUMNODES, the number of nodes to be used by the rule.
    //
    //    Input, double VERT1[2], VERT2[2], VERT3[2], the
    //    vertices of the triangle.
    //
    {
        int i;
        int j;

        double[] z = new double[2];

        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  Compute a quadrature rule for a triangle.");
        Console.WriteLine("  Check it by integrating orthonormal polynomials.");
        Console.WriteLine("  Polynomial exactness degree DEGREE = " + degree + "");

        double area = typeMethods.triangle_area(vert1, vert2, vert3);

        //
        //  Retrieve a symmetric quadrature rule.
        //
        double[] rnodes  = new double[2 * numnodes];
        double[] weights = new double[numnodes];

        SymmetricQuadrature.triasymq(degree, vert1, vert2, vert3, ref rnodes, ref weights, numnodes);
        //
        //  Construct the matrix of values of the orthogonal polynomials
        //  at the user-provided nodes
        //
        int npols = (degree + 1) * (degree + 2) / 2;

        double[] rints = new double[npols];

        for (j = 0; j < npols; j++)
        {
            rints[j] = 0.0;
        }

        for (i = 0; i < numnodes; i++)
        {
            z[0] = rnodes[0 + i * 2];
            z[1] = rnodes[1 + i * 2];
            double[] r    = typeMethods.triangle_to_ref(vert1, vert2, vert3, z);
            double[] pols = Orthogonal.ortho2eva(degree, r);
            for (j = 0; j < npols; j++)
            {
                rints[j] += weights[i] * pols[j];
            }
        }

        double scale = Math.Sqrt(Math.Sqrt(3.0)) / Math.Sqrt(area);

        for (j = 0; j < npols; j++)
        {
            rints[j] *= scale;
        }

        double d = Math.Pow(rints[0] - Math.Sqrt(area), 2);

        for (j = 1; j < npols; j++)
        {
            d += rints[j] * rints[j];
        }

        d = Math.Sqrt(d) / npols;

        Console.WriteLine("");
        Console.WriteLine("  RMS integration error = " + d + "");
    }
Beispiel #3
0
    public static void test04(int degree, int numnodes, double[] vert1, double[] vert2,
                              double[] vert3, string header)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST04 gets a rule and writes it to a file.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU GPL license.
    //
    //  Modified:
    //
    //    30 June 2014
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Hong Xiao, Zydrunas Gimbutas,
    //    A numerical algorithm for the construction of efficient quadrature
    //    rules in two and higher dimensions,
    //    Computers and Mathematics with Applications,
    //    Volume 59, 2010, pages 663-676.
    //
    //  Parameters:
    //
    //    Input, int DEGREE, the desired total polynomial degree exactness
    //    of the quadrature rule.  0 <= DEGREE <= 50.
    //
    //    Input, int NUMNODES, the number of nodes to be used by the rule.
    //
    //    Input, double VERT1[2], VERT2[2], VERT3[2], the
    //    vertices of the triangle.
    //
    //    Input, string HEADER, an identifier for the filenames.
    //
    {
        int           j;
        List <string> rule_unit = new();

        Console.WriteLine("");
        Console.WriteLine("TEST04");
        Console.WriteLine("  Get a quadrature rule for a triangle.");
        Console.WriteLine("  Then write it to a file.");
        Console.WriteLine("  Polynomial exactness degree DEGREE = " + degree + "");
        //
        //  Retrieve a symmetric quadrature rule.
        //
        double[] rnodes  = new double[2 * numnodes];
        double[] weights = new double[numnodes];

        SymmetricQuadrature.triasymq(degree, vert1, vert2, vert3, ref rnodes, ref weights, numnodes);
        //
        //  Write the points and weights to a file.
        //
        string rule_filename = header + ".txt";

        for (j = 0; j < numnodes; j++)
        {
            rule_unit.Add(rnodes[0 + j * 2] + "  "
                          + rnodes[1 + j * 2] + "  "
                          + weights[j] + "");
        }

        File.WriteAllLines(rule_filename, rule_unit);

        Console.WriteLine("");
        Console.WriteLine("  Quadrature rule written to file '" + rule_filename + "'");
    }
Beispiel #4
0
    public static void test02(int degree, int numnodes, double[] vert1, double[] vert2,
                              double[] vert3)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 calls TRIASYMQ for a quadrature rule of given order and region.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU GPL license.
    //
    //  Modified:
    //
    //    28 June 2014
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Hong Xiao, Zydrunas Gimbutas,
    //    A numerical algorithm for the construction of efficient quadrature
    //    rules in two and higher dimensions,
    //    Computers and Mathematics with Applications,
    //    Volume 59, 2010, pages 663-676.
    //
    //  Parameters:
    //
    //    Input, int DEGREE, the desired total polynomial degree exactness
    //    of the quadrature rule.  0 <= DEGREE <= 50.
    //
    //    Input, int NUMNODES, the number of nodes to be used by the rule.
    //
    //    Input, double VERT1[2], VERT2[2], VERT3[2], the
    //    vertices of the triangle.
    //
    {
        int j;

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  Symmetric quadrature rule for a triangle.");
        Console.WriteLine("  Polynomial exactness degree DEGREE = " + degree + "");

        double area = typeMethods.triangle_area(vert1, vert2, vert3);

        //
        //  Retrieve and print a symmetric quadrature rule.
        //
        double[] rnodes  = new double[2 * numnodes];
        double[] weights = new double[numnodes];

        SymmetricQuadrature.triasymq(degree, vert1, vert2, vert3, ref rnodes, ref weights, numnodes);

        Console.WriteLine("");
        Console.WriteLine("  NUMNODES = " + numnodes + "");

        Console.WriteLine("");
        Console.WriteLine("     J      W               X               Y");
        Console.WriteLine("");
        for (j = 0; j < numnodes; j++)
        {
            Console.WriteLine(j + "  "
                              + weights[j] + "  "
                              + rnodes[0 + j * 2] + "  "
                              + rnodes[1 + j * 2] + "");
        }

        double d = typeMethods.r8vec_sum(numnodes, weights);

        Console.WriteLine("   Sum  " + d + "");
        Console.WriteLine("  Area  " + area + "");
    }