Esempio n. 1
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests R8TRIS2.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]     element_neighbor = new int[3 * 2 * 9];
        int       element_num      = 0;
        const int node_num         = 9;

        double[] node_xy =
        {
            0.0, 0.0,
            0.0, 1.0,
            0.2, 0.5,
            0.3, 0.6,
            0.4, 0.5,
            0.6, 0.4,
            0.6, 0.5,
            1.0, 0.0,
            1.0, 1.0
        };
        int[] triangle = new int[3 * 2 * 9];

        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  R8TRIS2 computes the Delaunay triangulation of");
        Console.WriteLine("  a set of nodes in 2D.");
        //
        //  Set up the Delaunay triangulation.
        //
        Delauney.r8tris2(node_num, ref node_xy, ref element_num, ref triangle, ref element_neighbor);

        Print.triangulation_order3_print(node_num, element_num, node_xy,
                                         triangle, element_neighbor);
    }
Esempio n. 2
0
    private static void test03(int prob)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests PWL_INTERP_2D_SCATTERED_VALUE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       element_num = 0;
        int       i;
        int       j;
        const int ni = 25;

        double[] xi  = new double[25];
        double[] xyi = new double[2 * 25];
        double[] yi  = new double[25];

        const int g  = 2;
        int       nd = Data_2D.g00_size(g);

        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  PWL_INTERP_2D_SCATTERED_VALUE evaluates a");
        Console.WriteLine("  piecewise linear interpolant to scattered data.");
        Console.WriteLine("  Here, we use grid number " + g + "");
        Console.WriteLine("  with " + nd + " scattered points in the unit square");
        Console.WriteLine("  on problem " + prob + "");
        //
        //  Get the data points and evaluate the function there.
        //
        double[] xd = new double[nd];
        double[] yd = new double[nd];

        Data_2D.g00_xy(g, nd, ref xd, ref yd);

        double[] zd = new double[nd];
        Data_2D.f00_f0(prob, nd, xd, yd, ref zd);

        double[] xyd = new double[2 * nd];

        for (i = 0; i < nd; i++)
        {
            xyd[0 + i * 2] = xd[i];
            xyd[1 + i * 2] = yd[i];
        }

        //
        //  Set up the Delaunay triangulation.
        //
        int[] element_neighbor = new int[3 * 2 * nd];
        int[] triangle         = new int[3 * 2 * nd];

        Delauney.r8tris2(nd, ref xyd, ref element_num, ref triangle, ref element_neighbor);

        for (j = 0; j < element_num; j++)
        {
            for (i = 0; i < 3; i++)
            {
                switch (element_neighbor[i + j * 3])
                {
                case > 0:
                    element_neighbor[i + j * 3] -= 1;
                    break;
                }
            }
        }

        //
        //  Define the interpolation points.
        //
        int k = 0;

        for (i = 1; i <= 5; i++)
        {
            for (j = 1; j <= 5; j++)
            {
                xyi[0 + k * 2] = (2 * i - 1) / 10.0;
                xyi[1 + k * 2] = (2 * j - 1) / 10.0;
                k += 1;
            }
        }

        for (k = 0; k < ni; k++)
        {
            xi[k] = xyi[0 + k * 2];
            yi[k] = xyi[1 + k * 2];
        }

        double[] ze = new double[ni];
        Data_2D.f00_f0(prob, ni, xi, yi, ref ze);
        //
        //  Evaluate the interpolant.
        //
        double[] zi = Interp2D.pwl_interp_2d_scattered_value(nd, xyd, zd, element_num,
                                                             triangle, element_neighbor, ni, xyi);

        double rms = 0.0;

        for (k = 0; k < ni; k++)
        {
            rms += Math.Pow(zi[k] - ze[k], 2);
        }

        rms = Math.Sqrt(rms / ni);

        Console.WriteLine("");
        Console.WriteLine("  RMS error is " + rms + "");

        Console.WriteLine("");
        Console.WriteLine("     K      Xi(K)       Yi(K)       Zi(K)       Z(X,Y)");
        Console.WriteLine("");

        for (k = 0; k < ni; k++)
        {
            Console.WriteLine("  " + k.ToString().PadLeft(4)
                              + "  " + xyi[0 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + xyi[1 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + zi[k].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + ze[k].ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }
Esempio n. 3
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests PWL_INTERP_2D_SCATTERED_VALUE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    25 October 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int[]     element_neighbor = new int[3 * 2 * 9];
        int       element_num      = 0;
        int       i;
        int       j;
        const int ni       = 25;
        const int node_num = 9;

        double[] node_xy =
        {
            0.0, 0.0,
            0.0, 1.0,
            0.2, 0.5,
            0.3, 0.6,
            0.4, 0.5,
            0.6, 0.4,
            0.6, 0.5,
            1.0, 0.0,
            1.0, 1.0
        };
        int[]    triangle = new int[3 * 2 * 9];
        double[] xyi      = new double[2 * 25];
        double[] zd       = new double[9];

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  PWL_INTERP_2D_SCATTERED_VALUE evaluates a");
        Console.WriteLine("  piecewise linear interpolant to scattered data.");
        //
        //  Set up the Delaunay triangulation.
        //
        Delauney.r8tris2(node_num, ref node_xy, ref element_num, ref triangle, ref element_neighbor);

        for (j = 0; j < element_num; j++)
        {
            for (i = 0; i < 3; i++)
            {
                switch (element_neighbor[i + j * 3])
                {
                case > 0:
                    element_neighbor[i + j * 3] -= 1;
                    break;
                }
            }
        }

        Print.triangulation_order3_print(node_num, element_num, node_xy,
                                         triangle, element_neighbor);
        //
        //  Define the Z data.
        //
        for (i = 0; i < node_num; i++)
        {
            double x = node_xy[0 + i * 2];
            double y = node_xy[1 + i * 2];
            zd[i] = x + 2.0 * y;
        }

        //
        //  Define the interpolation points.
        //
        int k = 0;

        for (i = 0; i <= 4; i++)
        {
            for (j = 0; j <= 4; j++)
            {
                xyi[0 + k * 2] = (i - 1) / 4.0;
                xyi[1 + k * 2] = (j - 1) / 4.0;
                k += 1;
            }
        }

        //
        //  Evaluate the interpolant.
        //
        double[] zi = Interp2D.pwl_interp_2d_scattered_value(node_num, node_xy, zd, element_num,
                                                             triangle, element_neighbor, ni, xyi);

        Console.WriteLine("");
        Console.WriteLine("     K      Xi(K)       Yi(K)       Zi(K)       Z(X,Y)");
        Console.WriteLine("");
        for (k = 0; k < ni; k++)
        {
            double ze = xyi[0 + k * 2] + 2.0 * xyi[1 + k * 2];
            Console.WriteLine("  " + k.ToString().PadLeft(4)
                              + "  " + xyi[0 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + xyi[1 + k * 2].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + zi[k].ToString(CultureInfo.InvariantCulture).PadLeft(10)
                              + "  " + ze.ToString(CultureInfo.InvariantCulture).PadLeft(10) + "");
        }
    }