Beispiel #1
0
    private static void test007()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST007 tests TET_MESH_SEARCH_NAIVE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int face     = 0;
        int node_num = 0;

        double[]  p        = new double[3];
        int       step_num = 0;
        int       test;
        const int test_num  = 5;
        int       tet_num   = 0;
        const int tet_order = 4;

        double[] tet_xyz = new double[3 * 4];

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("TEST007");
        Console.WriteLine("  TET_MESH_SEARCH_NAIVE uses a naive algorithm");
        Console.WriteLine("  to search a tetrahedral mesh for the tetrahedron");
        Console.WriteLine("  containing a point.");
        //
        //  Set up the example tetrahedron mesh.
        //
        TetMesh.tet_mesh_order4_example_size(ref node_num, ref tet_num);

        Console.WriteLine("");
        Console.WriteLine("  This mesh has tetrahedron order " + tet_order + "");
        Console.WriteLine("  The number of tetrahedrons is   " + tet_num + "");

        double[] node_xyz = new double[3 * node_num];
        int[]    tet_node = new int[tet_order * tet_num];

        TetMesh.tet_mesh_order4_example_set(node_num, tet_num, ref node_xyz, ref tet_node);
        //
        //  The TET_NEIGHBOR array is needed for the Delaunay search.
        //
        int[] tet_neighbor = TetMesh.tet_mesh_neighbor_tets(tet_order, tet_num, tet_node);

        for (test = 1; test <= test_num; test++)
        {
            //
            //  Choose a tetrahedron at random.
            //
            int tet1 = UniformRNG.i4_uniform_ab(0, tet_num - 1, ref seed);

            Console.WriteLine("");
            Console.WriteLine("  Point was chosen from tetrahedron    " + tet1.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");

            int j;
            for (j = 0; j < 4; j++)
            {
                int k = tet_node[j + tet1 * 4];
                int i;
                for (i = 0; i < 3; i++)
                {
                    tet_xyz[i + j * 3] = node_xyz[i + k * 3];
                }
            }

            //
            //  Choose a point in the tetrahedron at random.
            //
            Tetrahedron.tetrahedron_sample(tet_xyz, 1, ref seed, ref p);
            //
            //  Naive search.
            //
            int tet2 = TetMesh.tet_mesh_search_naive(node_num, node_xyz, tet_order, tet_num,
                                                     tet_node, p, ref step_num);

            Console.WriteLine("  Naive search ended in tetrahedron    " + tet2.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + ", number of steps = " + step_num + "");
            //
            //  Delaunay search.
            //
            int tet3 = TetMesh.tet_mesh_search_delaunay(node_num, node_xyz, tet_order,
                                                        tet_num, tet_node, tet_neighbor, p, ref face, ref step_num);

            Console.WriteLine("  Delaunay search ended in tetrahedron " + tet3.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + ", number of steps = " + step_num + "");
        }
    }
    public static double[] projection(int fem_node_num, double[] fem_node_xyz,
                                      int fem_element_order, int fem_element_num, int[] fem_element_node,
                                      int[] fem_element_neighbor, int fem_value_dim, double[] fem_value,
                                      int sample_node_num, double[] sample_node_xyz)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PROJECTION evaluates an FEM function on a T3 or T6 triangulation.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    27 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int FEM_NODE_NUM, the number of nodes.
    //
    //    Input, double FEM_NODE_XYZ[3*FEM_NODE_NUM], the coordinates
    //    of the nodes.
    //
    //    Input, int FEM_ELEMENT_ORDER, the order of the elements.
    //
    //    Input, int FEM_ELEMENT_NUM, the number of elements.
    //
    //    Input, int FEM_ELEMENT_NODE(FEM_ELEMENT_ORDER,FEM_ELEMENT_NUM), the
    //    nodes that make up each element.
    //
    //    Input, int FEM_ELEMENT_NEIGHBOR[4*FEM_ELEMENT_NUM], the
    //    index of the neighboring element on each side, or -1 if no neighbor there.
    //
    //    Input, int FEM_VALUE_DIM, the "dimension" of the values.
    //
    //    Input, double FEM_VALUE[FEM_VALUE_DIM*FEM_NODE_NUM], the
    //    finite element coefficient values at each node.
    //
    //    Input, int SAMPLE_NODE_NUM, the number of sample nodes.
    //
    //    Input, double SAMPLE_NODE_XYZ[3*SAMPLE_NODE_NUM], the sample nodes.
    //
    //    Output, double PROJECTION[FEM_VALUE_DIM*SAMPLE_NODE_NUM],
    //    the sampled values.
    //
    {
        int face = 0;
        int j;

        double[] p_xyz    = new double[3];
        int      step_num = 0;

        double[] b            = new double[fem_element_order];
        double[] sample_value = new double[fem_value_dim * sample_node_num];
        double[] t_xyz        = new double[3 * fem_element_order];
        //
        //  For each sample point: find the element T that contains it,
        //  and evaluate the finite element function there.
        //
        for (j = 0; j < sample_node_num; j++)
        {
            p_xyz[0] = sample_node_xyz[0 + 3 * j];
            p_xyz[1] = sample_node_xyz[1 + 3 * j];
            p_xyz[2] = sample_node_xyz[2 + 3 * j];
            //
            //  Find the triangle T that contains the point.
            //
            int t = TetMesh.tet_mesh_search_delaunay(fem_node_num, fem_node_xyz,
                                                     fem_element_order, fem_element_num, fem_element_node,
                                                     fem_element_neighbor, p_xyz, ref face, ref step_num);

            switch (t)
            {
            case -1:
                Console.WriteLine("");
                Console.WriteLine("PROJECTION - Fatal error!");
                Console.WriteLine("  Search failed.");
                return(null);
            }

            //
            //  Evaluate the finite element basis functions at the point in T.
            //
            int t_node;
            int i;
            for (i = 0; i < fem_element_order; i++)
            {
                t_node           = fem_element_node[i + t * fem_element_order];
                t_xyz[0 + i * 3] = fem_node_xyz[0 + t_node * 3];
                t_xyz[1 + i * 3] = fem_node_xyz[1 + t_node * 3];
                t_xyz[2 + i * 3] = fem_node_xyz[2 + t_node * 3];
            }

            Basis_mn.basis_mn_tet4(t_xyz, 1, p_xyz, ref b);
            //
            //  Multiply by the finite element values to get the sample values.
            //
            for (i = 0; i < fem_value_dim; i++)
            {
                double dot = 0.0;
                int    k;
                for (k = 0; k < fem_element_order; k++)
                {
                    t_node = fem_element_node[k + t * fem_element_order];
                    dot   += fem_value[i + t_node * fem_value_dim] * b[k];
                }

                sample_value[i + j * fem_value_dim] = dot;
            }
        }

        return(sample_value);
    }